This commit is contained in:
2024-09-07 10:04:57 -07:00
parent 390090729b
commit 2301a9a9ee
31 changed files with 1121 additions and 1913 deletions

View File

@ -1,4 +1,5 @@
using Adaptation.Eaf.Management.ConfigurationData.CellAutomation;
using Adaptation.FileHandlers.json.WorkItems;
using Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration;
using Adaptation.Shared;
using Adaptation.Shared.Duplicator;
@ -7,9 +8,7 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Text.RegularExpressions;
namespace Adaptation.FileHandlers.Kanban;
@ -110,83 +109,86 @@ public class FileRead : Shared.FileRead, IFileRead
return results;
}
private void Save(string key, string fileNameWithoutExtension, string rootDirectory, JsonElement jsonElement)
#nullable enable
private void Save(string fileNameWithoutExtension, WorkItem[] workItems)
{
string old;
string json;
string checkFile;
string tasksDirectory;
string kanbanDirectory;
string vscodeDirectory;
string singletonDirectory;
List<string> indexLines = new();
indexLines.AddRange(_FrontMatterLines);
indexLines.Add(string.Empty);
indexLines.Add($"# {key}");
indexLines.Add(string.Empty);
indexLines.Add("## Backlog");
indexLines.Add(string.Empty);
indexLines.Add("## Todo");
indexLines.Add(string.Empty);
indexLines.Add("## In Progress");
indexLines.Add(string.Empty);
indexLines.Add("## Done");
string singletonDirectory = Path.Combine(rootDirectory, $"{key}-{fileNameWithoutExtension}");
string vscodeDirectory = Path.Combine(singletonDirectory, ".vscode");
if (!Directory.Exists(vscodeDirectory))
_ = Directory.CreateDirectory(vscodeDirectory);
checkFile = Path.Combine(vscodeDirectory, "settings.json");
if (!File.Exists(checkFile))
File.WriteAllText(checkFile, "{ \"[markdown]\": { \"editor.wordWrap\": \"off\" }, \"cSpell.words\": [ \"kanbn\" ] }");
string kanbanDirectory = Path.Combine(singletonDirectory, ".kanbn");
if (!Directory.Exists(kanbanDirectory))
_ = Directory.CreateDirectory(kanbanDirectory);
checkFile = Path.Combine(kanbanDirectory, ".json");
if (!File.Exists(checkFile))
File.WriteAllText(checkFile, jsonElement.ToString());
else
JsonSerializerOptions jsonSerializerOptions = new() { WriteIndented = true };
string rootDirectory = Path.Combine(_FileConnectorConfiguration.TargetFileLocation, fileNameWithoutExtension);
if (string.IsNullOrEmpty(rootDirectory))
throw new NullReferenceException(nameof(rootDirectory));
foreach (WorkItem workItem in workItems)
{
string singletonJson = jsonElement.ToString();
string checkJson = Regex.Replace(File.ReadAllText(checkFile), @"\s+", " ", RegexOptions.Multiline);
if (Regex.Replace(singletonJson, @"\s+", " ", RegexOptions.Multiline) != checkJson)
File.WriteAllText(checkFile, singletonJson);
json = JsonSerializer.Serialize(workItem, jsonSerializerOptions);
singletonDirectory = Path.Combine(rootDirectory, workItem.WorkItemType.Replace(" ", "-"), $"{workItem.Id}-{workItem.WorkItemType.Replace(" ", "-")}");
kanbanDirectory = Path.Combine(singletonDirectory, ".kanbn");
if (!Directory.Exists(kanbanDirectory))
_ = Directory.CreateDirectory(kanbanDirectory);
tasksDirectory = Path.Combine(kanbanDirectory, "tasks");
if (!Directory.Exists(tasksDirectory))
_ = Directory.CreateDirectory(tasksDirectory);
vscodeDirectory = Path.Combine(singletonDirectory, ".vscode");
if (!Directory.Exists(vscodeDirectory))
_ = Directory.CreateDirectory(vscodeDirectory);
checkFile = Path.Combine(vscodeDirectory, "settings.json");
if (!File.Exists(checkFile))
File.WriteAllText(checkFile, "{ \"[markdown]\": { \"editor.wordWrap\": \"off\" }, \"cSpell.words\": [ \"kanbn\" ] }");
indexLines.Clear();
indexLines.AddRange(_FrontMatterLines);
indexLines.Add(string.Empty);
indexLines.Add($"# {workItem.Id}");
indexLines.Add(string.Empty);
indexLines.Add("## Backlog");
indexLines.Add(string.Empty);
indexLines.Add("## Todo");
indexLines.Add(string.Empty);
indexLines.Add("## In Progress");
indexLines.Add(string.Empty);
indexLines.Add("## Done");
checkFile = Path.Combine(kanbanDirectory, "board.css");
if (!File.Exists(checkFile))
File.WriteAllLines(checkFile, _CSSLines);
checkFile = Path.Combine(kanbanDirectory, "index.md");
if (!File.Exists(checkFile))
File.WriteAllLines(checkFile, indexLines);
checkFile = Path.Combine(kanbanDirectory, ".json");
if (File.Exists(checkFile))
{
old = File.ReadAllText(checkFile);
if (old == json)
continue;
}
File.WriteAllText(checkFile, json);
}
string tasksDirectory = Path.Combine(kanbanDirectory, "tasks");
if (!Directory.Exists(tasksDirectory))
_ = Directory.CreateDirectory(tasksDirectory);
checkFile = Path.Combine(kanbanDirectory, "board.css");
if (!File.Exists(checkFile))
File.WriteAllLines(checkFile, _CSSLines);
checkFile = Path.Combine(kanbanDirectory, "index.md");
if (!File.Exists(checkFile))
File.WriteAllLines(checkFile, indexLines);
}
#pragma warning disable IDE0060
private void Save(string reportFullPath, DateTime dateTime)
#pragma warning restore IDE0060
{
string json = File.ReadAllText(reportFullPath);
WorkItem[]? workItems = JsonSerializer.Deserialize<WorkItem[]>(json);
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(reportFullPath);
if (workItems is null)
throw new Exception(nameof(workItems));
if (workItems.Length > 0)
Save(fileNameWithoutExtension, workItems);
}
private Tuple<string, Test[], JsonElement[], List<FileInfo>> GetExtractResult(string reportFullPath, DateTime dateTime)
{
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
string key;
JsonProperty[] jsonProperties;
string ticks = dateTime.Ticks.ToString();
_Logistics = new Logistics(reportFullPath, $"LOGISTICS_1{'\t'}A_JOBID={"BACKLOG"};A_MES_ENTITY={"BACKLOG"};");
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(reportFullPath).Replace(" ", "-").Replace("---", "-");
string rootDirectory = Path.Combine(_FileConnectorConfiguration.SourceFileLocation, fileNameWithoutExtension);
if (string.IsNullOrEmpty(rootDirectory))
throw new NullReferenceException(nameof(rootDirectory));
if (!Directory.Exists(rootDirectory))
_ = Directory.CreateDirectory(Path.Combine(rootDirectory, ticks));
string json = File.ReadAllText(reportFullPath);
JsonElement[] jsonElements = JsonSerializer.Deserialize<JsonElement[]>(json);
foreach (JsonElement jsonElement in jsonElements)
{
if (jsonElement.ValueKind != JsonValueKind.Object)
continue;
jsonProperties = jsonElement.EnumerateObject().ToArray();
if (jsonProperties.Length < 2)
continue;
key = jsonProperties[0].Value.ToString();
if (string.IsNullOrEmpty(key))
continue;
if (string.IsNullOrEmpty(jsonProperties[1].Value.ToString()))
continue;
Save(key, fileNameWithoutExtension, rootDirectory, jsonElement);
if (!_IsEAFHosted)
break;
}
if (_IsEAFHosted)
Save(reportFullPath, dateTime);
results = new(_Logistics.Logistics1[0], Array.Empty<Test>(), Array.Empty<JsonElement>(), new List<FileInfo>());
return results;
}