using Adaptation.Helpers; 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.Si { internal partial class 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 Items { get; } public Job(ConfigData configData, string mid) { Items = new List(); if (mid[0] != '{' || mid[mid.Length - 1] != '}' || !mid.Contains("\"Si\"")) IsAreaSi = false; else { string[] segments; const string hypen = "-"; Input input = JsonSerializer.Deserialize(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] == hypen[0] && input.MID[9] == hypen[0]) segments = input.MID.Split(hypen[0]); else segments = new string[] { hypen, hypen, hypen }; // AutomationMode = string.Concat(DateTime.Ticks, ".", input.MesEntity); if (segments[1] == hypen) BasicType = hypen; else BasicType = GetBasicType(configData, hypen, segments[1]); Equipment = input.MesEntity; JobName = DateTime.Ticks.ToString(); if (segments[0] == hypen) LotName = input.MID; else LotName = segments[1]; PackageName = hypen; //WAFER_ID WaferLot ProcessSpecName = hypen; //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 = hypen }); MoveOldFiles(configData); } } public string GetBasicType(ConfigData configData, string hypen, 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(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 StringBuilder(); 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 SqlConnection(configData.ConnectionStringLSL2SQL)) { sqlConnection.Open(); using (SqlCommand sqlCommand = new SqlCommand(sql.ToString(), sqlConnection)) scalar = sqlCommand.ExecuteScalar(); sqlConnection.Close(); } } catch (Exception) { } if (scalar is null) result = hypen; else result = scalar.ToString(); return result; } private void MoveOldFiles(ConfigData configData) { string yearWeek; string[] oldFiles; FileInfo fileInfo; string weekOfYear; string moveDirectory; DateTime daysOld = DateTime.Now.AddDays(-2); CultureInfo cultureInfo = new CultureInfo("en-US"); Calendar calendar = cultureInfo.Calendar; string[] directories = new string[] { configData.OIContextDataSearchPath, configData.OIContextDataPendingPath, configData.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) { } } } } } }