Hardcode Bio-Rad in OI output
UniqueId replacement for attachments Write input PDSF in output after EOF GetPropertyValue for MoveMatchingFiles ProcessDataStandardFormat over Tuple MoveMatchingFiles to use ProcessDataStandardFormatMapping
This commit is contained in:
		| @ -5,16 +5,70 @@ using Adaptation.Shared.Duplicator; | ||||
| using Adaptation.Shared.Methods; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Collections.ObjectModel; | ||||
| using System.IO; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Text.Json; | ||||
| using System.Threading; | ||||
|  | ||||
| namespace Adaptation.FileHandlers.MoveMatchingFiles; | ||||
|  | ||||
| #nullable enable | ||||
|  | ||||
| public class FileRead : Shared.FileRead, IFileRead | ||||
| { | ||||
|  | ||||
|     internal class PreWith | ||||
|     { | ||||
|  | ||||
|         internal string MatchingFile { get; private set; } | ||||
|         internal string CheckFile { get; private set; } | ||||
|         internal string ErrFile { get; private set; } | ||||
|         internal string CheckDirectory { get; private set; } | ||||
|         internal string NoWaitDirectory { get; private set; } | ||||
|  | ||||
|         internal PreWith(string matchingFile, string checkFile, string errFile, string checkDirectory, string noWaitDirectory) | ||||
|         { | ||||
|             MatchingFile = matchingFile; | ||||
|             CheckFile = checkFile; | ||||
|             ErrFile = errFile; | ||||
|             CheckDirectory = checkDirectory; | ||||
|             NoWaitDirectory = noWaitDirectory; | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     internal class Pre | ||||
|     { | ||||
|  | ||||
|         internal string MatchingFile { get; private set; } | ||||
|         internal string CheckFile { get; private set; } | ||||
|  | ||||
|         internal Pre(string matchingFile, string checkFile) | ||||
|         { | ||||
|             MatchingFile = matchingFile; | ||||
|             CheckFile = checkFile; | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     internal class Post | ||||
|     { | ||||
|  | ||||
|         internal string ErrFile { get; private set; } | ||||
|         internal string CheckFile { get; private set; } | ||||
|  | ||||
|         internal Post(string checkFile, string errFile) | ||||
|         { | ||||
|             ErrFile = errFile; | ||||
|             CheckFile = checkFile; | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     private readonly ProcessDataStandardFormatMapping _ProcessDataStandardFormatMapping; | ||||
|  | ||||
|     public FileRead(ISMTP smtp, Dictionary<string, string> fileParameter, string cellInstanceName, int? connectionCount, string cellInstanceConnectionName, FileConnectorConfiguration fileConnectorConfiguration, string equipmentTypeName, string parameterizedModelObjectDefinitionType, IList<ModelObjectParameterDefinition> modelObjectParameters, string equipmentDictionaryName, Dictionary<string, List<long>> dummyRuns, Dictionary<long, List<string>> staticRuns, bool useCyclicalForDescription, bool isEAFHosted) : | ||||
|         base(new Description(), false, smtp, fileParameter, cellInstanceName, connectionCount, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, staticRuns, useCyclicalForDescription, isEAFHosted: connectionCount is null) | ||||
|     { | ||||
| @ -27,6 +81,12 @@ public class FileRead : Shared.FileRead, IFileRead | ||||
|             throw new Exception(cellInstanceConnectionName); | ||||
|         if (!_IsDuplicator) | ||||
|             throw new Exception(cellInstanceConnectionName); | ||||
|         string processDataStandardFormatMappingOldColumnNames = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "Process.Data.Standard.Format.Mapping.Old.Column.Names"); | ||||
|         string processDataStandardFormatMappingNewColumnNames = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "Process.Data.Standard.Format.Mapping.New.Column.Names"); | ||||
|         string processDataStandardFormatMappingColumnIndices = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "Process.Data.Standard.Format.Mapping.Column.Indices"); | ||||
|         _ProcessDataStandardFormatMapping = GetProcessDataStandardFormatMapping(processDataStandardFormatMappingOldColumnNames, | ||||
|                                                                                 processDataStandardFormatMappingNewColumnNames, | ||||
|                                                                                 processDataStandardFormatMappingColumnIndices); | ||||
|     } | ||||
|  | ||||
|     void IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, Exception exception) | ||||
| @ -41,7 +101,8 @@ public class FileRead : Shared.FileRead, IFileRead | ||||
|         Move(extractResults); | ||||
|     } | ||||
|  | ||||
|     void IFileRead.WaitForThread() => WaitForThread(thread: null, threadExceptions: null); | ||||
|     void IFileRead.WaitForThread() => | ||||
|         WaitForThread(thread: null, threadExceptions: null); | ||||
|  | ||||
|     string IFileRead.GetEventDescription() | ||||
|     { | ||||
| @ -88,7 +149,7 @@ public class FileRead : Shared.FileRead, IFileRead | ||||
|         DateTime dateTime = DateTime.Now; | ||||
|         results = GetExtractResult(reportFullPath, dateTime); | ||||
|         if (results.Item3 is null) | ||||
|             results = new Tuple<string, Test[], JsonElement[], List<FileInfo>>(results.Item1, Array.Empty<Test>(), JsonSerializer.Deserialize<JsonElement[]>("[]"), results.Item4); | ||||
|             results = new Tuple<string, Test[], JsonElement[], List<FileInfo>>(results.Item1, Array.Empty<Test>(), JsonSerializer.Deserialize<JsonElement[]>("[]") ?? throw new Exception(), results.Item4); | ||||
|         if (results.Item3.Length > 0 && _IsEAFHosted) | ||||
|             WritePDSF(this, results.Item3); | ||||
|         UpdateLastTicksDuration(DateTime.Now.Ticks - dateTime.Ticks); | ||||
| @ -104,7 +165,69 @@ public class FileRead : Shared.FileRead, IFileRead | ||||
|         return results; | ||||
|     } | ||||
|  | ||||
|     private static List<string> GetSearchDirectories(int numberLength, string parentDirectory) | ||||
|     private static ProcessDataStandardFormatMapping GetProcessDataStandardFormatMapping(string processDataStandardFormatMappingOldColumnNames, string processDataStandardFormatMappingNewColumnNames, string processDataStandardFormatMappingColumnIndices) | ||||
|     { | ||||
|         ProcessDataStandardFormatMapping result; | ||||
|         string[] segmentsB; | ||||
|         List<string> distinct = new(); | ||||
|         Dictionary<string, string> keyValuePairs = new(); | ||||
|         string args4 = "Time,HeaderUniqueId,UniqueId,Date"; | ||||
|         string args5 = "Thickness 14 3mm Edge Mean,Thickness 14 3mm Edge % from R/2,Thickness 14 5mm Edge Mean,Thickness 14 5mm Edge % from R/2,Thickness 14 Center Mean,Thickness 14 Average,Thickness 14 Std Dev,Thickness 14 R/2 Mean"; | ||||
|         string args6 = "Thickness01,Thickness02,Thickness03,Thickness04,Thickness05,Thickness06,Thickness07,Thickness08,Thickness09,Thickness10,Thickness11,Thickness12,Thickness13,Thickness14"; | ||||
|         string args7 = "Test|EventId,Employee|Operator,Lot|Wafer,MeanThickness|WaferMeanThickness,RVThickness|RadialVariationThickness,ThicknessFourteen3mmEdgeMean|Thickness 14 3mm Edge Mean,ThicknessFourteen3mmEdgePercent|Thickness 14 3mm Edge % from R/2,ThicknessFourteen5mmEdgeMean|Thickness 14 5mm Edge Mean,ThicknessFourteen5mmEdgePercent|Thickness 14 5mm Edge % from R/2,ThicknessFourteenCenterMean|Thickness 14 Center Mean,ThicknessFourteenCriticalPointsAverage|Thickness 14 Average,ThicknessFourteenCriticalPointsStdDev|Thickness 14 Std Dev,ThicknessFourteenMeanFrom|Thickness 14 R/2 Mean,|BIORAD2"; | ||||
|         // string args8 = "Time,A_LOGISTICS,B_LOGISTICS,Test,Count,Index,MesEntity,Date,Employee,Lot,PSN,Reactor,Recipe,Cassette,HeaderUniqueId,Layer,PassFail,Position,RDS,Title,UniqueId,Wafer,Zone,MeanThickness,RVThickness,StdDev,Thickness,Slot,ThicknessFourteen3mmEdgeMean,ThicknessFourteen3mmEdgePercent,ThicknessFourteen5mmEdgeMean,ThicknessFourteen5mmEdgePercent,ThicknessFourteenCenterMean,ThicknessFourteenCriticalPointsAverage,ThicknessFourteenCriticalPointsStdDev,ThicknessFourteenMeanFrom,Thickness01,Thickness02,Thickness03,Thickness04,Thickness05,Thickness06,Thickness07,Thickness08,Thickness09,Thickness10,Thickness11,Thickness12,Thickness13,Thickness14"; | ||||
|         // string args9 = "Time,A_LOGISTICS,B_LOGISTICS,Count,Sequence,MesEntity,Index,Title,Recipe,DateTime,Operator,Batch,Cassette,UsedLast,Wafer,Position,Thickness,WaferMeanThickness,StdDev,PassFail,Line,RadialVariationThickness,Slot,RDS,PSN,Reactor,Layer,Zone,Employee,InferredLot,Thickness 14 3mm Edge Mean,Thickness 14 3mm Edge % from R/2,Thickness 14 5mm Edge Mean,Thickness 14 5mm Edge % from R/2,Thickness 14 Center Mean,Thickness 14 Average,Thickness 14 Std Dev,Thickness 14 R 2/Mean,Thickness01,Thickness02,Thickness03,Thickness04,Thickness05,Thickness06,Thickness07,Thickness08,Thickness09,Thickness10,Thickness11,Thickness12,Thickness13,Thickness14,EventId"; | ||||
|         // string args10 = "0,1,2,52,3,6,5,9,10,14,24,25,8,12,-1,26,19,15,23,7,-1,14,27,17,21,18,16,22,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51"; | ||||
|         string[] segments = args7.Split(','); | ||||
|         ReadOnlyCollection<string> ignoreColumns = new(args4.Split(',')); | ||||
|         ReadOnlyCollection<string> backfillColumns = new(args5.Split(',')); | ||||
|         ReadOnlyCollection<string> indexOnlyColumns = new(args6.Split(',')); | ||||
|         ReadOnlyCollection<string> newColumnNames = new(processDataStandardFormatMappingNewColumnNames.Split(',')); | ||||
|         ReadOnlyCollection<string> oldColumnNames = new(processDataStandardFormatMappingOldColumnNames.Split(',')); | ||||
|         ReadOnlyCollection<int> columnIndices = new(processDataStandardFormatMappingColumnIndices.Split(',').Select(int.Parse).ToArray()); | ||||
|         foreach (string segment in segments) | ||||
|         { | ||||
|             segmentsB = segment.Split('|'); | ||||
|             if (segmentsB.Length != 2) | ||||
|                 continue; | ||||
|             if (distinct.Contains(segmentsB[0])) | ||||
|                 continue; | ||||
|             distinct.Add(segmentsB[0]); | ||||
|             keyValuePairs.Add(segmentsB[0], segmentsB[1]); | ||||
|         } | ||||
|         result = new(backfillColumns: backfillColumns, | ||||
|                      columnIndices: columnIndices, | ||||
|                      newColumnNames: newColumnNames, | ||||
|                      ignoreColumns: ignoreColumns, | ||||
|                      indexOnlyColumns: indexOnlyColumns, | ||||
|                      keyValuePairs: new(keyValuePairs), | ||||
|                      oldColumnNames: oldColumnNames); | ||||
|         return result; | ||||
|     } | ||||
|  | ||||
|     private static ReadOnlyCollection<PreWith> GetPreWithCollection(ReadOnlyCollection<Pre> preCollection) | ||||
|     { | ||||
|         List<PreWith> results = new(); | ||||
|         string errFile; | ||||
|         PreWith preWith; | ||||
|         string? checkDirectory; | ||||
|         string noWaitDirectory; | ||||
|         foreach (Pre pre in preCollection) | ||||
|         { | ||||
|             errFile = string.Concat(pre.CheckFile, ".err"); | ||||
|             checkDirectory = Path.GetDirectoryName(pre.CheckFile); | ||||
|             if (string.IsNullOrEmpty(checkDirectory)) | ||||
|                 continue; | ||||
|             if (!Directory.Exists(checkDirectory)) | ||||
|                 _ = Directory.CreateDirectory(checkDirectory); | ||||
|             noWaitDirectory = Path.Combine(checkDirectory, "NoWaitDirectory"); | ||||
|             preWith = new(pre.MatchingFile, pre.CheckFile, errFile, checkDirectory, noWaitDirectory); | ||||
|             results.Add(preWith); | ||||
|         } | ||||
|         return results.AsReadOnly(); | ||||
|     } | ||||
|  | ||||
|     private static ReadOnlyCollection<string> GetSearchDirectories(int numberLength, string parentDirectory) | ||||
|     { | ||||
|         List<string> results = new(); | ||||
|         string[] directories = Directory.GetDirectories(parentDirectory, "*", SearchOption.TopDirectoryOnly); | ||||
| @ -115,10 +238,136 @@ public class FileRead : Shared.FileRead, IFileRead | ||||
|             results.Add(directory); | ||||
|         } | ||||
|         results.Sort(); | ||||
|         return results.AsReadOnly(); | ||||
|     } | ||||
|  | ||||
|     private static void CreatePointerFile(int numberLength, string parentDirectory, ReadOnlyCollection<string> matchingFiles) | ||||
|     { | ||||
|         string checkFile; | ||||
|         string writeFile; | ||||
|         string? directoryName; | ||||
|         int parentDirectoryLength = parentDirectory.Length; | ||||
|         foreach (string matchingFile in matchingFiles) | ||||
|         { | ||||
|             directoryName = Path.GetDirectoryName(matchingFile); | ||||
|             if (directoryName is null) | ||||
|                 continue; | ||||
|             checkFile = $"{matchingFile[0]}{directoryName.Substring(parentDirectoryLength + numberLength + 1)}"; | ||||
|             writeFile = Path.Combine(parentDirectory, $"{directoryName.Substring(parentDirectory.Length + 1, numberLength)}.txt"); | ||||
|             if (File.Exists(writeFile)) | ||||
|                 continue; | ||||
|             File.AppendAllLines(writeFile, new string[] { parentDirectory, matchingFile, directoryName, checkFile }); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private static ReadOnlyCollection<Pre> GetPreCollection(int numberLength, string parentDirectory, ReadOnlyCollection<string> matchingFiles) | ||||
|     { | ||||
|         List<Pre> results = new(); | ||||
|         Pre pre; | ||||
|         string checkFile; | ||||
|         int parentDirectoryLength = parentDirectory.Length; | ||||
|         foreach (string matchingFile in matchingFiles) | ||||
|         { | ||||
|             checkFile = $"{matchingFile[0]}{matchingFile.Substring(parentDirectoryLength + numberLength + 1)}"; | ||||
|             pre = new(matchingFile, checkFile); | ||||
|             results.Add(pre); | ||||
|         } | ||||
|         return results.AsReadOnly(); | ||||
|     } | ||||
|  | ||||
|     private void MoveCollection(DateTime dateTime, ProcessDataStandardFormat? processDataStandardFormat, ReadOnlyCollection<PreWith> preWithCollection) | ||||
|     { | ||||
|         ReadOnlyCollection<Post> postCollection = GetPostCollection(dateTime, processDataStandardFormat, preWithCollection); | ||||
|         if (postCollection.Count != 0) | ||||
|         { | ||||
|             Thread.Sleep(500); | ||||
|             StringBuilder stringBuilder = new(); | ||||
|             foreach (Post post in postCollection) | ||||
|             { | ||||
|                 if (File.Exists(post.ErrFile)) | ||||
|                     _ = stringBuilder.AppendLine(File.ReadAllText(post.ErrFile)); | ||||
|                 if (File.Exists(post.CheckFile)) | ||||
|                     _ = stringBuilder.AppendLine($"<{post.CheckFile}> was not consumed by the end!"); | ||||
|             } | ||||
|             if (stringBuilder.Length > 0) | ||||
|                 throw new Exception(stringBuilder.ToString()); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private ReadOnlyCollection<Post> GetPostCollection(DateTime dateTime, ProcessDataStandardFormat? processDataStandardFormat, ReadOnlyCollection<PreWith> preWithCollection) | ||||
|     { | ||||
|         List<Post> results = new(); | ||||
|         Post post; | ||||
|         long preWait; | ||||
|         foreach (PreWith preWith in preWithCollection) | ||||
|         { | ||||
|             if (processDataStandardFormat is null) | ||||
|                 File.Move(preWith.MatchingFile, preWith.CheckFile); | ||||
|             else | ||||
|             { | ||||
|                 ProcessDataStandardFormat.Write(preWith.CheckFile, processDataStandardFormat); | ||||
|                 File.Delete(preWith.MatchingFile); | ||||
|             } | ||||
|             if (Directory.Exists(preWith.NoWaitDirectory)) | ||||
|             { | ||||
|                 post = new(preWith.CheckFile, preWith.ErrFile); | ||||
|                 results.Add(post); | ||||
|                 continue; | ||||
|             } | ||||
|             if (_FileConnectorConfiguration?.FileHandleWaitTime is null) | ||||
|                 preWait = DateTime.Now.AddMilliseconds(1234).Ticks; | ||||
|             else | ||||
|                 preWait = DateTime.Now.AddMilliseconds(_FileConnectorConfiguration.FileHandleWaitTime.Value).Ticks; | ||||
|             for (short i = 0; i < short.MaxValue; i++) | ||||
|             { | ||||
|                 if (DateTime.Now.Ticks > preWait) | ||||
|                     break; | ||||
|                 Thread.Sleep(500); | ||||
|             } | ||||
|             for (int i = 0; i < int.MaxValue; i++) | ||||
|             { | ||||
|                 if (File.Exists(preWith.ErrFile)) | ||||
|                     throw new Exception(File.ReadAllText(preWith.ErrFile)); | ||||
|                 if (!File.Exists(preWith.CheckFile)) | ||||
|                     break; | ||||
|                 if (new TimeSpan(DateTime.Now.Ticks - dateTime.Ticks).TotalSeconds > _BreakAfterSeconds) | ||||
|                     throw new Exception($"Not all files were consumed after {_BreakAfterSeconds} second(s)!"); | ||||
|                 Thread.Sleep(500); | ||||
|             } | ||||
|         } | ||||
|         return results.AsReadOnly(); | ||||
|     } | ||||
|  | ||||
|     private Tuple<string, Test[], JsonElement[], List<FileInfo>> GetExtractResult(string reportFullPath, DateTime dateTime) | ||||
|     { | ||||
|         Tuple<string, Test[], JsonElement[], List<FileInfo>> results = new(string.Empty, Array.Empty<Test>(), Array.Empty<JsonElement>(), new List<FileInfo>()); | ||||
|         ProcessDataStandardFormat? processDataStandardFormat = ProcessDataStandardFormat.GetProcessDataStandardFormat(reportFullPath, _ProcessDataStandardFormatMapping); | ||||
|         if (processDataStandardFormat is not null) | ||||
|             _Logistics = new Logistics(reportFullPath, processDataStandardFormat); | ||||
|         else | ||||
|         { | ||||
|             processDataStandardFormat = ProcessDataStandardFormat.GetProcessDataStandardFormat(reportFullPath); | ||||
|             _Logistics = new Logistics(reportFullPath, processDataStandardFormat); | ||||
|             processDataStandardFormat = null; | ||||
|         } | ||||
|         SetFileParameterLotIDToLogisticsMID(); | ||||
|         int numberLength = 2; | ||||
|         long ticks = dateTime.Ticks; | ||||
|         string parentParentDirectory = GetParentParent(reportFullPath); | ||||
|         ReadOnlyCollection<string> searchDirectories = GetSearchDirectories(numberLength, parentParentDirectory); | ||||
|         ReadOnlyCollection<string> matchingFiles = GetMatchingFiles(ticks, reportFullPath, searchDirectories); | ||||
|         if (matchingFiles.Count != searchDirectories.Count) | ||||
|             throw new Exception($"Didn't find all files after {_BreakAfterSeconds} second(s)!"); | ||||
|         try | ||||
|         { CreatePointerFile(numberLength, parentParentDirectory, matchingFiles); } | ||||
|         catch (Exception) { } | ||||
|         ReadOnlyCollection<Pre> preCollection = GetPreCollection(numberLength, parentParentDirectory, matchingFiles); | ||||
|         ReadOnlyCollection<PreWith> preWithCollection = GetPreWithCollection(preCollection); | ||||
|         MoveCollection(dateTime, processDataStandardFormat, preWithCollection); | ||||
|         return results; | ||||
|     } | ||||
|  | ||||
|     private List<string> GetMatchingFiles(long ticks, string reportFullPath, List<string> searchDirectories) | ||||
|     private ReadOnlyCollection<string> GetMatchingFiles(long ticks, string reportFullPath, ReadOnlyCollection<string> searchDirectories) | ||||
|     { | ||||
|         List<string> results = new(); | ||||
|         string[] found; | ||||
| @ -137,129 +386,7 @@ public class FileRead : Shared.FileRead, IFileRead | ||||
|                     break; | ||||
|             } | ||||
|         } | ||||
|         return results; | ||||
|     } | ||||
|  | ||||
|     private static List<(string matchingFile, string checkFile)> GetCollection(int numberLength, string parentDirectory, List<string> matchingFiles) | ||||
|     { | ||||
|         List<(string matchingFile, string checkFile)> results = new(); | ||||
|         string checkFile; | ||||
|         int parentDirectoryLength = parentDirectory.Length; | ||||
|         foreach (string matchingFile in matchingFiles) | ||||
|         { | ||||
|             checkFile = $"{matchingFile[0]}{matchingFile.Substring(parentDirectoryLength + numberLength + 1)}"; | ||||
|             results.Add(new(matchingFile, checkFile)); | ||||
|         } | ||||
|         return results; | ||||
|     } | ||||
|  | ||||
|     private static List<(string, string, string, string, string)> GetCollection(List<(string matchingFile, string checkFile)> collection) | ||||
|     { | ||||
|         List<(string, string, string, string, string)> results = new(); | ||||
|         string errFile; | ||||
|         string checkDirectory; | ||||
|         string noWaitDirectory; | ||||
|         foreach ((string matchingFile, string checkFile) in collection) | ||||
|         { | ||||
|             errFile = string.Concat(checkFile, ".err"); | ||||
|             checkDirectory = Path.GetDirectoryName(checkFile); | ||||
|             if (!Directory.Exists(checkDirectory)) | ||||
|                 _ = Directory.CreateDirectory(checkDirectory); | ||||
|             noWaitDirectory = Path.Combine(checkDirectory, "NoWaitDirectory"); | ||||
|             results.Add(new(matchingFile, checkFile, errFile, checkDirectory, noWaitDirectory)); | ||||
|         } | ||||
|         return results; | ||||
|     } | ||||
|  | ||||
|     private void MoveCollection(DateTime dateTime, List<(string matchingFile, string checkFile)> collection) | ||||
|     { | ||||
|         long preWait; | ||||
|         List<(string checkFile, string errFile)> postCollection = new(); | ||||
|         foreach ((string matchingFile, string checkFile, string errFile, string checkDirectory, string noWaitDirectory) in GetCollection(collection)) | ||||
|         { | ||||
|             File.Move(matchingFile, checkFile); | ||||
|             if (Directory.Exists(noWaitDirectory)) | ||||
|             { | ||||
|                 postCollection.Add(new(checkFile, errFile)); | ||||
|                 continue; | ||||
|             } | ||||
|             if (_FileConnectorConfiguration?.FileHandleWaitTime is null) | ||||
|                 preWait = DateTime.Now.AddMilliseconds(1234).Ticks; | ||||
|             else | ||||
|                 preWait = DateTime.Now.AddMilliseconds(_FileConnectorConfiguration.FileHandleWaitTime.Value).Ticks; | ||||
|             for (short i = 0; i < short.MaxValue; i++) | ||||
|             { | ||||
|                 if (DateTime.Now.Ticks > preWait) | ||||
|                     break; | ||||
|                 Thread.Sleep(500); | ||||
|             } | ||||
|             for (int i = 0; i < int.MaxValue; i++) | ||||
|             { | ||||
|                 if (File.Exists(errFile)) | ||||
|                     throw new Exception(File.ReadAllText(errFile)); | ||||
|                 if (!File.Exists(checkFile)) | ||||
|                     break; | ||||
|                 if (new TimeSpan(DateTime.Now.Ticks - dateTime.Ticks).TotalSeconds > _BreakAfterSeconds) | ||||
|                     throw new Exception($"Not all files were consumed after {_BreakAfterSeconds} second(s)!"); | ||||
|                 Thread.Sleep(500); | ||||
|             } | ||||
|         } | ||||
|         if (postCollection.Count != 0) | ||||
|         { | ||||
|             Thread.Sleep(500); | ||||
|             StringBuilder stringBuilder = new(); | ||||
|             foreach ((string checkFile, string errFile) in postCollection) | ||||
|             { | ||||
|                 if (File.Exists(errFile)) | ||||
|                     _ = stringBuilder.AppendLine(File.ReadAllText(errFile)); | ||||
|                 if (File.Exists(checkFile)) | ||||
|                     _ = stringBuilder.AppendLine($"<{checkFile}> was not consumed by the end!"); | ||||
|             } | ||||
|             if (stringBuilder.Length > 0) | ||||
|                 throw new Exception(stringBuilder.ToString()); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private static void CreatePointerFile(int numberLength, string parentDirectory, List<string> matchingFiles) | ||||
|     { | ||||
| #nullable enable | ||||
|         string checkFile; | ||||
|         string writeFile; | ||||
|         string? directoryName; | ||||
|         int parentDirectoryLength = parentDirectory.Length; | ||||
|         foreach (string matchingFile in matchingFiles) | ||||
|         { | ||||
|             directoryName = Path.GetDirectoryName(matchingFile); | ||||
|             if (directoryName is null) | ||||
|                 continue; | ||||
|             checkFile = $"{matchingFile[0]}{directoryName.Substring(parentDirectoryLength + numberLength + 1)}"; | ||||
|             writeFile = Path.Combine(parentDirectory, $"{directoryName.Substring(parentDirectory.Length + 1, numberLength)}.txt"); | ||||
|             if (File.Exists(writeFile)) | ||||
|                 continue; | ||||
|             File.AppendAllLines(writeFile, new string[] { parentDirectory, matchingFile, directoryName, checkFile }); | ||||
|         } | ||||
| #nullable disable | ||||
|     } | ||||
|  | ||||
|     private Tuple<string, Test[], JsonElement[], List<FileInfo>> GetExtractResult(string reportFullPath, DateTime dateTime) | ||||
|     { | ||||
|         Tuple<string, Test[], JsonElement[], List<FileInfo>> results = new(string.Empty, null, null, new List<FileInfo>()); | ||||
|         Tuple<string, string[], string[]> pdsf = ProcessDataStandardFormat.GetLogisticsColumnsAndBody(reportFullPath); | ||||
|         _Logistics = new Logistics(reportFullPath, pdsf.Item1); | ||||
|         SetFileParameterLotIDToLogisticsMID(); | ||||
|         int numberLength = 2; | ||||
|         long ticks = dateTime.Ticks; | ||||
|         string parentParentDirectory = GetParentParent(reportFullPath); | ||||
|         List<string> searchDirectories = GetSearchDirectories(numberLength, parentParentDirectory); | ||||
|         List<string> matchingFiles = GetMatchingFiles(ticks, reportFullPath, searchDirectories); | ||||
|         if (matchingFiles.Count != searchDirectories.Count) | ||||
|             throw new Exception($"Didn't find all files after {_BreakAfterSeconds} second(s)!"); | ||||
|         try | ||||
|         { CreatePointerFile(numberLength, parentParentDirectory, matchingFiles); } | ||||
|         catch (Exception) { } | ||||
|         List<(string matchingFile, string checkFile)> collection = GetCollection(numberLength, parentParentDirectory, matchingFiles); | ||||
|         MoveCollection(dateTime, collection); | ||||
|         return results; | ||||
|         return results.AsReadOnly(); | ||||
|     } | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user