Empty file ISO Add date back for just .kanbn Removed HardcodedFileSearchAndSort Sync with 01-23 JsonToTsv System.Text.Json White-List Ready to move to Move Helper Remove Whitelist Force Start At Check for .git directory before ls Optional Allow root for unc path nuget bump PreVerify EnforceCodeStyleInBuild dotnet_analyzer_diagnostic HelperGit searchDelegate Host File AlertIfNewDeviceIsConnected AOT SetFrontMatterAndH1 Match Error Unknown with better logging Undo 04-05 WriteAppendToHostConfFile MonA IsKanbanIndex Dotnet Format Pre-commit NPM CreateWindowsShortcut Working directory Split description Copy tests Ready to test Delete after a couple of days GitConfigCleanUp knb Files
83 lines
5.7 KiB
C#
83 lines
5.7 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace File_Folder_Helper.Day;
|
|
|
|
internal static partial class Helper20240129
|
|
{
|
|
|
|
private record Record([property: JsonPropertyName("Part Name")] string? PartName,
|
|
[property: JsonPropertyName("Part Revision")] string? PartRevision,
|
|
[property: JsonPropertyName("Test Name")] string? TestName,
|
|
[property: JsonPropertyName("Description")] string? Description,
|
|
[property: JsonPropertyName("Lot Number")] string? LotNumber,
|
|
[property: JsonPropertyName("Job Name")] string? JobName,
|
|
[property: JsonPropertyName("Process Name")] string? ProcessName,
|
|
[property: JsonPropertyName("Reasonable Limit (Upper)")] double? ReasonableLimitUpper,
|
|
[property: JsonPropertyName("Alarm Reasonable Limit (Upper)")] double? AlarmReasonableLimitUpper,
|
|
[property: JsonPropertyName("Specification Limit (Upper)")] double? SpecificationLimitUpper,
|
|
[property: JsonPropertyName("Alarm Specification Limit (Upper)")] double? AlarmSpecificationLimitUpper,
|
|
[property: JsonPropertyName("Warning Limit (Upper)")] double? WarningLimitUpper,
|
|
[property: JsonPropertyName("Alarm Warning Limit (Upper)")] double? AlarmWarningLimitUpper,
|
|
[property: JsonPropertyName("Specification Limit (Target)")] double? SpecificationLimitTarget,
|
|
[property: JsonPropertyName("Warning Limit (Lower)")] double? WarningLimitLower,
|
|
[property: JsonPropertyName("Alarm Warning Limit (Lower)")] double? AlarmWarningLimitLower,
|
|
[property: JsonPropertyName("Specification Limit (Lower)")] double? SpecificationLimitLower,
|
|
[property: JsonPropertyName("Alarm Specification Limit (Lower)")] double? AlarmSpecificationLimitLower,
|
|
[property: JsonPropertyName("Reasonable Limit (Lower)")] double? ReasonableLimitLower,
|
|
[property: JsonPropertyName("Alarm Reasonable Limit (Lower)")] double? AlarmReasonableLimitLower,
|
|
[property: JsonPropertyName("Original Test Name")] string? OriginalTestName,
|
|
[property: JsonPropertyName("Test Id")] int? TestId,
|
|
[property: JsonPropertyName("count")] int? Count);
|
|
|
|
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
|
|
[JsonSerializable(typeof(Record[]))]
|
|
private partial class Helper20240129RecordCollectionSourceGenerationContext : JsonSerializerContext
|
|
{
|
|
}
|
|
|
|
private static List<string> GetLines(Record[] records)
|
|
{
|
|
List<string> lines = [];
|
|
lines.Add($"{nameof(Record.PartName)}\t{nameof(Record.PartRevision)}\t{nameof(Record.TestName)}\t{nameof(Record.Description)}\t{nameof(Record.LotNumber)}\t{nameof(Record.JobName)}\t{nameof(Record.ProcessName)}\t{nameof(Record.ReasonableLimitUpper)}\t{nameof(Record.AlarmReasonableLimitUpper)}\t{nameof(Record.SpecificationLimitUpper)}\t{nameof(Record.AlarmSpecificationLimitUpper)}\t{nameof(Record.WarningLimitUpper)}\t{nameof(Record.AlarmWarningLimitUpper)}\t{nameof(Record.SpecificationLimitTarget)}\t{nameof(Record.WarningLimitLower)}\t{nameof(Record.AlarmWarningLimitLower)}\t{nameof(Record.SpecificationLimitLower)}\t{nameof(Record.AlarmSpecificationLimitLower)}\t{nameof(Record.ReasonableLimitLower)}\t{nameof(Record.AlarmReasonableLimitLower)}\t{nameof(Record.OriginalTestName)}\t{nameof(Record.TestId)}\t{nameof(Record.Count)}");
|
|
foreach (Record record in records)
|
|
lines.Add($"{record.PartName}\t{record.PartRevision}\t{record.TestName}\t{record.Description}\t{record.LotNumber}\t{record.JobName}\t{record.ProcessName}\t{record.ReasonableLimitUpper}\t{record.AlarmReasonableLimitUpper}\t{record.SpecificationLimitUpper}\t{record.AlarmSpecificationLimitUpper}\t{record.WarningLimitUpper}\t{record.AlarmWarningLimitUpper}\t{record.SpecificationLimitTarget}\t{record.WarningLimitLower}\t{record.AlarmWarningLimitLower}\t{record.SpecificationLimitLower}\t{record.AlarmSpecificationLimitLower}\t{record.ReasonableLimitLower}\t{record.AlarmReasonableLimitLower}\t{record.OriginalTestName}\t{record.TestId}\t{record.Count}");
|
|
return lines;
|
|
}
|
|
|
|
private static void ConvertAndWrite(string pattern, string sourceDirectory)
|
|
{
|
|
long ticks;
|
|
string json;
|
|
string fileName;
|
|
string checkFile;
|
|
Record[]? records;
|
|
List<string> lines;
|
|
string[] files = Directory.GetFiles(sourceDirectory, pattern, SearchOption.TopDirectoryOnly);
|
|
foreach (string file in files)
|
|
{
|
|
ticks = DateTime.Now.Ticks;
|
|
json = File.ReadAllText(file);
|
|
fileName = Path.GetFileName(file);
|
|
checkFile = Path.Combine(sourceDirectory, $"{fileName}.{ticks}.tsv");
|
|
records = JsonSerializer.Deserialize(json, Helper20240129RecordCollectionSourceGenerationContext.Default.RecordArray);
|
|
if (records is null)
|
|
continue;
|
|
lines = GetLines(records);
|
|
File.WriteAllLines(checkFile, lines);
|
|
checkFile = Path.Combine(sourceDirectory, $"{fileName}.{ticks}.done");
|
|
File.Move(file, checkFile);
|
|
Thread.Sleep(100);
|
|
}
|
|
}
|
|
|
|
internal static void JsonToTsv(ILogger<Worker> logger, List<string> args)
|
|
{
|
|
string pattern = args[2];
|
|
string sourceDirectory = args[0];
|
|
logger.LogInformation(sourceDirectory);
|
|
ConvertAndWrite(pattern, sourceDirectory);
|
|
}
|
|
|
|
} |