disk-info-helper

selenium-helper (Not fully tested)

sync-helper (Not fully tested)
This commit is contained in:
2025-06-23 11:16:17 -07:00
parent e50a90f0fc
commit 97797fc440
15 changed files with 807 additions and 23 deletions

51
Helpers/SyncHelper.cs Normal file
View 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}";
}
}