Ready to test

This commit is contained in:
2022-02-18 16:42:50 -07:00
parent 6259bd1996
commit ce231b256a
149 changed files with 16269 additions and 10552 deletions

View File

@ -0,0 +1,13 @@
namespace Adaptation.FileHandlers.TIBCO.Transport;
public class Input
{
public string Sequence { get; set; }
public string Area { get; set; }
public string EquipmentType { get; set; }
public string MesEntity { get; set; }
public string MID { get; set; }
public string Recipe { get; set; }
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
namespace Adaptation.FileHandlers.TIBCO.Transport;
public class Item
{
public string Name { get; set; } //WaferLot //UniqueID
public string Type { get; set; } //SatelliteGroup //Sort
public string Number { get; set; } //PocketNumber //Slot
public string Qty { get; set; } //1
public string CarrierName { get; set; } //PROCESS_GROUP
}

View File

@ -0,0 +1,187 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Globalization;
using System.IO;
using System.Text;
using System.Text.Json;
namespace Adaptation.FileHandlers.TIBCO.Transport;
public class Job
{
public string AutomationMode { get; }
public string BasicType { get; }
public string Equipment { get; }
public string JobName { get; }
public string LotName { get; }
public string PackageName { get; }
public string ProcessSpecName { get; }
public string ProcessType { get; }
public string ProductName { get; }
public string Qty { get; }
public string RecipeName { get; }
public string StateModel { get; }
//
public bool IsAreaSi { get; }
public DateTime DateTime { get; }
public List<Item> Items { get; }
public Job(string oiContextDataPendingPath, string oiContextDataResultsPath, string oiContextDataSearchPath, string lsl2SQLConnectionString, string mid)
{
Items = new List<Item>();
if (mid[0] != '{' || mid[mid.Length - 1] != '}' || !mid.Contains("\"Si\""))
IsAreaSi = false;
else
{
string[] segments;
const string hyphen = "-";
Input input = JsonSerializer.Deserialize<Input>(mid);
IsAreaSi = input.Area == "Si";
if (!long.TryParse(input.Sequence, out long sequence))
DateTime = DateTime.Now;
else
DateTime = new DateTime(sequence);
if (!string.IsNullOrEmpty(input.MID) && input.MID.Length > 9 && input.MID[2] == hyphen[0] && input.MID[9] == hyphen[0])
segments = input.MID.Split(hyphen[0]);
else
segments = new string[] { hyphen, hyphen, hyphen };
//
AutomationMode = string.Concat(DateTime.Ticks, ".", input.MesEntity);
if (segments[1] == hyphen)
BasicType = hyphen;
else
BasicType = GetBasicType(lsl2SQLConnectionString, hyphen, segments[1]);
Equipment = input.MesEntity;
JobName = DateTime.Ticks.ToString();
if (segments[0] == hyphen)
LotName = input.MID;
else
LotName = segments[1];
PackageName = hyphen; //WAFER_ID WaferLot
ProcessSpecName = hyphen; //WAFER_POS PocketNumber
ProcessType = segments[0];
ProductName = segments[2].Split('.')[0];
Qty = "1";
RecipeName = input.Recipe;
StateModel = input.EquipmentType;
Items.Add(new Item { Name = "0", Type = "NA", Number = (0 + 1).ToString(), Qty = "1", CarrierName = hyphen });
MoveOldFiles(oiContextDataSearchPath, oiContextDataPendingPath, oiContextDataResultsPath);
}
}
public string GetBasicType(string lsl2SQLConnectionString, string hyphen, string rds)
{
string result;
// string json;
// string loadLock;
// JsonElement jsonElement;
// DateTime dateTime = DateTime.Now;
// string rdsFile = Path.Combine(configData.OIContextDataResultsPath, $"{DateTime.Ticks}.rds");
// string jsonFile = Path.Combine(configData.OIContextDataResultsPath, $"{DateTime.Ticks}.json");
// File.WriteAllText(Path.Combine(configData.OIContextDataSearchPath, $"{DateTime.Ticks}.rds"), rds);
// CultureInfo cultureInfo = new CultureInfo("en-US");
// Calendar calendar = cultureInfo.Calendar;
// string weekOfYear = calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
// string yearWeek = string.Concat(dateTime.ToString("yyyy"), "___Week_", weekOfYear);
// string resultsDirectory = Path.Combine(configData.OIContextDataResultsPath, yearWeek);
// if (!Directory.Exists(resultsDirectory))
// Directory.CreateDirectory(resultsDirectory);
// long breakAfter = dateTime.AddSeconds(60).Ticks;
// for (int i = 0; i < short.MaxValue; i++)
// {
// if (File.Exists(rdsFile) && File.Exists(jsonFile))
// {
// loadLock = string.Empty;
// json = File.ReadAllText(jsonFile);
// jsonElement = JsonSerializer.Deserialize<JsonElement>(json);
// if (jsonElement.ValueKind == JsonValueKind.Object)
// {
// foreach (JsonProperty jsonProperty in jsonElement.EnumerateObject())
// {
// if (jsonProperty.Name != "LoadLock")
// continue;
// loadLock = jsonProperty.Value.ToString();
// }
// }
// if (string.IsNullOrEmpty(loadLock))
// File.Move(jsonFile, Path.Combine(configData.OIContextDataResultsPath, $"{DateTime.Ticks}.err"));
// else
// {
// File.Move(rdsFile, Path.Combine(configData.OIContextDataResultsPath, yearWeek, $"{DateTime.Ticks}.rds"));
// File.Move(jsonFile, Path.Combine(configData.OIContextDataResultsPath, yearWeek, $"{DateTime.Ticks}.json"));
// result = loadLock;
// }
// break;
// }
// if (DateTime.Now.Ticks > breakAfter)
// break;
// }
object scalar = null;
StringBuilder sql = new();
_ = sql.Append(" SELECT ").
Append(" CASE ").
Append(" WHEN LOAD_LOCK_SIDE = 'L' THEN 'Left - ' ").
Append(" WHEN LOAD_LOCK_SIDE = 'R' THEN 'Right - ' ").
Append(" ELSE LOAD_LOCK_SIDE ").
Append(" END + REACTOR_TYPE AS LOAD_LOCK ").
Append(" FROM [LSL2SQL].[dbo].[REACT_RUN] ").
Append($" WHERE RDS_NO = '{rds}' ");
//Append(" AND LOAD_SIG != '' ");
try
{
using SqlConnection sqlConnection = new(lsl2SQLConnectionString);
sqlConnection.Open();
using (SqlCommand sqlCommand = new(sql.ToString(), sqlConnection))
scalar = sqlCommand.ExecuteScalar();
sqlConnection.Close();
}
catch (Exception)
{
}
if (scalar is null)
result = hyphen;
else
result = scalar.ToString();
return result;
}
private static void MoveOldFiles(string oiContextDataPendingPath, string oiContextDataResultsPath, string oiContextDataSearchPath)
{
string yearWeek;
string[] oldFiles;
FileInfo fileInfo;
string weekOfYear;
string moveDirectory;
DateTime daysOld = DateTime.Now.AddDays(-2);
CultureInfo cultureInfo = new("en-US");
Calendar calendar = cultureInfo.Calendar;
string[] directories = new string[] { oiContextDataSearchPath, oiContextDataPendingPath, oiContextDataResultsPath };
foreach (string directory in directories)
{
try
{
oldFiles = Directory.GetFiles(directory, "*", SearchOption.TopDirectoryOnly);
foreach (string oldFile in oldFiles)
{
fileInfo = new FileInfo(oldFile);
if (!fileInfo.Exists || fileInfo.LastWriteTime > daysOld)
continue;
weekOfYear = calendar.GetWeekOfYear(fileInfo.LastWriteTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
yearWeek = string.Concat(fileInfo.LastWriteTime.ToString("yyyy"), "___Week_", weekOfYear);
moveDirectory = Path.Combine(fileInfo.DirectoryName, yearWeek);
if (!Directory.Exists(moveDirectory))
_ = Directory.CreateDirectory(moveDirectory);
try
{ File.Move(oldFile, Path.Combine(moveDirectory, fileInfo.Name)); }
catch (Exception) { }
}
}
catch (Exception)
{
}
}
}
}

View File

@ -0,0 +1,70 @@
namespace Adaptation.FileHandlers.TIBCO.Transport;
/// <summary>
/// EDA-Configurator.pdf
/// CDS Namespace Reply Variables
/// </summary>
public class Logistics
{
/// <summary>
/// Basic Type
/// </summary>
public string BASIC_TYPE { get; set; }
/// <summary>
/// Text for additional information
/// </summary>
public string INFO { get; set; }
/// <summary>
/// Unique assignment of lot processing to the basic cell (Dresden)
/// </summary>
public string JOBID { get; set; }
/// <summary>
/// Equipment name used in MES
/// </summary>
public string MES_ENTITY { get; set; }
/// <summary>
/// Lot number, name for a lot
/// </summary>
public string MID { get; set; }
/// <summary>
/// Recipe (Process Program ID)
/// </summary>
public string PPID { get; set; }
/// <summary>
/// Process group (e.g. C5PR)
/// </summary>
public string PROCESS_GROUP { get; set; }
/// <summary>
/// Product name
/// </summary>
public string PRODUCT { get; set; }
/// <summary>
/// Total number of wafers in lot
/// </summary>
public string TOTAL_NUMBER_OF_WAFERS { get; set; }
/// <summary>
/// Equipment sequence number
/// </summary>
public string SEQUENCE { get; set; }
/// <summary>
/// Unique wafer number (barcode, OCR)
/// </summary>
public string WAFER_ID { get; set; }
/// <summary>
/// Wafer position in a tube (Furnace)
/// </summary>
public string WAFER_POS { get; set; }
}

View File

@ -0,0 +1,228 @@
using Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration;
using Adaptation.Shared.Methods;
using Infineon.Yoda;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading;
namespace Adaptation.FileHandlers.TIBCO.Transport;
internal partial class Main
{
private static ISMTP _SMTP;
private static object _IfxTransport;
private static string _CellInstanceName;
private static string _LSL2SQLConnectionString;
private static string _OIContextDataSearchPath;
private static string _OIContextDataPendingPath;
private static string _OIContextDataResultsPath;
private static FileConnectorConfiguration _FileConnectorConfiguration;
internal static void Initialize(ISMTP smtp, string cellInstanceName, FileConnectorConfiguration fileConnectorConfiguration, string oiContextDataPendingPath, string oiContextDataResultsPath, string oiContextDataSearchPath, string lsl2SQLConnectionString)
{
_SMTP = smtp;
_IfxTransport = null;
_CellInstanceName = cellInstanceName;
_LSL2SQLConnectionString = lsl2SQLConnectionString;
_OIContextDataSearchPath = oiContextDataSearchPath;
_OIContextDataPendingPath = oiContextDataPendingPath;
_OIContextDataResultsPath = oiContextDataResultsPath;
_FileConnectorConfiguration = fileConnectorConfiguration;
}
internal static List<string> Setup(bool useSleep, bool setIfxTransport, string tibcoParameterChannel, string tibcoParameterSubjectPrefix, string tibcoParameterConfigurationLocation, string tibcoParameterConfigurationLocationCopy, string tibcoParameterSubject)
{
List<string> results = new();
if (useSleep)
{
for (int i = 1; i < 4; i++)
Thread.Sleep(500);
}
if (setIfxTransport)
{
results.Add(string.Concat("IfxTransport Subject: ", tibcoParameterSubject));
IfxDoc ifxDoc = new();
ifxDoc.Add(IfxConst.SUBJECT_PREFIX, tibcoParameterSubjectPrefix);
ifxDoc.Add(IfxConst.IFX_CHANNEL, tibcoParameterChannel);
ifxDoc.Add(IfxConst.IFX_CONFIGURATION_LOCATION, tibcoParameterConfigurationLocation);
ifxDoc.Add(IfxConst.IFX_CONFIGURATION_LOCATION_LOCAL_COPY, tibcoParameterConfigurationLocationCopy);
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));
}
for (int i = 1; i < 3; i++)
Thread.Sleep(500);
if (_IfxTransport is null)
throw new Exception();
else
{
IfxTransport ifxTransport = (IfxTransport)_IfxTransport;
string[] subjects = tibcoParameterSubject.Split('|');
foreach (string subject in subjects)
ifxTransport.Subscribe(string.Concat(tibcoParameterSubjectPrefix, ".", subject));
ifxTransport.ReliableMessage += MainTransport_ReliableMessage;
for (int i = 1; i < 3; i++)
Thread.Sleep(500);
}
return results;
}
private static void MoveSourceFiles(string[] sourceFiles, string pdsfFileLogistics, Calendar calendar)
{
DateTime dateTime;
string weekOfYear;
string checkDirectory;
foreach (string pdsfFile in sourceFiles)
{
if (pdsfFile == pdsfFileLogistics)
continue;
dateTime = new FileInfo(pdsfFile).LastWriteTime;
weekOfYear = calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
checkDirectory = string.Concat(Path.GetDirectoryName(pdsfFile), @"\_ Logistics Archive\", dateTime.ToString("yyyy"), "_Week_", weekOfYear);
if (!Directory.Exists(checkDirectory))
_ = Directory.CreateDirectory(checkDirectory);
try
{ File.Move(pdsfFile, string.Concat(checkDirectory, @"\", Path.GetFileName(pdsfFile))); }
catch (Exception) { }
}
}
private static string GetJobsMID(IfxDoc envelopeDocument)
{
string mid;
if (envelopeDocument is null || !envelopeDocument.FieldExists("LotName"))
mid = string.Empty;
else
mid = envelopeDocument.GetFieldByName("LotName").ToString();
return mid;
}
private static IfxDoc GetJobsReply(Job job)
{
IfxDoc result = new();
IfxDoc itemDoc;
IfxDoc jobDoc = new();
IfxDoc lotDoc = new();
IfxDoc recipeDoc = new();
List<IfxDoc> itemDocs = new();
jobDoc.Add("AutomationMode", job.AutomationMode);
jobDoc.Add("CreationTimestamp", job.DateTime);
jobDoc.Add("CreationUser", "-");
jobDoc.Add("CurrentState", true);
jobDoc.Add("Equipment", job.Equipment);
jobDoc.Add("JobName", job.JobName);
jobDoc.Add("LastUpdateTimestamp", job.DateTime);
jobDoc.Add("LastUpdateUser", "-");
jobDoc.Add("ProcessType", job.ProcessType);
jobDoc.Add("StateModel", job.StateModel);
jobDoc.Add("Status", "-");
lotDoc.Add("BasicType", job.BasicType);
lotDoc.Add("IsActive", true);
lotDoc.Add("LotName", job.LotName);
lotDoc.Add("LotState", "-");
lotDoc.Add("PackageName", job.PackageName);
lotDoc.Add("ProcessSpecName", job.ProcessSpecName);
lotDoc.Add("ProductName", job.ProductName);
lotDoc.Add("Qty", job.Qty);
lotDoc.Add("Qty2", "-");
recipeDoc.Add("RecipeName", job.RecipeName);
lotDoc.Add("SpecName", "-");
foreach (Item item in job.Items)
{
itemDoc = new IfxDoc();
itemDoc.Add("Name", item.Name);
itemDoc.Add("Type", item.Type);
itemDoc.Add("Number", item.Number);
itemDoc.Add("Qty", item.Qty);
itemDoc.Add("CarrierName", item.CarrierName);
itemDocs.Add(itemDoc);
}
jobDoc.Add("Recipe", recipeDoc);
lotDoc.Add("Items", itemDocs.ToArray());
jobDoc.Add("Lots", new IfxDoc[] { lotDoc });
result.Add("FAJobs", new IfxDoc[] { jobDoc });
result.Add("IFX_ECD", "0");
result.Add("IFX_ETX", 0);
return result;
}
private static void MainTransport_ReliableMessage(string subject, string replySubject, IfxEnvelope ifxEnvelope)
{
try
{
string mid = string.Empty;
string[] sourceFiles = null;
DateTime dateTime = DateTime.Now;
string pdsfFileLogistics = string.Empty;
IfxDoc envelopeDocument = ifxEnvelope.ExtractDocument();
CultureInfo cultureInfo = new("en-US");
Calendar calendar = cultureInfo.Calendar;
string weekOfYear = calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
string weekOfYearSegment = string.Concat(@"\", dateTime.ToString("yyyy"), "_Week_", weekOfYear, @"\", dateTime.ToString("yyyy-MM-dd"));
if (!string.IsNullOrEmpty(_FileConnectorConfiguration.SourceFileLocation))
{
string directory = string.Concat(_FileConnectorConfiguration.SourceFileLocation, weekOfYearSegment);
if (!Directory.Exists(directory))
_ = Directory.CreateDirectory(directory);
string fileName = string.Concat(directory, @"\", subject.Replace(".", "~"), " - ", DateTime.Now.Ticks, ".xml");
try
{ envelopeDocument.SaveAsXml(fileName); }
catch (Exception) { }
}
if (!subject.EndsWith("GETJOBS"))
throw new Exception();
mid = GetJobsMID(envelopeDocument);
Job job = new(_OIContextDataPendingPath, _OIContextDataResultsPath, _OIContextDataSearchPath, _LSL2SQLConnectionString, mid);
if (job.IsAreaSi)
{
IfxDoc sendReply = GetJobsReply(job);
ifxEnvelope.Transport.SendReply(ifxEnvelope, sendReply);
if (!string.IsNullOrEmpty(_FileConnectorConfiguration.TargetFileLocation))
{
string directory = string.Concat(_FileConnectorConfiguration.TargetFileLocation, weekOfYearSegment);
if (!Directory.Exists(directory))
_ = Directory.CreateDirectory(directory);
string fileName = string.Concat(directory, @"\", subject.Replace(".", "~"), " - ", DateTime.Now.Ticks, ".xml");
try
{ sendReply.SaveAsXml(fileName); }
catch (Exception) { }
}
}
if (sourceFiles is not null && !string.IsNullOrEmpty(pdsfFileLogistics))
MoveSourceFiles(sourceFiles, pdsfFileLogistics, calendar);
}
catch (Exception exception)
{
subject = string.Concat("Exception:", _CellInstanceName, ":MainTransport_ReliableMessage");
string body = string.Concat(exception.Message, Environment.NewLine, Environment.NewLine, exception.StackTrace);
try
{ _SMTP.SendHighPriorityEmailMessage(subject, body); }
catch (Exception) { }
string directory = _FileConnectorConfiguration.ErrorTargetFileLocation;
if (!string.IsNullOrEmpty(directory) && Directory.Exists(directory))
{
string fileName = string.Concat(directory, @"\", subject.Replace(".", "~"), " - ", DateTime.Now.Ticks, ".txt");
try
{ File.WriteAllLines(fileName, new string[] { exception.Message, string.Empty, string.Empty, exception.StackTrace }); }
catch (Exception) { }
}
}
}
}