mirror of
https://github.com/GalaxyViewer/GalaxyViewer.git
synced 2026-08-14 00:57:53 +00:00
🚧 Data now saves to the session db table successfully
This commit is contained in:
@@ -6,7 +6,7 @@ namespace GalaxyViewer.Services;
|
||||
public interface ILiteDbService
|
||||
{
|
||||
LiteDatabase Database { get; }
|
||||
ILiteCollection<T> GetCollection<T>(string name);
|
||||
SessionModel GetSession();
|
||||
void SaveSession(SessionModel session);
|
||||
ILiteCollection<SessionModel> GetCollection<SessionModel>(string name);
|
||||
}
|
||||
@@ -95,15 +95,6 @@ namespace GalaxyViewer.Services
|
||||
|
||||
private void ClearSessionData()
|
||||
{
|
||||
// Commented out the code that clears the session data
|
||||
// ILiteCollection<SessionModel>? sessionCollection;
|
||||
// if (_database.CollectionExists("session"))
|
||||
// {
|
||||
// sessionCollection = _database.GetCollection<SessionModel>("session");
|
||||
// sessionCollection.DeleteAll();
|
||||
// Log.Information("Session data cleared on startup");
|
||||
// }
|
||||
|
||||
var sessionCollection = _database.GetCollection<SessionModel>("session");
|
||||
if (sessionCollection.Count() == 0)
|
||||
{
|
||||
@@ -119,12 +110,12 @@ namespace GalaxyViewer.Services
|
||||
|
||||
public SessionModel GetSession()
|
||||
{
|
||||
return _database.GetCollection<SessionModel>("sessions").FindOne(Query.All()) ?? new SessionModel();
|
||||
return _database.GetCollection<SessionModel>("session").FindOne(Query.All()) ?? new SessionModel();
|
||||
}
|
||||
|
||||
public void SaveSession(SessionModel session)
|
||||
{
|
||||
_database.GetCollection<SessionModel>("sessions").Upsert(session);
|
||||
_database.GetCollection<SessionModel>("session").Upsert(session);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using GalaxyViewer.Models;
|
||||
using GalaxyViewer.Services;
|
||||
using Serilog;
|
||||
using LiteDB;
|
||||
using System;
|
||||
|
||||
namespace GalaxyViewer
|
||||
namespace GalaxyViewer.Services
|
||||
{
|
||||
public class SessionManager
|
||||
{
|
||||
@@ -23,19 +23,15 @@ namespace GalaxyViewer
|
||||
get => _session;
|
||||
set
|
||||
{
|
||||
if (_session != value)
|
||||
{
|
||||
_session = value;
|
||||
_liteDbService.SaveSession(_session);
|
||||
OnSessionChanged();
|
||||
}
|
||||
_session = value;
|
||||
_liteDbService.SaveSession(_session);
|
||||
OnSessionChanged(_session);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnSessionChanged()
|
||||
protected virtual void OnSessionChanged(SessionModel session)
|
||||
{
|
||||
SessionChanged?.Invoke(this, _session);
|
||||
Log.Information("Session changed: {@Session}", _session);
|
||||
SessionChanged?.Invoke(this, session);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,11 @@ public class SessionManagerTests
|
||||
};
|
||||
|
||||
var mockSessionCollection = new Mock<ILiteCollection<SessionModel>>();
|
||||
mockLiteDbService.Setup(service => service.GetCollection<SessionModel>("sessions")).Returns(mockSessionCollection.Object);
|
||||
mockSessionCollection.Setup(collection => collection.FindOne(It.IsAny<Query>())).Returns(session);
|
||||
mockLiteDbService.Setup(service => service.GetCollection<SessionModel>("session"))
|
||||
.Returns(mockSessionCollection.Object);
|
||||
mockLiteDbService.Setup(service => service.GetSession()).Returns(session);
|
||||
mockLiteDbService.Setup(service => service.SaveSession(It.IsAny<SessionModel>()))
|
||||
.Callback<SessionModel>(s => mockSessionCollection.Object.Upsert(s));
|
||||
|
||||
var sessionManager = new SessionManager(mockLiteDbService.Object);
|
||||
|
||||
@@ -41,6 +44,7 @@ public class SessionManagerTests
|
||||
};
|
||||
|
||||
// Assert
|
||||
mockSessionCollection.Verify(collection => collection.Upsert(It.IsAny<SessionModel>()), Times.Once);
|
||||
mockSessionCollection.Verify(collection => collection.Upsert(It.IsAny<SessionModel>()),
|
||||
Times.Once);
|
||||
}
|
||||
}
|
||||
@@ -166,7 +166,9 @@ namespace GalaxyViewer.ViewModels
|
||||
|
||||
// Use a specific uriString for the testing phase
|
||||
var isTestingPhase = true; // Set this flag based on your testing condition
|
||||
loginParams.URI = isTestingPhase ? "https://login.agni.lindenlab.com/cgi-bin/login.cgi" : SelectedGrid.LoginUri;
|
||||
loginParams.URI = isTestingPhase
|
||||
? "https://login.agni.lindenlab.com/cgi-bin/login.cgi"
|
||||
: SelectedGrid.LoginUri;
|
||||
loginParams.MfaEnabled = true;
|
||||
loginParams.Platform = ourPlatform;
|
||||
loginParams.PlatformVersion = Environment.OSVersion.VersionString;
|
||||
|
||||
Reference in New Issue
Block a user