file-watcher/Helpers/SyncHelper.cs
Mike Phares e6df9ae54e disk-info-helper
selenium-helper (Not fully tested)

sync-helper (Not fully tested)
2025-05-19 09:59:09 -07:00

51 lines
1.8 KiB
C#

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}";
}
}