Refactor application structure and add unit tests
Added: - New `ProgressService` class for managing progress indicators. - New `AssetDatabase`, `AssetOpenHandlerAttribute`, and `AsyncAssetOpenHandlerAttribute` classes for asset handling. - `Ghost.UnitTest` project for unit testing with associated files and configurations. Changed: - `ActivationHandler` class to ensure correct handling of `LaunchActivatedEventArgs`. - `App.xaml.cs` to register `INotificationService` and `IProgressService`, replacing `StackedNotificationService`. - `OnLaunched` method in `App.xaml.cs` to correctly call `ActivationHandler.Handle(args)` and start the host. - `INavigationAware` interface from internal to public for broader access. - `EditorState.cs` to activate `EditorApplication` with the current service provider. - Property names in `AssetItem` and `ExplorerItem` structs to `Name` and `FullName`. - `NotificationService` class to implement `INotificationService` and refactor notification handling. - `AssetPathToGlyphConverter` to handle file extensions consistently. - Bindings in `ProjectPage.xaml` and `ProjectPage.xaml.cs` to use `FullName` instead of `Path`. - `EngineEditorWindow` and `LandingWindow` classes to utilize new notification and progress services. - `Logger` class to include a new method for logging errors with exceptions. Updated: - Manifest files and project files to reflect new structure and dependencies. - Solution file `GhostEngine.sln` to include the new unit test project. - Added several new test classes and methods in `UnitTests.cs`.
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Ghost.Engine.Models;
|
||||
namespace Ghost.Engine.Models;
|
||||
|
||||
public enum LogLevel
|
||||
{
|
||||
@@ -21,7 +19,7 @@ internal class LogMessage
|
||||
get; set;
|
||||
}
|
||||
|
||||
public StackTrace? StackTrace
|
||||
public string? StackTrace
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
@@ -31,7 +29,7 @@ internal class LogMessage
|
||||
get; set;
|
||||
}
|
||||
|
||||
public LogMessage(LogLevel level, string message, StackTrace? stackTrace = null)
|
||||
public LogMessage(LogLevel level, string message, string? stackTrace = null)
|
||||
{
|
||||
Level = level;
|
||||
Message = message;
|
||||
|
||||
13
Ghost.Engine/Resources/StaticResource.cs
Normal file
13
Ghost.Engine/Resources/StaticResource.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Ghost.Engine.Resources;
|
||||
|
||||
public static class StaticResource
|
||||
{
|
||||
public static JsonSerializerOptions defaultSerializerOptions = new()
|
||||
{
|
||||
WriteIndented = true,
|
||||
IncludeFields = true,
|
||||
IgnoreReadOnlyProperties = true,
|
||||
};
|
||||
}
|
||||
@@ -16,7 +16,7 @@ public static class Logger
|
||||
private const int _MAX_LOGS = 4096;
|
||||
|
||||
private static readonly List<LogMessage> _logs = new();
|
||||
internal static List<LogMessage> Logs => _logs;
|
||||
internal static IReadOnlyList<LogMessage> Logs => _logs;
|
||||
|
||||
internal static event Action<LogChangeType>? OnLogsUpdate;
|
||||
|
||||
@@ -39,7 +39,21 @@ public static class Logger
|
||||
stackTrace = new StackTrace(skipFrame, true);
|
||||
}
|
||||
|
||||
var logMessage = new LogMessage(level, message, stackTrace);
|
||||
var logMessage = new LogMessage(level, message, stackTrace?.ToString());
|
||||
_logs.Add(logMessage);
|
||||
|
||||
OnLogsUpdate?.Invoke(LogChangeType.LogAdded);
|
||||
}
|
||||
|
||||
private static void LogExceptionInternal(Exception ex)
|
||||
{
|
||||
if (_logs.Count >= _MAX_LOGS)
|
||||
{
|
||||
_logs.RemoveAt(0);
|
||||
OnLogsUpdate?.Invoke(LogChangeType.LogRemoved);
|
||||
}
|
||||
|
||||
var logMessage = new LogMessage(LogLevel.Error, ex.Message, ex.StackTrace);
|
||||
_logs.Add(logMessage);
|
||||
|
||||
OnLogsUpdate?.Invoke(LogChangeType.LogAdded);
|
||||
@@ -65,6 +79,11 @@ public static class Logger
|
||||
LogInternal(LogLevel.Error, message, 3);
|
||||
}
|
||||
|
||||
public static void LogError(Exception ex)
|
||||
{
|
||||
LogExceptionInternal(ex);
|
||||
}
|
||||
|
||||
internal static void Clear()
|
||||
{
|
||||
_logs.Clear();
|
||||
|
||||
Reference in New Issue
Block a user