961 lines
42 KiB
C#
961 lines
42 KiB
C#
using APCViewer.Models;
|
|
using APCViewer.Models.Methods;
|
|
using IFX.Shared;
|
|
using Shared;
|
|
using Shared.Metrology;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
|
|
namespace APCViewer.Singleton;
|
|
|
|
public class Background : Models.Properties.IBackground, IBackground
|
|
{
|
|
|
|
protected readonly List<Exception> _Exceptions;
|
|
protected readonly string _WorkingDirectory;
|
|
protected string _Message;
|
|
public List<Exception> Exceptions => _Exceptions;
|
|
public string Message => _Message;
|
|
public string WorkingDirectory => _WorkingDirectory;
|
|
|
|
private bool _Stop;
|
|
private readonly Serilog.ILogger _Log;
|
|
private DateTime _PrimaryInstanceSetAt;
|
|
private readonly AppSettings _AppSettings;
|
|
private readonly IFX.Shared.IsEnvironment _IsEnvironment;
|
|
|
|
private readonly string[] _SiEquipmentTypes;
|
|
private readonly string[] _GaNEquipmentTypes;
|
|
|
|
private readonly Dictionary<string, string> _GaNPDSFFiles;
|
|
private readonly Dictionary<string, string> _SiPDSFFiles;
|
|
private readonly Dictionary<string, string> _GaNIPDSFFiles;
|
|
private readonly Dictionary<string, string> _SiIPDSFFiles;
|
|
private readonly Dictionary<string, object> _GaNAPCLogistics;
|
|
private readonly Dictionary<string, object> _SiAPCLogistics;
|
|
private readonly Dictionary<string, object> _GaNEDALogistics;
|
|
private readonly Dictionary<string, object> _SiEDALogistics;
|
|
private readonly Dictionary<string, object> _GaNEAFLogLogistics;
|
|
private readonly Dictionary<string, object> _SiEAFLogLogistics;
|
|
|
|
public Background(IFX.Shared.IsEnvironment isEnvironment, AppSettings appSettings, string workingDirectory)
|
|
{
|
|
_Stop = false;
|
|
_AppSettings = appSettings;
|
|
_Message = string.Empty;
|
|
_IsEnvironment = isEnvironment;
|
|
_Exceptions = new List<Exception>();
|
|
_WorkingDirectory = workingDirectory;
|
|
_PrimaryInstanceSetAt = DateTime.MinValue;
|
|
_Log = Serilog.Log.ForContext<Background>();
|
|
_GaNPDSFFiles = new Dictionary<string, string>();
|
|
_SiPDSFFiles = new Dictionary<string, string>();
|
|
_GaNIPDSFFiles = new Dictionary<string, string>();
|
|
_SiIPDSFFiles = new Dictionary<string, string>();
|
|
_GaNAPCLogistics = new Dictionary<string, object>();
|
|
_SiAPCLogistics = new Dictionary<string, object>();
|
|
_GaNEDALogistics = new Dictionary<string, object>();
|
|
_SiEDALogistics = new Dictionary<string, object>();
|
|
_GaNEAFLogLogistics = new Dictionary<string, object>();
|
|
_SiEAFLogLogistics = new Dictionary<string, object>();
|
|
_GaNEquipmentTypes = GetEquipmentTypes(isGaN: true, isSi: false);
|
|
_SiEquipmentTypes = GetEquipmentTypes(isGaN: false, isSi: true);
|
|
}
|
|
|
|
void IBackground.Catch(Exception exception)
|
|
{
|
|
_Exceptions.Add(exception);
|
|
_Log.Error(exception, "Error:");
|
|
}
|
|
|
|
void IBackground.Stop(bool immediate)
|
|
{
|
|
if (!_Stop)
|
|
_Stop = true;
|
|
}
|
|
|
|
void IBackground.Update()
|
|
{
|
|
// https://blog.magnusmontin.net/2018/11/05/platform-conditional-compilation-in-net-core/
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
_Log.Debug("Running on Linux!");
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
_Log.Debug("Running on macOS!");
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
_Log.Debug("Running on Windows!");
|
|
#if Linux
|
|
_Log.Debug("Built on Linux!");
|
|
#elif OSX
|
|
_Log.Debug("Built on macOS!");
|
|
#elif Windows
|
|
_Log.Debug("Built in Windows!");
|
|
#else
|
|
()("Built in Unknown!");
|
|
#endif
|
|
if (string.IsNullOrEmpty(_AppSettings.URLs) && !_IsEnvironment.Development)
|
|
throw new Exception("Invalid Application Settings URLs!");
|
|
if (_IsEnvironment.Development)
|
|
{
|
|
}
|
|
else if (_IsEnvironment.Staging)
|
|
{
|
|
}
|
|
else if (_IsEnvironment.Production)
|
|
{
|
|
}
|
|
else
|
|
throw new Exception();
|
|
}
|
|
|
|
List<string> IBackground.DoBackup()
|
|
{
|
|
List<string> results = new();
|
|
DoBackup();
|
|
return results;
|
|
}
|
|
|
|
void IBackground.ClearMessage() => _Message = string.Empty;
|
|
|
|
void IBackground.SetIsPrimaryInstance() => _PrimaryInstanceSetAt = DateTime.Now;
|
|
|
|
void IBackground.ClearIsPrimaryInstance() => _PrimaryInstanceSetAt = DateTime.MinValue;
|
|
|
|
bool IBackground.IsPrimaryInstance()
|
|
{
|
|
bool result;
|
|
DateTime dateTime = DateTime.Now.AddDays(-1);
|
|
result = _PrimaryInstanceSetAt > dateTime;
|
|
return result;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
|
return result;
|
|
}
|
|
|
|
private void DoBackup()
|
|
{
|
|
string encrypt = RijndaelEncryption.Encrypt("4hink", _AppSettings.Company);
|
|
_ = RijndaelEncryption.Decrypt(encrypt, _AppSettings.Company);
|
|
}
|
|
|
|
public void APCDataCallback()
|
|
{
|
|
Data(_AppSettings.Server, _SiEquipmentTypes, _SiAPCLogistics, _SiPDSFFiles, isAPC: true);
|
|
Data(_AppSettings.Server, _GaNEquipmentTypes, _GaNAPCLogistics, _GaNPDSFFiles, isAPC: true);
|
|
}
|
|
|
|
public void EDADataCallback()
|
|
{
|
|
Data(_AppSettings.Server, _SiEquipmentTypes, _SiEDALogistics, _SiPDSFFiles, isEDA: true);
|
|
Data(_AppSettings.Server, _GaNEquipmentTypes, _GaNEDALogistics, _GaNPDSFFiles, isEDA: true);
|
|
}
|
|
|
|
public void EAFLogDataCallback()
|
|
{
|
|
Data(_AppSettings.Server, _SiEquipmentTypes, _SiEAFLogLogistics, _SiIPDSFFiles, isEAFLog: true);
|
|
Data(_AppSettings.Server, _GaNEquipmentTypes, _GaNEAFLogLogistics, _GaNIPDSFFiles, isEAFLog: true);
|
|
}
|
|
|
|
public string GetPDSF(long Sequence)
|
|
{
|
|
string result = string.Empty;
|
|
if (string.IsNullOrEmpty(result))
|
|
{
|
|
foreach (KeyValuePair<string, object> element in _GaNEDALogistics)
|
|
{
|
|
if (((Logistics)element.Value).Sequence == Sequence)
|
|
{
|
|
result = element.Key;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (string.IsNullOrEmpty(result))
|
|
{
|
|
foreach (KeyValuePair<string, object> element in _SiEDALogistics)
|
|
{
|
|
if (((Logistics)element.Value).Sequence == Sequence)
|
|
{
|
|
result = element.Key;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (string.IsNullOrEmpty(result))
|
|
{
|
|
foreach (KeyValuePair<string, object> element in _GaNAPCLogistics)
|
|
{
|
|
if (((Logistics)element.Value).Sequence == Sequence)
|
|
{
|
|
result = element.Key;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (string.IsNullOrEmpty(result))
|
|
{
|
|
foreach (KeyValuePair<string, object> element in _SiAPCLogistics)
|
|
{
|
|
if (((Logistics)element.Value).Sequence == Sequence)
|
|
{
|
|
result = element.Key;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public string GetIPDSF(long Sequence)
|
|
{
|
|
string result = string.Empty;
|
|
if (string.IsNullOrEmpty(result))
|
|
{
|
|
foreach (KeyValuePair<string, object> element in _GaNEAFLogLogistics)
|
|
{
|
|
if (((Logistics)element.Value).Sequence == Sequence)
|
|
{
|
|
result = element.Key;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (string.IsNullOrEmpty(result))
|
|
{
|
|
foreach (KeyValuePair<string, object> element in _SiEAFLogLogistics)
|
|
{
|
|
if (((Logistics)element.Value).Sequence == Sequence)
|
|
{
|
|
result = element.Key;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public Tuple<int, Dictionary<string, Dictionary<string, List<Logistics>>>, List<Tuple<string[], Logistics>>, string?> SetViewBag(string? directory, string? filter, bool isGaN = false, bool isSi = false, bool forPDSF = false, bool forIPDSF = false)
|
|
{
|
|
Tuple<int, Dictionary<string, Dictionary<string, List<Logistics>>>, List<Tuple<string[], Logistics>>, string?> result;
|
|
if (isGaN && isSi)
|
|
throw new Exception();
|
|
else if (!isGaN && !isSi)
|
|
isGaN = true;
|
|
if (isGaN)
|
|
result = SetViewBag(_GaNAPCLogistics, _GaNEDALogistics, _GaNEAFLogLogistics, directory, filter, forPDSF, forIPDSF);
|
|
else if (isSi)
|
|
result = SetViewBag(_SiAPCLogistics, _SiEDALogistics, _SiEAFLogLogistics, directory, filter, forPDSF, forIPDSF);
|
|
else
|
|
throw new Exception();
|
|
return result;
|
|
}
|
|
|
|
public Tuple<List<string[]>, List<string[]>> GetTimePivot(bool isGaN = false, bool isSi = false)
|
|
{
|
|
List<string[]> forPDSF;
|
|
List<string[]> forIPDSF;
|
|
if (isGaN && isSi)
|
|
throw new Exception();
|
|
else if (!isGaN && !isSi)
|
|
isGaN = true;
|
|
if (isGaN)
|
|
{
|
|
forIPDSF = GetTimePivot(_GaNEquipmentTypes, _GaNAPCLogistics, _GaNEDALogistics, _GaNEAFLogLogistics, forPDSF: false, forIPDSF: true);
|
|
forPDSF = GetTimePivot(_GaNEquipmentTypes, _GaNAPCLogistics, _GaNEDALogistics, _GaNEAFLogLogistics, forPDSF: true, forIPDSF: false);
|
|
}
|
|
else if (isSi)
|
|
{
|
|
forIPDSF = GetTimePivot(_SiEquipmentTypes, _SiAPCLogistics, _SiEDALogistics, _SiEAFLogLogistics, forPDSF: false, forIPDSF: true);
|
|
forPDSF = GetTimePivot(_SiEquipmentTypes, _SiAPCLogistics, _SiEDALogistics, _SiEAFLogLogistics, forPDSF: true, forIPDSF: false);
|
|
}
|
|
else
|
|
throw new Exception();
|
|
return new Tuple<List<string[]>, List<string[]>>(forIPDSF, forPDSF);
|
|
}
|
|
|
|
public static string[] GetEquipmentTypes(bool isGaN = false, bool isSi = false)
|
|
{
|
|
string[] results;
|
|
if (isGaN && isSi)
|
|
throw new Exception();
|
|
else if (!isGaN && !isSi)
|
|
isGaN = true;
|
|
if (isSi)
|
|
{
|
|
results = new string[]
|
|
{
|
|
Shared.EquipmentType.MET08ANLYSDIFAAST230_Semi.ToString(),
|
|
Shared.EquipmentType.MET08DDUPSFS6420.ToString(),
|
|
Shared.EquipmentType.MET08DDUPSP1TBI.ToString(),
|
|
Shared.EquipmentType.MET08RESIHGCV.ToString(),
|
|
Shared.EquipmentType.MET08RESIMAPCDE.ToString(),
|
|
Shared.EquipmentType.MET08THFTIRQS408M.ToString(),
|
|
Shared.EquipmentType.MET08THFTIRSTRATUS.ToString()
|
|
};
|
|
}
|
|
else if (isGaN)
|
|
{
|
|
results = new string[]
|
|
{
|
|
Shared.EquipmentType.DEP08EGANAIXG5.ToString(),
|
|
Shared.EquipmentType.MET08AFMD3100.ToString(),
|
|
Shared.EquipmentType.MET08BVHGPROBE.ToString(),
|
|
Shared.EquipmentType.MET08CVHGPROBE802B150.ToString(),
|
|
Shared.EquipmentType.MET08CVHGPROBE802B150_Monthly.ToString(),
|
|
Shared.EquipmentType.MET08CVHGPROBE802B150_Weekly.ToString(),
|
|
Shared.EquipmentType.MET08DDINCAN8620.ToString(),
|
|
Shared.EquipmentType.MET08DDINCAN8620_Daily.ToString(),
|
|
Shared.EquipmentType.MET08EBEAMINTEGRITY26.ToString(),
|
|
Shared.EquipmentType.MET08HALLHL5580.ToString(),
|
|
Shared.EquipmentType.MET08HALLHL5580_Monthly.ToString(),
|
|
Shared.EquipmentType.MET08HALLHL5580_Weekly.ToString(),
|
|
Shared.EquipmentType.MET08MESMICROSCOPE.ToString(),
|
|
Shared.EquipmentType.MET08NDFRESIMAP151C.ToString(),
|
|
Shared.EquipmentType.MET08NDFRESIMAP151C_Verification.ToString(),
|
|
Shared.EquipmentType.MET08PLMAPRPM.ToString(),
|
|
Shared.EquipmentType.MET08PLMAPRPM_Daily.ToString(),
|
|
Shared.EquipmentType.MET08PLMAPRPM_Verification.ToString(),
|
|
Shared.EquipmentType.MET08PLMPPLATO.ToString(),
|
|
Shared.EquipmentType.MET08PRFUSB4000.ToString(),
|
|
Shared.EquipmentType.MET08UVH44GS100M.ToString(),
|
|
Shared.EquipmentType.MET08VPDSUBCON.ToString(),
|
|
Shared.EquipmentType.MET08WGEOMX203641Q.ToString(),
|
|
Shared.EquipmentType.MET08WGEOMX203641Q_Verification.ToString(),
|
|
Shared.EquipmentType.METBRXRAYJV7300L.ToString(),
|
|
Shared.EquipmentType.MET08XRDXPERTPROMRDXL.ToString(),
|
|
Shared.EquipmentType.MET08XRDXPERTPROMRDXL_Monthly.ToString(),
|
|
Shared.EquipmentType.MET08XRDXPERTPROMRDXL_Weekly.ToString()
|
|
};
|
|
}
|
|
else
|
|
throw new Exception();
|
|
return results;
|
|
}
|
|
|
|
public Tuple<int, Dictionary<string, Dictionary<string, List<Logistics>>>, List<Tuple<string[], Logistics>>, string?> SetViewBag(Dictionary<string, object> apcLogistics, Dictionary<string, object> edaLogistics, Dictionary<string, object> eafLogLogistics, string? directory = null, string? filter = null, bool forPDSF = false, bool forIPDSF = false)
|
|
{
|
|
Tuple<int, Dictionary<string, Dictionary<string, List<Logistics>>>, List<Tuple<string[], Logistics>>, string?> result;
|
|
int files = 0;
|
|
string apc = "APC";
|
|
string eaf = "EAF";
|
|
string eda = "EDA";
|
|
string root = "Root";
|
|
string error = "Error !!!";
|
|
string staging = "Staging";
|
|
string production = "Production";
|
|
string development = "Development";
|
|
List<Tuple<string[], Logistics>> sorted = new();
|
|
string[] technologies = new string[] { eaf, eda, apc };
|
|
Dictionary<string, Logistics> logisticsCollection = new();
|
|
Dictionary<long, Tuple<string[], Logistics>> pairs = new();
|
|
Dictionary<string, Dictionary<string, List<Logistics>>> grouped = new();
|
|
string[] environments = new string[] { root, staging, production, development };
|
|
foreach (string t in technologies)
|
|
{
|
|
if (_Stop)
|
|
break;
|
|
foreach (string e in environments)
|
|
{
|
|
if (_Stop)
|
|
break;
|
|
grouped.Add(string.Concat(t, " - ", e), new Dictionary<string, List<Logistics>>());
|
|
grouped.Add(string.Concat(t, " - ", e, " ", error), new Dictionary<string, List<Logistics>>());
|
|
}
|
|
}
|
|
string searchPattern;
|
|
if (forPDSF && forIPDSF)
|
|
throw new Exception();
|
|
else if (!forPDSF && !forIPDSF)
|
|
throw new Exception();
|
|
else if (forPDSF)
|
|
searchPattern = "*.pdsf";
|
|
else if (forIPDSF)
|
|
searchPattern = "*.ipdsf";
|
|
else
|
|
throw new Exception();
|
|
if (!string.IsNullOrEmpty(directory) && Directory.Exists(directory))
|
|
{
|
|
Logistics logistics;
|
|
Tuple<string, string[], string[]> pdsf;
|
|
string[] pdsfFiles = Directory.GetFiles(directory, searchPattern, SearchOption.AllDirectories);
|
|
foreach (string pdsfFile in pdsfFiles)
|
|
{
|
|
if (_Stop)
|
|
break;
|
|
pdsf = ProcessDataStandardFormat.GetLogisticsColumnsAndBody(pdsfFile);
|
|
logistics = new Logistics(pdsfFile, pdsf.Item1);
|
|
if (!logistics.Logistics2.Any())
|
|
logistics.Logistics2.Add(new Logistics2(string.Empty));
|
|
logisticsCollection.Add(pdsfFile, logistics);
|
|
}
|
|
}
|
|
else if (forIPDSF)
|
|
{
|
|
if (eafLogLogistics is not null)
|
|
{
|
|
foreach (KeyValuePair<string, object> element in eafLogLogistics)
|
|
logisticsCollection.Add(element.Key, (Logistics)element.Value);
|
|
}
|
|
}
|
|
else if (forPDSF)
|
|
{
|
|
if (edaLogistics is not null)
|
|
{
|
|
foreach (KeyValuePair<string, object> element in edaLogistics)
|
|
logisticsCollection.Add(element.Key, (Logistics)element.Value);
|
|
}
|
|
if (apcLogistics is not null)
|
|
{
|
|
foreach (KeyValuePair<string, object> element in apcLogistics)
|
|
logisticsCollection.Add(element.Key, (Logistics)element.Value);
|
|
}
|
|
}
|
|
if (logisticsCollection.Any())
|
|
{
|
|
string key;
|
|
string technology;
|
|
string environment;
|
|
string? equipmentType;
|
|
List<long> sequences = new();
|
|
foreach (KeyValuePair<string, Logistics> element in logisticsCollection)
|
|
{
|
|
if (_Stop)
|
|
break;
|
|
if (element.Key.Contains(@"\EC_EAFLog\"))
|
|
technology = eaf;
|
|
else if (element.Key.Contains(@"\EC_EDA\"))
|
|
technology = eda;
|
|
else if (element.Key.Contains(@"\EC_APC\"))
|
|
technology = apc;
|
|
else
|
|
technology = eaf;
|
|
if (element.Key.Contains(@"\Production\"))
|
|
environment = production;
|
|
else if (element.Key.Contains(@"\Staging\"))
|
|
environment = staging;
|
|
else if (element.Key.Contains(@"\DEV\"))
|
|
environment = development;
|
|
else
|
|
environment = root;
|
|
equipmentType = Path.GetFileNameWithoutExtension(Path.GetDirectoryName(Path.GetDirectoryName(element.Key)));
|
|
if (string.IsNullOrEmpty(equipmentType))
|
|
continue;
|
|
if (equipmentType == "ViewerPath")
|
|
equipmentType = Path.GetFileNameWithoutExtension(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(element.Key))));
|
|
if (string.IsNullOrEmpty(filter) || technology == filter || environment == filter || equipmentType == filter)
|
|
{
|
|
files += 1;
|
|
if (!element.Key.Contains(@"\Error\") && !element.Key.Contains(@"\BadPath\"))
|
|
key = string.Concat(technology, " - ", environment);
|
|
else
|
|
key = string.Concat(technology, " - ", environment, " ", error);
|
|
if (string.IsNullOrEmpty(equipmentType))
|
|
continue;
|
|
if (!grouped[key].ContainsKey(equipmentType))
|
|
grouped[key].Add(equipmentType, new List<Logistics>());
|
|
grouped[key][equipmentType].Add(element.Value);
|
|
if (!sequences.Contains(element.Value.Sequence))
|
|
{
|
|
sequences.Add(element.Value.Sequence);
|
|
pairs.Add(element.Value.Sequence, new Tuple<string[], Logistics>(new string[] { key, equipmentType }, element.Value));
|
|
}
|
|
else
|
|
{
|
|
for (short i = 1; i < short.MaxValue; i++)
|
|
{
|
|
if (_Stop)
|
|
break;
|
|
if (sequences.Contains(element.Value.Sequence + i))
|
|
continue;
|
|
else
|
|
{
|
|
sequences.Add(element.Value.Sequence + i);
|
|
pairs.Add(element.Value.Sequence + i, new Tuple<string[], Logistics>(new string[] { string.Concat("*", key), equipmentType }, element.Value));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
sequences = (from l in sequences orderby l descending select l).ToList();
|
|
foreach (long sequence in sequences)
|
|
sorted.Add(pairs[sequence]);
|
|
}
|
|
result = new Tuple<int, Dictionary<string, Dictionary<string, List<Logistics>>>, List<Tuple<string[], Logistics>>, string?>(files, grouped, sorted, directory);
|
|
return result;
|
|
}
|
|
|
|
public List<string[]> GetTimePivot(string[] equipmentTypes, Dictionary<string, object> apcLogistics, Dictionary<string, object> edaLogistics, Dictionary<string, object> eafLogLogistics, bool forPDSF = false, bool forIPDSF = false)
|
|
{
|
|
List<string[]> results = new();
|
|
Dictionary<string, Logistics> logisticsCollection = new();
|
|
if (forPDSF && forIPDSF)
|
|
throw new Exception();
|
|
else if (!forPDSF && !forIPDSF)
|
|
throw new Exception();
|
|
else if (forIPDSF)
|
|
{
|
|
if (eafLogLogistics is not null)
|
|
{
|
|
foreach (KeyValuePair<string, object> element in eafLogLogistics)
|
|
logisticsCollection.Add(element.Key, (Logistics)element.Value);
|
|
}
|
|
}
|
|
else if (forPDSF)
|
|
{
|
|
if (edaLogistics is not null)
|
|
{
|
|
foreach (KeyValuePair<string, object> element in edaLogistics)
|
|
logisticsCollection.Add(element.Key, (Logistics)element.Value);
|
|
}
|
|
if (apcLogistics is not null)
|
|
{
|
|
foreach (KeyValuePair<string, object> element in apcLogistics)
|
|
logisticsCollection.Add(element.Key, (Logistics)element.Value);
|
|
}
|
|
}
|
|
if (logisticsCollection.Any())
|
|
{
|
|
int eT = 0;
|
|
int jID = 1;
|
|
int pJID = 2;
|
|
int pN = 3;
|
|
int k = 4;
|
|
string key;
|
|
string partNumber;
|
|
string? equipmentConnection;
|
|
DateTime dateTime = DateTime.Now;
|
|
List<string> segments = new();
|
|
StringBuilder stringBuilder = new();
|
|
long minutes15 = dateTime.AddMinutes(-15).Ticks;
|
|
long minutes30 = dateTime.AddMinutes(-30).Ticks;
|
|
long hours1 = dateTime.AddHours(-1).Ticks;
|
|
long hours3 = dateTime.AddHours(-3).Ticks;
|
|
long days1 = dateTime.AddDays(-1).Ticks;
|
|
long days2 = dateTime.AddDays(-2).Ticks;
|
|
long days4 = dateTime.AddDays(-4).Ticks;
|
|
long days7 = dateTime.AddDays(-7).Ticks;
|
|
List<string> keys = new();
|
|
List<string[]> keySegments = new();
|
|
List<string> equipmentConnections = new();
|
|
foreach (string item in equipmentTypes)
|
|
equipmentConnections.Add(item.ToString());
|
|
Dictionary<string, List<Logistics>> m15 = new();
|
|
Dictionary<string, List<Logistics>> m30 = new();
|
|
Dictionary<string, List<Logistics>> h1 = new();
|
|
Dictionary<string, List<Logistics>> h3 = new();
|
|
Dictionary<string, List<Logistics>> d1 = new();
|
|
Dictionary<string, List<Logistics>> d2 = new();
|
|
Dictionary<string, List<Logistics>> d4 = new();
|
|
Dictionary<string, List<Logistics>> d7 = new();
|
|
Dictionary<string, List<Logistics>> more = new();
|
|
string[] si = new string[] { EquipmentType.MET08DDUPSFS6420.ToString(), EquipmentType.MET08DDUPSP1TBI.ToString(), EquipmentType.MET08RESIHGCV.ToString(), EquipmentType.MET08RESIMAPCDE.ToString(), EquipmentType.MET08THFTIRQS408M.ToString(), EquipmentType.MET08THFTIRSTRATUS.ToString() };
|
|
foreach (KeyValuePair<string, Logistics> element in logisticsCollection)
|
|
{
|
|
if (_Stop)
|
|
break;
|
|
equipmentConnection = Path.GetFileNameWithoutExtension(Path.GetDirectoryName(Path.GetDirectoryName(element.Key)));
|
|
if (string.IsNullOrEmpty(equipmentConnection))
|
|
continue;
|
|
if (equipmentConnections.Contains(equipmentConnection))
|
|
_ = equipmentConnections.Remove(equipmentConnection);
|
|
if (!element.Value.Logistics2.Any())
|
|
partNumber = string.Empty;
|
|
else
|
|
partNumber = element.Value.Logistics2[0].PartNumber;
|
|
if (string.IsNullOrEmpty(partNumber) && element.Value.Logistics1.Any())
|
|
{
|
|
key = "PRODUCT=";
|
|
if (element.Value.Logistics1[0].Contains(key))
|
|
{
|
|
segments = element.Value.Logistics1[0].Split(new string[] { key }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
|
partNumber = segments[1].Split(';')[0];
|
|
}
|
|
}
|
|
if (string.IsNullOrEmpty(partNumber))
|
|
partNumber = " ";
|
|
segments.Clear();
|
|
segments.Add(equipmentConnection);
|
|
segments.Add(element.Value.JobID);
|
|
if (si.Contains(equipmentConnection))
|
|
segments.Add("Si");
|
|
else
|
|
segments.Add(element.Value.ProcessJobID);
|
|
segments.Add(partNumber);
|
|
_ = stringBuilder.Clear();
|
|
foreach (string segment in segments)
|
|
_ = stringBuilder.Append(segment).Append('|');
|
|
key = stringBuilder.ToString();
|
|
segments.Add(key);
|
|
if (element.Value.Sequence > minutes15)
|
|
{
|
|
if (!keys.Contains(key))
|
|
{
|
|
keys.Add(key);
|
|
keySegments.Add(segments.ToArray());
|
|
m15.Add(key, new List<Logistics>());
|
|
m30.Add(key, new List<Logistics>());
|
|
h1.Add(key, new List<Logistics>());
|
|
h3.Add(key, new List<Logistics>());
|
|
d1.Add(key, new List<Logistics>());
|
|
d2.Add(key, new List<Logistics>());
|
|
d4.Add(key, new List<Logistics>());
|
|
d7.Add(key, new List<Logistics>());
|
|
more.Add(key, new List<Logistics>());
|
|
}
|
|
m15[key].Add(element.Value);
|
|
}
|
|
else if (element.Value.Sequence > minutes30)
|
|
{
|
|
if (!keys.Contains(key))
|
|
{
|
|
keys.Add(key);
|
|
keySegments.Add(segments.ToArray());
|
|
m15.Add(key, new List<Logistics>());
|
|
m30.Add(key, new List<Logistics>());
|
|
h1.Add(key, new List<Logistics>());
|
|
h3.Add(key, new List<Logistics>());
|
|
d1.Add(key, new List<Logistics>());
|
|
d2.Add(key, new List<Logistics>());
|
|
d4.Add(key, new List<Logistics>());
|
|
d7.Add(key, new List<Logistics>());
|
|
more.Add(key, new List<Logistics>());
|
|
}
|
|
m30[key].Add(element.Value);
|
|
}
|
|
else if (element.Value.Sequence > hours1)
|
|
{
|
|
if (!keys.Contains(key))
|
|
{
|
|
keys.Add(key);
|
|
keySegments.Add(segments.ToArray());
|
|
m15.Add(key, new List<Logistics>());
|
|
m30.Add(key, new List<Logistics>());
|
|
h1.Add(key, new List<Logistics>());
|
|
h3.Add(key, new List<Logistics>());
|
|
d1.Add(key, new List<Logistics>());
|
|
d2.Add(key, new List<Logistics>());
|
|
d4.Add(key, new List<Logistics>());
|
|
d7.Add(key, new List<Logistics>());
|
|
more.Add(key, new List<Logistics>());
|
|
}
|
|
h1[key].Add(element.Value);
|
|
}
|
|
else if (element.Value.Sequence > hours3)
|
|
{
|
|
if (!keys.Contains(key))
|
|
{
|
|
keys.Add(key);
|
|
keySegments.Add(segments.ToArray());
|
|
m15.Add(key, new List<Logistics>());
|
|
m30.Add(key, new List<Logistics>());
|
|
h1.Add(key, new List<Logistics>());
|
|
h3.Add(key, new List<Logistics>());
|
|
d1.Add(key, new List<Logistics>());
|
|
d2.Add(key, new List<Logistics>());
|
|
d4.Add(key, new List<Logistics>());
|
|
d7.Add(key, new List<Logistics>());
|
|
more.Add(key, new List<Logistics>());
|
|
}
|
|
h3[key].Add(element.Value);
|
|
}
|
|
else if (element.Value.Sequence > days1)
|
|
{
|
|
if (!keys.Contains(key))
|
|
{
|
|
keys.Add(key);
|
|
keySegments.Add(segments.ToArray());
|
|
m15.Add(key, new List<Logistics>());
|
|
m30.Add(key, new List<Logistics>());
|
|
h1.Add(key, new List<Logistics>());
|
|
h3.Add(key, new List<Logistics>());
|
|
d1.Add(key, new List<Logistics>());
|
|
d2.Add(key, new List<Logistics>());
|
|
d4.Add(key, new List<Logistics>());
|
|
d7.Add(key, new List<Logistics>());
|
|
more.Add(key, new List<Logistics>());
|
|
}
|
|
d1[key].Add(element.Value);
|
|
}
|
|
else if (element.Value.Sequence > days2)
|
|
{
|
|
if (!keys.Contains(key))
|
|
{
|
|
keys.Add(key);
|
|
keySegments.Add(segments.ToArray());
|
|
m15.Add(key, new List<Logistics>());
|
|
m30.Add(key, new List<Logistics>());
|
|
h1.Add(key, new List<Logistics>());
|
|
h3.Add(key, new List<Logistics>());
|
|
d1.Add(key, new List<Logistics>());
|
|
d2.Add(key, new List<Logistics>());
|
|
d4.Add(key, new List<Logistics>());
|
|
d7.Add(key, new List<Logistics>());
|
|
more.Add(key, new List<Logistics>());
|
|
}
|
|
d2[key].Add(element.Value);
|
|
}
|
|
else if (element.Value.Sequence > days4)
|
|
{
|
|
if (!keys.Contains(key))
|
|
{
|
|
keys.Add(key);
|
|
keySegments.Add(segments.ToArray());
|
|
m15.Add(key, new List<Logistics>());
|
|
m30.Add(key, new List<Logistics>());
|
|
h1.Add(key, new List<Logistics>());
|
|
h3.Add(key, new List<Logistics>());
|
|
d1.Add(key, new List<Logistics>());
|
|
d2.Add(key, new List<Logistics>());
|
|
d4.Add(key, new List<Logistics>());
|
|
d7.Add(key, new List<Logistics>());
|
|
more.Add(key, new List<Logistics>());
|
|
}
|
|
d4[key].Add(element.Value);
|
|
}
|
|
else if (element.Value.Sequence > days7)
|
|
{
|
|
if (!keys.Contains(key))
|
|
{
|
|
keys.Add(key);
|
|
keySegments.Add(segments.ToArray());
|
|
m15.Add(key, new List<Logistics>());
|
|
m30.Add(key, new List<Logistics>());
|
|
h1.Add(key, new List<Logistics>());
|
|
h3.Add(key, new List<Logistics>());
|
|
d1.Add(key, new List<Logistics>());
|
|
d2.Add(key, new List<Logistics>());
|
|
d4.Add(key, new List<Logistics>());
|
|
d7.Add(key, new List<Logistics>());
|
|
more.Add(key, new List<Logistics>());
|
|
}
|
|
d7[key].Add(element.Value);
|
|
}
|
|
else
|
|
{
|
|
if (!keys.Contains(key))
|
|
{
|
|
keys.Add(key);
|
|
keySegments.Add(segments.ToArray());
|
|
m15.Add(key, new List<Logistics>());
|
|
m30.Add(key, new List<Logistics>());
|
|
h1.Add(key, new List<Logistics>());
|
|
h3.Add(key, new List<Logistics>());
|
|
d1.Add(key, new List<Logistics>());
|
|
d2.Add(key, new List<Logistics>());
|
|
d4.Add(key, new List<Logistics>());
|
|
d7.Add(key, new List<Logistics>());
|
|
more.Add(key, new List<Logistics>());
|
|
}
|
|
more[key].Add(element.Value);
|
|
}
|
|
}
|
|
int count;
|
|
List<string> row;
|
|
results.Add(new string[] { "ET", nameof(Logistics.JobID), nameof(Logistics.ProcessJobID), nameof(Logistics2.PartNumber), "m15", "m30", "h1", "h3", "d1", "d2", "d4", "d7", "more" });
|
|
for (int i = 0; i < equipmentConnections.Count; i++)
|
|
results.Add(new string[] { equipmentConnections[i], " ", " ", " ", "0", "0", "0", "0", "0", "0", "0", "0", "0" });
|
|
keySegments = (from l in keySegments orderby l[eT], l[jID], l[pJID], l[pN] select l).ToList();
|
|
foreach (string[] keySegment in keySegments)
|
|
{
|
|
if (_Stop)
|
|
break;
|
|
count = 0;
|
|
key = keySegment[k];
|
|
row = new List<string>(new string[] { keySegment[eT], keySegment[pJID], keySegment[jID], keySegment[pN] });
|
|
count += m15[key].Count;
|
|
row.Add(count.ToString());
|
|
count += m30[key].Count;
|
|
row.Add(count.ToString());
|
|
count += h1[key].Count;
|
|
row.Add(count.ToString());
|
|
count += h3[key].Count;
|
|
row.Add(count.ToString());
|
|
count += d1[key].Count;
|
|
row.Add(count.ToString());
|
|
count += d2[key].Count;
|
|
row.Add(count.ToString());
|
|
count += d4[key].Count;
|
|
row.Add(count.ToString());
|
|
count += d7[key].Count;
|
|
row.Add(count.ToString());
|
|
count += more[key].Count;
|
|
row.Add(count.ToString());
|
|
results.Add(row.ToArray());
|
|
}
|
|
}
|
|
return results;
|
|
}
|
|
|
|
public void Data(string server, string[] equipmentTypes, Dictionary<string, object> inputLogistics, Dictionary<string, string> inputPDSFFiles, bool isEAFLog = false, bool isEDA = false, bool isAPC = false)
|
|
{
|
|
DateTime dateTime;
|
|
string[] pdsfFiles;
|
|
string checkDirectory;
|
|
DateTime creationTime;
|
|
DateTime lastWriteTime;
|
|
string[] cellInstanceDirectories;
|
|
string[] equipmentTypeDirectories;
|
|
long ticks = DateTime.Now.AddDays(-5).Ticks;
|
|
List<string> pdsfFileCollection = new();
|
|
long pollPathTicks = DateTime.Now.AddMinutes(-5).Ticks;
|
|
Tuple<string, string[], string[]> pdsf;
|
|
if (inputLogistics is null)
|
|
inputLogistics = new Dictionary<string, object>();
|
|
if (inputPDSFFiles is null)
|
|
inputPDSFFiles = new Dictionary<string, string>();
|
|
if (inputLogistics.Any())
|
|
{
|
|
string[] fileKeys = inputLogistics.Keys.ToArray();
|
|
foreach (string fileKey in fileKeys)
|
|
{
|
|
if (_Stop)
|
|
break;
|
|
if (!File.Exists(fileKey))
|
|
continue;
|
|
creationTime = new FileInfo(fileKey).CreationTime;
|
|
lastWriteTime = new FileInfo(fileKey).LastWriteTime;
|
|
if (creationTime < lastWriteTime)
|
|
dateTime = creationTime;
|
|
else
|
|
dateTime = lastWriteTime;
|
|
if (dateTime.Ticks < ticks)
|
|
{
|
|
if (inputLogistics.ContainsKey(fileKey))
|
|
_ = inputLogistics.Remove(fileKey);
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
string key;
|
|
int loopEnd;
|
|
int loopStart;
|
|
string searchPattern;
|
|
string equipmentType;
|
|
string rootDirectoryPath;
|
|
bool isDuplicatorDirectory;
|
|
if (isEAFLog && isEDA && isAPC)
|
|
throw new Exception();
|
|
else if (!isEAFLog && !isEDA && !isAPC)
|
|
throw new Exception();
|
|
else if (isEAFLog)
|
|
{
|
|
loopEnd = 4;
|
|
loopStart = 1;
|
|
searchPattern = "*.ipdsf";
|
|
rootDirectoryPath = string.Concat(@"\\", server, @"\EC_EAFLog");
|
|
}
|
|
else if (isEDA)
|
|
{
|
|
loopEnd = 6;
|
|
loopStart = 2;
|
|
searchPattern = "*.pdsf";
|
|
rootDirectoryPath = string.Concat(@"\\", server, @"\EC_EDA");
|
|
}
|
|
else if (isAPC)
|
|
{
|
|
loopEnd = 7;
|
|
loopStart = 6;
|
|
searchPattern = "*.pdsf";
|
|
rootDirectoryPath = string.Concat(@"\\", server, @"\EC_APC");
|
|
}
|
|
else
|
|
throw new Exception();
|
|
string[] rootDirectories = Directory.GetDirectories(rootDirectoryPath, "*", SearchOption.TopDirectoryOnly);
|
|
foreach (string rootDirectory in rootDirectories)
|
|
{
|
|
if (_Stop)
|
|
break;
|
|
if (rootDirectory.Contains(@"\DEV"))
|
|
continue;
|
|
checkDirectory = string.Concat(rootDirectory, @"\Traces");
|
|
if (!Directory.Exists(checkDirectory))
|
|
continue;
|
|
equipmentTypeDirectories = Directory.GetDirectories(checkDirectory, "*", SearchOption.TopDirectoryOnly);
|
|
foreach (string equipmentTypeDirectory in equipmentTypeDirectories)
|
|
{
|
|
if (_Stop)
|
|
break;
|
|
equipmentType = Path.GetFileName(equipmentTypeDirectory);
|
|
if (!equipmentTypes.Contains(equipmentType))
|
|
continue;
|
|
for (int i = loopStart; i < loopEnd; i++)
|
|
{
|
|
if (_Stop)
|
|
break;
|
|
checkDirectory = i switch
|
|
{
|
|
1 => string.Concat(equipmentTypeDirectory, @"\Source"),
|
|
2 => string.Concat(equipmentTypeDirectory, @"\Error"),
|
|
3 => string.Concat(equipmentTypeDirectory, @"\Target"),
|
|
4 => string.Concat(equipmentTypeDirectory, @"\BadPath"),
|
|
5 => string.Concat(equipmentTypeDirectory, @"\PollPath"),
|
|
6 => string.Concat(equipmentTypeDirectory, @"\ViewerPath"),
|
|
_ => throw new Exception(),
|
|
};
|
|
if (!Directory.Exists(checkDirectory))
|
|
continue;
|
|
pdsfFiles = Directory.GetFiles(checkDirectory, searchPattern, SearchOption.AllDirectories);
|
|
if (isAPC && !pdsfFiles.Any() && i == 6)
|
|
{
|
|
pdsfFileCollection.Clear();
|
|
cellInstanceDirectories = Directory.GetDirectories(checkDirectory, "*", SearchOption.TopDirectoryOnly);
|
|
foreach (string cellInstanceDirectory in cellInstanceDirectories)
|
|
pdsfFileCollection.AddRange(Directory.GetFiles(cellInstanceDirectory, searchPattern, SearchOption.TopDirectoryOnly));
|
|
pdsfFiles = pdsfFileCollection.ToArray();
|
|
}
|
|
foreach (string pdsfFile in pdsfFiles)
|
|
{
|
|
if (_Stop)
|
|
break;
|
|
creationTime = new FileInfo(pdsfFile).CreationTime;
|
|
lastWriteTime = new FileInfo(pdsfFile).LastWriteTime;
|
|
isDuplicatorDirectory = Path.GetDirectoryName(pdsfFile) != checkDirectory && Path.GetFileName(Path.GetDirectoryName(Path.GetDirectoryName(pdsfFile))) == equipmentType;
|
|
if (creationTime < lastWriteTime)
|
|
dateTime = creationTime;
|
|
else
|
|
dateTime = lastWriteTime;
|
|
if (dateTime.Ticks < ticks)
|
|
{
|
|
if (inputLogistics.ContainsKey(pdsfFile))
|
|
{
|
|
_ = inputLogistics.Remove(pdsfFile);
|
|
continue;
|
|
}
|
|
}
|
|
else if (isDuplicatorDirectory)
|
|
continue;
|
|
else if (checkDirectory.Contains("PollPath") && dateTime.Ticks > pollPathTicks)
|
|
continue;
|
|
else if (!inputLogistics.ContainsKey(pdsfFile))
|
|
{
|
|
pdsf = ProcessDataStandardFormat.GetLogisticsColumnsAndBody(pdsfFile);
|
|
Logistics logistics = new(pdsfFile, pdsf.Item1);
|
|
if (!logistics.Logistics2.Any())
|
|
logistics.Logistics2.Add(new Logistics2(string.Empty));
|
|
key = Path.GetFileName(pdsfFile);
|
|
if (!inputPDSFFiles.ContainsKey(key))
|
|
inputPDSFFiles.Add(key, pdsfFile);
|
|
else
|
|
{
|
|
foreach (KeyValuePair<string, object> element in inputLogistics)
|
|
{
|
|
if (Path.GetFileName(element.Key) == key)
|
|
{
|
|
if (!File.Exists(element.Key))
|
|
_ = inputLogistics.Remove(element.Key);
|
|
}
|
|
}
|
|
}
|
|
inputLogistics.Add(pdsfFile, logistics);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
} |