Ready to test
This commit is contained in:
187
Adaptation/FileHandlers/TIBCO/Transport/Job.cs
Normal file
187
Adaptation/FileHandlers/TIBCO/Transport/Job.cs
Normal 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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user