Skip to content

Commit

Permalink
Merge pull request #32 from archi-Doc/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
archi-Doc authored Jun 18, 2024
2 parents 1922cbc + d49c3ad commit 98f440a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
14 changes: 7 additions & 7 deletions CrystalData.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,18 +14,16 @@ 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
Debug|Any CPU = Debug|Any CPU
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
Expand All @@ -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
Expand Down
15 changes: 6 additions & 9 deletions CrystalData/Filer/CrystalFiler.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -180,9 +177,8 @@ public Task<CrystalResult> 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)
Expand All @@ -191,7 +187,7 @@ public Task<CrystalResult> LimitNumberOfFiles()
var r = SerializeHelper.TryDeserialize<TData>(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);
}

Expand All @@ -209,7 +205,7 @@ public Task<CrystalResult> 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<TData>(result.Data.Span, formatHint, true);
Expand All @@ -220,6 +216,7 @@ public Task<CrystalResult> LimitNumberOfFiles()
}
}

// Checksum mismatch or deserialization error.
_ = this.rawFiler.DeleteAsync(path);
this.TryDeleteWaypoint(x);
}
Expand Down Expand Up @@ -413,14 +410,14 @@ public async Task<CrystalResult> LimitNumberOfFiles()

public async Task<(CrystalObjectResult<TData> Result, Waypoint Waypoint, string Path)> LoadLatest<TData>(PrepareParam param, SaveFormat formatHint)
where TData : class, ITinyhandSerialize<TData>, ITinyhandReconstruct<TData>
{//
{
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<TData>(param, formatHint).ConfigureAwait(false);
if (result.Result.IsFailure && this.backup is not null)
{// Load backup
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Version>0.16.1</Version>
<Version>0.17.0</Version>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion Sandbox/Program.cs → Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static async Task Main(string[] args)
context.AddCrystal<FirstData>(
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.
Expand All @@ -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<Crystalizer>(); // 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<FirstData>(); // Retrieve a data instance from the service provider.

Expand Down

0 comments on commit 98f440a

Please sign in to comment.