Refactor activation handling and introduce entity system
Added new `ActivationHandler` class for folder initialization. Added `ProjectService` class for project-related operations. Added `Ghost.Entities` project with entity management classes. Added `EngineEditorWindow` for enhanced user interface. Changed project files to restructure dependencies and remove unused references. Changed `ProjectRepository` to use asynchronous methods for improved performance. Changed data binding in `CreateProjectPage.xaml` and `OpenProjectPage.xaml` to use new data models. Changed `App.xaml.cs` to utilize the new `ActivationHandler` and include additional services. Removed `IActivationHandler` interface and integrated its functionality into `ActivationHandler`. Removed `EditorActivationHandler` as its functionality was merged into `ActivationHandler`. Updated `AssemblyInfo.cs` to include global using directives for entity types. Updated image assets to reflect visual resource changes.
This commit is contained in:
64
Ghost.Data/DataContext/ProjectRepository.cs
Normal file
64
Ghost.Data/DataContext/ProjectRepository.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using Ghost.Data.Models;
|
||||
using Ghost.Data.Resources;
|
||||
using System.Data.SQLite;
|
||||
|
||||
namespace Ghost.Data.DataContext;
|
||||
|
||||
internal static class ProjectRepository
|
||||
{
|
||||
private const string _CONNECTION_STRING = "Data Source={0}\\projects.db;Version=3;";
|
||||
private const string _CREATE_PROJECT_TABLE_STRING = "CREATE TABLE IF NOT EXISTS Projects (ID INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT, Path TEXT, EngineVersion TEXT, LastOpened DATETIME);";
|
||||
private const string _SELECT_PROJECT_STRING = "SELECT * FROM Projects";
|
||||
private const string _INSERT_PROJECT_STRING = "INSERT INTO Projects (Name, Path, EngineVersion, LastOpened) VALUES (@Name, @Path, @EngineVersion, @LastOpened);";
|
||||
|
||||
private static string GetConnectionString() => string.Format(_CONNECTION_STRING, DataPath.ApplicationDataFolder);
|
||||
|
||||
private static async Task EnsureTableCreatedAsync(SQLiteConnection connection)
|
||||
{
|
||||
using var createCommand = connection.CreateCommand();
|
||||
createCommand.CommandText = _CREATE_PROJECT_TABLE_STRING;
|
||||
await createCommand.ExecuteNonQueryAsync();
|
||||
}
|
||||
|
||||
public static async IAsyncEnumerable<ProjectInfo> LoadProjectsAsync()
|
||||
{
|
||||
using var connection = new SQLiteConnection(GetConnectionString());
|
||||
await connection.OpenAsync();
|
||||
|
||||
await EnsureTableCreatedAsync(connection);
|
||||
|
||||
using var command = connection.CreateCommand();
|
||||
command.CommandText = _SELECT_PROJECT_STRING;
|
||||
|
||||
using var reader = command.ExecuteReader();
|
||||
while (await reader.ReadAsync())
|
||||
{
|
||||
var project = new ProjectInfo
|
||||
{
|
||||
Name = reader.GetString(1),
|
||||
Path = reader.GetString(2),
|
||||
EngineVersion = new Version(reader.GetString(3)),
|
||||
LastOpened = reader.GetDateTime(4)
|
||||
};
|
||||
|
||||
yield return project;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task AddProjectAsync(ProjectInfo project)
|
||||
{
|
||||
using var connection = new SQLiteConnection(GetConnectionString());
|
||||
await connection.OpenAsync();
|
||||
|
||||
await EnsureTableCreatedAsync(connection);
|
||||
|
||||
using var command = connection.CreateCommand();
|
||||
command.CommandText = _INSERT_PROJECT_STRING;
|
||||
|
||||
command.Parameters.AddWithValue("@Name", project.Name);
|
||||
command.Parameters.AddWithValue("@Path", project.Path);
|
||||
command.Parameters.AddWithValue("@EngineVersion", project.EngineVersion.ToString());
|
||||
command.Parameters.AddWithValue("@LastOpened", project.LastOpened);
|
||||
await command.ExecuteNonQueryAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user