Duplicator and now deleting if not sending to EDA
This commit is contained in:
		| @ -1,12 +1,16 @@ | ||||
| using Adaptation.Eaf.Management.ConfigurationData.CellAutomation; | ||||
| using Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration; | ||||
| using Adaptation.Shared; | ||||
| using Adaptation.Shared.Deposition; | ||||
| using Adaptation.Shared.Duplicator; | ||||
| using Adaptation.Shared.Methods; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Diagnostics; | ||||
| using System.Globalization; | ||||
| using System.IO; | ||||
| using System.Linq; | ||||
| using System.Reflection; | ||||
| using System.Text.Json; | ||||
| using System.Text.Json.Serialization; | ||||
| using System.Threading; | ||||
| @ -17,9 +21,13 @@ public class FileRead : Shared.FileRead, IFileRead | ||||
| { | ||||
|  | ||||
|     private readonly bool _IsXToAPC; | ||||
|     private readonly bool _IsXToSPaCe; | ||||
|     private readonly bool _IsXToSPaCeVillach; | ||||
|     private readonly bool _IsXToIQSSi; | ||||
|     private readonly string _MemoryPath; | ||||
|     private readonly bool _IsXToOpenInsight; | ||||
|     private readonly bool _IsXToOpenInsightMetrologyViewer; | ||||
|     private readonly Dictionary<string, string> _CellNames; | ||||
|     private readonly bool _IsXToOpenInsightMetrologyViewerAttachments; | ||||
|     private readonly string _OpenInsightCommonGatewayInterfaceContacts; | ||||
|  | ||||
|     public FileRead(ISMTP smtp, Dictionary<string, string> fileParameter, string cellInstanceName, string cellInstanceConnectionName, FileConnectorConfiguration fileConnectorConfiguration, string equipmentTypeName, string parameterizedModelObjectDefinitionType, IList<ModelObjectParameterDefinition> modelObjectParameters, string equipmentDictionaryName, Dictionary<string, List<long>> dummyRuns, bool useCyclicalForDescription, bool isEAFHosted) : | ||||
|         base(new Description(), false, smtp, fileParameter, cellInstanceName, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, useCyclicalForDescription, isEAFHosted) | ||||
| @ -35,9 +43,13 @@ public class FileRead : Shared.FileRead, IFileRead | ||||
|             throw new Exception(cellInstanceConnectionName); | ||||
|         _IsXToAPC = _Hyphens == (int)Hyphen.IsXToAPC; | ||||
|         _CellNames = new Dictionary<string, string>(); | ||||
|         _IsXToSPaCe = _Hyphens == (int)Hyphen.IsXToSPaCe; | ||||
|         _IsXToSPaCeVillach = _Hyphens == (int)Hyphen.IsXToSPaCeVillach; | ||||
|         _IsXToIQSSi = _Hyphens == (int)Hyphen.IsXToIQSSi; | ||||
|         _IsXToOpenInsight = _Hyphens == (int)Hyphen.IsXToOpenInsight; | ||||
|         _IsXToOpenInsightMetrologyViewer = _Hyphens == (int)Hyphen.IsXToOpenInsightMetrologyViewer; | ||||
|         _MemoryPath = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "Path.Memory"); | ||||
|         _IsXToOpenInsightMetrologyViewerAttachments = _Hyphens == (int)Hyphen.IsXToOpenInsightMetrologyViewerAttachments; | ||||
|         ModelObjectParameterDefinition[] cellInstanceCollection = GetProperties(cellInstanceConnectionName, modelObjectParameters, "CellInstance.", ".Path"); | ||||
|         _OpenInsightCommonGatewayInterfaceContacts = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "OpenInsight.CommonGatewayInterface.Contacts"); | ||||
|         foreach (ModelObjectParameterDefinition modelObjectParameterDefinition in cellInstanceCollection) | ||||
|             _CellNames.Add(modelObjectParameterDefinition.Name.Split('.')[1], modelObjectParameterDefinition.Value); | ||||
|     } | ||||
| @ -113,16 +125,16 @@ public class FileRead : Shared.FileRead, IFileRead | ||||
|             throw new Exception(); | ||||
|     } | ||||
|  | ||||
|     protected static List<Description> GetDescriptions(JsonElement[] jsonElements) | ||||
|     protected static List<jpeg.Description> GetDescriptions(JsonElement[] jsonElements) | ||||
|     { | ||||
|         List<Description> results = new(); | ||||
|         Description description; | ||||
|         List<jpeg.Description> results = new(); | ||||
|         jpeg.Description description; | ||||
|         JsonSerializerOptions jsonSerializerOptions = new() { NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString }; | ||||
|         foreach (JsonElement jsonElement in jsonElements) | ||||
|         { | ||||
|             if (jsonElement.ValueKind != JsonValueKind.Object) | ||||
|                 throw new Exception(); | ||||
|             description = JsonSerializer.Deserialize<Description>(jsonElement.ToString(), jsonSerializerOptions); | ||||
|             description = JsonSerializer.Deserialize<jpeg.Description>(jsonElement.ToString(), jsonSerializerOptions); | ||||
|             results.Add(description); | ||||
|         } | ||||
|         return results; | ||||
| @ -136,7 +148,7 @@ public class FileRead : Shared.FileRead, IFileRead | ||||
|         _Logistics = new Logistics(reportFullPath, pdsf.Item1); | ||||
|         SetFileParameterLotIDToLogisticsMID(); | ||||
|         JsonElement[] jsonElements = ProcessDataStandardFormat.GetArray(pdsf); | ||||
|         List<Description> descriptions = GetDescriptions(jsonElements); | ||||
|         List<jpeg.Description> descriptions = GetDescriptions(jsonElements); | ||||
|         Tuple<Test[], Dictionary<Test, List<Shared.Properties.IDescription>>> tuple = GetTuple(this, from l in descriptions select (Shared.Properties.IDescription)l, extra: false); | ||||
|         results = new Tuple<string, Test[], JsonElement[], List<FileInfo>>(pdsf.Item1, tuple.Item1, jsonElements, new List<FileInfo>()); | ||||
|         bool isDummyRun = _DummyRuns.Any() && _DummyRuns.ContainsKey(_Logistics.JobID) && _DummyRuns[_Logistics.JobID].Any() && (from l in _DummyRuns[_Logistics.JobID] where l == _Logistics.Sequence select 1).Any(); | ||||
| @ -146,10 +158,22 @@ public class FileRead : Shared.FileRead, IFileRead | ||||
|             { File.SetLastWriteTime(reportFullPath, dateTime); } | ||||
|             catch (Exception) { } | ||||
|         } | ||||
|         string[] segments = Path.GetFileNameWithoutExtension(reportFullPath).Split('_'); | ||||
|         if (_IsXToIQSSi) | ||||
|             duplicateDirectory = string.Concat(_FileConnectorConfiguration.TargetFileLocation, @"\All"); | ||||
|         else if (!_IsXToOpenInsight) | ||||
|             duplicateDirectory = string.Concat(_FileConnectorConfiguration.TargetFileLocation, @"\", segments[0]); | ||||
|         else | ||||
|             duplicateDirectory = string.Concat(Path.GetDirectoryName(Path.GetDirectoryName(_FileConnectorConfiguration.TargetFileLocation)), @"\Data"); | ||||
|         if (segments.Length > 2) | ||||
|             duplicateDirectory = string.Concat(duplicateDirectory, @"-", segments[2]); | ||||
|         if (!Directory.Exists(duplicateDirectory)) | ||||
|             _ = Directory.CreateDirectory(duplicateDirectory); | ||||
|         if (isDummyRun || _FileConnectorConfiguration.FileScanningIntervalInSeconds > 0) | ||||
|         { | ||||
|             if (!Directory.Exists(duplicateDirectory)) | ||||
|                 _ = Directory.CreateDirectory(duplicateDirectory); | ||||
|             string successDirectory; | ||||
|             string[] segments = Path.GetFileNameWithoutExtension(reportFullPath).Split('_'); | ||||
|             if (!_IsXToAPC) | ||||
|                 successDirectory = string.Empty; | ||||
|             else | ||||
| @ -158,31 +182,67 @@ public class FileRead : Shared.FileRead, IFileRead | ||||
|                 if (!Directory.Exists(successDirectory)) | ||||
|                     _ = Directory.CreateDirectory(successDirectory); | ||||
|             } | ||||
|             if (_IsXToSPaCe || _IsXToSPaCeVillach) | ||||
|                 duplicateDirectory = _FileConnectorConfiguration.TargetFileLocation; | ||||
|             else | ||||
|                 duplicateDirectory = string.Concat(_FileConnectorConfiguration.TargetFileLocation, @"\", segments[0]); | ||||
|             if (segments.Length > 2) | ||||
|                 duplicateDirectory = string.Concat(duplicateDirectory, @"-", segments[2]); | ||||
|             if (!Directory.Exists(duplicateDirectory)) | ||||
|                 _ = Directory.CreateDirectory(duplicateDirectory); | ||||
|             List<Tuple<Shared.Properties.IScopeInfo, string>> tuples = new(); | ||||
|             string duplicateFile = string.Concat(duplicateDirectory, @"\", Path.GetFileName(reportFullPath)); | ||||
|             if (isDummyRun) | ||||
|             string weekOfYear = _Calendar.GetWeekOfYear(_Logistics.DateTimeFromSequence, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00"); | ||||
|             string weekDirectory = string.Concat(_Logistics.DateTimeFromSequence.ToString("yyyy"), "_Week_", weekOfYear, @"\", _Logistics.DateTimeFromSequence.ToString("yyyy-MM-dd")); | ||||
|             string logisticsSequenceMemoryDirectory = string.Concat(_MemoryPath, @"\", _EquipmentType, @"\Source\", weekDirectory, @"\", _Logistics.Sequence); | ||||
|             if (!Directory.Exists(logisticsSequenceMemoryDirectory)) | ||||
|                 _ = Directory.CreateDirectory(logisticsSequenceMemoryDirectory); | ||||
|             if (_IsXToAPC) | ||||
|             { | ||||
|                 foreach (KeyValuePair<Test, List<Shared.Properties.IDescription>> keyValuePair in tuple.Item2) | ||||
|                 if (!isDummyRun && _IsEAFHosted) | ||||
|                     File.Copy(reportFullPath, duplicateFile, overwrite: true); | ||||
|             } | ||||
|             if (!isDummyRun && _IsEAFHosted) | ||||
|                 WaitForFileConsumption(_FileConnectorConfiguration.SourceDirectoryCloaking, _Logistics, dateTime, successDirectory, duplicateDirectory, duplicateFile, tuples); | ||||
|             else | ||||
|             { | ||||
|                 long breakAfter = DateTime.Now.AddSeconds(_FileConnectorConfiguration.ConnectionRetryInterval.Value).Ticks; | ||||
|                 for (short i = 0; i < short.MaxValue; i++) | ||||
|                 if (_IsXToOpenInsightMetrologyViewer) | ||||
|                     _Log.Debug("Not sure if this data should post to OI Metrology Viewer?"); | ||||
|                 else if (!_IsXToOpenInsight) | ||||
|                     throw new Exception($"Only {nameof(_IsXToOpenInsight)} is codded!"); | ||||
|                 else if (_IsXToOpenInsight) | ||||
|                 { | ||||
|                     if (!_IsEAFHosted || DateTime.Now.Ticks > breakAfter) | ||||
|                         break; | ||||
|                     Thread.Sleep(500); | ||||
|                     if (!isDummyRun && _IsEAFHosted) | ||||
|                         ProcessData.PostOpenInsightCommonGatewayInterfaceContacts(this, _Logistics, _OpenInsightCommonGatewayInterfaceContacts, dateTime, logisticsSequenceMemoryDirectory, descriptions); | ||||
|                 } | ||||
|                 else | ||||
|                     throw new Exception(); | ||||
|             } | ||||
|         } | ||||
|         if (_IsXToOpenInsightMetrologyViewerAttachments) | ||||
|         { | ||||
|             string destinationDirectory; | ||||
|             //string destinationDirectory = WriteScopeInfo(_ProgressPath, _Logistics, dateTime, duplicateDirectory, tuples); | ||||
|             FileInfo fileInfo = new(reportFullPath); | ||||
|             string logisticsSequence = _Logistics.Sequence.ToString(); | ||||
|             if (fileInfo.Exists && fileInfo.LastWriteTime < fileInfo.CreationTime) | ||||
|                 File.SetLastWriteTime(reportFullPath, fileInfo.CreationTime); | ||||
|             string jobIdDirectory = string.Concat(Path.GetDirectoryName(Path.GetDirectoryName(_FileConnectorConfiguration.TargetFileLocation)), @"\", _Logistics.JobID); | ||||
|             if (!Directory.Exists(jobIdDirectory)) | ||||
|                 _ = Directory.CreateDirectory(jobIdDirectory); | ||||
|             string[] matchDirectories; | ||||
|             if (!_IsEAFHosted) | ||||
|                 matchDirectories = new string[] { Path.GetDirectoryName(Path.GetDirectoryName(reportFullPath)) }; | ||||
|             else | ||||
|                 matchDirectories = Directory.GetDirectories(jobIdDirectory, string.Concat(_Logistics.MID, '*', logisticsSequence, '*'), SearchOption.TopDirectoryOnly); | ||||
|             if ((matchDirectories is null) || matchDirectories.Length != 1) | ||||
|                 throw new Exception("Didn't find directory by logistics sequence"); | ||||
|             destinationDirectory = matchDirectories[0]; | ||||
|             if (isDummyRun) | ||||
|                 Shared0607(reportFullPath, duplicateDirectory, logisticsSequence, destinationDirectory); | ||||
|             else | ||||
|             { | ||||
|                 var wsRequest = new { _Logistics, descriptions }; | ||||
|                 JsonSerializerOptions jsonSerializerOptions = new() { WriteIndented = true }; | ||||
|                 string json = JsonSerializer.Serialize(wsRequest, wsRequest.GetType(), jsonSerializerOptions); | ||||
|                 if (_IsEAFHosted) | ||||
|                     Shared1277(reportFullPath, destinationDirectory, logisticsSequence, jobIdDirectory, json); | ||||
|                 else | ||||
|                 { | ||||
|                     string jsonFileName = Path.ChangeExtension(reportFullPath, ".json"); | ||||
|                     string historicalText = File.ReadAllText(jsonFileName); | ||||
|                     if (json != historicalText) | ||||
|                         throw new Exception("File doesn't match historical!"); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @ -2,12 +2,14 @@ | ||||
|  | ||||
| public enum Hyphen | ||||
| { | ||||
|     IsXToIQS, | ||||
|     IsXToOpenInsightMetrologyViewer, | ||||
|     IsXToIQSSi, | ||||
|     IsXToOpenInsight, | ||||
|     IsXToOpenInsightMetrologyViewerAttachments, | ||||
|     IsXToAPC, | ||||
|     IsXToSPaCe, | ||||
|     IsXToSPaCeVillach, | ||||
|     IsXToArchive, | ||||
|     IsArchive, | ||||
|     IsDummy, | ||||
|     IsNaEDA | ||||
| } | ||||
							
								
								
									
										74
									
								
								Adaptation/FileHandlers/DEP08SIASM/ProcessData.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								Adaptation/FileHandlers/DEP08SIASM/ProcessData.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,74 @@ | ||||
| using Adaptation.Shared; | ||||
| using Adaptation.Shared.Properties; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Text; | ||||
|  | ||||
| namespace Adaptation.FileHandlers.DEP08SIASM; | ||||
|  | ||||
| public class ProcessData | ||||
| { | ||||
|  | ||||
|     internal static List<Tuple<int, Enum, string>> HyphenTuples => new() | ||||
|     { | ||||
|         new Tuple<int, Enum, string>(0, Hyphen.IsNaEDA, @"\EC_EDA\Staging\Traces\~\Source"), | ||||
|         new Tuple<int, Enum, string>(15, Hyphen.IsXToOpenInsightMetrologyViewer, @"\EC_EAFLog\TracesMES\~\Source"), | ||||
|         new Tuple<int, Enum, string>(-361, Hyphen.IsXToIQSSi, @"\EC_SPC_Si\Traces\~\PollPath"), | ||||
|         new Tuple<int, Enum, string>(362, Hyphen.IsXToOpenInsight, @"\\messa01ec.ec.local\APPS\Metrology\~\Source"), | ||||
|         new Tuple<int, Enum, string>(-363, Hyphen.IsXToOpenInsightMetrologyViewerAttachments, @"\EC_Characterization_Si\In Process\~\Source"), | ||||
|         new Tuple<int, Enum, string>(-3604, Hyphen.IsXToAPC, @"\EC_APC\Staging\Traces\~\PollPath"), | ||||
|         new Tuple<int, Enum, string>(-365, Hyphen.IsXToSPaCe, @"\EC_SPC_Si\Traces\~\Source"), | ||||
|         new Tuple<int, Enum, string>(1806, Hyphen.IsXToArchive, @"\EC_EAFLog\TracesArchive\~\Source"), | ||||
|         new Tuple<int, Enum, string>(367, Hyphen.IsArchive, @"\EC_Characterization_Si\Processed") | ||||
|         // new Tuple<int, Enum, string>(1808, Hyphen.IsDummy | ||||
|     }; | ||||
|  | ||||
|     internal static string GetLines(IFileRead fileRead, Logistics logistics, List<jpeg.Description> descriptions) | ||||
|     { | ||||
|         StringBuilder result = new(); | ||||
|         if (fileRead is null) | ||||
|         { } | ||||
|         if (logistics is null) | ||||
|         { } | ||||
|         if (descriptions is null) | ||||
|         { } | ||||
|         return result.ToString(); | ||||
|     } | ||||
|  | ||||
|     internal static void PostOpenInsightMetrologyViewerAttachments(IFileRead fileRead, Logistics logistics, string openInsightMetrologyViewerAPI, DateTime dateTime, string logisticsSequenceMemoryDirectory, List<jpeg.Description> descriptions, string matchDirectory) | ||||
|     { | ||||
|         if (fileRead is null) | ||||
|         { } | ||||
|         if (logistics is null) | ||||
|         { } | ||||
|         if (openInsightMetrologyViewerAPI is null) | ||||
|         { } | ||||
|         if (dateTime == DateTime.MinValue) | ||||
|         { } | ||||
|         if (logisticsSequenceMemoryDirectory is null) | ||||
|         { } | ||||
|         if (descriptions is null) | ||||
|         { } | ||||
|         if (matchDirectory is null) | ||||
|         { } | ||||
|         //Not used | ||||
|     } | ||||
|  | ||||
|     internal static void PostOpenInsightCommonGatewayInterfaceContacts(IFileRead fileRead, Logistics logistics, string openInsightMetrologyViewerAPI, DateTime dateTime, string logisticsSequenceMemoryDirectory, List<jpeg.Description> descriptions) | ||||
|     { | ||||
|         if (fileRead is null) | ||||
|         { } | ||||
|         if (logistics is null) | ||||
|         { } | ||||
|         if (openInsightMetrologyViewerAPI is null) | ||||
|         { } | ||||
|         if (dateTime == DateTime.MinValue) | ||||
|         { } | ||||
|         if (logisticsSequenceMemoryDirectory is null) | ||||
|         { } | ||||
|         if (descriptions is null) | ||||
|         { } | ||||
|         //Not used | ||||
|     } | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user