MET08DDUPSP1TBI - v2.43.0 - FileInfo added GetMID
This commit is contained in:
@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
@ -30,10 +28,10 @@ public class Job
|
||||
public DateTime DateTime { get; }
|
||||
public List<Item> Items { get; }
|
||||
|
||||
public Job(string oiContextDataPendingPath, string oiContextDataResultsPath, string oiContextDataSearchPath, string lsl2SQLConnectionString, Dictionary<int, List<(string MID, int Count)>> _RDS, string mid)
|
||||
public Job(string lsl2SQLConnectionString, Dictionary<int, List<(string MID, int Count)>> _RDS, string mid)
|
||||
{
|
||||
Items = new List<Item>();
|
||||
if (mid[0] != '{' || mid[mid.Length - 1] != '}' || !mid.Contains("\"Si\""))
|
||||
if (string.IsNullOrEmpty(mid) || mid[0] != '{' || mid[mid.Length - 1] != '}' || !mid.Contains("\"Si\""))
|
||||
IsAreaSi = false;
|
||||
else
|
||||
{
|
||||
@ -55,32 +53,43 @@ public class Job
|
||||
psn = string.Empty;
|
||||
reactor = string.Empty;
|
||||
}
|
||||
else if (rds > 0)
|
||||
else if (rds is < 100000 or > 100000000)
|
||||
{
|
||||
psn = string.Empty;
|
||||
reactor = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
psn = segments[2];
|
||||
reactor = segments[0];
|
||||
lock (_RDS)
|
||||
{
|
||||
if (!_RDS.ContainsKey(rds))
|
||||
_RDS.Add(rds, new());
|
||||
List<(string MID, int Count)> collection = _RDS[rds];
|
||||
if (collection.Count == 0)
|
||||
_RDS[rds].Add(new(input.MID, 1));
|
||||
else
|
||||
bool rdsCollectionCountIsZero = _RDS[rds].Count == 0;
|
||||
if (rdsCollectionCountIsZero)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(reactor) && !string.IsNullOrEmpty(psn))
|
||||
_RDS[rds].Add(new(input.MID, 1));
|
||||
else
|
||||
{
|
||||
string lsl2SQLMID = GetMID(lsl2SQLConnectionString, rds);
|
||||
if (string.IsNullOrEmpty(lsl2SQLMID))
|
||||
_RDS[rds].Add(new(input.MID, 1));
|
||||
else
|
||||
_RDS[rds].Add(new(lsl2SQLMID, 1));
|
||||
}
|
||||
}
|
||||
IEnumerable<IGrouping<string, (string MID, int Count)>> grouped = _RDS[rds].GroupBy(l => l.MID);
|
||||
orderedMatches.AddRange(from l in grouped orderby l.Count() descending select l);
|
||||
if (!rdsCollectionCountIsZero)
|
||||
{
|
||||
IEnumerable<IGrouping<string, (string MID, int Count)>> grouped = collection.GroupBy(l => l.MID);
|
||||
orderedMatches.AddRange(from l in grouped orderby l.Count() descending select l);
|
||||
int length = (from l in orderedMatches where l.Key == input.MID select true).Count();
|
||||
_RDS[rds].Add(new(input.MID, length + 1));
|
||||
}
|
||||
if (_RDS.Count > 1000)
|
||||
_ = _RDS.Remove(_RDS.ElementAt(0).Key);
|
||||
}
|
||||
psn = segments[2];
|
||||
reactor = segments[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
psn = string.Empty;
|
||||
reactor = string.Empty;
|
||||
}
|
||||
AutomationMode = string.Concat(DateTime.Ticks, ".", input.MesEntity);
|
||||
Equipment = input.MesEntity;
|
||||
@ -92,7 +101,7 @@ public class Job
|
||||
reactor = segments[0];
|
||||
}
|
||||
const string hyphen = "-";
|
||||
if (rds < 1)
|
||||
if (rds is < 100000 or > 100000000)
|
||||
{
|
||||
BasicType = hyphen;
|
||||
LotName = input.MID;
|
||||
@ -110,11 +119,10 @@ public class Job
|
||||
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 static string GetBasicType(string lsl2SQLConnectionString, string hyphen, int rds)
|
||||
private static string GetBasicType(string lsl2SQLConnectionString, string hyphen, int rds)
|
||||
{
|
||||
string result;
|
||||
// string json;
|
||||
@ -181,8 +189,7 @@ public class Job
|
||||
sqlConnection.Close();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
{ }
|
||||
if (scalar is null)
|
||||
result = hyphen;
|
||||
else
|
||||
@ -190,41 +197,29 @@ public class Job
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void MoveOldFiles(string oiContextDataPendingPath, string oiContextDataResultsPath, string oiContextDataSearchPath)
|
||||
private static string GetMID(string lsl2SQLConnectionString, int rds)
|
||||
{
|
||||
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)
|
||||
string result;
|
||||
object scalar = null;
|
||||
StringBuilder sql = new();
|
||||
_ = sql.Append(" SELECT CONCAT(REACTOR, '-', RDS_NO, '-', PS_NO) [MID] ").
|
||||
Append(" FROM [LSL2SQL].[dbo].[REACT_RUN] ").
|
||||
Append($" WHERE RDS_NO = '{rds}' ");
|
||||
try
|
||||
{
|
||||
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)
|
||||
{
|
||||
}
|
||||
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 = string.Empty;
|
||||
else
|
||||
result = scalar.ToString();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user