WS Result bug fix, Nuget bump, PSN, Reactor,

Extra RDS rule, OpenInsightApi and testRunTitle
This commit is contained in:
2023-03-07 08:52:07 -07:00
parent 52c6ef93f1
commit bb857211e9
14 changed files with 145 additions and 23 deletions

View File

@ -6,6 +6,7 @@ using Adaptation.Shared.Methods;
using Adaptation.Shared.Metrology;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
@ -18,6 +19,8 @@ public class FileRead : Shared.FileRead, IFileRead
private readonly string _IqsConnectionString;
private readonly string _OpenInsightFilePattern;
private readonly string _OpenInsightApiECDirectory;
private readonly string _OpenInsightApiIFXDirectory;
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, Dictionary<long, List<string>> staticRuns, bool useCyclicalForDescription, bool isEAFHosted) :
base(new Description(), false, smtp, fileParameter, cellInstanceName, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, staticRuns, useCyclicalForDescription, isEAFHosted)
@ -31,6 +34,8 @@ public class FileRead : Shared.FileRead, IFileRead
throw new Exception(cellInstanceConnectionName);
if (!_IsDuplicator)
throw new Exception(cellInstanceConnectionName);
_OpenInsightApiIFXDirectory = @"\\messdv002.na.infineon.com\Candela\Archive\API";
_OpenInsightApiECDirectory = @"\\messv02ecc1.ec.local\EC_Metrology_Si\Archive\API";
_IqsConnectionString = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "IQS.ConnectionString");
_OpenInsightFilePattern = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "OpenInsight.FilePattern");
}
@ -148,7 +153,7 @@ public class FileRead : Shared.FileRead, IFileRead
return results.ToString();
}
private void SaveOpenInsightFile(string reportFullPath, DateTime dateTime, List<txt.Description> descriptions, Test[] tests)
private void SaveOpenInsightFile(string reportFullPath, DateTime dateTime, string logistics, List<txt.Description> descriptions, Test[] tests)
{
bool isDummyRun = false;
List<(Shared.Properties.IScopeInfo, string)> collection = new();
@ -179,6 +184,8 @@ public class FileRead : Shared.FileRead, IFileRead
collection.Add(new(new ScopeInfo(tests[0], $"{subGroupId.Value} {_OpenInsightFilePattern}"), lines));
else
collection.Add(new(new ScopeInfo(tests[0], $"{subGroupId.Value} E{count.Value} {_OpenInsightFilePattern}"), lines));
string weekOfYear = _Calendar.GetWeekOfYear(_Logistics.DateTimeFromSequence, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
FromIQS.Save(_OpenInsightApiECDirectory, _OpenInsightApiIFXDirectory, _Logistics, reportFullPath, logistics, descriptions.First(), lines, subGroupId, weekOfYear);
}
}
if (_IsEAFHosted && _FileConnectorConfiguration.FileScanningIntervalInSeconds > 0)
@ -195,7 +202,7 @@ public class FileRead : Shared.FileRead, IFileRead
List<txt.Description> descriptions = txt.ProcessData.GetDescriptions(jsonElements);
Test[] tests = (from l in descriptions select (Test)l.Test).ToArray();
if (_IsEAFHosted && _FileConnectorConfiguration.FileScanningIntervalInSeconds > 0)
SaveOpenInsightFile(reportFullPath, dateTime, descriptions, tests);
SaveOpenInsightFile(reportFullPath, dateTime, pdsf.Item1, descriptions, tests);
results = new Tuple<string, Test[], JsonElement[], List<FileInfo>>(pdsf.Item1, tests, jsonElements, new List<FileInfo>());
return results;
}

View File

@ -3,6 +3,7 @@ using System;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
@ -127,6 +128,82 @@ public class FromIQS
return new(result, count, commandText);
}
private static string GetJson(Logistics logistics, string logisticLines, txt.Description description)
{
string result;
StringBuilder stringBuilder = new();
var @object = new
{
description.MesEntity,
description.Employee,
description.Layer,
description.PSN,
description.RDS,
description.Reactor,
description.Recipe,
description.Zone,
logistics.DateTimeFromSequence.Ticks
};
string[] pair;
string[] segments;
foreach (string line in logisticLines.Split(new string[] { Environment.NewLine }, StringSplitOptions.None))
{
segments = line.Split('\t');
if (segments.Length < 2)
continue;
segments = segments[1].Split(';');
_ = stringBuilder.Append('{');
foreach (string segment in segments)
{
pair = segment.Split('=');
if (pair.Length != 2 || pair[0].Length < 3)
continue;
_ = stringBuilder.Append('"').Append(pair[0].Substring(2)).Append('"').Append(':').Append('"').Append(pair[1]).Append('"').Append(',');
}
if (stringBuilder.Length > 0)
_ = stringBuilder.Remove(stringBuilder.Length - 1, 1);
_ = stringBuilder.Append('}').Append(',');
}
if (stringBuilder.Length > 0)
_ = stringBuilder.Remove(stringBuilder.Length - 1, 1);
_ = stringBuilder.Append(']').Append('}');
_ = stringBuilder.Insert(0, ",\"Logistics\":[");
string json = JsonSerializer.Serialize(@object);
_ = stringBuilder.Insert(0, json.Substring(0, json.Length - 1));
JsonElement? jsonElement = JsonSerializer.Deserialize<JsonElement>(stringBuilder.ToString());
result = jsonElement is null ? "{}" : JsonSerializer.Serialize(jsonElement, new JsonSerializerOptions { WriteIndented = true });
return result;
}
internal static void Save(string openInsightApiECDirectory, string openInsightApiIFXDirectory, Logistics logistics, string reportFullPath, string logisticLines, txt.Description description, string lines, long? subGroupId, string weekOfYear)
{
string fileName = Path.GetFileName(reportFullPath);
string json = GetJson(logistics, logisticLines, description);
string? ecPathRoot = Path.GetPathRoot(openInsightApiECDirectory);
string? ifxPathRoot = Path.GetPathRoot(openInsightApiIFXDirectory);
bool ecExists = ecPathRoot is not null && Directory.Exists(ecPathRoot);
bool ifxExists = ifxPathRoot is not null && Directory.Exists(ifxPathRoot);
string weekYear = $"{logistics.DateTimeFromSequence:yyyy}_Week_{weekOfYear}";
string ecDirectory = Path.Combine(openInsightApiECDirectory, weekYear, $"-{description.PSN}", $"-{description.Reactor}", $"-{description.RDS}", $"-{subGroupId}");
string ifxDirectory = Path.Combine(openInsightApiIFXDirectory, weekYear, $"-{description.PSN}", $"-{description.Reactor}", $"-{description.RDS}", $"-{subGroupId}");
if (ecExists && !Directory.Exists(ecDirectory))
_ = Directory.CreateDirectory(ecDirectory);
if (ifxExists && !Directory.Exists(ifxDirectory))
_ = Directory.CreateDirectory(ifxDirectory);
if (ecExists)
File.Copy(reportFullPath, Path.Combine(ecDirectory, fileName));
if (ifxExists)
File.Copy(reportFullPath, Path.Combine(ifxDirectory, fileName));
if (ecExists)
File.WriteAllText(Path.Combine(ecDirectory, $"{logistics.DateTimeFromSequence.Ticks}.txt"), lines);
if (ifxExists)
File.WriteAllText(Path.Combine(ifxDirectory, $"{logistics.DateTimeFromSequence.Ticks}.txt"), lines);
if (ecExists)
File.WriteAllText(Path.Combine(ecDirectory, $"{logistics.DateTimeFromSequence.Ticks}.json"), json);
if (ifxExists)
File.WriteAllText(Path.Combine(ifxDirectory, $"{logistics.DateTimeFromSequence.Ticks}.json"), json);
}
#nullable disable
}

View File

@ -85,11 +85,11 @@ public class ProcessData : IProcessData
return results;
}
private static (string, string) GetReactorAndRDS(string defaultReactor, string defaultRDS, string text, string formattedText, string[] segments)
private static (string, string) GetReactorAndRDS(string defaultReactor, string defaultRDS, string text, string formattedText, string[] segments, bool hasRDS)
{
string rds;
string reactor;
if (string.IsNullOrEmpty(text) || segments.Length == 0 || string.IsNullOrEmpty(formattedText))
if (string.IsNullOrEmpty(text) || segments.Length == 0 || string.IsNullOrEmpty(formattedText) || (segments.Length > 1 && !hasRDS))
reactor = defaultReactor;
else
reactor = segments[0];
@ -105,11 +105,11 @@ public class ProcessData : IProcessData
return new(reactor, rds);
}
private static (string, string) GetLayerAndPSN(string defaultLayer, string defaultPSN, string[] segments)
private static (string, string) GetLayerAndPSN(string defaultLayer, string defaultPSN, string[] segments, bool hasRDS)
{
string psn;
string layer;
if (segments.Length <= 2)
if (segments.Length <= 2 || (segments.Length > 1 && !hasRDS))
{
psn = defaultPSN;
layer = defaultLayer;
@ -193,8 +193,9 @@ public class ProcessData : IProcessData
title = title.Substring(2);
run = title;
string[] segments = title.Split('-');
(reactor, rds) = GetReactorAndRDS(defaultReactor, defaultRDS, text, title, segments);
(layer, psn) = GetLayerAndPSN(defaultLayer, defaultPSN, segments);
bool hasRDS = Regex.IsMatch(title, "[-]?[0-9]{5,}[-]?");
(reactor, rds) = GetReactorAndRDS(defaultReactor, defaultRDS, text, title, segments, hasRDS);
(layer, psn) = GetLayerAndPSN(defaultLayer, defaultPSN, segments, hasRDS);
zone = GetZone(segments);
employee = defaultEmployee;
}

View File

@ -242,11 +242,11 @@ public class ProcessData : IProcessData
return result;
}
private static (string, string) GetReactorAndRDS(string defaultReactor, string defaultRDS, string text, string formattedText, string[] segments)
private static (string, string) GetReactorAndRDS(string defaultReactor, string defaultRDS, string text, string formattedText, string[] segments, bool hasRDS)
{
string rds;
string reactor;
if (string.IsNullOrEmpty(text) || segments.Length == 0 || string.IsNullOrEmpty(formattedText))
if (string.IsNullOrEmpty(text) || segments.Length == 0 || string.IsNullOrEmpty(formattedText) || (segments.Length > 1 && !hasRDS))
reactor = defaultReactor;
else
reactor = segments[0];
@ -262,11 +262,11 @@ public class ProcessData : IProcessData
return new(reactor, rds);
}
private static (string, string) GetLayerAndPSN(string defaultLayer, string defaultPSN, string[] segments)
private static (string, string) GetLayerAndPSN(string defaultLayer, string defaultPSN, string[] segments, bool hasRDS)
{
string psn;
string layer;
if (segments.Length <= 2)
if (segments.Length <= 2 || (segments.Length > 1 && !hasRDS))
{
psn = defaultPSN;
layer = defaultLayer;
@ -352,8 +352,9 @@ public class ProcessData : IProcessData
title = title.Substring(2);
run = title;
string[] segments = title.Split('-');
(reactor, rds) = GetReactorAndRDS(defaultReactor, defaultRDS, text, title, segments);
(layer, psn) = GetLayerAndPSN(defaultLayer, defaultPSN, segments);
bool hasRDS = Regex.IsMatch(title, "[-]?[0-9]{5,}[-]?");
(reactor, rds) = GetReactorAndRDS(defaultReactor, defaultRDS, text, title, segments, hasRDS);
(layer, psn) = GetLayerAndPSN(defaultLayer, defaultPSN, segments, hasRDS);
zone = GetZone(segments);
employee = defaultEmployee;
}