Sort Day 2024 Q2
This commit is contained in:
parent
728f45f613
commit
cfbd2ba0b0
@ -13,6 +13,40 @@ internal static partial class Helper20240403
|
|||||||
string Pattern,
|
string Pattern,
|
||||||
string Primary);
|
string Primary);
|
||||||
|
|
||||||
|
private static void AlertIfNewDeviceIsConnected(DynamicHostConfigurationProtocolConfiguration dynamicHostConfigurationProtocolConfiguration, ILogger<Worker> logger)
|
||||||
|
{
|
||||||
|
string[] files = Directory.GetFiles(dynamicHostConfigurationProtocolConfiguration.Directory, dynamicHostConfigurationProtocolConfiguration.Pattern, SearchOption.TopDirectoryOnly);
|
||||||
|
string? match = GetMatch(dynamicHostConfigurationProtocolConfiguration, files);
|
||||||
|
if (string.IsNullOrEmpty(match))
|
||||||
|
throw new NotSupportedException($"{dynamicHostConfigurationProtocolConfiguration.Primary} doesn't exist!");
|
||||||
|
ReadOnlyDictionary<string, int> keyToCounts = GetKeyToCounts(dynamicHostConfigurationProtocolConfiguration, files);
|
||||||
|
foreach (KeyValuePair<string, int> keyToCount in keyToCounts)
|
||||||
|
{
|
||||||
|
if (keyToCount.Value < 2)
|
||||||
|
continue;
|
||||||
|
logger.LogInformation("{Key}: {Count}", keyToCount.Key, keyToCount.Value);
|
||||||
|
}
|
||||||
|
ReadOnlyDictionary<string, ReadOnlyDictionary<string, ReadOnlyCollection<string>>> keyValuePairs = GetKeyValuePairs(dynamicHostConfigurationProtocolConfiguration, files);
|
||||||
|
foreach (KeyValuePair<string, ReadOnlyDictionary<string, ReadOnlyCollection<string>>> keyValuePair in keyValuePairs)
|
||||||
|
{
|
||||||
|
if (!keyValuePair.Key.EndsWith(dynamicHostConfigurationProtocolConfiguration.Primary))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void AlertIfNewDeviceIsConnected(ILogger<Worker> logger, List<string> args)
|
||||||
|
{
|
||||||
|
string ignore = args[6];
|
||||||
|
string pattern = args[2];
|
||||||
|
string primary = args[3];
|
||||||
|
string keyIndex = args[5];
|
||||||
|
string directory = args[0];
|
||||||
|
logger.LogInformation(directory);
|
||||||
|
string[] columns = args[4].Split('|');
|
||||||
|
DynamicHostConfigurationProtocolConfiguration dynamicHostConfigurationProtocolConfiguration = new(columns, directory, ignore, int.Parse(keyIndex), pattern, primary);
|
||||||
|
AlertIfNewDeviceIsConnected(dynamicHostConfigurationProtocolConfiguration, logger);
|
||||||
|
}
|
||||||
|
|
||||||
private static string? GetMatch(DynamicHostConfigurationProtocolConfiguration dynamicHostConfigurationProtocolConfiguration, string[] files)
|
private static string? GetMatch(DynamicHostConfigurationProtocolConfiguration dynamicHostConfigurationProtocolConfiguration, string[] files)
|
||||||
{
|
{
|
||||||
string? result = null;
|
string? result = null;
|
||||||
@ -114,38 +148,4 @@ internal static partial class Helper20240403
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AlertIfNewDeviceIsConnected(DynamicHostConfigurationProtocolConfiguration dynamicHostConfigurationProtocolConfiguration, ILogger<Worker> logger)
|
|
||||||
{
|
|
||||||
string[] files = Directory.GetFiles(dynamicHostConfigurationProtocolConfiguration.Directory, dynamicHostConfigurationProtocolConfiguration.Pattern, SearchOption.TopDirectoryOnly);
|
|
||||||
string? match = GetMatch(dynamicHostConfigurationProtocolConfiguration, files);
|
|
||||||
if (string.IsNullOrEmpty(match))
|
|
||||||
throw new NotSupportedException($"{dynamicHostConfigurationProtocolConfiguration.Primary} doesn't exist!");
|
|
||||||
ReadOnlyDictionary<string, int> keyToCounts = GetKeyToCounts(dynamicHostConfigurationProtocolConfiguration, files);
|
|
||||||
foreach (KeyValuePair<string, int> keyToCount in keyToCounts)
|
|
||||||
{
|
|
||||||
if (keyToCount.Value < 2)
|
|
||||||
continue;
|
|
||||||
logger.LogInformation("{Key}: {Count}", keyToCount.Key, keyToCount.Value);
|
|
||||||
}
|
|
||||||
ReadOnlyDictionary<string, ReadOnlyDictionary<string, ReadOnlyCollection<string>>> keyValuePairs = GetKeyValuePairs(dynamicHostConfigurationProtocolConfiguration, files);
|
|
||||||
foreach (KeyValuePair<string, ReadOnlyDictionary<string, ReadOnlyCollection<string>>> keyValuePair in keyValuePairs)
|
|
||||||
{
|
|
||||||
if (!keyValuePair.Key.EndsWith(dynamicHostConfigurationProtocolConfiguration.Primary))
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static void AlertIfNewDeviceIsConnected(ILogger<Worker> logger, List<string> args)
|
|
||||||
{
|
|
||||||
string ignore = args[6];
|
|
||||||
string pattern = args[2];
|
|
||||||
string primary = args[3];
|
|
||||||
string keyIndex = args[5];
|
|
||||||
string directory = args[0];
|
|
||||||
logger.LogInformation(directory);
|
|
||||||
string[] columns = args[4].Split('|');
|
|
||||||
DynamicHostConfigurationProtocolConfiguration dynamicHostConfigurationProtocolConfiguration = new(columns, directory, ignore, int.Parse(keyIndex), pattern, primary);
|
|
||||||
AlertIfNewDeviceIsConnected(dynamicHostConfigurationProtocolConfiguration, logger);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -21,27 +21,6 @@ internal static partial class Helper20240404
|
|||||||
string RegularExpressionPattern,
|
string RegularExpressionPattern,
|
||||||
string SearchPattern);
|
string SearchPattern);
|
||||||
|
|
||||||
private static MetaData? GetMetaData(CommaSeparatedValuesConfiguration commaSeparatedValuesConfiguration, string fileNameWithoutExtension)
|
|
||||||
{
|
|
||||||
MetaData? result;
|
|
||||||
Match match = Regex.Match(fileNameWithoutExtension, commaSeparatedValuesConfiguration.RegularExpressionPattern);
|
|
||||||
if (!match.Success || match.Groups.Count != commaSeparatedValuesConfiguration.RegularExpressionGroupCount)
|
|
||||||
result = null;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int deviceId = int.Parse(match.Groups["DeviceId"].Value);
|
|
||||||
int deviceNumber = int.Parse(match.Groups["DeviceNumber"].Value);
|
|
||||||
result = new(deviceId,
|
|
||||||
match.Groups["DeviceType"].Value,
|
|
||||||
deviceNumber,
|
|
||||||
match.Groups["DescriptionName"].Value,
|
|
||||||
match.Groups["DescriptionTest"].Value,
|
|
||||||
match.Groups["Frequency"].Value,
|
|
||||||
match.Groups["Date"].Value);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void ParseCSV(CommaSeparatedValuesConfiguration commaSeparatedValuesConfiguration, ILogger<Worker> logger)
|
private static void ParseCSV(CommaSeparatedValuesConfiguration commaSeparatedValuesConfiguration, ILogger<Worker> logger)
|
||||||
{
|
{
|
||||||
string line;
|
string line;
|
||||||
@ -93,4 +72,25 @@ internal static partial class Helper20240404
|
|||||||
ParseCSV(commaSeparatedValuesConfiguration, logger);
|
ParseCSV(commaSeparatedValuesConfiguration, logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static MetaData? GetMetaData(CommaSeparatedValuesConfiguration commaSeparatedValuesConfiguration, string fileNameWithoutExtension)
|
||||||
|
{
|
||||||
|
MetaData? result;
|
||||||
|
Match match = Regex.Match(fileNameWithoutExtension, commaSeparatedValuesConfiguration.RegularExpressionPattern);
|
||||||
|
if (!match.Success || match.Groups.Count != commaSeparatedValuesConfiguration.RegularExpressionGroupCount)
|
||||||
|
result = null;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int deviceId = int.Parse(match.Groups["DeviceId"].Value);
|
||||||
|
int deviceNumber = int.Parse(match.Groups["DeviceNumber"].Value);
|
||||||
|
result = new(deviceId,
|
||||||
|
match.Groups["DeviceType"].Value,
|
||||||
|
deviceNumber,
|
||||||
|
match.Groups["DescriptionName"].Value,
|
||||||
|
match.Groups["DescriptionTest"].Value,
|
||||||
|
match.Groups["Frequency"].Value,
|
||||||
|
match.Groups["Date"].Value);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -236,40 +236,6 @@ internal static partial class Helper20240517
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ReadOnlyCollection<(string, string)> GetAggregationLines(string harFile)
|
|
||||||
{
|
|
||||||
List<(string, string)> results = [];
|
|
||||||
if (!File.Exists(harFile))
|
|
||||||
throw new Exception();
|
|
||||||
string lastUrl = string.Empty;
|
|
||||||
string text = "\"text\": \"{";
|
|
||||||
string[] lines = File.ReadAllLines(harFile);
|
|
||||||
foreach (string line in lines)
|
|
||||||
{
|
|
||||||
if (line.Contains("\"url\": \""))
|
|
||||||
lastUrl = line;
|
|
||||||
if (!line.Contains(text))
|
|
||||||
continue;
|
|
||||||
if (!line.Contains("aggregations"))
|
|
||||||
continue;
|
|
||||||
if (lastUrl.Contains("search?asset=NONE"))
|
|
||||||
continue;
|
|
||||||
results.Add(new(lastUrl, line.Trim()[(text.Length - 1)..^1].Replace("\\\"", "\"")));
|
|
||||||
lastUrl = string.Empty;
|
|
||||||
}
|
|
||||||
return new(results);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void SaveAmazon(IReadOnlyList<Datum> data, string personIdFile)
|
|
||||||
{
|
|
||||||
string json;
|
|
||||||
Dictionary<string, Datum> keyValuePairs = [];
|
|
||||||
foreach (Datum datum in data)
|
|
||||||
_ = keyValuePairs.TryAdd(datum.Name.Split('.')[0], datum);
|
|
||||||
json = JsonSerializer.Serialize(keyValuePairs, DictionaryDatumGenerationContext.Default.DictionaryStringDatum);
|
|
||||||
File.WriteAllText(personIdFile, json);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void SaveAmazon(string destination, string harFile)
|
private static void SaveAmazon(string destination, string harFile)
|
||||||
{
|
{
|
||||||
string offset;
|
string offset;
|
||||||
@ -331,4 +297,38 @@ internal static partial class Helper20240517
|
|||||||
logger?.LogInformation("{harFiles} count", harFiles.Length);
|
logger?.LogInformation("{harFiles} count", harFiles.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void SaveAmazon(IReadOnlyList<Datum> data, string personIdFile)
|
||||||
|
{
|
||||||
|
string json;
|
||||||
|
Dictionary<string, Datum> keyValuePairs = [];
|
||||||
|
foreach (Datum datum in data)
|
||||||
|
_ = keyValuePairs.TryAdd(datum.Name.Split('.')[0], datum);
|
||||||
|
json = JsonSerializer.Serialize(keyValuePairs, DictionaryDatumGenerationContext.Default.DictionaryStringDatum);
|
||||||
|
File.WriteAllText(personIdFile, json);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ReadOnlyCollection<(string, string)> GetAggregationLines(string harFile)
|
||||||
|
{
|
||||||
|
List<(string, string)> results = [];
|
||||||
|
if (!File.Exists(harFile))
|
||||||
|
throw new Exception();
|
||||||
|
string lastUrl = string.Empty;
|
||||||
|
string text = "\"text\": \"{";
|
||||||
|
string[] lines = File.ReadAllLines(harFile);
|
||||||
|
foreach (string line in lines)
|
||||||
|
{
|
||||||
|
if (line.Contains("\"url\": \""))
|
||||||
|
lastUrl = line;
|
||||||
|
if (!line.Contains(text))
|
||||||
|
continue;
|
||||||
|
if (!line.Contains("aggregations"))
|
||||||
|
continue;
|
||||||
|
if (lastUrl.Contains("search?asset=NONE"))
|
||||||
|
continue;
|
||||||
|
results.Add(new(lastUrl, line.Trim()[(text.Length - 1)..^1].Replace("\\\"", "\"")));
|
||||||
|
lastUrl = string.Empty;
|
||||||
|
}
|
||||||
|
return new(results);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user