946 lines
50 KiB
C#
946 lines
50 KiB
C#
using Adaptation.Shared;
|
|
using Adaptation.Shared.Metrology;
|
|
using Infineon.Yoda;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Xml;
|
|
|
|
namespace Adaptation.Si
|
|
{
|
|
|
|
internal class Transport
|
|
{
|
|
|
|
private static object _IfxTransport;
|
|
private static ConfigData _ConfigData;
|
|
private static Dictionary<string, List<Parameters>> _Parameters;
|
|
|
|
internal static void Initialize(ConfigData configData)
|
|
{
|
|
_IfxTransport = null;
|
|
_ConfigData = configData;
|
|
_Parameters = new Dictionary<string, List<Parameters>>();
|
|
}
|
|
|
|
internal static List<string> Setup(bool useSleep, bool setIfxTransport, bool setParameters)
|
|
{
|
|
List<string> results = new List<string>();
|
|
if (useSleep)
|
|
{
|
|
for (int i = 1; i < 50; i++)
|
|
Thread.Sleep(500);
|
|
}
|
|
if (setIfxTransport)
|
|
{
|
|
results.Add(string.Concat("IfxTransport Subject: ", _ConfigData.IfxSubject));
|
|
IfxDoc ifxDoc = new IfxDoc();
|
|
ifxDoc.Add(IfxConst.SUBJECT_PREFIX, _ConfigData.IfxSubjectPrefix);
|
|
ifxDoc.Add(IfxConst.IFX_CHANNEL, _ConfigData.IfxChannel);
|
|
ifxDoc.Add(IfxConst.IFX_CONFIGURATION_LOCATION, _ConfigData.IfxConfigurationLocation);
|
|
ifxDoc.Add(IfxConst.IFX_CONFIGURATION_LOCATION_LOCAL_COPY, _ConfigData.IfxConfigurationLocationLocalCopy);
|
|
results.Add(string.Concat("IfxTransport Config: ", ifxDoc));
|
|
_IfxTransport = new IfxTransport();
|
|
IfxTransport ifxTransport = (IfxTransport)_IfxTransport;
|
|
ifxTransport.Create(ifxDoc);
|
|
if (useSleep)
|
|
{
|
|
for (int i = 1; i < 10; i++)
|
|
Thread.Sleep(500);
|
|
}
|
|
results.Add(string.Concat("IfxTransport Current Daemon: ", ifxTransport.CurrentDaemon));
|
|
results.Add(string.Concat("IfxTransport Current Network: ", ifxTransport.CurrentNetwork));
|
|
results.Add(string.Concat("IfxTransport Current Service: ", ifxTransport.CurrentService));
|
|
results.Add(string.Concat("IfxTransport Current PoolName: ", ifxTransport.CurrentPoolName));
|
|
}
|
|
if (setParameters)
|
|
{
|
|
try { _Parameters = GetParameters(); } catch { /* Dev doesn't have this table */ }
|
|
}
|
|
return results;
|
|
}
|
|
|
|
private static Dictionary<string, List<Parameters>> GetParameters()
|
|
{
|
|
Dictionary<string, List<Parameters>> results = new Dictionary<string, List<Parameters>>();
|
|
List<Parameters> parameters = Parameters.GetParameters();
|
|
string iqsName;
|
|
foreach (var parameter in parameters)
|
|
{
|
|
iqsName = string.Concat(parameter.Iqs_name);
|
|
if (!results.ContainsKey(iqsName))
|
|
results.Add(iqsName, new List<Parameters>());
|
|
results[iqsName].Add(parameter);
|
|
}
|
|
return results;
|
|
}
|
|
|
|
internal static bool IsMappedPart(List<string> parts)
|
|
{
|
|
List<string> check = (from l in parts where _ConfigData.MappedParts.Contains(l) select l).ToList();
|
|
return check.Any();
|
|
}
|
|
|
|
internal static List<string> GetDistinctParts(List<PreRunInfo> preRunInfo)
|
|
{
|
|
List<string> results = new List<string>();
|
|
foreach (var item in preRunInfo)
|
|
results.Add(item.PartNumber);
|
|
results = results.Distinct().ToList();
|
|
return results;
|
|
}
|
|
|
|
internal static Dictionary<Test, IScopeInfo> GetScopeInfoCollections(ILogic logic, ConfigData configData, Dictionary<Test, Dictionary<string, List<string>>> rawData, Dictionary<Test, List<int>> tests)
|
|
{
|
|
Dictionary<Test, IScopeInfo> results = new Dictionary<Test, IScopeInfo>();
|
|
int min;
|
|
int max;
|
|
IScopeInfo scopeInfo;
|
|
foreach (var element in rawData)
|
|
{
|
|
min = tests[element.Key].Min();
|
|
max = tests[element.Key].Max() + 1;
|
|
scopeInfo = new ScopeInfo(logic, configData, element.Key);
|
|
results.Add(element.Key, scopeInfo);
|
|
}
|
|
return results;
|
|
}
|
|
|
|
internal static ExtractResult MergeAndMaybeSort(ExtractResult extractResult, List<PreRunInfo> preRunInfo, Dictionary<Test, List<int>> tests)
|
|
{
|
|
if (!preRunInfo.Any())
|
|
throw new Exception();
|
|
if (tests.ElementAt(0).Key != Test.AFMRoughness && tests.ElementAt(0).Key != Test.UV)
|
|
{
|
|
int min;
|
|
int max;
|
|
List<PreRunInfo> matchingPreRunInfo;
|
|
Dictionary<Enum, List<string>> keyValuePairs;
|
|
foreach (var testKeyValuePair in tests)
|
|
{
|
|
min = testKeyValuePair.Value.Min();
|
|
max = testKeyValuePair.Value.Max() + 1;
|
|
for (int i = min; i < max; i++)
|
|
{
|
|
switch (testKeyValuePair.Key)
|
|
{
|
|
default:
|
|
if (preRunInfo.Count != 1)
|
|
throw new Exception();
|
|
else
|
|
matchingPreRunInfo = preRunInfo;
|
|
break;
|
|
}
|
|
if (matchingPreRunInfo.Count > 1)
|
|
throw new Exception();
|
|
for (int g = 1; g < 3; g++)
|
|
{
|
|
switch (g)
|
|
{
|
|
case 1: keyValuePairs = extractResult.DatabaseHeaders; break;
|
|
case 2: keyValuePairs = extractResult.DatabaseDetails; break;
|
|
default: throw new Exception();
|
|
}
|
|
foreach (var element in keyValuePairs)
|
|
{
|
|
if (matchingPreRunInfo.Count == 0)
|
|
element.Value[i] = string.Empty;
|
|
else
|
|
{
|
|
switch (element.Key)
|
|
{
|
|
case Column.SID: break;
|
|
//case "MID": element.Value[i] = matchingPreRunInfo[0].MID; break;
|
|
case Column.Lot: element.Value[i] = matchingPreRunInfo[0].RunNumber; break;
|
|
case Column.Recipe: element.Value[i] = matchingPreRunInfo[0].Recipe; break;
|
|
case Column.Part: element.Value[i] = matchingPreRunInfo[0].PartNumber; break;
|
|
case Column.Date: element.Value[i] = matchingPreRunInfo[0].Date; break;
|
|
case Column.Wafer_ID: element.Value[i] = matchingPreRunInfo[0].PocketNumber; break;
|
|
case Column.WaferPocket_Candela: element.Value[i] = matchingPreRunInfo[0].PocketNumber; break;
|
|
case Column.Wafer_Scribe: element.Value[i] = matchingPreRunInfo[0].WaferLot; break;
|
|
//case "SatelliteGroup": element.Value[i] = matchingPreRunInfo[0].SatelliteGroup; break;
|
|
//case "StartStamp": element.Value[i] = matchingPreRunInfo[0].StartStamp; break;
|
|
default: throw new Exception();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (tests.ElementAt(0).Key == Test.CandelaKlarfDC || tests.ElementAt(0).Key == Test.CandelaLaser || tests.ElementAt(0).Key == Test.CandelaPSL || tests.ElementAt(0).Key == Test.CandelaVerify)
|
|
{
|
|
int min;
|
|
int max;
|
|
List<int> sortIndeices;
|
|
List<string> singleColumnSortedValues;
|
|
List<string> singleColumnBeforeSortValues;
|
|
Dictionary<Enum, List<string>> valuesCollection;
|
|
foreach (var testKeyValuePair in tests)
|
|
{
|
|
if (testKeyValuePair.Key == Test.CandelaKlarfDC || testKeyValuePair.Key == Test.CandelaLaser || testKeyValuePair.Key == Test.CandelaPSL || testKeyValuePair.Key == Test.CandelaVerify)
|
|
{
|
|
min = testKeyValuePair.Value.Min();
|
|
max = testKeyValuePair.Value.Max() + 1;
|
|
sortIndeices = new List<int>();
|
|
singleColumnBeforeSortValues = (from l in extractResult.DatabaseDetails[Column.WaferPocket_Candela] select l).ToList();
|
|
singleColumnSortedValues = (from l in extractResult.DatabaseDetails[Column.WaferPocket_Candela] orderby !string.IsNullOrEmpty(l), l select l).ToList();
|
|
for (int i = min; i < max; i++)
|
|
sortIndeices.Add(singleColumnBeforeSortValues.IndexOf(singleColumnSortedValues[i]));
|
|
valuesCollection = new Dictionary<Enum, List<string>>();
|
|
foreach (var element in extractResult.DatabaseDetails)
|
|
{
|
|
valuesCollection.Add(element.Key, new List<string>());
|
|
for (int i = min; i < max; i++)
|
|
valuesCollection[element.Key].Add(extractResult.DatabaseDetails[element.Key][i]);
|
|
element.Value.Clear();
|
|
for (int i = min; i < max; i++)
|
|
extractResult.DatabaseDetails[element.Key].Add(valuesCollection[element.Key][sortIndeices[i]]);
|
|
}
|
|
valuesCollection = new Dictionary<Enum, List<string>>();
|
|
foreach (var element in extractResult.Details)
|
|
{
|
|
valuesCollection.Add(element.Key, new List<string>());
|
|
for (int i = min; i < max; i++)
|
|
valuesCollection[element.Key].Add(extractResult.Details[element.Key][i]);
|
|
element.Value.Clear();
|
|
for (int i = min; i < max; i++)
|
|
extractResult.Details[element.Key].Add(valuesCollection[element.Key][sortIndeices[i]]);
|
|
}
|
|
valuesCollection = new Dictionary<Enum, List<string>>();
|
|
foreach (var element in extractResult.Parameters)
|
|
{
|
|
valuesCollection.Add(element.Key, new List<string>());
|
|
for (int i = min; i < max; i++)
|
|
valuesCollection[element.Key].Add(extractResult.Parameters[element.Key][i]);
|
|
element.Value.Clear();
|
|
for (int i = min; i < max; i++)
|
|
extractResult.Parameters[element.Key].Add(valuesCollection[element.Key][sortIndeices[i]]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return extractResult;
|
|
}
|
|
|
|
private static Dictionary<Column, List<PartParameters>> GetPartParameters(string partNumber, bool isMappedPart)
|
|
{
|
|
Dictionary<Column, List<PartParameters>> results = new Dictionary<Column, List<PartParameters>>();
|
|
List<PartParameters> partParameters = PartParameters.GetPartParameters(partNumber);
|
|
foreach (var partParameter in partParameters)
|
|
{
|
|
if (Convert.IsDBNull(partParameter.Enum) || !Enum.TryParse(partParameter.Enum.ToString(), out Column column))
|
|
{
|
|
if (isMappedPart && partParameter.Crit_to_ship.ToString() == "CRIT")
|
|
throw new Exception();
|
|
else
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
if (!results.ContainsKey(column))
|
|
results.Add(column, new List<PartParameters>());
|
|
results[column].Add(partParameter);
|
|
}
|
|
}
|
|
return results;
|
|
}
|
|
|
|
private static List<PartHistory> GetPartHistory(string partNumber)
|
|
{
|
|
List<PartHistory> results = PartHistory.GetPartHistory(partNumber);
|
|
return results;
|
|
}
|
|
|
|
private static DataKeys GetDataKeys(Dictionary<Enum, List<string>> columns, Logistics logistics, Dictionary<Enum, List<int>> ignoreIndeices, DataKeys dataKeys, int r, bool forParameter)
|
|
{
|
|
DataKeys result = dataKeys;
|
|
Column key;
|
|
if (!forParameter)
|
|
{
|
|
key = Column.Employee;
|
|
if (!columns.ContainsKey(key))
|
|
result.Employee = "AUTO";
|
|
else
|
|
result.Employee = columns[key][r];
|
|
}
|
|
key = Column.WaferPosition_BV;
|
|
if (columns.ContainsKey(key) && (!ignoreIndeices.ContainsKey(key) || !ignoreIndeices[key].Contains(r)))
|
|
result.WaferPosition = columns[key][r];
|
|
key = Column.WaferPosition_CV;
|
|
if (columns.ContainsKey(key) && (!ignoreIndeices.ContainsKey(key) || !ignoreIndeices[key].Contains(r)))
|
|
result.WaferPosition = columns[key][r];
|
|
key = Column.WaferPosition_Hall;
|
|
if (columns.ContainsKey(key) && (!ignoreIndeices.ContainsKey(key) || !ignoreIndeices[key].Contains(r)))
|
|
result.WaferPosition = columns[key][r];
|
|
key = Column.WaferPosition_PR;
|
|
if (columns.ContainsKey(key) && (!ignoreIndeices.ContainsKey(key) || !ignoreIndeices[key].Contains(r)))
|
|
result.WaferPosition = columns[key][r];
|
|
//
|
|
key = Column.Wafer_Region;
|
|
if (columns.ContainsKey(key) && (!ignoreIndeices.ContainsKey(key) || !ignoreIndeices[key].Contains(r)))
|
|
result.WaferRegion = columns[key][r];
|
|
//
|
|
key = Column.Wafer_Scribe;
|
|
if (columns.ContainsKey(key) && (!ignoreIndeices.ContainsKey(key) || !ignoreIndeices[key].Contains(r)))
|
|
result.WaferScribe = columns[key][r];
|
|
//
|
|
key = Column.X_Coord;
|
|
if (columns.ContainsKey(key) && (!ignoreIndeices.ContainsKey(key) || !ignoreIndeices[key].Contains(r)))
|
|
result.X = columns[key][r];
|
|
//
|
|
key = Column.Y_Coord;
|
|
if (columns.ContainsKey(key) && (!ignoreIndeices.ContainsKey(key) || !ignoreIndeices[key].Contains(r)))
|
|
result.Y = columns[key][r];
|
|
return result;
|
|
}
|
|
|
|
private static ExtractorKeys GetExtractorKeys(Dictionary<Enum, List<string>> columns, Logistics logistics, Dictionary<Enum, List<int>> ignoreIndeices, ExtractorKeys extractorKeys, int r, bool forParameter)
|
|
{
|
|
ExtractorKeys result = extractorKeys;
|
|
Column key;
|
|
key = Column.Lot;
|
|
if (columns.ContainsKey(key) && (!ignoreIndeices.ContainsKey(key) || !ignoreIndeices[key].Contains(r)))
|
|
result.Lot = columns[key][r];
|
|
//
|
|
key = Column.Part;
|
|
if (columns.ContainsKey(key) && (!ignoreIndeices.ContainsKey(key) || !ignoreIndeices[key].Contains(r)))
|
|
result.Part = columns[key][r];
|
|
//
|
|
key = Column.Process;
|
|
if (columns.ContainsKey(key) && (!ignoreIndeices.ContainsKey(key) || !ignoreIndeices[key].Contains(r)))
|
|
result.Process = columns[key][r];
|
|
//
|
|
key = Column.Recipe;
|
|
if (columns.ContainsKey(key) && (!ignoreIndeices.ContainsKey(key) || !ignoreIndeices[key].Contains(r)))
|
|
result.Recipe = columns[key][r];
|
|
//
|
|
key = Column.Wafer_ID;
|
|
if (columns.ContainsKey(key) && (!ignoreIndeices.ContainsKey(key) || !ignoreIndeices[key].Contains(r)))
|
|
result.WaferID = columns[key][r];
|
|
key = Column.Denton_Gun_Pocket;
|
|
if (columns.ContainsKey(key) && (!ignoreIndeices.ContainsKey(key) || !ignoreIndeices[key].Contains(r)))
|
|
result.WaferID = columns[key][r];
|
|
key = Column.WaferPocket_Candela;
|
|
if (columns.ContainsKey(key) && (!ignoreIndeices.ContainsKey(key) || !ignoreIndeices[key].Contains(r)))
|
|
result.WaferID = columns[key][r];
|
|
key = Column.WaferPocket_Warp;
|
|
if (columns.ContainsKey(key) && (!ignoreIndeices.ContainsKey(key) || !ignoreIndeices[key].Contains(r)))
|
|
result.WaferID = columns[key][r];
|
|
return result;
|
|
}
|
|
|
|
private static string GetUnit(string columnDiplayName, string columnDatabaseName)
|
|
{
|
|
string result;
|
|
if (_Parameters.ContainsKey(columnDiplayName) && !(_Parameters[columnDiplayName][0].Units is null) && !string.IsNullOrEmpty(_Parameters[columnDiplayName][0].Units.ToString()))
|
|
result = _Parameters[columnDiplayName][0].Units.ToString();
|
|
else if (_Parameters.ContainsKey(columnDatabaseName) && !(_Parameters[columnDatabaseName][0].Units is null) && !string.IsNullOrEmpty(_Parameters[columnDatabaseName][0].Units.ToString()))
|
|
result = _Parameters[columnDatabaseName][0].Units.ToString();
|
|
else
|
|
result = "xx";
|
|
return result;
|
|
}
|
|
|
|
private static double? GetLsl(PartParameters partParameters)
|
|
{
|
|
if (!(partParameters.Lsl is null) && !string.IsNullOrEmpty(partParameters.Lsl.ToString()))
|
|
{
|
|
double.TryParse(partParameters.Lsl.ToString(), out double lsl);
|
|
return lsl;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private static double? GetUsl(PartParameters partParameters)
|
|
{
|
|
if (!(partParameters.Usl is null) && !string.IsNullOrEmpty(partParameters.Usl.ToString()))
|
|
{
|
|
double.TryParse(partParameters.Usl.ToString(), out double usl);
|
|
return usl;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private static double? GetTsl(PartParameters partParameters)
|
|
{
|
|
if (!(partParameters.Target is null) && !string.IsNullOrEmpty(partParameters.Target.ToString()))
|
|
{
|
|
double.TryParse(partParameters.Target.ToString(), out double tsl);
|
|
return tsl;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private static Dictionary<string, List<string>> GetKeyValuePairs(Logistics logistics, ExtractResult extractResult, string xml2Text)
|
|
{
|
|
Dictionary<string, List<string>> results = new Dictionary<string, List<string>>();
|
|
bool documentKeys = false;
|
|
bool fieldParameter = false;
|
|
bool isFirstParmeter = true;
|
|
bool documnetParameter = false;
|
|
string elementName = string.Empty;
|
|
const string elementField = "Field";
|
|
bool fieldParameterNameKeys = false;
|
|
bool fieldParameterNameValue = false;
|
|
string attributeNameValue = string.Empty;
|
|
const string elementDocument = "Document";
|
|
string parameterAttributeNameValue = string.Empty;
|
|
string keyOrSettingAttributeNameValue = string.Empty;
|
|
string parameterKeyAttributeNameValue = string.Empty;
|
|
const string attributeNameValueParameter = "PARAMETER";
|
|
const string attributeNameValueParameterName = "PARAMETERNAME";
|
|
StringReader stringReader = new StringReader(xml2Text);
|
|
XmlReaderSettings xmlReaderSettings = new XmlReaderSettings { IgnoreWhitespace = true };
|
|
XmlReader xmlReader = XmlReader.Create(stringReader, xmlReaderSettings);
|
|
while (xmlReader.Read())
|
|
{
|
|
switch (xmlReader.NodeType)
|
|
{
|
|
case XmlNodeType.Element:
|
|
elementName = xmlReader.Name;
|
|
if (elementName == elementDocument || elementName == elementField)
|
|
{
|
|
while (xmlReader.HasAttributes && xmlReader.MoveToNextAttribute())
|
|
{
|
|
if (xmlReader.Name == "name")
|
|
{
|
|
attributeNameValue = xmlReader.Value;
|
|
if (!documentKeys && attributeNameValue == "KEYS")
|
|
documentKeys = true;
|
|
else if (documentKeys && !fieldParameter && elementName == elementField && attributeNameValue != attributeNameValueParameter)
|
|
keyOrSettingAttributeNameValue = attributeNameValue;
|
|
else if (documentKeys && !fieldParameter && elementName == elementField && attributeNameValue == attributeNameValueParameter)
|
|
fieldParameter = true;
|
|
else if (documentKeys && fieldParameter && elementName == elementDocument && attributeNameValue == attributeNameValueParameter && !documnetParameter)
|
|
documnetParameter = true;
|
|
else if (documentKeys && fieldParameter && documnetParameter && elementName == elementField && attributeNameValue == attributeNameValueParameterName && string.IsNullOrEmpty(parameterAttributeNameValue))
|
|
{
|
|
xmlReader.Read(); xmlReader.Read(); parameterAttributeNameValue = xmlReader.Value;
|
|
}
|
|
else if (documentKeys && fieldParameter && documnetParameter && !string.IsNullOrEmpty(parameterAttributeNameValue))
|
|
{
|
|
if (elementName == elementDocument && attributeNameValue == attributeNameValueParameter)
|
|
{
|
|
parameterAttributeNameValue = string.Empty;
|
|
if (isFirstParmeter)
|
|
isFirstParmeter = false;
|
|
if (fieldParameterNameValue)
|
|
fieldParameterNameValue = false;
|
|
if (fieldParameterNameKeys)
|
|
fieldParameterNameKeys = false;
|
|
if (!string.IsNullOrEmpty(parameterKeyAttributeNameValue))
|
|
parameterKeyAttributeNameValue = string.Empty;
|
|
}
|
|
else if (attributeNameValue == "VALUE")
|
|
{
|
|
if (!fieldParameterNameValue)
|
|
fieldParameterNameValue = true;
|
|
if (fieldParameterNameKeys)
|
|
fieldParameterNameKeys = false;
|
|
}
|
|
else if (!fieldParameterNameKeys && attributeNameValue == "KEYS")
|
|
fieldParameterNameKeys = true;
|
|
else if (fieldParameterNameValue && fieldParameterNameKeys)
|
|
parameterKeyAttributeNameValue = attributeNameValue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case XmlNodeType.Text:
|
|
if (documentKeys && !documnetParameter)
|
|
{
|
|
if (!results.ContainsKey(keyOrSettingAttributeNameValue))
|
|
results.Add(keyOrSettingAttributeNameValue, new List<string>());
|
|
results[keyOrSettingAttributeNameValue].Add(xmlReader.Value);
|
|
}
|
|
else if (fieldParameter && documnetParameter && !string.IsNullOrEmpty(parameterAttributeNameValue) && fieldParameterNameValue && !fieldParameterNameKeys)
|
|
{
|
|
if (!results.ContainsKey(parameterAttributeNameValue))
|
|
results.Add(parameterAttributeNameValue, new List<string>());
|
|
results[parameterAttributeNameValue].Add(xmlReader.Value);
|
|
}
|
|
else if (fieldParameter && documnetParameter && !string.IsNullOrEmpty(parameterAttributeNameValue) && fieldParameterNameValue && fieldParameterNameKeys && isFirstParmeter)
|
|
{
|
|
if (!results.ContainsKey(parameterKeyAttributeNameValue))
|
|
results.Add(parameterKeyAttributeNameValue, new List<string>());
|
|
results[parameterKeyAttributeNameValue].Add(xmlReader.Value);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
return results;
|
|
}
|
|
|
|
internal static void SaveXmlAsHtml(Logistics logistics, ExtractResult extractResult, ConfigData configData, string xml2Text, string htmlDirectory, string file)
|
|
{
|
|
StringBuilder html = new StringBuilder();
|
|
html.Clear();
|
|
html.AppendLine("<html>");
|
|
html.AppendLine("<head>");
|
|
html.Append("<title>").Append(configData.GetEquipmentType()).AppendLine("</title>");
|
|
html.AppendLine("</head>");
|
|
html.AppendLine("<body>");
|
|
int count;
|
|
string htmlFile;
|
|
List<int> counts = new List<int>();
|
|
Array array = Enum.GetValues(typeof(Column));
|
|
List<string> allDataKeyNames = new List<string>();
|
|
List<string> allSettingNames = new List<string>();
|
|
List<string> logisticsColumns = new List<string>();
|
|
List<string> presentSettingNames = new List<string>();
|
|
List<string> allLDSParameterNames = new List<string>();
|
|
List<string> allExtractorKeyNames = new List<string>();
|
|
List<string> parameterOrRowColumns = new List<string>();
|
|
Dictionary<string, List<string>> keyValuePairs = GetKeyValuePairs(logistics, extractResult, xml2Text);
|
|
foreach (var item in typeof(Settings).GetProperties())
|
|
allSettingNames.Add(item.Name);
|
|
foreach (var item in typeof(ExtractorKeys).GetProperties())
|
|
allExtractorKeyNames.Add(item.Name);
|
|
foreach (var item in typeof(DataKeys).GetProperties())
|
|
allDataKeyNames.Add(item.Name);
|
|
foreach (var item in typeof(Parameter).GetProperties())
|
|
allLDSParameterNames.Add(item.Name);
|
|
Dictionary<string, Column> columnNames = new Dictionary<string, Column>();
|
|
foreach (Column column in array)
|
|
columnNames.Add(column.GetDiplayName(), column);
|
|
foreach (KeyValuePair<string, List<string>> element in keyValuePairs)
|
|
{
|
|
counts.Add(element.Value.Count());
|
|
if (columnNames.ContainsKey(element.Key))
|
|
parameterOrRowColumns.Add(element.Key);
|
|
else
|
|
{
|
|
if (Enum.TryParse(element.Key, out Description.RowColumn rowColumnTry))
|
|
parameterOrRowColumns.Add(rowColumnTry.ToString());
|
|
else
|
|
{
|
|
if (Enum.TryParse(element.Key, out Description.LogisticsColumn logisticsColumnTry))
|
|
logisticsColumns.Add(logisticsColumnTry.ToString());
|
|
else
|
|
{
|
|
if (allSettingNames.Contains(element.Key))
|
|
presentSettingNames.Add(element.Key);
|
|
else
|
|
{
|
|
if (allExtractorKeyNames.Contains(element.Key))
|
|
parameterOrRowColumns.Add(element.Key);
|
|
else
|
|
{
|
|
if (allDataKeyNames.Contains(element.Key))
|
|
parameterOrRowColumns.Add(element.Key);
|
|
else
|
|
{
|
|
if (allLDSParameterNames.Contains(element.Key))
|
|
parameterOrRowColumns.Add(element.Key);
|
|
else
|
|
throw new Exception();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
count = counts.Max();
|
|
html.AppendLine("<table border = '2' CellPadding = '2' ");
|
|
html.Append(" id = '").Append(configData.GetEquipmentType()).AppendLine("' ");
|
|
html.Append(" title = '").Append("Missing \"Column\"(s)").AppendLine("' ");
|
|
html.AppendLine(">");
|
|
html.AppendLine("<tr>");
|
|
foreach (var element in keyValuePairs)
|
|
{
|
|
if (element.Value.Count() == 0 && parameterOrRowColumns.Contains(element.Key))
|
|
html.Append("<th nowrap>").Append(element.Key).AppendLine("</th>");
|
|
}
|
|
html.AppendLine("</tr>");
|
|
html.AppendLine("</table>");
|
|
//
|
|
html.AppendLine("<hr>");
|
|
//
|
|
html.AppendLine("<table border = '2' CellPadding = '2' ");
|
|
html.Append(" id = '").Append(configData.GetEquipmentType()).AppendLine("' ");
|
|
html.Append(" title = '").Append("\"settingNames\"(s)").AppendLine("' ");
|
|
html.AppendLine(">");
|
|
html.AppendLine("<tr>");
|
|
foreach (var item in presentSettingNames)
|
|
html.Append("<th nowrap>").Append(item).AppendLine("</th>");
|
|
html.AppendLine("</tr>");
|
|
html.AppendLine("<tr>");
|
|
foreach (var element in keyValuePairs)
|
|
{
|
|
if (presentSettingNames.Contains(element.Key))
|
|
{
|
|
if (string.IsNullOrEmpty(element.Value[0]))
|
|
html.AppendLine("<td nowrap> </td>");
|
|
else
|
|
html.Append("<td nowrap>").Append(element.Value[0]).AppendLine("</td>");
|
|
}
|
|
}
|
|
html.AppendLine("</tr>");
|
|
html.AppendLine("</table>");
|
|
//
|
|
html.AppendLine("<hr>");
|
|
//
|
|
html.AppendLine("<table border = '2' CellPadding = '2' ");
|
|
html.Append(" id = '").Append(configData.GetEquipmentType()).AppendLine("' ");
|
|
html.Append(" title = '").Append("\"LogisticsColumn\"(s)").AppendLine("' ");
|
|
html.AppendLine(">");
|
|
html.AppendLine("<tr>");
|
|
foreach (var item in logisticsColumns)
|
|
html.Append("<th nowrap>").Append(item).AppendLine("</th>");
|
|
html.AppendLine("</tr>");
|
|
for (int i = 0; i < 1; i++)
|
|
{
|
|
html.AppendLine("<tr>");
|
|
foreach (var element in keyValuePairs)
|
|
{
|
|
if (logisticsColumns.Contains(element.Key))
|
|
{
|
|
if (string.IsNullOrEmpty(element.Value[i]))
|
|
html.AppendLine("<td nowrap> </td>");
|
|
else
|
|
html.Append("<td nowrap>").Append(element.Value[i]).AppendLine("</td>");
|
|
}
|
|
}
|
|
}
|
|
html.AppendLine("</tr>");
|
|
html.AppendLine("</table>");
|
|
//
|
|
html.AppendLine("<hr>");
|
|
//
|
|
html.AppendLine("<table border = '2' CellPadding = '2' ");
|
|
html.Append(" id = '").Append(configData.GetEquipmentType()).AppendLine("' ");
|
|
html.Append(" title = '").Append("\"Parameter\"(s) Single-row").AppendLine("' ");
|
|
html.AppendLine(">");
|
|
html.AppendLine("<tr>");
|
|
foreach (var item in parameterOrRowColumns)
|
|
html.Append("<th nowrap>").Append(item).AppendLine("</th>");
|
|
html.AppendLine("</tr>");
|
|
for (int i = 0; i < 1; i++)
|
|
{
|
|
html.AppendLine("<tr>");
|
|
foreach (var element in keyValuePairs)
|
|
{
|
|
if (parameterOrRowColumns.Contains(element.Key))
|
|
{
|
|
if (element.Value.Count() > 1 || element.Value.Count() <= i || string.IsNullOrEmpty(element.Value[i]))
|
|
html.Append("<td nowrap> </td>");
|
|
else
|
|
{
|
|
if (!allExtractorKeyNames.Contains(element.Key) && element.Key != "SID")
|
|
html.Append("<td nowrap>").Append(element.Value[i]).AppendLine("</td>");
|
|
else
|
|
html.Append("<td nowrap style = \"background:yellow;\">").Append(element.Value[i]).AppendLine("</td>");
|
|
}
|
|
}
|
|
}
|
|
html.AppendLine("</tr>");
|
|
}
|
|
html.AppendLine("</table>");
|
|
//
|
|
html.AppendLine("<hr>");
|
|
//
|
|
html.AppendLine("<table border = '2' CellPadding = '2' ");
|
|
html.Append(" id = '").Append(configData.GetEquipmentType()).AppendLine("' ");
|
|
html.Append(" title = '").Append("\"Parameter\"(s) Multi-row").AppendLine("' ");
|
|
html.AppendLine(">");
|
|
html.AppendLine("<tr>");
|
|
foreach (var item in parameterOrRowColumns)
|
|
html.Append("<th nowrap>").Append(item).AppendLine("</th>");
|
|
html.AppendLine("</tr>");
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
html.AppendLine("<tr>");
|
|
foreach (var element in keyValuePairs)
|
|
{
|
|
if (parameterOrRowColumns.Contains(element.Key))
|
|
{
|
|
if (element.Value.Count() == 1 || element.Value.Count() <= i || string.IsNullOrEmpty(element.Value[i]))
|
|
html.Append("<td nowrap> </td>");
|
|
else
|
|
{
|
|
if (!allExtractorKeyNames.Contains(element.Key))
|
|
html.Append("<td nowrap>").Append(element.Value[i]).AppendLine("</td>");
|
|
else
|
|
html.Append("<td nowrap style = \"background:yellow;\">").Append(element.Value[i]).AppendLine("</td>");
|
|
}
|
|
}
|
|
}
|
|
html.AppendLine("</tr>");
|
|
}
|
|
html.AppendLine("</table>");
|
|
//
|
|
html.AppendLine("</body>");
|
|
html.AppendLine("</html>");
|
|
htmlFile = string.Concat(htmlDirectory, @"\", Path.GetFileNameWithoutExtension(file), ".html");
|
|
File.WriteAllText(htmlFile, html.ToString());
|
|
File.SetLastWriteTime(htmlFile, logistics.DateTimeFromSequence);
|
|
try { File.SetLastWriteTime(htmlFile, logistics.DateTimeFromSequence); } catch (Exception) { }
|
|
}
|
|
|
|
internal static Dictionary<string, IfxDoc> GetIfxDocs(Logistics logistics, ExtractResult extractResult, ConfigData configData, string writePath, Dictionary<Test, List<int>> tests, List<string> distinctParts, Dictionary<Test, IScopeInfo> scopeInfoCollections, bool isMappedPart)
|
|
{
|
|
Dictionary<string, IfxDoc> results = new Dictionary<string, IfxDoc>();
|
|
int c;
|
|
int min;
|
|
int max;
|
|
DATA data;
|
|
string sid;
|
|
string file;
|
|
IfxDoc ifxDoc;
|
|
string nullData;
|
|
string xml2Text;
|
|
IScopeInfo scopeInfo;
|
|
Parameter parameter;
|
|
string testAppendage;
|
|
string htmlDirectory;
|
|
List<PartHistory> partHistory;
|
|
List<int> rowCheck = new List<int>();
|
|
if (scopeInfoCollections.Any())
|
|
{
|
|
string xmlDirectory = string.Empty;
|
|
ExtendedParameter extendedParameter;
|
|
List<ExtendedParameter> extendedParameters;
|
|
Dictionary<Enum, List<int>> ignoreIndeices;
|
|
List<IfxDoc> parameters = new List<IfxDoc>();
|
|
List<ParameterCollection> parameterCollections = new List<ParameterCollection>();
|
|
string directory = string.Concat(writePath, @"\", configData.GetEquipmentType(), @"\Target");
|
|
Dictionary<Enum, List<string>> toolHeadersAndDatabaseHeadersCollection = extractResult.GetToolHeadersAndDatabaseHeadersCollection();
|
|
Dictionary<Enum, List<string>> toolDetailsAndDatabaseDetailsCollection = extractResult.GetToolDetailsAndDatabaseDetailsCollection();
|
|
if (logistics.NullData is null)
|
|
nullData = string.Empty;
|
|
else
|
|
nullData = logistics.NullData.ToString();
|
|
if (!distinctParts.Any())
|
|
partHistory = new List<PartHistory>();
|
|
else
|
|
{
|
|
if (distinctParts.Count != 1)
|
|
throw new Exception();
|
|
partHistory = GetPartHistory(distinctParts[0]);
|
|
}
|
|
if (!string.IsNullOrEmpty(writePath))
|
|
{
|
|
xmlDirectory = string.Concat(directory, @"\xml");
|
|
if (!Directory.Exists(xmlDirectory))
|
|
Directory.CreateDirectory(xmlDirectory);
|
|
}
|
|
foreach (var testKeyValuePair in tests)
|
|
{
|
|
if (isMappedPart && !partHistory.Any())
|
|
throw new Exception();
|
|
min = testKeyValuePair.Value.Min();
|
|
max = testKeyValuePair.Value.Max() + 1;
|
|
scopeInfo = scopeInfoCollections[testKeyValuePair.Key];
|
|
ignoreIndeices = extractResult.IgnoreIndeices[testKeyValuePair.Key];
|
|
data = new DATA(_ConfigData.IfxSubjectPrefix, logistics, scopeInfo, extractResult.DatabaseHeaders[Column.SID][min]);
|
|
if (toolHeadersAndDatabaseHeadersCollection.Any())
|
|
{
|
|
data.DataKeys = GetDataKeys(toolHeadersAndDatabaseHeadersCollection, logistics, ignoreIndeices, data.DataKeys, r: min, forParameter: false);
|
|
data.ExtractorKeys = GetExtractorKeys(toolHeadersAndDatabaseHeadersCollection, logistics, ignoreIndeices, data.ExtractorKeys, r: min, forParameter: false);
|
|
}
|
|
if (partHistory.Any())
|
|
{
|
|
if (!(partHistory[0].Process_flow is null) && !string.IsNullOrEmpty(partHistory[0].Process_flow.ToString()))
|
|
data.ExtractorKeys.ProcessFlow = partHistory[0].Process_flow.ToString();
|
|
}
|
|
c = 0;
|
|
parameterCollections.Clear();
|
|
foreach (KeyValuePair<Enum, List<string>> element in extractResult.Parameters)
|
|
{
|
|
rowCheck.Clear();
|
|
for (int r = min; r < max; r++)
|
|
{
|
|
if (ignoreIndeices[element.Key].Contains(r))
|
|
rowCheck.Add(r);
|
|
}
|
|
if (rowCheck.Count != (max - min))
|
|
{
|
|
extendedParameters = extractResult.ExtendedParameters[element.Key];
|
|
parameterCollections.Add(new ParameterCollection());
|
|
for (int r = min; r < max; r++)
|
|
{
|
|
if (!ignoreIndeices[element.Key].Contains(r))
|
|
{
|
|
extendedParameter = extendedParameters[r];
|
|
if (!extendedParameter.Ignore.Value && extendedParameter.CriticalToShip.HasValue && extendedParameter.CriticalToShip.Value)
|
|
{
|
|
parameter = new Parameter(logistics, extendedParameter);
|
|
if (toolDetailsAndDatabaseDetailsCollection.Any())
|
|
{
|
|
parameter.DataKeys = GetDataKeys(toolDetailsAndDatabaseDetailsCollection, logistics, ignoreIndeices, parameter.DataKeys, r, forParameter: true);
|
|
parameter.ExtractorKeys = GetExtractorKeys(toolDetailsAndDatabaseDetailsCollection, logistics, ignoreIndeices, parameter.ExtractorKeys, r, forParameter: true);
|
|
}
|
|
parameterCollections[c].Collection.Add(parameter);
|
|
}
|
|
}
|
|
}
|
|
c += 1;
|
|
}
|
|
}
|
|
if (parameterCollections.Any())
|
|
parameterCollections = (from l in parameterCollections where l.Collection.Any() select l).ToList();
|
|
if (parameterCollections.Any())
|
|
{
|
|
parameters.Clear();
|
|
foreach (var item in parameterCollections)
|
|
parameters.Add(item.GetIfxDoc());
|
|
ifxDoc = data.GetIfxDoc(parameters);
|
|
if (ifxDoc.GetFieldCount() == 0)
|
|
throw new Exception();
|
|
else
|
|
{
|
|
xml2Text = ifxDoc.GetAsXml2();
|
|
if (!(logistics.NullData is null) && !string.IsNullOrEmpty(nullData) && xml2Text.Contains(nullData))
|
|
throw new Exception();
|
|
if (xml2Text.Contains("<Field name=\"Lot\"><String>-</String>") && !(rowCheck is null))
|
|
throw new Exception();
|
|
if (!string.IsNullOrEmpty(writePath))
|
|
{
|
|
//testAppendage = string.Concat(" - ", (int)element.Key);
|
|
testAppendage = string.Concat(" - ", scopeInfo.FileNameWithoutExtension);
|
|
file = string.Concat(xmlDirectory, @"\", logistics.JobID, "_", logistics.Sequence, testAppendage, ".xml");
|
|
ifxDoc.Save(file, IfxConst.IfxDocFileType.Xml2, Overwrite: true);
|
|
if (logistics.TotalSecondsSinceLastWriteTimeFromSequence > 600)
|
|
{
|
|
try { File.SetLastWriteTime(file, logistics.DateTimeFromSequence); } catch (Exception) { }
|
|
}
|
|
htmlDirectory = string.Concat(directory, @"\html");
|
|
if (!Directory.Exists(htmlDirectory))
|
|
Directory.CreateDirectory(htmlDirectory);
|
|
SaveXmlAsHtml(logistics, extractResult, configData, xml2Text, htmlDirectory, file);
|
|
}
|
|
sid = extractResult.DatabaseHeaders[Column.SID][min];
|
|
if (!isMappedPart && results.ContainsKey(sid))
|
|
{
|
|
sid = string.Concat(sid, " ", DateTime.Now.Ticks.ToString());
|
|
Thread.Sleep(100);
|
|
}
|
|
results.Add(sid, ifxDoc);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return results;
|
|
}
|
|
|
|
internal static List<LDS2559Reply.DATA> SendIfxDocs(ILogic logic, ConfigData configData, bool isMappedPart, Dictionary<string, IfxDoc> ifxDocs)
|
|
{
|
|
List<LDS2559Reply.DATA> results = new List<LDS2559Reply.DATA>();
|
|
IfxDoc reply;
|
|
string replyString;
|
|
LDS2559Reply.DATA lds2559Data;
|
|
if (_IfxTransport is null)
|
|
{
|
|
bool setParameters = !_Parameters.Any();
|
|
List<string> messages = Setup(useSleep: false, setIfxTransport: true, setParameters: setParameters);
|
|
foreach (string message in messages)
|
|
{
|
|
System.Diagnostics.Debug.Print(message);
|
|
}
|
|
}
|
|
if (_IfxTransport is null)
|
|
throw new Exception();
|
|
else
|
|
{
|
|
IfxTransport ifxTransport = (IfxTransport)_IfxTransport;
|
|
if (isMappedPart && !(configData.EquipmentConnection is null))
|
|
{
|
|
DateTime dateTime = new DateTime(2019, 08, 25);
|
|
if (!(logic.Logistics is null) && logic.Logistics.DateTimeFromSequence >= dateTime)
|
|
{
|
|
foreach (var element in ifxDocs)
|
|
{
|
|
if (element.Value.GetFieldCount() == 0)
|
|
throw new Exception();
|
|
else
|
|
element.Value.Save(string.Concat(@"\\MESSV02ECC1.EC.LOCAL\EC_EAFLog\Production\IFXDocs\", configData.GetEquipmentType(), @"\", element.Key.Replace("*", string.Empty), ".xml"), IfxConst.IfxDocFileType.Xml2, Overwrite: true);
|
|
}
|
|
}
|
|
}
|
|
foreach (var element in ifxDocs)
|
|
{
|
|
if (element.Value.GetFieldCount() == 0)
|
|
throw new Exception();
|
|
else
|
|
{
|
|
element.Value.SendSubject = string.Concat(ifxTransport.SubjectPrefix, ".", _ConfigData.IfxSubject);
|
|
if (ifxTransport.SubjectPrefix.StartsWith("MES_"))
|
|
{
|
|
ifxTransport.Publish(element.Value, false, 60);
|
|
lds2559Data = null;
|
|
}
|
|
else
|
|
{
|
|
if (!isMappedPart)
|
|
lds2559Data = null;
|
|
else
|
|
{
|
|
IfxEnvelope ifxEnvelope = ifxTransport.SendRequest(element.Value, false, 60, IfxConst.IfxMessageType.Yoda);
|
|
if (ifxEnvelope is null)
|
|
throw new Exception("SendRequest timeout occurred");
|
|
else
|
|
{
|
|
reply = ifxEnvelope.ExtractDocument();
|
|
replyString = reply.ToString();
|
|
try { lds2559Data = new LDS2559Reply.DATA(reply); } catch (Exception) { lds2559Data = null; }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
results.Add(lds2559Data);
|
|
}
|
|
}
|
|
return results;
|
|
}
|
|
|
|
internal static string EvaluateSendResults(ILogic logic, ConfigData configData, List<string> distinctParts, bool isMappedPart, List<LDS2559Reply.DATA> transportSendResults)
|
|
{
|
|
StringBuilder result = new StringBuilder();
|
|
string mID;
|
|
if (logic is null || logic.Logistics is null || logic.Logistics.MID is null)
|
|
mID = string.Empty;
|
|
else
|
|
mID = logic.Logistics.MID;
|
|
string part;
|
|
if (!distinctParts.Any())
|
|
part = string.Empty;
|
|
else
|
|
{
|
|
if (!isMappedPart)
|
|
part = distinctParts[0];
|
|
else
|
|
part = string.Concat(distinctParts[0], " (Mapped) ");
|
|
}
|
|
if (!transportSendResults.Any())
|
|
throw new Exception(string.Concat(configData.GetEquipmentType(), " - ", mID, " - ", part, " Nothing was sent!"));
|
|
foreach (var item in transportSendResults)
|
|
{
|
|
if (item is null)
|
|
result.AppendLine(string.Concat(configData.GetEquipmentType(), " - ", mID, " - ", part, " null"));
|
|
else
|
|
{
|
|
if (item.UNACCEPTED is null || (!(item.ETC is null) && item.ETC.ToString() == "-1"))
|
|
throw new Exception(string.Concat(configData.GetEquipmentType(), " - ", mID, " - ", part, " Invalid data"));
|
|
else
|
|
{
|
|
double.TryParse(item.UNACCEPTED.ToString(), out double unaccepted);
|
|
if (unaccepted > 0)
|
|
throw new Exception("Unaccepted record present");
|
|
else
|
|
result.AppendLine(string.Concat("Reply: ", item, Environment.NewLine, Environment.NewLine));
|
|
}
|
|
}
|
|
}
|
|
return result.ToString();
|
|
}
|
|
|
|
}
|
|
|
|
}
|