diff --git a/CrystalData.sln b/CrystalData.sln index b6110bd..79f6788 100644 --- a/CrystalData.sln +++ b/CrystalData.sln @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.8.34219.65 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sandbox", "Sandbox\Sandbox.csproj", "{2B574101-BAE8-4BB9-A8DA-22760EA4BD90}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0EAF5544-B4BB-4198-81AB-56835FC8DDED}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig @@ -16,7 +14,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Advanced", "Advanced\Advanc EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "xUnitTest", "xUnitTest\xUnitTest.csproj", "{460E04B0-4CA5-4672-8BCB-D3D03D07B2D8}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickStart", "QuickStart\QuickStart.csproj", "{B89EE766-400C-4688-BEFA-F242661C8C8A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QuickStart", "QuickStart\QuickStart.csproj", "{B89EE766-400C-4688-BEFA-F242661C8C8A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Playground", "Playground\Playground.csproj", "{F560C481-8D65-4D71-8A68-7F32AC3AAAE0}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -24,10 +24,6 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {2B574101-BAE8-4BB9-A8DA-22760EA4BD90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2B574101-BAE8-4BB9-A8DA-22760EA4BD90}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2B574101-BAE8-4BB9-A8DA-22760EA4BD90}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2B574101-BAE8-4BB9-A8DA-22760EA4BD90}.Release|Any CPU.Build.0 = Release|Any CPU {3D362860-ACA2-4192-976D-11DC5DA9AD69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3D362860-ACA2-4192-976D-11DC5DA9AD69}.Debug|Any CPU.Build.0 = Debug|Any CPU {3D362860-ACA2-4192-976D-11DC5DA9AD69}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -44,6 +40,10 @@ Global {B89EE766-400C-4688-BEFA-F242661C8C8A}.Debug|Any CPU.Build.0 = Debug|Any CPU {B89EE766-400C-4688-BEFA-F242661C8C8A}.Release|Any CPU.ActiveCfg = Release|Any CPU {B89EE766-400C-4688-BEFA-F242661C8C8A}.Release|Any CPU.Build.0 = Release|Any CPU + {F560C481-8D65-4D71-8A68-7F32AC3AAAE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F560C481-8D65-4D71-8A68-7F32AC3AAAE0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F560C481-8D65-4D71-8A68-7F32AC3AAAE0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F560C481-8D65-4D71-8A68-7F32AC3AAAE0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CrystalData/Filer/CrystalFiler.cs b/CrystalData/Filer/CrystalFiler.cs index 4f4d4be..a7cd092 100644 --- a/CrystalData/Filer/CrystalFiler.cs +++ b/CrystalData/Filer/CrystalFiler.cs @@ -1,8 +1,5 @@ // Copyright (c) All contributors. All rights reserved. Licensed under the MIT license. -using static System.Runtime.InteropServices.JavaScript.JSType; -using static FastExpressionCompiler.ExpressionCompiler; - namespace CrystalData.Filer; public class CrystalFiler @@ -180,9 +177,8 @@ public Task LimitNumberOfFiles() } string path; - // if (!this.crystalFiler.IsProtected) - { + {// No file history path = this.GetFilePath(); var result = await this.rawFiler.ReadAsync(path, 0, -1).ConfigureAwait(false); if (result.IsSuccess) @@ -191,7 +187,7 @@ public Task LimitNumberOfFiles() var r = SerializeHelper.TryDeserialize(result.Data.Span, formatHint, true); result.Return(); if (r.Data is not null) - { + {// Success return (new(CrystalResult.Success, r.Data), new(Waypoint.InvalidJournalPosition, 0, hash), path); } @@ -209,7 +205,7 @@ public Task LimitNumberOfFiles() path = this.GetFilePath(x); var result = await this.rawFiler.ReadAsync(path, 0, -1).ConfigureAwait(false); if (result.IsSuccess) - {// Success + {// Read successful if (FarmHash.Hash64(result.Data.Memory.Span) == x.Hash) { var r = SerializeHelper.TryDeserialize(result.Data.Span, formatHint, true); @@ -220,6 +216,7 @@ public Task LimitNumberOfFiles() } } + // Checksum mismatch or deserialization error. _ = this.rawFiler.DeleteAsync(path); this.TryDeleteWaypoint(x); } @@ -413,14 +410,14 @@ public async Task LimitNumberOfFiles() public async Task<(CrystalObjectResult Result, Waypoint Waypoint, string Path)> LoadLatest(PrepareParam param, SaveFormat formatHint) where TData : class, ITinyhandSerialize, ITinyhandReconstruct - {// + { if (this.main is null) { return (new(CrystalResult.NotPrepared), Waypoint.Invalid, string.Empty); } if (!this.IsProtected) - {// Not protected + {// Not protected (no file history) var result = await this.main.LoadLatest(param, formatHint).ConfigureAwait(false); if (result.Result.IsFailure && this.backup is not null) {// Load backup diff --git a/Directory.Build.props b/Directory.Build.props index d9304c7..53b393b 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@  - 0.16.1 + 0.17.0 latest enable enable diff --git a/Sandbox/Sandbox.csproj b/Playground/Playground.csproj similarity index 100% rename from Sandbox/Sandbox.csproj rename to Playground/Playground.csproj diff --git a/Sandbox/Program.cs b/Playground/Program.cs similarity index 95% rename from Sandbox/Program.cs rename to Playground/Program.cs index a8430f2..7f22abc 100644 --- a/Sandbox/Program.cs +++ b/Playground/Program.cs @@ -40,6 +40,7 @@ public static async Task Main(string[] args) context.AddCrystal( new CrystalConfiguration() { + RequiredForLoading = true, SavePolicy = SavePolicy.Manual, // The timing of saving data is controlled by the application. SaveFormat = SaveFormat.Utf8, // The format is utf8 text. NumberOfFileHistories = 0, // No history file. @@ -58,7 +59,7 @@ public static async Task Main(string[] args) var unit = builder.Build(); // Build. TinyhandSerializer.ServiceProvider = unit.Context.ServiceProvider; var crystalizer = unit.Context.ServiceProvider.GetRequiredService(); // Obtains a Crystalizer instance for data storage operations. - await crystalizer.PrepareAndLoadAll(false); // Prepare resources for storage operations and read data from files. + await crystalizer.PrepareAndLoadAll(true); // Prepare resources for storage operations and read data from files. var data = unit.Context.ServiceProvider.GetRequiredService(); // Retrieve a data instance from the service provider.