Removed logic to create directories in ADO _
Move Matching and PDSF alignment
This commit is contained in:
parent
58ce014b10
commit
c5d86f3c43
@ -7,7 +7,6 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
@ -69,7 +68,6 @@ public class ProcessData : IProcessData
|
|||||||
throw new Exception(nameof(workItems));
|
throw new Exception(nameof(workItems));
|
||||||
_Details.Add(workItems);
|
_Details.Add(workItems);
|
||||||
ReadOnlyDictionary<int, Record> keyValuePairs = GetWorkItems(workItems, keepRelations);
|
ReadOnlyDictionary<int, Record> keyValuePairs = GetWorkItems(workItems, keepRelations);
|
||||||
WriteFileStructure(destinationDirectory, keyValuePairs);
|
|
||||||
WriteFiles(fileRead, destinationDirectory, fileInfoCollection, keyValuePairs);
|
WriteFiles(fileRead, destinationDirectory, fileInfoCollection, keyValuePairs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,18 +81,6 @@ public class ProcessData : IProcessData
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void WriteFileStructure(string destinationDirectory, ReadOnlyDictionary<int, Record> keyValuePairs)
|
|
||||||
{
|
|
||||||
ReadOnlyCollection<string> collection = GetDirectories(destinationDirectory, keyValuePairs);
|
|
||||||
foreach (string directory in collection)
|
|
||||||
{
|
|
||||||
if (directory.Length > 222)
|
|
||||||
continue;
|
|
||||||
if (!Directory.Exists(directory))
|
|
||||||
_ = Directory.CreateDirectory(directory);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void WriteFiles(IFileRead fileRead, string destinationDirectory, List<FileInfo> fileInfoCollection, ReadOnlyDictionary<int, Record> keyValuePairs)
|
private static void WriteFiles(IFileRead fileRead, string destinationDirectory, List<FileInfo> fileInfoCollection, ReadOnlyDictionary<int, Record> keyValuePairs)
|
||||||
{
|
{
|
||||||
string old;
|
string old;
|
||||||
@ -112,10 +98,10 @@ public class ProcessData : IProcessData
|
|||||||
workItem = keyValuePair.Value.WorkItem;
|
workItem = keyValuePair.Value.WorkItem;
|
||||||
workItemType = workItem.WorkItemType.Replace(" ", "-");
|
workItemType = workItem.WorkItemType.Replace(" ", "-");
|
||||||
json = JsonSerializer.Serialize(workItem, WorkItemSourceGenerationContext.Default.WorkItem);
|
json = JsonSerializer.Serialize(workItem, WorkItemSourceGenerationContext.Default.WorkItem);
|
||||||
singletonDirectory = Path.Combine(rootDirectory, workItemType, $"{workItem.Id}-{workItemType}", $"{workItem.Id}");
|
singletonDirectory = Path.Combine(rootDirectory, workItemType, $"{workItem.Id}");
|
||||||
if (!Directory.Exists(singletonDirectory))
|
if (!Directory.Exists(singletonDirectory))
|
||||||
_ = Directory.CreateDirectory(singletonDirectory);
|
_ = Directory.CreateDirectory(singletonDirectory);
|
||||||
checkFile = Path.Combine(singletonDirectory, ".json");
|
checkFile = Path.Combine(singletonDirectory, $"{workItem.Id}-{workItemType.ToLower()}.json");
|
||||||
old = File.Exists(checkFile) ? File.ReadAllText(checkFile) : string.Empty;
|
old = File.Exists(checkFile) ? File.ReadAllText(checkFile) : string.Empty;
|
||||||
if (old == json)
|
if (old == json)
|
||||||
continue;
|
continue;
|
||||||
@ -159,33 +145,6 @@ public class ProcessData : IProcessData
|
|||||||
return new(results);
|
return new(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ReadOnlyCollection<string> GetDirectories(string destinationDirectory, ReadOnlyDictionary<int, Record> keyValuePairs)
|
|
||||||
{
|
|
||||||
List<string> results = new();
|
|
||||||
Record record;
|
|
||||||
string directory;
|
|
||||||
List<bool> nests = new();
|
|
||||||
ReadOnlyCollection<string> childrenDirectories;
|
|
||||||
string dateDirectory = Path.Combine(destinationDirectory, "_", DateTime.Now.ToString("yyyy-MM-dd"));
|
|
||||||
foreach (KeyValuePair<int, Record> keyValuePair in keyValuePairs)
|
|
||||||
{
|
|
||||||
record = keyValuePair.Value;
|
|
||||||
if (record.Parent is not null && (record.WorkItem.Parent is null || record.Parent.Id != record.WorkItem.Parent.Value))
|
|
||||||
continue;
|
|
||||||
if (record.Parent is not null)
|
|
||||||
continue;
|
|
||||||
// if (record.WorkItem.Id == 110730)
|
|
||||||
// continue;
|
|
||||||
// if (record.WorkItem.Id == 110732)
|
|
||||||
// continue;
|
|
||||||
nests.Clear();
|
|
||||||
directory = Path.Combine(dateDirectory, $"{record.WorkItem.WorkItemType.Substring(0, 1)}-{record.WorkItem.Id}-{record.WorkItem.Title.Trim().Substring(0, 1)}");
|
|
||||||
childrenDirectories = GetChildrenDirectories(keyValuePairs, nests, directory, record);
|
|
||||||
results.AddRange(childrenDirectories);
|
|
||||||
}
|
|
||||||
return new(results.Distinct().ToArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string GetIndexLines(ReadOnlyCollection<string> frontMatterLines, Record record)
|
private static string GetIndexLines(ReadOnlyCollection<string> frontMatterLines, Record record)
|
||||||
{
|
{
|
||||||
List<string> results = new();
|
List<string> results = new();
|
||||||
@ -235,32 +194,4 @@ public class ProcessData : IProcessData
|
|||||||
return string.Join(Environment.NewLine, results);
|
return string.Join(Environment.NewLine, results);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ReadOnlyCollection<string> GetChildrenDirectories(ReadOnlyDictionary<int, Record> keyValuePairs, List<bool> nests, string parentDirectory, Record record)
|
|
||||||
{
|
|
||||||
List<string> results = new();
|
|
||||||
nests.Add(true);
|
|
||||||
string directory;
|
|
||||||
Record? childRecord;
|
|
||||||
ReadOnlyCollection<string> childrenDirectories;
|
|
||||||
if (record.Children is not null)
|
|
||||||
{
|
|
||||||
foreach (Record r in record.Children)
|
|
||||||
{
|
|
||||||
// if (record.WorkItem.Id == 110730)
|
|
||||||
// continue;
|
|
||||||
// if (record.WorkItem.Id == 110732)
|
|
||||||
// continue;
|
|
||||||
directory = Path.Combine(parentDirectory, $"{r.WorkItem.WorkItemType.Substring(0, 1)}-{r.WorkItem.Id}-{r.WorkItem.Title.Trim().Substring(0, 1)}");
|
|
||||||
results.Add(directory);
|
|
||||||
if (!keyValuePairs.TryGetValue(r.WorkItem.Id, out childRecord))
|
|
||||||
continue;
|
|
||||||
if (nests.Count > 99)
|
|
||||||
break;
|
|
||||||
childrenDirectories = GetChildrenDirectories(keyValuePairs, nests, directory, childRecord);
|
|
||||||
results.AddRange(childrenDirectories);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new(results);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -268,7 +268,7 @@ public class FileRead : Shared.FileRead, IFileRead
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ReadOnlyCollection<Pre> GetPreCollection(int numberLength, string parentDirectory, ReadOnlyCollection<string> matchingFiles, bool _)
|
private static ReadOnlyCollection<Pre> GetPreCollection(int numberLength, string parentDirectory, ReadOnlyCollection<string> matchingFiles)
|
||||||
{
|
{
|
||||||
List<Pre> results = new();
|
List<Pre> results = new();
|
||||||
Pre pre;
|
Pre pre;
|
||||||
@ -351,7 +351,7 @@ public class FileRead : Shared.FileRead, IFileRead
|
|||||||
ProcessDataStandardFormat processDataStandardFormat = ProcessDataStandardFormat.GetProcessDataStandardFormat(reportFullPath, _ProcessDataStandardFormatMapping);
|
ProcessDataStandardFormat processDataStandardFormat = ProcessDataStandardFormat.GetProcessDataStandardFormat(reportFullPath, _ProcessDataStandardFormatMapping);
|
||||||
_Logistics = new Logistics(reportFullPath, processDataStandardFormat);
|
_Logistics = new Logistics(reportFullPath, processDataStandardFormat);
|
||||||
if (!_IsEAFHosted)
|
if (!_IsEAFHosted)
|
||||||
ProcessDataStandardFormat.Write(".pdsf", processDataStandardFormat, wsResults: null);
|
ProcessDataStandardFormat.Write("../../.pdsf", processDataStandardFormat, wsResults: null);
|
||||||
SetFileParameterLotIDToLogisticsMID();
|
SetFileParameterLotIDToLogisticsMID();
|
||||||
int numberLength = 2;
|
int numberLength = 2;
|
||||||
long ticks = dateTime.Ticks;
|
long ticks = dateTime.Ticks;
|
||||||
@ -366,8 +366,7 @@ public class FileRead : Shared.FileRead, IFileRead
|
|||||||
{ CreatePointerFile(numberLength, parentParentDirectory, matchingFiles); }
|
{ CreatePointerFile(numberLength, parentParentDirectory, matchingFiles); }
|
||||||
catch (Exception) { }
|
catch (Exception) { }
|
||||||
}
|
}
|
||||||
bool mesEntityMatchesProcess = false;
|
ReadOnlyCollection<Pre> preCollection = GetPreCollection(numberLength, parentParentDirectory, matchingFiles);
|
||||||
ReadOnlyCollection<Pre> preCollection = GetPreCollection(numberLength, parentParentDirectory, matchingFiles, mesEntityMatchesProcess);
|
|
||||||
ReadOnlyCollection<PreWith> preWithCollection = GetPreWithCollection(preCollection);
|
ReadOnlyCollection<PreWith> preWithCollection = GetPreWithCollection(preCollection);
|
||||||
MoveCollection(dateTime, processDataStandardFormat, preWithCollection);
|
MoveCollection(dateTime, processDataStandardFormat, preWithCollection);
|
||||||
return results;
|
return results;
|
||||||
|
@ -360,6 +360,63 @@ internal class ProcessDataStandardFormat
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetJson(ProcessDataStandardFormat processDataStandardFormat)
|
||||||
|
{
|
||||||
|
if (processDataStandardFormat.InputPDSF is null)
|
||||||
|
throw new NullReferenceException(nameof(processDataStandardFormat.InputPDSF));
|
||||||
|
#pragma warning disable CA1845, IDE0057
|
||||||
|
string result;
|
||||||
|
string line;
|
||||||
|
string value;
|
||||||
|
string[] segments;
|
||||||
|
List<string> lines = new();
|
||||||
|
for (int i = 0; i < processDataStandardFormat.InputPDSF.Body.Count; i++)
|
||||||
|
{
|
||||||
|
line = "{";
|
||||||
|
segments = processDataStandardFormat.InputPDSF.Body[i].Trim().Split('\t');
|
||||||
|
if (segments.Length != processDataStandardFormat.InputPDSF.Columns.Count)
|
||||||
|
break;
|
||||||
|
for (int c = 0; c < segments.Length; c++)
|
||||||
|
{
|
||||||
|
value = segments[c].Replace("\"", "\\\"").Replace("\\", "\\\\");
|
||||||
|
line += string.Concat('"', processDataStandardFormat.InputPDSF.Columns[c].Trim('"'), '"', ':', '"', value, '"', ',');
|
||||||
|
}
|
||||||
|
line = string.Concat(line.Substring(0, line.Length - 1), '}');
|
||||||
|
lines.Add(line);
|
||||||
|
}
|
||||||
|
result = string.Concat(
|
||||||
|
'{',
|
||||||
|
Environment.NewLine,
|
||||||
|
'"',
|
||||||
|
"Count",
|
||||||
|
'"',
|
||||||
|
": ",
|
||||||
|
processDataStandardFormat.Body.Count,
|
||||||
|
',',
|
||||||
|
Environment.NewLine,
|
||||||
|
'"',
|
||||||
|
"Records",
|
||||||
|
'"',
|
||||||
|
": ",
|
||||||
|
Environment.NewLine,
|
||||||
|
'[',
|
||||||
|
Environment.NewLine,
|
||||||
|
string.Join($",{Environment.NewLine}", lines),
|
||||||
|
Environment.NewLine,
|
||||||
|
']',
|
||||||
|
',',
|
||||||
|
Environment.NewLine,
|
||||||
|
'"',
|
||||||
|
"Sequence",
|
||||||
|
'"',
|
||||||
|
": ",
|
||||||
|
processDataStandardFormat.Sequence,
|
||||||
|
Environment.NewLine,
|
||||||
|
'}');
|
||||||
|
return result;
|
||||||
|
#pragma warning restore CA1845, IDE0057
|
||||||
|
}
|
||||||
|
|
||||||
internal static void Write(string path, ProcessDataStandardFormat processDataStandardFormat, List<Metrology.WS.Results>? wsResults)
|
internal static void Write(string path, ProcessDataStandardFormat processDataStandardFormat, List<Metrology.WS.Results>? wsResults)
|
||||||
{
|
{
|
||||||
List<string> results = new();
|
List<string> results = new();
|
||||||
@ -399,9 +456,10 @@ internal class ProcessDataStandardFormat
|
|||||||
results.Add($"{segments[0]}\t{segments[1][0]}_HeaderId={wsResults[0].HeaderId};{segments[1][0]}_SubgroupId={wsResults[0].SubgroupId};{segments[1]}");
|
results.Add($"{segments[0]}\t{segments[1][0]}_HeaderId={wsResults[0].HeaderId};{segments[1][0]}_SubgroupId={wsResults[0].SubgroupId};{segments[1]}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
results.Add("EOF");
|
results.Add("END_HEADER");
|
||||||
if (processDataStandardFormat.InputPDSF is not null)
|
if (processDataStandardFormat.InputPDSF is not null)
|
||||||
{
|
{
|
||||||
|
results.Add(string.Empty);
|
||||||
List<char> hyphens = new();
|
List<char> hyphens = new();
|
||||||
results.AddRange(processDataStandardFormat.InputPDSF.Header.Select(l => l.Replace('\t', '|')));
|
results.AddRange(processDataStandardFormat.InputPDSF.Header.Select(l => l.Replace('\t', '|')));
|
||||||
results.Add(string.Empty);
|
results.Add(string.Empty);
|
||||||
@ -412,6 +470,11 @@ internal class ProcessDataStandardFormat
|
|||||||
results.AddRange(processDataStandardFormat.InputPDSF.Body.Select(l => l.Replace('\t', '|')));
|
results.AddRange(processDataStandardFormat.InputPDSF.Body.Select(l => l.Replace('\t', '|')));
|
||||||
results.Add(string.Empty);
|
results.Add(string.Empty);
|
||||||
results.AddRange(processDataStandardFormat.InputPDSF.Footer.Select(l => l.Replace('\t', '|')));
|
results.AddRange(processDataStandardFormat.InputPDSF.Footer.Select(l => l.Replace('\t', '|')));
|
||||||
|
results.Add(string.Empty);
|
||||||
|
results.Add("EOF");
|
||||||
|
results.Add(string.Empty);
|
||||||
|
string json = GetJson(processDataStandardFormat);
|
||||||
|
results.Add(json);
|
||||||
}
|
}
|
||||||
File.WriteAllText(path, string.Join(Environment.NewLine, results));
|
File.WriteAllText(path, string.Join(Environment.NewLine, results));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user