disk-info-helper
selenium-helper (Not fully tested) sync-helper (Not fully tested)
This commit is contained in:
51
Helpers/SyncHelper.cs
Normal file
51
Helpers/SyncHelper.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using File_Watcher.Models;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace File_Watcher.Helpers;
|
||||
|
||||
internal static partial class SyncHelper
|
||||
{
|
||||
|
||||
private record Record(string RelativePath,
|
||||
long Size,
|
||||
long Ticks);
|
||||
|
||||
private record RelativePath(string Path,
|
||||
Record[] Records);
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(RelativePath))]
|
||||
private partial class RelativePathSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Dictionary<string, object>))]
|
||||
private partial class DictionaryStringObjectBSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
internal static bool Check(AppSettings _, ILogger<Worker> __) =>
|
||||
true;
|
||||
|
||||
internal static string GetReply(string body, Dictionary<string, object> keyValuePairs)
|
||||
{
|
||||
string? json;
|
||||
RelativePath? relativePath;
|
||||
if (!string.IsNullOrEmpty(body) && body[0] == '{')
|
||||
{
|
||||
File.WriteAllText(".json", body);
|
||||
relativePath = JsonSerializer.Deserialize(body, RelativePathSourceGenerationContext.Default.RelativePath) ?? throw new NullReferenceException();
|
||||
}
|
||||
else
|
||||
{
|
||||
json = JsonSerializer.Serialize(keyValuePairs, DictionaryStringObjectBSourceGenerationContext.Default.DictionaryStringObject);
|
||||
File.WriteAllText(".json", json);
|
||||
relativePath = JsonSerializer.Deserialize(json, RelativePathSourceGenerationContext.Default.RelativePath) ?? throw new NullReferenceException();
|
||||
}
|
||||
if (relativePath is null)
|
||||
{ }
|
||||
return $"wait-{relativePath?.Records.Length}";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user