Moved to ADO2024 PI#
Ran SortCodeMethods
This commit is contained in:
91
ADO2024/PI1/Helper-2024-04-09.cs
Normal file
91
ADO2024/PI1/Helper-2024-04-09.cs
Normal file
@ -0,0 +1,91 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace File_Folder_Helper.ADO2024.PI1;
|
||||
|
||||
internal static partial class Helper20240409
|
||||
{
|
||||
|
||||
internal record FsSize( // cSpell:disable
|
||||
[property: JsonPropertyName("name")] string Name,
|
||||
[property: JsonPropertyName("object")] string Object,
|
||||
[property: JsonPropertyName("pmon")] string PMon,
|
||||
[property: JsonPropertyName("unit")] string Unit,
|
||||
[property: JsonPropertyName("timeresolution")] string TimeResolution,
|
||||
[property: JsonPropertyName("aggr")] string Aggr,
|
||||
[property: JsonPropertyName("data")] List<double[]> Data
|
||||
); // cSpell:restore
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true, AllowTrailingCommas = true)]
|
||||
[JsonSerializable(typeof(FsSize))]
|
||||
internal partial class FsSizeSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
internal static void MonA(ILogger<Worker> logger, List<string> args)
|
||||
{
|
||||
string url;
|
||||
FsSize? fsSize;
|
||||
string[] segments;
|
||||
Task<string> json;
|
||||
string jsonSection;
|
||||
string urlBase = args[3];
|
||||
string selector = args[6];
|
||||
string urlPartA = args[4];
|
||||
string urlPartC = args[5];
|
||||
string directory = args[0];
|
||||
string aggregation = args[8];
|
||||
int skip = int.Parse(args[7]);
|
||||
string searchPattern = args[2];
|
||||
string fileNameWithoutExtension;
|
||||
string[] ignore = args[9].Split(',');
|
||||
Task<HttpResponseMessage> httpResponseMessage;
|
||||
string[] files = Directory.GetFiles(directory, searchPattern, SearchOption.TopDirectoryOnly);
|
||||
HttpClient httpClient = new(new HttpClientHandler { UseCookies = false }) { BaseAddress = new Uri(urlBase) };
|
||||
logger.LogInformation("{directory} has {files}(s)", directory, files.Length);
|
||||
foreach (string file in files)
|
||||
{
|
||||
fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file);
|
||||
if (ignore.Contains(fileNameWithoutExtension))
|
||||
continue;
|
||||
url = $"{httpClient.BaseAddress}{urlPartA}{fileNameWithoutExtension}{urlPartC}";
|
||||
httpResponseMessage = httpClient.GetAsync(url);
|
||||
httpResponseMessage.Wait();
|
||||
if (!httpResponseMessage.Result.IsSuccessStatusCode)
|
||||
{
|
||||
logger.LogWarning("{StatusCode} for {url}", httpResponseMessage.Result.StatusCode, url);
|
||||
continue;
|
||||
}
|
||||
json = httpResponseMessage.Result.Content.ReadAsStringAsync();
|
||||
json.Wait();
|
||||
if (json.Result.Length < 3)
|
||||
{
|
||||
logger.LogInformation("{Size} | {Julian} | {PMon} | {FileNameWithoutExtension}", -1, -1, "{}", fileNameWithoutExtension);
|
||||
continue;
|
||||
}
|
||||
segments = json.Result.Split($"\"{fileNameWithoutExtension}{selector}");
|
||||
if (segments.Length < 2)
|
||||
{
|
||||
logger.LogInformation("{Size} | {Julian} | {PMon} | {FileNameWithoutExtension}", -1, -1, selector, fileNameWithoutExtension);
|
||||
continue;
|
||||
}
|
||||
for (int i = 1; i < segments.Length; i++)
|
||||
{
|
||||
jsonSection = segments[i][skip..][..^1];
|
||||
fsSize = JsonSerializer.Deserialize(jsonSection, FsSizeSourceGenerationContext.Default.FsSize);
|
||||
if (fsSize is null)
|
||||
continue;
|
||||
if (fsSize.Aggr != aggregation)
|
||||
continue;
|
||||
if (fsSize.Data.Count == 0 || fsSize.Data[0].Length == 0)
|
||||
{
|
||||
logger.LogInformation("{Size} | {Julian} | {PMon} | {FileNameWithoutExtension}", -1, -1, nameof(FsSize.Data), fileNameWithoutExtension);
|
||||
continue;
|
||||
}
|
||||
logger.LogInformation("{Size} | {Julian} | {PMon} | {FileNameWithoutExtension}", fsSize.Data[0][1].ToString().PadLeft(20, '0'), fsSize.Data[0][0], fsSize.PMon, fileNameWithoutExtension);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user