Match TFS Changeset 303362
This commit is contained in:
912
EDA Viewer/Singleton/Background.cs
Normal file
912
EDA Viewer/Singleton/Background.cs
Normal file
@ -0,0 +1,912 @@
|
||||
using EDAViewer.Models;
|
||||
using EDAViewer.Singleton.Helper;
|
||||
using Infineon.Monitoring.MonA;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Shared;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace EDAViewer.Singleton
|
||||
{
|
||||
|
||||
public partial class Background : IBackground
|
||||
{
|
||||
|
||||
public List<Timer> Timers => _Timers;
|
||||
public string Message { get; private set; }
|
||||
public string WorkingDirectory { get; private set; }
|
||||
public List<Exception> Exceptions { get; private set; }
|
||||
|
||||
private bool _ShuttingDown;
|
||||
private readonly object _Lock;
|
||||
private readonly Calendar _Calendar;
|
||||
private readonly List<Timer> _Timers;
|
||||
private readonly AppSettings _AppSettings;
|
||||
private readonly string[] _SiEquipmentTypes;
|
||||
private readonly string[] _GaNEquipmentTypes;
|
||||
private readonly IsEnvironment _IsEnvironment;
|
||||
|
||||
private const string _Site = "sjc";
|
||||
|
||||
private Log _Log;
|
||||
private DateTime _PrimaryInstanceSetAt;
|
||||
private string _EdaDataCollectionPlansLastRun;
|
||||
|
||||
public Background(IsEnvironment isEnvironment, AppSettings appSettings, string workingDirectory)
|
||||
{
|
||||
_Log = null;
|
||||
Exceptions = new();
|
||||
_IsEnvironment = isEnvironment;
|
||||
_Lock = new object();
|
||||
_ShuttingDown = false;
|
||||
if (_Lock is null)
|
||||
{ }
|
||||
Message = string.Empty;
|
||||
_AppSettings = appSettings;
|
||||
_Timers = new List<Timer>();
|
||||
_IsEnvironment = isEnvironment;
|
||||
WorkingDirectory = workingDirectory;
|
||||
_PrimaryInstanceSetAt = DateTime.MinValue;
|
||||
_EdaDataCollectionPlansLastRun = string.Empty;
|
||||
_SiEquipmentTypes = GetEquipmentTypes(isGaN: false, isSi: true);
|
||||
_GaNEquipmentTypes = GetEquipmentTypes(isGaN: true, isSi: false);
|
||||
CultureInfo cultureInfo = new CultureInfo("en-US");
|
||||
_Calendar = cultureInfo.Calendar;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (Timer timer in _Timers)
|
||||
timer.Dispose();
|
||||
}
|
||||
|
||||
void IBackground.Update(ILogger<object> logger)
|
||||
{
|
||||
Update(logger);
|
||||
}
|
||||
|
||||
internal void Update(ILogger<object> logger)
|
||||
{
|
||||
_Log = new Log(logger);
|
||||
//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 unkown!");
|
||||
#endif
|
||||
if (string.IsNullOrEmpty(_AppSettings.URLs) && !_IsEnvironment.Development)
|
||||
throw new Exception("Invalid Application Settings URLs!");
|
||||
}
|
||||
|
||||
internal void Catch(Exception exception)
|
||||
{
|
||||
Exceptions.Add(exception);
|
||||
_Log.Error(exception);
|
||||
if (!string.IsNullOrEmpty(_AppSettings.MonARessource))
|
||||
{
|
||||
MonIn monIn = MonIn.GetInstance();
|
||||
monIn.SendStatus(_Site, _AppSettings.MonARessource, "Heartbeat", State.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
public void SendStatusOk()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_AppSettings.MonARessource))
|
||||
{
|
||||
MonIn monIn = MonIn.GetInstance();
|
||||
monIn.SendStatus(_Site, _AppSettings.MonARessource, "Heartbeat", State.Ok);
|
||||
}
|
||||
}
|
||||
|
||||
public string GetCountDirectory(string verb)
|
||||
{
|
||||
DateTime dateTime = DateTime.Now;
|
||||
CultureInfo cultureInfo = new("en-US");
|
||||
Calendar calendar = cultureInfo.Calendar;
|
||||
string weekOfYear = calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
//string nameSpace = System.Reflection.Assembly.GetExecutingAssembly().EntryPoint.DeclaringType.Namespace;
|
||||
string nameSpace = GetType().Namespace.Split('.')[0];
|
||||
if (!string.IsNullOrEmpty(_AppSettings.MonARessource))
|
||||
{
|
||||
MonIn monIn = MonIn.GetInstance();
|
||||
monIn.SendStatus(_Site, _AppSettings.MonARessource, "Heartbeat", State.Up);
|
||||
}
|
||||
return string.Concat(@"\\", _AppSettings.Server, @"\EC_EDA\Counts\", dateTime.ToString("yyyy"), @"\", "Week_", weekOfYear, @"\", dateTime.ToString("yyyy - MM - dd"), @"\", "Application", @"\", nameSpace, @"\", verb, @"\", dateTime.Ticks);
|
||||
}
|
||||
|
||||
public void Stop(bool immediate)
|
||||
{
|
||||
_ShuttingDown = true;
|
||||
foreach (Timer timer in _Timers)
|
||||
timer.Change(Timeout.Infinite, 0);
|
||||
if (!_IsEnvironment.Development)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_AppSettings.MonARessource))
|
||||
{
|
||||
MonIn monIn = MonIn.GetInstance();
|
||||
monIn.SendStatus(_Site, _AppSettings.MonARessource, "Heartbeat", State.Down);
|
||||
}
|
||||
string countDirectory = GetCountDirectory("Stop");
|
||||
Directory.CreateDirectory(countDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearMessage()
|
||||
{
|
||||
Message = string.Empty;
|
||||
}
|
||||
|
||||
public void SetIsPrimaryInstance()
|
||||
{
|
||||
_PrimaryInstanceSetAt = DateTime.Now;
|
||||
}
|
||||
|
||||
public void ClearIsPrimaryInstance()
|
||||
{
|
||||
_PrimaryInstanceSetAt = DateTime.MinValue;
|
||||
}
|
||||
|
||||
public bool IsPrimaryInstance()
|
||||
{
|
||||
bool result;
|
||||
DateTime dateTime = DateTime.Now.AddDays(-1);
|
||||
result = _PrimaryInstanceSetAt > dateTime;
|
||||
return result;
|
||||
}
|
||||
|
||||
public void EdaDataCollectionPlansCallback()
|
||||
{
|
||||
string cSharpFormat = "yyyy-MM-dd_hh:mm:ss tt";
|
||||
string oracleFormat = "yyyy-MM-dd_hh:mi:ss AM";
|
||||
_Log.Debug(string.Concat("A) _EdaDataCollectionPlansLastRun = ", _EdaDataCollectionPlansLastRun));
|
||||
DataCollectionPlans(_AppSettings, _EdaDataCollectionPlansLastRun, cSharpFormat, oracleFormat);
|
||||
_EdaDataCollectionPlansLastRun = DateTime.Now.ToString(cSharpFormat);
|
||||
_Log.Debug(string.Concat("B) _EdaDataCollectionPlansLastRun = ", _EdaDataCollectionPlansLastRun));
|
||||
}
|
||||
private void DeleteEmptyDirectories(string directory)
|
||||
{
|
||||
string[] files = Directory.GetFiles(directory, "*", SearchOption.AllDirectories);
|
||||
string[] directories = Directory.GetDirectories(directory, "*", SearchOption.AllDirectories);
|
||||
if (files.Length == 0 && directories.Length == 0)
|
||||
Directory.Delete(directory);
|
||||
else
|
||||
{
|
||||
foreach (string subDirectory in Directory.GetDirectories(directory, "*", SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
DeleteEmptyDirectories(subDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ZipFilesByDate(string sourceDirectory, SearchOption searchOption = SearchOption.TopDirectoryOnly, string dayFormat = null)
|
||||
{
|
||||
string key;
|
||||
bool addFile;
|
||||
string fileName;
|
||||
string[] segments;
|
||||
string[] subFiles;
|
||||
string weekOfYear;
|
||||
FileInfo fileInfo;
|
||||
DateTime creationTime;
|
||||
DateTime lastWriteTime;
|
||||
Regex regex = new Regex("[a-zA-Z0-9]{1,}");
|
||||
DateTime dateTime = DateTime.Now.AddDays(-6);
|
||||
DateTime firstEmail = new DateTime(2019, 3, 8);
|
||||
CultureInfo cultureInfo = new CultureInfo("en-US");
|
||||
Calendar calendar = cultureInfo.Calendar;
|
||||
int ticksLength = dateTime.Ticks.ToString().Length;
|
||||
Dictionary<string, DateTime> weeks = new Dictionary<string, DateTime>();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
dateTime = firstEmail.AddDays(i);
|
||||
weekOfYear = calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
key = string.Concat(dateTime.ToString("yyyy"), "_Week_", weekOfYear);
|
||||
if (!weeks.ContainsKey(key))
|
||||
weeks.Add(key, dateTime);
|
||||
}
|
||||
weekOfYear = calendar.GetWeekOfYear(DateTime.Now, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
string skipKey = string.Concat(DateTime.Now.ToString("yyyy"), "_Week_", weekOfYear);
|
||||
Dictionary<string, List<string>> keyValuePairs = new Dictionary<string, List<string>>();
|
||||
string[] topDirectories = Directory.GetDirectories(sourceDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
if (topDirectories.Length == 0)
|
||||
topDirectories = new string[] { sourceDirectory };
|
||||
foreach (string topDirectory in topDirectories)
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
keyValuePairs.Clear();
|
||||
subFiles = Directory.GetFiles(topDirectory, "*", searchOption);
|
||||
foreach (string subFile in subFiles)
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
addFile = false;
|
||||
if (subFile.EndsWith(".zip"))
|
||||
continue;
|
||||
fileName = Path.GetFileName(subFile);
|
||||
fileInfo = new FileInfo(subFile);
|
||||
creationTime = fileInfo.CreationTime;
|
||||
if (creationTime > dateTime)
|
||||
continue;
|
||||
lastWriteTime = fileInfo.LastWriteTime;
|
||||
if (fileName.Contains(lastWriteTime.ToString("yyyyMMdd")) || fileName.Contains(lastWriteTime.ToString("yyyy-MM-dd")) ||
|
||||
fileName.Contains(creationTime.ToString("yyyyMMdd")) || fileName.Contains(creationTime.ToString("yyyy-MM-dd")) ||
|
||||
fileName.Contains(lastWriteTime.ToString("yyMMdd")) || fileName.Contains(lastWriteTime.ToString("yy-MM-dd")) ||
|
||||
fileName.Contains(creationTime.ToString("yyMMdd")) || fileName.Contains(creationTime.ToString("yy-MM-dd")) ||
|
||||
fileName.Contains(lastWriteTime.AddDays(-1).ToString("yyyyMMdd")) || fileName.Contains(lastWriteTime.AddDays(-1).ToString("yyyy-MM-dd")) ||
|
||||
fileName.Contains(creationTime.AddDays(-1).ToString("yyyyMMdd")) || fileName.Contains(creationTime.AddDays(-1).ToString("yyyy-MM-dd")) ||
|
||||
fileName.Contains(lastWriteTime.AddDays(-1).ToString("yyMMdd")) || fileName.Contains(lastWriteTime.AddDays(-1).ToString("yy-MM-dd")) ||
|
||||
fileName.Contains(creationTime.AddDays(-1).ToString("yyMMdd")) || fileName.Contains(creationTime.AddDays(-1).ToString("yy-MM-dd")))
|
||||
addFile = true;
|
||||
if (!addFile && fileName.Length > ticksLength)
|
||||
{
|
||||
MatchCollection matches = regex.Matches(fileName);
|
||||
foreach (Match match in matches)
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
if (match.Value.Length != ticksLength)
|
||||
continue;
|
||||
if (!long.TryParse(match.Value, out long ticks))
|
||||
continue;
|
||||
addFile = true;
|
||||
break;
|
||||
}
|
||||
if (addFile)
|
||||
break;
|
||||
}
|
||||
if (addFile)
|
||||
{
|
||||
weekOfYear = calendar.GetWeekOfYear(lastWriteTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
if (string.IsNullOrEmpty(dayFormat))
|
||||
key = string.Concat(lastWriteTime.ToString("yyyy"), "_Week_", weekOfYear);
|
||||
else
|
||||
key = string.Concat(lastWriteTime.ToString("yyyy"), "_Week_", weekOfYear, "_", lastWriteTime.ToString(dayFormat));
|
||||
if (key == skipKey)
|
||||
continue;
|
||||
if (!keyValuePairs.ContainsKey(key))
|
||||
keyValuePairs.Add(key, new List<string>());
|
||||
keyValuePairs[key].Add(subFile);
|
||||
}
|
||||
}
|
||||
foreach (KeyValuePair<string, List<string>> element in keyValuePairs)
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
key = string.Concat(topDirectory, @"\", element.Key, ".zip");
|
||||
if (File.Exists(key))
|
||||
{
|
||||
for (short i = 101; i < short.MaxValue; i++)
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
key = string.Concat(topDirectory, @"\", element.Key, "_", i, ".zip");
|
||||
if (!File.Exists(key))
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
lock (_Lock)
|
||||
{
|
||||
using (ZipArchive zip = ZipFile.Open(key, ZipArchiveMode.Create))
|
||||
{
|
||||
foreach (string file in element.Value)
|
||||
{
|
||||
zip.CreateEntryFromFile(file, Path.GetFileName(file));
|
||||
File.Delete(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
subFiles = Directory.GetFiles(topDirectory, "*.zip", SearchOption.TopDirectoryOnly);
|
||||
foreach (string subFile in subFiles)
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
fileName = Path.GetFileNameWithoutExtension(subFile);
|
||||
segments = fileName.Split('_');
|
||||
if (segments.Length > 2)
|
||||
fileName = string.Concat(segments[0], '_', segments[1], '_', segments[2]);
|
||||
if (weeks.ContainsKey(fileName))
|
||||
{
|
||||
try
|
||||
{ File.SetLastWriteTime(subFile, weeks[fileName]); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
}
|
||||
if (topDirectory != sourceDirectory)
|
||||
try
|
||||
{ DeleteEmptyDirectories(topDirectory); }
|
||||
catch (Exception) { }
|
||||
//Print(topDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
public void LogPathCleanUpByWeek(string server, bool isEDA = false, bool isNA = false)
|
||||
{
|
||||
if (isEDA && isNA)
|
||||
throw new Exception();
|
||||
else if (!isEDA && !isNA)
|
||||
throw new Exception();
|
||||
string share;
|
||||
Tuple<string, string>[] tuples;
|
||||
if (isEDA)
|
||||
{
|
||||
share = string.Concat(@"\\", server, @"\ec_eda");
|
||||
tuples = new Tuple<string, string>[]
|
||||
{
|
||||
new Tuple<string, string>(@"\Staging\Traces\MET08ANLYSDIFAAST230\LogFile", string.Empty),
|
||||
//new Tuple<string, string>(@"\Staging\Traces\DEP08EGANAIXG5HT\R69-HSMS\LogFile", "yyyy_MM_dd"),
|
||||
//new Tuple<string, string>(@"\Staging\Traces\DEP08EGANAIXG5\LogFile\R69-HSMS", "yyyy_MM_dd"),
|
||||
//new Tuple<string, string>(@"\Staging\Traces\DEP08EGANAIXG5HT\R71-HSMS\LogFile", "yyyy_MM_dd"),
|
||||
//new Tuple<string, string>(@"\Staging\Traces\DEP08EGANAIXG5\LogFile\R71-HSMS", "yyyy_MM_dd"),
|
||||
new Tuple<string, string>(@"\Staging\Traces\MET08XRDXPERTPROMRDXL_Monthly\LogFile", string.Empty),
|
||||
new Tuple<string, string>(@"\Staging\Traces\MET08XRDXPERTPROMRDXL_Weekly\LogFile", string.Empty),
|
||||
new Tuple<string, string>(@"\Staging\Traces\MET08DDINCAN8620_Daily\LogFile", string.Empty),
|
||||
new Tuple<string, string>(@"\Staging\Traces\MET08PRFUSB4000\LogFile", string.Empty),
|
||||
};
|
||||
}
|
||||
else if (isNA)
|
||||
throw new Exception();
|
||||
else
|
||||
throw new Exception();
|
||||
string[] files;
|
||||
string weekOfYear;
|
||||
FileInfo fileInfo;
|
||||
string newDirectroy;
|
||||
string sourceDirectory;
|
||||
DateTime lastWriteTime;
|
||||
string[] topDirectories;
|
||||
long twoDays = DateTime.Now.AddDays(-2).Ticks;
|
||||
foreach (Tuple<string, string> tuple in tuples)
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
sourceDirectory = string.Concat(share, tuple.Item1);
|
||||
if (!Directory.Exists(sourceDirectory))
|
||||
continue;
|
||||
if (isEDA)
|
||||
topDirectories = new string[] { sourceDirectory };
|
||||
else if (isNA)
|
||||
throw new Exception();
|
||||
else
|
||||
throw new Exception();
|
||||
if (topDirectories.Length == 0)
|
||||
topDirectories = new string[] { sourceDirectory };
|
||||
foreach (string topDirectory in topDirectories)
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
files = Directory.GetFiles(topDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
if (file.EndsWith(".zip"))
|
||||
continue;
|
||||
fileInfo = new FileInfo(file);
|
||||
lastWriteTime = fileInfo.LastAccessTime;
|
||||
if (lastWriteTime.Ticks > twoDays)
|
||||
continue;
|
||||
weekOfYear = _Calendar.GetWeekOfYear(lastWriteTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
newDirectroy = string.Concat(topDirectory, @"\", lastWriteTime.ToString("yyyy"), "___Week_", weekOfYear, @"\", lastWriteTime.ToString("yyyy_MM_dd"));
|
||||
if (!Directory.Exists(newDirectroy))
|
||||
Directory.CreateDirectory(newDirectroy);
|
||||
if (!fileInfo.Exists)
|
||||
continue;
|
||||
if (!_ShuttingDown)
|
||||
{
|
||||
lock (_Lock)
|
||||
File.Move(file, string.Concat(newDirectroy, @"\", Path.GetFileName(file)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (Tuple<string, string> tuple in tuples)
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
sourceDirectory = string.Concat(share, tuple.Item1);
|
||||
if (!Directory.Exists(sourceDirectory))
|
||||
continue;
|
||||
ZipFilesByDate(sourceDirectory, SearchOption.AllDirectories, tuple.Item2);
|
||||
}
|
||||
}
|
||||
|
||||
public void LogPathCleanUpByWeekCallback()
|
||||
{
|
||||
DateTime dateTime = DateTime.Now;
|
||||
if (dateTime.Hour > 8 && dateTime.Hour < 17)
|
||||
{
|
||||
_Log.Debug(string.Concat("A) ", nameof(LogPathCleanUpByWeek)));
|
||||
LogPathCleanUpByWeek(_AppSettings.Server, isEDA: true);
|
||||
_Log.Debug(string.Concat("B) ", nameof(LogPathCleanUpByWeek)));
|
||||
}
|
||||
}
|
||||
|
||||
public void EDAOutputArchive(string sourceDirectory)
|
||||
{
|
||||
string key;
|
||||
string[] files;
|
||||
string[] cellIntaces;
|
||||
string fileWeekOfYear;
|
||||
DateTime fileDateTime;
|
||||
string checkDirectory;
|
||||
string cellInstancesName;
|
||||
string emptyFilesDirectory;
|
||||
int today = DateTime.Now.Day;
|
||||
string recipeArchiveDirectory;
|
||||
Dictionary<string, List<string>> keyValuePairs = new Dictionary<string, List<string>>();
|
||||
string[] equipmentTypes = Directory.GetDirectories(sourceDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string equipmentType in equipmentTypes)
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
if (equipmentType.EndsWith(@"\_ Copy") || equipmentType.EndsWith(@"\_ Empty") || equipmentType.EndsWith(@"\CellInstance") || equipmentType.EndsWith(@"\IQS") || equipmentType.EndsWith(@"\Villach"))
|
||||
continue;
|
||||
checkDirectory = string.Concat(equipmentType, @"\Ignore\Recipe");
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
Directory.CreateDirectory(checkDirectory);
|
||||
cellIntaces = Directory.GetDirectories(checkDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string cellIntace in cellIntaces)
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
keyValuePairs.Clear();
|
||||
cellInstancesName = Path.GetFileName(cellIntace);
|
||||
recipeArchiveDirectory = string.Concat(equipmentType, @"\Ignore\!Archive\Recipe\", cellInstancesName);
|
||||
if (!Directory.Exists(recipeArchiveDirectory))
|
||||
Directory.CreateDirectory(recipeArchiveDirectory);
|
||||
emptyFilesDirectory = string.Concat(equipmentType, @"\Ignore\!Archive\EmptyFiles\", cellInstancesName);
|
||||
if (!Directory.Exists(emptyFilesDirectory))
|
||||
Directory.CreateDirectory(emptyFilesDirectory);
|
||||
files = Directory.GetFiles(cellIntace, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
fileDateTime = new FileInfo(file).LastWriteTime;
|
||||
if (fileDateTime.Day != today)
|
||||
{
|
||||
fileWeekOfYear = _Calendar.GetWeekOfYear(fileDateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
key = string.Concat(fileDateTime.ToString("yyyy-MM-dd"), "_Week_", fileWeekOfYear);
|
||||
if (!keyValuePairs.ContainsKey(key))
|
||||
keyValuePairs.Add(key, new List<string>());
|
||||
keyValuePairs[key].Add(file);
|
||||
}
|
||||
}
|
||||
foreach (KeyValuePair<string, List<string>> element in keyValuePairs)
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
lock (_Lock)
|
||||
{
|
||||
key = string.Concat(recipeArchiveDirectory, @"\", element.Key.Split('-')[0]);
|
||||
if (!Directory.Exists(key))
|
||||
Directory.CreateDirectory(key);
|
||||
key = string.Concat(recipeArchiveDirectory, @"\", element.Key.Split('-')[0], @"\", element.Key, ".zip");
|
||||
if (File.Exists(key))
|
||||
{
|
||||
for (short i = 101; i < short.MaxValue; i++)
|
||||
{
|
||||
key = string.Concat(recipeArchiveDirectory, @"\", element.Key.Split('-')[0], @"\", element.Key, "_", i, ".zip");
|
||||
if (!File.Exists(key))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(key))
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
lock (_Lock)
|
||||
{
|
||||
using ZipArchive zip = ZipFile.Open(key, ZipArchiveMode.Create);
|
||||
foreach (string file in element.Value)
|
||||
{
|
||||
zip.CreateEntryFromFile(file, Path.GetFileName(file));
|
||||
File.Delete(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void EDAOutputArchiveCallback()
|
||||
{
|
||||
DateTime dateTime = DateTime.Now;
|
||||
if (dateTime.Hour > 8 && dateTime.Hour < 17)
|
||||
{
|
||||
string sourceDirectory = string.Concat(@"\\", _AppSettings.Server, @"\ec_eda\Staging\Traces");
|
||||
if (!Directory.Exists(sourceDirectory))
|
||||
_Log.Debug(string.Concat("// Source directory <", sourceDirectory, "> doesn't exist."));
|
||||
else
|
||||
EDAOutputArchive(sourceDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private Stream ToStream(string @this)
|
||||
{
|
||||
var stream = new MemoryStream();
|
||||
var writer = new StreamWriter(stream);
|
||||
writer.Write(@this);
|
||||
writer.Flush();
|
||||
stream.Position = 0;
|
||||
return stream;
|
||||
}
|
||||
|
||||
private T ParseXML<T>(string @this, bool throwExceptions) where T : class
|
||||
{
|
||||
object result = null;
|
||||
try
|
||||
{
|
||||
Stream stream = ToStream(@this.Trim());
|
||||
var reader = XmlReader.Create(stream, new XmlReaderSettings() { ConformanceLevel = ConformanceLevel.Document });
|
||||
//XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
|
||||
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T), typeof(T).GetNestedTypes());
|
||||
result = xmlSerializer.Deserialize(reader);
|
||||
stream.Dispose();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (throwExceptions)
|
||||
throw;
|
||||
}
|
||||
return result as T;
|
||||
}
|
||||
|
||||
public void DataCollectionPlans(AppSettings appSettings, string edaDataCollectionPlansLastRun, string cSharpFormat, string oracleFormat)
|
||||
{
|
||||
bool _ShuttingDown = false;
|
||||
object _Lock = new object();
|
||||
bool dev = appSettings.Server.Contains("_ec_");
|
||||
Dictionary<string, Dictionary<ModuleInstanceTypeName, List<List<object>>>> rows = new Dictionary<string, Dictionary<ModuleInstanceTypeName, List<List<object>>>>();
|
||||
//
|
||||
//int moduleinstancetypename = 0;
|
||||
int unitname = 1;
|
||||
//int modulename = 2;
|
||||
int containername = 3;
|
||||
int configurationstate = 4;
|
||||
int configurationproductivestate = 5;
|
||||
//int containermodifiername = 6;
|
||||
int containermodifieddate = 7;
|
||||
int containerconfiguration = 8;
|
||||
int configurationmodifieddate = 9;
|
||||
string objectTypeDirectory;
|
||||
string workingDirectory = string.Concat(@"\\", appSettings.Server, @"\EC_EDA");
|
||||
// ()
|
||||
{
|
||||
object @object;
|
||||
string @string;
|
||||
int fieldCount;
|
||||
List<object> row;
|
||||
string decrypted;
|
||||
string connectionName;
|
||||
string connectionString;
|
||||
StringBuilder sql = new StringBuilder();
|
||||
Array objectTypes = Enum.GetValues(typeof(ModuleInstanceTypeName));
|
||||
List<Tuple<string, string>> connections = new List<Tuple<string, string>>();
|
||||
if (dev)
|
||||
{
|
||||
connectionName = @"DEV";
|
||||
connectionString = EDAViewer.Singleton.Helper.Background.EDADatabase.GetEdaDevelopment();
|
||||
decrypted = RijndaelEncryption.Decrypt(appSettings.IFXEDADatabasePassword, appSettings.Company);
|
||||
connectionString = string.Concat(connectionString, decrypted, ";");
|
||||
connections.Add(new Tuple<string, string>(connectionName, connectionString));
|
||||
}
|
||||
else
|
||||
{
|
||||
connectionName = "Staging";
|
||||
connectionString = EDAViewer.Singleton.Helper.Background.EDADatabase.GetEdaStaging();
|
||||
decrypted = RijndaelEncryption.Decrypt(appSettings.ECEDADatabasePassword, appSettings.Company);
|
||||
connectionString = string.Concat(connectionString, decrypted, ";");
|
||||
connections.Add(new Tuple<string, string>(connectionName, connectionString));
|
||||
connectionName = "Production";
|
||||
connectionString = EDAViewer.Singleton.Helper.Background.EDADatabase.GetEdaProduction();
|
||||
connectionString = string.Concat(connectionString, decrypted, ";");
|
||||
connections.Add(new Tuple<string, string>(connectionName, connectionString));
|
||||
}
|
||||
foreach (Tuple<string, string> connection in connections)
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
rows.Add(connection.Item1, new Dictionary<ModuleInstanceTypeName, List<List<object>>>());
|
||||
foreach (ModuleInstanceTypeName objectType in objectTypes)
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
if (string.IsNullOrEmpty(edaDataCollectionPlansLastRun))
|
||||
{
|
||||
objectTypeDirectory = string.Concat(workingDirectory, @"\", connection.Item1, @"\", objectType);
|
||||
if (!Directory.Exists(objectTypeDirectory))
|
||||
Directory.CreateDirectory(objectTypeDirectory);
|
||||
else
|
||||
edaDataCollectionPlansLastRun = new DirectoryInfo(objectTypeDirectory).LastWriteTime.ToString(cSharpFormat);
|
||||
}
|
||||
if (!rows[connection.Item1].ContainsKey(objectType))
|
||||
rows[connection.Item1].Add(objectType, new List<List<object>>());
|
||||
using (Oracle.ManagedDataAccess.Client.OracleConnection oracleConnection = new Oracle.ManagedDataAccess.Client.OracleConnection(connection.Item2))
|
||||
{
|
||||
sql.Clear();
|
||||
oracleConnection.Open();
|
||||
sql.Append(" select v.moduleinstancetypename, v.unitname, ").
|
||||
Append(" v.modulename, v.containername, v.configurationstate, ").
|
||||
Append(" v.configurationproductivestate, v.containermodifiername, ").
|
||||
Append(" v.containermodifieddate, v.containerconfiguration, v.configurationmodifieddate ").
|
||||
Append(" from veditconfiguration v ").
|
||||
Append(" where v.moduleinstancetypename = '").Append(objectType.ToString()).Append("' ");
|
||||
//Append(" and v.containerversion in ('4.80', '4.111') ");
|
||||
if (!string.IsNullOrEmpty(edaDataCollectionPlansLastRun))
|
||||
sql.Append(" and greatest(v.containermodifieddate, v.configurationmodifieddate) >= to_date('").Append(edaDataCollectionPlansLastRun).Append("', '").Append(oracleFormat).Append("') ");
|
||||
//Print(sql.ToString());
|
||||
using (Oracle.ManagedDataAccess.Client.OracleCommand oracleCommand = new Oracle.ManagedDataAccess.Client.OracleCommand(sql.ToString(), oracleConnection))
|
||||
{
|
||||
using (Oracle.ManagedDataAccess.Client.OracleDataReader oracleDataReader = oracleCommand.ExecuteReader())
|
||||
{
|
||||
fieldCount = oracleDataReader.FieldCount;
|
||||
while (oracleDataReader.Read())
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
row = new List<object>();
|
||||
for (int c = 0; c < fieldCount; c++)
|
||||
{
|
||||
@object = oracleDataReader.GetValue(c);
|
||||
row.Add(@object);
|
||||
@string = @object.ToString();
|
||||
//if (@string.Length < 128)
|
||||
// _Log.Debug(@string);
|
||||
}
|
||||
rows[connection.Item1][objectType].Add(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rows.Any())
|
||||
{
|
||||
string csv;
|
||||
string xml;
|
||||
string json;
|
||||
string text;
|
||||
string html;
|
||||
Common common;
|
||||
string emptyAPC;
|
||||
string fileName;
|
||||
string edaObjectFile;
|
||||
string goldDirectory;
|
||||
string unitDirectory;
|
||||
string replace = "$$$";
|
||||
string edaObjectDirectory;
|
||||
DateTime lastModifiedDate;
|
||||
DateTime containerModifiedDate;
|
||||
PDSFConfiguration configuration;
|
||||
DateTime configurationModifiedDate;
|
||||
JsonSerializerOptions jsonSerializerOptions = new JsonSerializerOptions { WriteIndented = true };
|
||||
foreach (KeyValuePair<string, Dictionary<ModuleInstanceTypeName, List<List<object>>>> databaseElement in rows)
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
emptyAPC = string.Concat(workingDirectory, @"\", databaseElement.Key, @"\EmptyAPC.xlsx");
|
||||
foreach (KeyValuePair<ModuleInstanceTypeName, List<List<object>>> tableNameElement in databaseElement.Value)
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
objectTypeDirectory = string.Concat(workingDirectory, @"\", databaseElement.Key, @"\", tableNameElement.Key);
|
||||
foreach (List<object> rowItem in tableNameElement.Value)
|
||||
{
|
||||
if (_ShuttingDown)
|
||||
break;
|
||||
//foreach (var item in rowItem)
|
||||
// Print(item.ToString());
|
||||
//if (!rowItem[containername].ToString().Contains("Plan_Pdsf_Health_Cp2Mg"))
|
||||
//if (!rowItem[unitname].ToString().Contains("XRD04") || !rowItem[containername].ToString().Contains("Plan_Pdsf"))
|
||||
// continue;
|
||||
containerModifiedDate = DateTime.Parse(rowItem[containermodifieddate].ToString());
|
||||
configurationModifiedDate = DateTime.Parse(rowItem[configurationmodifieddate].ToString());
|
||||
if (containerModifiedDate < configurationModifiedDate)
|
||||
lastModifiedDate = configurationModifiedDate;
|
||||
else
|
||||
lastModifiedDate = containerModifiedDate;
|
||||
goldDirectory = string.Concat(objectTypeDirectory, @"\", rowItem[unitname], @"\", rowItem[containername], @"\Gold");
|
||||
if (!Directory.Exists(goldDirectory))
|
||||
Directory.CreateDirectory(goldDirectory);
|
||||
edaObjectDirectory = string.Concat(objectTypeDirectory, @"\", rowItem[unitname], @"\", rowItem[containername], @"\", rowItem[configurationstate], @"\", rowItem[configurationproductivestate], @"\", lastModifiedDate.ToString("yyyy-MM-dd_"), new TimeSpan(lastModifiedDate.Ticks - new DateTime(lastModifiedDate.Year, lastModifiedDate.Month, lastModifiedDate.Day).Ticks).TotalSeconds);
|
||||
if (!Directory.Exists(edaObjectDirectory))
|
||||
Directory.CreateDirectory(edaObjectDirectory);
|
||||
edaObjectFile = string.Concat(edaObjectDirectory, @"\", rowItem[unitname], " ", rowItem[containername], " - ", replace, " - ", rowItem[configurationstate].ToString(), " ", rowItem[configurationproductivestate].ToString());
|
||||
xml = rowItem[containerconfiguration].ToString();
|
||||
//continue;
|
||||
lock (_Lock)
|
||||
{
|
||||
fileName = string.Concat(edaObjectFile.Replace(replace, "Raw"), ".xml");
|
||||
File.WriteAllText(fileName, xml);
|
||||
try
|
||||
{ File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); }
|
||||
catch (Exception) { }
|
||||
common = new Common(ModuleInstanceTypeName.Pdsf, rowItem[unitname], rowItem[containername], rowItem[configurationstate], rowItem[configurationproductivestate]);
|
||||
configuration = ParseXML<PDSFConfiguration>(xml, throwExceptions: true);
|
||||
if (!Directory.Exists(Path.GetPathRoot(configuration.Settings.StoragePath)))
|
||||
continue;
|
||||
if (configuration is null)
|
||||
continue;
|
||||
else
|
||||
{
|
||||
common.Update(configuration);
|
||||
json = JsonSerializer.Serialize(configuration, configuration.GetType(), jsonSerializerOptions);
|
||||
if (!Directory.Exists(common.StoragePath))
|
||||
Directory.CreateDirectory(common.StoragePath);
|
||||
if (!common.StoragePath.Contains(common.UnitName) && (common.StoragePath.Contains(@"01EquipmentIntegration") || common.StoragePath.Contains(@"02BusinessIntegration")))
|
||||
{
|
||||
common.StoragePath = common.StoragePath.Replace("Traces", "Empty");
|
||||
if (!Directory.Exists(common.StoragePath))
|
||||
Directory.CreateDirectory(common.StoragePath);
|
||||
if (common.UnitName != "PRF01")
|
||||
{
|
||||
unitDirectory = string.Concat(Path.GetDirectoryName(common.StoragePath), @"\", common.UnitName);
|
||||
common.StoragePath = string.Concat(unitDirectory, @"\BadPath");
|
||||
if (!Directory.Exists(common.StoragePath))
|
||||
Directory.CreateDirectory(common.StoragePath);
|
||||
common.StoragePath = string.Concat(unitDirectory, @"\LogFile");
|
||||
if (!Directory.Exists(common.StoragePath))
|
||||
Directory.CreateDirectory(common.StoragePath);
|
||||
common.StoragePath = string.Concat(unitDirectory, @"\PollPath");
|
||||
if (!Directory.Exists(common.StoragePath))
|
||||
Directory.CreateDirectory(common.StoragePath);
|
||||
}
|
||||
}
|
||||
fileName = string.Concat(edaObjectFile.Replace(replace, "Partial"), ".csv");
|
||||
File.WriteAllText(fileName, common.ParametersAsCsv);
|
||||
try
|
||||
{ File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); }
|
||||
catch (Exception) { }
|
||||
fileName = string.Concat(edaObjectFile.Replace(replace, "Partial"), ".json");
|
||||
File.WriteAllText(fileName, json);
|
||||
text = EDAViewer.Singleton.Helper.Background.EdaDCP.GetText(edaObjectFile, common, json);
|
||||
fileName = string.Concat(edaObjectFile.Replace(replace, "Partial"), ".txt");
|
||||
File.WriteAllText(fileName, text);
|
||||
try
|
||||
{ File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); }
|
||||
catch (Exception) { }
|
||||
html = EDAViewer.Singleton.Helper.Background.EdaDCP.GetEdaObjectToHtml(edaObjectFile, common);
|
||||
fileName = string.Concat(edaObjectFile.Replace(replace, "Partial"), ".html");
|
||||
File.WriteAllText(fileName, html);
|
||||
try
|
||||
{ File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); }
|
||||
catch (Exception) { }
|
||||
xml = EDAViewer.Singleton.Helper.Background.EdaDCP.GetEdaObjectToDMSGridFormat(edaObjectFile, common, useAlias: false);
|
||||
fileName = string.Concat(edaObjectFile.Replace(replace, "DMSGridFormat"), ".xml");
|
||||
File.WriteAllText(fileName, xml);
|
||||
try
|
||||
{ File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); }
|
||||
catch (Exception) { }
|
||||
xml = EDAViewer.Singleton.Helper.Background.EdaDCP.GetEdaObjectToDMSGridFormat(edaObjectFile, common, useAlias: true);
|
||||
fileName = string.Concat(edaObjectFile.Replace(replace, "DMSGridFormat - Alias"), ".xml");
|
||||
File.WriteAllText(fileName, xml);
|
||||
try
|
||||
{ File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); }
|
||||
catch (Exception) { }
|
||||
csv = EDAViewer.Singleton.Helper.Background.EdaDCP.GetEdaObjectToAPCParameter(edaObjectFile, common);
|
||||
fileName = string.Concat(edaObjectFile.Replace(replace, "APCParameter"), ".csv");
|
||||
File.WriteAllText(fileName, csv);
|
||||
try
|
||||
{ File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); }
|
||||
catch (Exception) { }
|
||||
csv = EDAViewer.Singleton.Helper.Background.EdaDCP.GetEdaObjectToAPCRunKeyNumber(edaObjectFile, common);
|
||||
fileName = string.Concat(edaObjectFile.Replace(replace, "APCRunKeyNumber"), ".csv");
|
||||
File.WriteAllText(fileName, csv);
|
||||
try
|
||||
{ File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); }
|
||||
catch (Exception) { }
|
||||
fileName = string.Concat(edaObjectFile.Replace(replace, "APC"), ".xlsx");
|
||||
if (File.Exists(emptyAPC) && !File.Exists(fileName))
|
||||
{
|
||||
File.Copy(emptyAPC, fileName);
|
||||
try
|
||||
{ File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
try
|
||||
{ Directory.SetLastWriteTime(objectTypeDirectory, DateTime.Now); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
3821
EDA Viewer/Singleton/Helper/BackgroundEDA - A.cs
Normal file
3821
EDA Viewer/Singleton/Helper/BackgroundEDA - A.cs
Normal file
File diff suppressed because it is too large
Load Diff
29
EDA Viewer/Singleton/Helper/BackgroundEDADatabase.cs
Normal file
29
EDA Viewer/Singleton/Helper/BackgroundEDADatabase.cs
Normal file
@ -0,0 +1,29 @@
|
||||
namespace EDAViewer.Singleton.Helper
|
||||
{
|
||||
|
||||
public partial class Background
|
||||
{
|
||||
|
||||
public partial class EDADatabase
|
||||
{
|
||||
|
||||
public static string GetEdaDevelopment()
|
||||
{
|
||||
return "Data Source=(description=(address_list=(address=(protocol=tcp)(host=fimest-db.mes.infineon.com)(port=7001)))(connect_data=(sid=fimest))); User Id=edatest; Password=";
|
||||
}
|
||||
|
||||
public static string GetEdaStaging()
|
||||
{
|
||||
return "Data Source=(description=(address_list=(address=(protocol=tcp)(host=fimess-db.ec.local)(port=7001)))(connect_data=(sid=fimess))); User Id=edastag; Password=";
|
||||
}
|
||||
|
||||
public static string GetEdaProduction()
|
||||
{
|
||||
return "Data Source=(description=(address_list=(address=(protocol=tcp)(host=fimesp-db.ec.local)(port=7002)))(connect_data=(sid=fimesp))); User Id=edaprod; Password=";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
429
EDA Viewer/Singleton/Helper/BackgroundEdaDCP.cs
Normal file
429
EDA Viewer/Singleton/Helper/BackgroundEdaDCP.cs
Normal file
@ -0,0 +1,429 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace EDAViewer.Singleton.Helper
|
||||
{
|
||||
|
||||
public partial class Background
|
||||
{
|
||||
|
||||
public class EdaDCP
|
||||
{
|
||||
|
||||
internal static string GetEdaObjectToHtml(string edaObjectFile, Common common)
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
string title = string.Concat(Path.GetFileName(edaObjectFile), " - ", common.Source);
|
||||
result.AppendLine("<!DOCTYPE html>");
|
||||
result.AppendLine("<html lang=\"en\">");
|
||||
result.AppendLine("<head>");
|
||||
result.AppendLine("<style>table, th, td{border:1px solid black;} td{padding:2px}</style>");
|
||||
result.Append("<title>").Append(title).AppendLine("</title>");
|
||||
result.AppendLine("</head>");
|
||||
result.AppendLine("<body>");
|
||||
result.AppendLine("<table>");
|
||||
result.AppendLine("<tr>");
|
||||
result.Append("<th nowrap>").Append("Unit Name").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Container Name").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Configuration State").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Configuration Productive State").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("LogisticsEquipmentAlias").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Source").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("StoragePath").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("StartTimeFormat").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Filename").AppendLine("</th>");
|
||||
result.AppendLine("</tr>");
|
||||
result.AppendLine("<tr>");
|
||||
result.Append("<td nowrap>").Append(common.UnitName).AppendLine("</td>");
|
||||
result.Append("<td nowrap>").Append(common.ContainerName).AppendLine("</td>");
|
||||
result.Append("<td nowrap>").Append(common.ConfigurationState).AppendLine("</td>");
|
||||
result.Append("<td nowrap>").Append(common.ConfigurationProductiveState).AppendLine("</td>");
|
||||
result.Append("<td nowrap>").Append(common.LogisticsEquipmentAlias).AppendLine("</td>");
|
||||
result.Append("<td nowrap>").Append(common.Source).AppendLine("</td>");
|
||||
result.Append("<td nowrap>").Append(common.StoragePath).AppendLine("</td>");
|
||||
result.Append("<td nowrap>").Append(common.StartTimeFormat).AppendLine("</td>");
|
||||
result.Append("<td nowrap>").Append(common.Filename).AppendLine("</td>");
|
||||
result.AppendLine("</tr>");
|
||||
result.AppendLine("</table>");
|
||||
result.AppendLine("<hr>");
|
||||
result.AppendLine("<table>");
|
||||
result.AppendLine("<tr>");
|
||||
result.Append("<th nowrap>").Append("Use").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Order").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Key").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Placeholder").AppendLine("</th>");
|
||||
result.AppendLine("</tr>");
|
||||
foreach (string[] item in common.LogisticsAttributes)
|
||||
{
|
||||
if (item.Length > 2 && !item[2].StartsWith("Z_"))
|
||||
{
|
||||
result.AppendLine("<tr>");
|
||||
foreach (string value in item)
|
||||
result.Append("<td nowrap>").Append(value).AppendLine("</td>");
|
||||
result.AppendLine("</tr>");
|
||||
}
|
||||
}
|
||||
result.AppendLine("</table>");
|
||||
result.AppendLine("<hr>");
|
||||
result.AppendLine("<table>");
|
||||
result.AppendLine("<tr>");
|
||||
result.Append("<th nowrap>").Append("ID").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Prefix").AppendLine("</th>");
|
||||
result.AppendLine("</tr>");
|
||||
foreach (string[] item in common.LogisticsColumns)
|
||||
{
|
||||
result.AppendLine("<tr>");
|
||||
foreach (string value in item)
|
||||
result.Append("<td nowrap>").Append(value).AppendLine("</td>");
|
||||
result.AppendLine("</tr>");
|
||||
}
|
||||
result.AppendLine("</table>");
|
||||
result.AppendLine("<hr>");
|
||||
result.AppendLine("<table>");
|
||||
result.AppendLine("<tr>");
|
||||
result.Append("<th nowrap>").Append("Use").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Order").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("FullName").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Alias").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("HardWareId").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Description").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Formula").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Virtual").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Column#").AppendLine("</th>");
|
||||
result.AppendLine("</tr>");
|
||||
foreach (string[] item in common.Parameters)
|
||||
{
|
||||
result.AppendLine("<tr>");
|
||||
foreach (string value in item)
|
||||
result.Append("<td nowrap>").Append(value).AppendLine("</td>");
|
||||
result.AppendLine("</tr>");
|
||||
}
|
||||
result.AppendLine("</table>");
|
||||
result.AppendLine("<hr>");
|
||||
result.AppendLine("<table>");
|
||||
result.AppendLine("<tr>");
|
||||
result.Append("<th nowrap>").Append("Parent Name").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Name").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("ParameterName").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Formula").AppendLine("</th>");
|
||||
result.AppendLine("</tr>");
|
||||
foreach (string[] item in common.GeneralTriggers)
|
||||
{
|
||||
result.AppendLine("<tr>");
|
||||
foreach (string value in item)
|
||||
result.Append("<td nowrap>").Append(value).AppendLine("</td>");
|
||||
result.AppendLine("</tr>");
|
||||
}
|
||||
result.AppendLine("</table>");
|
||||
result.AppendLine("<hr>");
|
||||
result.AppendLine("<table>");
|
||||
result.AppendLine("<tr>");
|
||||
result.Append("<th nowrap>").Append("Name").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Rule").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("ResolveGlobalVariableBeforeTrigger").AppendLine("</th>");
|
||||
result.AppendLine("</tr>");
|
||||
foreach (string[] item in common.StartTriggersDCP)
|
||||
{
|
||||
result.AppendLine("<tr>");
|
||||
foreach (string value in item)
|
||||
result.Append("<td nowrap>").Append(value).AppendLine("</td>");
|
||||
result.AppendLine("</tr>");
|
||||
}
|
||||
result.AppendLine("</table>");
|
||||
result.AppendLine("<hr>");
|
||||
result.AppendLine("<table>");
|
||||
result.AppendLine("<tr>");
|
||||
result.Append("<th nowrap>").Append("Name").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Fixed").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Rule").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Scenario").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("DefaultJobIndex").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("DefaultCarrierIndex").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("DefaultSlotIndex").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("DataPool").AppendLine("</th>");
|
||||
result.AppendLine("</tr>");
|
||||
foreach (string[] item in common.LogisticsTriggers)
|
||||
{
|
||||
result.AppendLine("<tr>");
|
||||
foreach (string value in item)
|
||||
result.Append("<td nowrap>").Append(value).AppendLine("</td>");
|
||||
result.AppendLine("<td>");
|
||||
result.AppendLine("<table>");
|
||||
result.AppendLine("<tr>");
|
||||
result.Append("<th nowrap>").Append("KeyName").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("ParameterName").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Formula").AppendLine("</th>");
|
||||
result.AppendLine("</tr>");
|
||||
foreach (KeyValuePair<int, string[]> keyValuePair in common.LogisticsTriggersKeysKeyMapping)
|
||||
{
|
||||
result.AppendLine("<tr>");
|
||||
foreach (string value in keyValuePair.Value)
|
||||
result.Append("<td nowrap>").Append(value).AppendLine("</td>");
|
||||
result.AppendLine("</tr>");
|
||||
}
|
||||
result.AppendLine("</table>");
|
||||
result.AppendLine("</td>");
|
||||
result.AppendLine("<td>");
|
||||
result.AppendLine("<table>");
|
||||
result.AppendLine("<tr>");
|
||||
result.Append("<th nowrap>").Append("LogisticsKey").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Source").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("MappedParameterName").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Formula").AppendLine("</th>");
|
||||
result.AppendLine("</tr>");
|
||||
foreach (KeyValuePair<int, List<string[]>> keyValuePair in common.LogisticsTriggersCallDefinitionAttributes)
|
||||
{
|
||||
foreach (string[] values in keyValuePair.Value)
|
||||
{
|
||||
if (values.Length > 0 && !values[0].StartsWith("Z_"))
|
||||
{
|
||||
result.AppendLine("<tr>");
|
||||
foreach (string value in values)
|
||||
result.Append("<td nowrap>").Append(value).AppendLine("</td>");
|
||||
result.AppendLine("</tr>");
|
||||
}
|
||||
}
|
||||
}
|
||||
result.AppendLine("</table>");
|
||||
result.AppendLine("</td>");
|
||||
result.AppendLine("</tr>");
|
||||
}
|
||||
result.AppendLine("</table>");
|
||||
result.AppendLine("<hr>");
|
||||
result.AppendLine("<table>");
|
||||
result.AppendLine("<tr>");
|
||||
result.Append("<th nowrap>").Append("Name").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("Rule").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("ResolveGlobalVariableBeforeTrigger").AppendLine("</th>");
|
||||
result.Append("<th nowrap>").Append("ResetGlobalVariablesAfterTrigger").AppendLine("</th>");
|
||||
result.AppendLine("</tr>");
|
||||
foreach (string[] item in common.StopTriggersDCP)
|
||||
{
|
||||
result.AppendLine("<tr>");
|
||||
foreach (string value in item)
|
||||
result.Append("<td nowrap>").Append(value).AppendLine("</td>");
|
||||
result.AppendLine("</tr>");
|
||||
}
|
||||
result.AppendLine("</table>");
|
||||
result.AppendLine("<hr>");
|
||||
result.AppendLine("</body>");
|
||||
result.AppendLine("</html>");
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
private static string ReplaceNull(object @object)
|
||||
{
|
||||
if (@object is null)
|
||||
return string.Empty;
|
||||
else
|
||||
return @object.ToString();
|
||||
}
|
||||
|
||||
private static void TextResolveEntry(StringBuilder result, dynamic expandoObject, int level, string super, int? i, bool group)
|
||||
{
|
||||
level += 1;
|
||||
foreach (dynamic entry in expandoObject)
|
||||
{
|
||||
if (entry.Value is ExpandoObject)
|
||||
TextResolveEntry(result, entry.Value, level, string.Concat(super, " : ", entry.Key), i, group);
|
||||
else
|
||||
{
|
||||
if (!(entry.Value is ICollection<object>))
|
||||
{
|
||||
if (i is null)
|
||||
result.Append(level).Append(") ").Append(super).Append(" : ").Append(entry.Key).Append("--->").AppendLine(ReplaceNull(entry.Value));
|
||||
else
|
||||
result.Append(level).Append(") ").Append(super).Append(" : ").Append(entry.Key).Append("[").Append(i.Value).Append("]--->").AppendLine(ReplaceNull(entry.Value));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!group)
|
||||
{
|
||||
for (i = 0; i.Value < entry.Value.Count; i++)
|
||||
{
|
||||
if (entry.Value[i.Value] is ExpandoObject)
|
||||
TextResolveEntry(result, entry.Value[i.Value], level, string.Concat(super, " : ", entry.Key), i.Value, group);
|
||||
else
|
||||
result.Append(level).Append(") ").Append(super).Append(" : ").Append(entry.Key).Append("[").Append(i.Value).Append("]--->").AppendLine(ReplaceNull(entry.Value[i.Value]));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i.Value < entry.Value.Count; i++)
|
||||
{
|
||||
if (!(entry.Value[i.Value] is ExpandoObject))
|
||||
result.Append(level).Append(") ").Append(super).Append(" : ").Append(entry.Key).Append("[").Append(i.Value).Append("]--->").AppendLine(ReplaceNull(entry.Value[i.Value]));
|
||||
}
|
||||
for (i = 0; i.Value < entry.Value.Count; i++)
|
||||
{
|
||||
if (entry.Value[i.Value] is ExpandoObject)
|
||||
TextResolveEntry(result, entry.Value[i.Value], level, string.Concat(super, " : ", entry.Key), i.Value, group);
|
||||
}
|
||||
}
|
||||
i = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
level -= 1;
|
||||
}
|
||||
|
||||
internal static string GetText(string edaObjectFile, Common common, string json)
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
if (result.Length > 0) //Skipping because System.Text.Json changed the way Expando works
|
||||
{
|
||||
string title = string.Concat(Path.GetFileName(edaObjectFile), " - ", common.Source);
|
||||
dynamic expandoObject = JsonSerializer.Deserialize<ExpandoObject>(json);
|
||||
result.AppendLine(title);
|
||||
result.AppendLine("Loop -> \"Normal\"");
|
||||
result.AppendLine(edaObjectFile);
|
||||
result.AppendLine();
|
||||
TextResolveEntry(result, expandoObject, 0, string.Empty, null, group: false);
|
||||
result.AppendLine();
|
||||
result.AppendLine();
|
||||
result.AppendLine();
|
||||
result.AppendLine(title);
|
||||
result.AppendLine("Loop -> \"Grouped\"");
|
||||
result.AppendLine(edaObjectFile);
|
||||
result.AppendLine();
|
||||
TextResolveEntry(result, expandoObject, 0, string.Empty, null, group: true);
|
||||
}
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
internal static string GetEdaObjectToDMSGridFormat(string edaObjectFile, Common common, bool useAlias)
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
string[] segments;
|
||||
int? recordStart = null;
|
||||
string name = string.Concat(common.LogisticsEquipmentAlias, "_", common.ContainerName);
|
||||
result.AppendLine("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
|
||||
result.Append("<Format Name=\"").Append(name).Append("\">").AppendLine();
|
||||
result.AppendLine(" <General RecordStart=\"\" RecordLength=\"0\" ReadCommand=\"\" DecimalSeparator=\".\">");
|
||||
result.AppendLine(" <RecordTerminator><13><10></RecordTerminator>");
|
||||
result.AppendLine(" <ColumnSeparator><9></ColumnSeparator>");
|
||||
result.AppendLine(" </General>");
|
||||
result.AppendLine(" <Fields>");
|
||||
for (int i = 0; i < common.Parameters.Count; i++)
|
||||
{
|
||||
if (recordStart is null && common.Parameters[i][3] == "RECORD_START")
|
||||
recordStart = i;
|
||||
if (recordStart.HasValue && common.Parameters[i][0] == "True")
|
||||
{
|
||||
if (useAlias && !string.IsNullOrEmpty(common.Parameters[i][3]))
|
||||
name = common.Parameters[i][3].Replace("'", string.Empty);
|
||||
else
|
||||
{
|
||||
segments = common.Parameters[i][2].Split('/');
|
||||
name = segments[segments.Length - 1];
|
||||
}
|
||||
result.Append(" <Field Name=\"").Append(name).Append("\" ColumnNumber=\"").Append(i + common.LogisticsColumns.Count + 2).Append("\" StartPosition=\"\" Length=\"\" DataType=\"Text\" NullReplacement=\"\" />").AppendLine();
|
||||
}
|
||||
}
|
||||
result.AppendLine(" </Fields>");
|
||||
result.AppendLine(" <Conditions>");
|
||||
result.AppendLine(" <Column />");
|
||||
result.AppendLine(" <Row>");
|
||||
result.AppendLine(" <Condition>");
|
||||
result.AppendLine(" <SkipHeaderCount>7</SkipHeaderCount>");
|
||||
result.AppendLine(" <SkipRowFilter>0</SkipRowFilter>");
|
||||
result.AppendLine(" <SkipRowValue>");
|
||||
result.AppendLine(" </SkipRowValue>");
|
||||
result.AppendLine(" </Condition>");
|
||||
result.AppendLine(" </Row>");
|
||||
result.AppendLine(" </Conditions>");
|
||||
result.AppendLine("</Format>");
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
internal static string GetEdaObjectToAPCParameter(string edaObjectFile, Common common)
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
string parameter;
|
||||
string[] segments;
|
||||
string parameterSub35;
|
||||
string name = string.Concat(common.LogisticsEquipmentAlias, "_", common.ContainerName);
|
||||
result.AppendLine("ExportFileVersion=1.0.6");
|
||||
result.AppendLine("ExportFromTabsheet=Para");
|
||||
result.AppendLine("FieldName\tLongName\tMatchMode\tEquipment\tName\tPdsfNameConvCol\tPdsfNameDataType\tType\tChamberInfo\tUnifiedPara\tDateFormat\tUsername\tId\tWorkcenterId\tSite\tArea\tWorkcenter\tValidFrom\tValidTo");
|
||||
result.AppendLine("TIME_PREV_DIFF\tTIME_PREV_DIFF\tEXACT\t*\tTIME_PREV_DIFF\t\tNUMERIC\tRUN\t\tTIME_PREV_DIFF\t\tPHARES\t95069\t4571\tMesa\t\t\t4/15/2020 6:10 PM");
|
||||
result.AppendLine("TIME\tTIME\tEXACT\t*\tTIME\t\tNUMERIC\tRUN\t\tTIME\t\tPHARES\t95070\t4571\tMesa\t\t\t4/15/2020 6:10 PM");
|
||||
for (int i = 0; i < common.Parameters.Count; i++)
|
||||
{
|
||||
if (common.Parameters[i][0] == "True")
|
||||
{
|
||||
segments = common.Parameters[i][2].Split('/');
|
||||
parameter = segments[segments.Length - 1];
|
||||
if (parameter.Length < 35)
|
||||
parameterSub35 = parameter;
|
||||
else
|
||||
parameterSub35 = parameter.Substring(0, 35);
|
||||
result.Append(parameterSub35).Append("\tDIVERSE\tEXACT\t*\t").Append(parameterSub35).AppendLine("\t\tNUMERIC\tRUN\t\t\t\tPHARES\t9000000012\t4571\tMesa\t\t\t4/15/2020 6:10 PM");
|
||||
}
|
||||
}
|
||||
result.AppendLine();
|
||||
result.AppendLine();
|
||||
result.AppendLine();
|
||||
for (int i = 0; i < common.Parameters.Count; i++)
|
||||
{
|
||||
if (common.Parameters[i][0] == "True")
|
||||
{
|
||||
segments = common.Parameters[i][2].Split('/');
|
||||
parameter = segments[segments.Length - 1];
|
||||
result.Append(parameter).Append("\tDIVERSE\tEXACT\t*\t").Append(parameter).AppendLine("\t\tNUMERIC\tRUN\t\t\t\tPHARES\t9000000012\t4571\tMesa\t\t\t4/15/2020 6:10 PM");
|
||||
}
|
||||
}
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
internal static string GetEdaObjectToAPCRunKeyNumber(string edaObjectFile, Common common)
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
string parameter;
|
||||
string[] segments;
|
||||
string parameterSub21;
|
||||
string parameterSub35;
|
||||
string name = string.Concat(common.LogisticsEquipmentAlias, "_", common.ContainerName);
|
||||
result.AppendLine("ExportFileVersion=1.0.6");
|
||||
result.AppendLine("ExportFromTabsheet=Run-Keynumbers");
|
||||
result.AppendLine("FeatureName\tShortName\tChamber\tComments\tVarMode\tPara\tExclude0\tTrigOn1\tTrigOn2\tTrigOn3\tTrigOff1\tTrigOff2\tTrigOff3\tTrigDelay\tTrigNorm\tTrigNvl\tTrigTrg\tAddCondOn\tActive\tFilter1\tFilter2\tFilter3\tFilter4\tUnit\tId\tWorkcenterId\tSite\tArea\tWorkcenter\tUsername\tValidFrom\tValidTo");
|
||||
for (int i = 0; i < common.Parameters.Count; i++)
|
||||
{
|
||||
if (common.Parameters[i][0] == "True")
|
||||
{
|
||||
segments = common.Parameters[i][2].Split('/');
|
||||
parameter = segments[segments.Length - 1];
|
||||
if (parameter.Length < 35)
|
||||
parameterSub35 = parameter;
|
||||
else
|
||||
parameterSub35 = parameter.Substring(0, 35);
|
||||
if (parameter.Length < 21)
|
||||
parameterSub21 = parameter;
|
||||
else
|
||||
parameterSub21 = parameter.Substring(0, 21);
|
||||
result.Append(parameterSub21).Append("_MIN\t").Append(parameterSub21).Append("_MIN\t\t\tMIN\t").Append(parameterSub35).AppendLine("\t0\tTIME\t=\tRUNSTART\tTIME\t=\tRUNEND\t\t\t\t\t\t1\t\t\t\t\t\t-1\t-1\t\t\t\tECPHARES\t5/2/2017 2:44 PM");
|
||||
}
|
||||
}
|
||||
result.AppendLine();
|
||||
result.AppendLine();
|
||||
result.AppendLine();
|
||||
for (int i = 0; i < common.Parameters.Count; i++)
|
||||
{
|
||||
if (common.Parameters[i][0] == "True")
|
||||
{
|
||||
segments = common.Parameters[i][2].Split('/');
|
||||
parameter = segments[segments.Length - 1];
|
||||
result.Append(parameter).Append("_MIN\t").Append(parameter).Append("_MIN\t\t\tMIN\t").Append(parameter).AppendLine("\t0\tTIME\t=\tRUNSTART\tTIME\t=\tRUNEND\t\t\t\t\t\t1\t\t\t\t\t\t-1\t-1\t\t\t\tECPHARES\t5/2/2017 2:44 PM");
|
||||
}
|
||||
}
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
164
EDA Viewer/Singleton/Helper/Common.cs
Normal file
164
EDA Viewer/Singleton/Helper/Common.cs
Normal file
@ -0,0 +1,164 @@
|
||||
using EDAViewer.Singleton.Helper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace EDAViewer.Singleton.Helper
|
||||
{
|
||||
|
||||
[Serializable]
|
||||
public class Common
|
||||
{
|
||||
|
||||
public ModuleInstanceTypeName? ObjectType { get; set; }
|
||||
public string ConfigurationState { get; set; }
|
||||
public string ConfigurationProductiveState { get; set; }
|
||||
public string UnitName { get; set; }
|
||||
public string ContainerName { get; set; }
|
||||
//
|
||||
public string StoragePath { get; set; }
|
||||
public string StartTimeFormat { get; set; }
|
||||
public string Filename { get; set; }
|
||||
//
|
||||
public string Source { get; set; }
|
||||
public string LogisticsEquipmentAlias { get; set; }
|
||||
public List<string[]> LogisticsAttributes { get; set; }
|
||||
public List<string[]> LogisticsColumns { get; set; }
|
||||
public List<string[]> Parameters { get; set; }
|
||||
public string ParametersAsCsv { get; set; }
|
||||
public List<string[]> GeneralTriggers { get; set; }
|
||||
public List<string[]> StartTriggersDCP { get; set; }
|
||||
public List<string[]> LogisticsTriggers { get; set; }
|
||||
public Dictionary<int, string[]> LogisticsTriggersKeysKeyMapping { get; set; }
|
||||
public Dictionary<int, List<string[]>> LogisticsTriggersCallDefinitionAttributes { get; set; }
|
||||
public List<string[]> StopTriggersDCP { get; set; }
|
||||
|
||||
[Obsolete("Only for DeserializeObject")]
|
||||
public Common()
|
||||
{
|
||||
ObjectType = null;
|
||||
ConfigurationState = string.Empty;
|
||||
ConfigurationProductiveState = string.Empty;
|
||||
UnitName = string.Empty;
|
||||
ContainerName = string.Empty;
|
||||
CommonLogic();
|
||||
}
|
||||
|
||||
public Common(ModuleInstanceTypeName objectType, object unitName, object containerName, object configurationState, object configurationProductiveState)
|
||||
{
|
||||
ObjectType = objectType;
|
||||
ConfigurationState = configurationState.ToString();
|
||||
ConfigurationProductiveState = configurationProductiveState.ToString();
|
||||
UnitName = unitName.ToString();
|
||||
ContainerName = containerName.ToString();
|
||||
CommonLogic(configurationState.ToString(), configurationProductiveState.ToString(), unitName.ToString(), containerName.ToString());
|
||||
}
|
||||
|
||||
private void CommonLogic(string configurationState = "", string configurationProductiveState = "", string unitName = "", string containerame = "")
|
||||
{
|
||||
LogisticsAttributes = new List<string[]>();
|
||||
LogisticsColumns = new List<string[]>();
|
||||
Parameters = new List<string[]>();
|
||||
ParametersAsCsv = string.Empty;
|
||||
GeneralTriggers = new List<string[]>();
|
||||
StartTriggersDCP = new List<string[]>();
|
||||
LogisticsTriggers = new List<string[]>();
|
||||
LogisticsTriggersKeysKeyMapping = new Dictionary<int, string[]>();
|
||||
LogisticsTriggersCallDefinitionAttributes = new Dictionary<int, List<string[]>>();
|
||||
StopTriggersDCP = new List<string[]>();
|
||||
}
|
||||
|
||||
public void Update(PDSFConfiguration configuration)
|
||||
{
|
||||
StoragePath = configuration.Settings.StoragePath;
|
||||
StartTimeFormat = configuration.Settings.StartTimeFormat;
|
||||
Filename = configuration.Settings.Filename;
|
||||
//
|
||||
Source = configuration.DataCollection.Source;
|
||||
LogisticsEquipmentAlias = configuration.DataCollection.Logistics.EquipmentAlias;
|
||||
//if (LogisticsEquipmentAlias == "R47-PLC")
|
||||
//{ }
|
||||
foreach (PDSFConfigurationDataCollectionLogisticsAttribute item in (from l in configuration.DataCollection.Logistics.Attributes orderby l.Use descending, l.Order select l))
|
||||
LogisticsAttributes.Add(new string[] { item.Use.ToString(), item.Order.ToString("000"), item.Key, item.Placeholder });
|
||||
foreach (PDSFConfigurationDataCollectionLogisticsColumn item in configuration.DataCollection.Logistics.Columns)
|
||||
LogisticsColumns.Add(new string[] { item.ID.ToString(), item.Prefix });
|
||||
foreach (PDSFConfigurationDataCollectionParameter1 item in (from l in configuration.DataCollection.VirtualParameters orderby l.Use descending, l.Order select l))
|
||||
{
|
||||
if (string.IsNullOrEmpty(item.Alias) && !string.IsNullOrEmpty(item.Conditions.ConditionModel.Name))
|
||||
{
|
||||
if (item.Use)
|
||||
Parameters.Add(new string[] { item.Use.ToString(), item.Order.ToString("000"), item.FullName, item.Conditions.ConditionModel.Name, item.HardWareId, item.Description, item.Conditions.ConditionModel.Formula, true.ToString(), (configuration.DataCollection.Logistics.Columns.Length + 1 + item.Order).ToString("000") });
|
||||
else
|
||||
Parameters.Add(new string[] { item.Use.ToString(), item.Order.ToString("000"), item.FullName, item.Conditions.ConditionModel.Name, item.HardWareId, item.Description, string.Empty, true.ToString(), (configuration.DataCollection.Logistics.Columns.Length + 1 + item.Order).ToString("000") });
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.Use)
|
||||
Parameters.Add(new string[] { item.Use.ToString(), item.Order.ToString("000"), item.FullName, item.Alias, item.HardWareId, item.Description, item.Conditions.ConditionModel.Formula, true.ToString(), (configuration.DataCollection.Logistics.Columns.Length + 1 + item.Order).ToString("000") });
|
||||
else
|
||||
Parameters.Add(new string[] { item.Use.ToString(), item.Order.ToString("000"), item.FullName, item.Alias, item.HardWareId, item.Description, string.Empty, true.ToString(), (configuration.DataCollection.Logistics.Columns.Length + 1 + item.Order).ToString("000") });
|
||||
}
|
||||
}
|
||||
foreach (PDSFConfigurationDataCollectionParameter item in (from l in configuration.DataCollection.Parameters orderby l.Use descending, l.Order select l))
|
||||
{
|
||||
if (string.IsNullOrEmpty(item?.Alias) && !string.IsNullOrEmpty(item?.Conditions?.ConditionModel?.Name))
|
||||
{
|
||||
if (item.Use)
|
||||
Parameters.Add(new string[] { item.Use.ToString(), item.Order.ToString("000"), item.FullName, item.Conditions.ConditionModel.Name, item.HardWareId, item.Description, item.Conditions.ConditionModel.Formula, false.ToString(), (configuration.DataCollection.Logistics.Columns.Length + 1 + item.Order).ToString("000") });
|
||||
else
|
||||
Parameters.Add(new string[] { item.Use.ToString(), item.Order.ToString("000"), item.FullName, item.Conditions.ConditionModel.Name, item.HardWareId, item.Description, string.Empty, false.ToString(), (configuration.DataCollection.Logistics.Columns.Length + 1 + item.Order).ToString("000") });
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.Use)
|
||||
Parameters.Add(new string[] { item.Use.ToString(), item.Order.ToString("000"), item.FullName, item.Alias, item.HardWareId, item.Description, item.Conditions.ConditionModel.Formula, false.ToString(), (configuration.DataCollection.Logistics.Columns.Length + 1 + item.Order).ToString("000") });
|
||||
else
|
||||
Parameters.Add(new string[] { item.Use.ToString(), item.Order.ToString("000"), item.FullName, item.Alias, item.HardWareId, item.Description, string.Empty, false.ToString(), (configuration.DataCollection.Logistics.Columns.Length + 1 + item.Order).ToString("000") });
|
||||
}
|
||||
}
|
||||
Parameters = (from l in Parameters orderby l[0] descending, l[1] select l).ToList();
|
||||
StringBuilder text = new StringBuilder();
|
||||
//text.AppendLine("\"AliasName\";\"Condition\";\"EventId\";\"ExceptionId\";\"Formula\";\"HardwareId\";\"OrderId\";\"ParameterName\";\"Remark\";\"ReportName\";\"SourceId\";\"Use\"");
|
||||
//"Test";"";"";"";"";"";"1";"MICROSCOPE01/MET08MESMICROSCOPE/Test";"";"MICROSCOPE01/MET08MESMICROSCOPE/FileRead";"";"True""
|
||||
text.AppendLine("\"Use\";\"OrderId\";\"ReportName\";\"ParameterName\";\"AliasName\";\"HardwareId\";\"Remark\";\"Formula\"");
|
||||
foreach (string[] item in Parameters)
|
||||
{
|
||||
for (int i = 0; i < 7; i++)
|
||||
text.Append("\"").Append(item[i]).Append("\";");
|
||||
text.Remove(text.Length - 1, 1);
|
||||
text.AppendLine();
|
||||
}
|
||||
ParametersAsCsv = text.ToString();
|
||||
foreach (PDSFConfigurationDataCollectionGeneralTriggers item in configuration.DataCollection.GeneralTriggers)
|
||||
{
|
||||
foreach (PDSFConfigurationDataCollectionGeneralTriggersVariableModel gv in item.GlobalVariables)
|
||||
GeneralTriggers.Add(new string[] { item.Name, gv.Name, gv.ParameterName, gv.Formula });
|
||||
}
|
||||
{
|
||||
PDSFConfigurationDataCollectionStartTriggersDCP item = configuration.DataCollection.StartTriggers.DCP;
|
||||
if (!(item is null))
|
||||
StartTriggersDCP.Add(new string[] { item.Name, item.Rule, item.ResolveGlobalVariableBeforeTrigger.ToString() });
|
||||
}
|
||||
if (!(configuration.DataCollection.Logistics.Triggers.UpdateTrigger is null))
|
||||
{
|
||||
foreach (PDSFConfigurationDataCollectionLogisticsTriggersUpdateTriggerLogisticRequest item in configuration.DataCollection.Logistics.Triggers.UpdateTrigger.LogisticRequest)
|
||||
{
|
||||
LogisticsTriggers.Add(new string[] { item.Name.ToString(), item.LogisticsColumn.Fixed.ToString(), item.Rule, item.Keys.Scenario, item.Keys.DefaultJobIndex.ToString(), item.Keys.DefaultCarrierIndex.ToString(), item.Keys.DefaultSlotIndex.ToString(), item.DataPool.ToString() });
|
||||
if (!(item.Keys.KeyMapping is null))
|
||||
LogisticsTriggersKeysKeyMapping.Add(item.Name, new string[] { item.Keys.KeyMapping.KeyName, item.Keys.KeyMapping.ParameterName, item.Keys.KeyMapping.Formula });
|
||||
LogisticsTriggersCallDefinitionAttributes.Add(item.Name, new List<string[]>());
|
||||
foreach (PDSFConfigurationDataCollectionLogisticsTriggersUpdateTriggerLogisticRequestCallDefinitionLogisticCallDefinitionAttribute att in item.CallDefinition.Attributes)
|
||||
LogisticsTriggersCallDefinitionAttributes[item.Name].Add(new string[] { att.LogisticsKey, att.Source, att.MappedParameterName, att.Formula });
|
||||
}
|
||||
}
|
||||
{
|
||||
PDSFConfigurationDataCollectionStopTriggersDCP item = configuration.DataCollection.StopTriggers.DCP;
|
||||
if (!(item is null))
|
||||
StopTriggersDCP.Add(new string[] { item.Name, item.Rule, item.ResolveGlobalVariableBeforeTrigger.ToString(), item.ResetGlobalVariablesAfterTrigger.ToString() });
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
8
EDA Viewer/Singleton/Helper/ModuleInstanceTypeName.cs
Normal file
8
EDA Viewer/Singleton/Helper/ModuleInstanceTypeName.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace EDAViewer.Singleton.Helper
|
||||
{
|
||||
public enum ModuleInstanceTypeName
|
||||
{
|
||||
Pdsf
|
||||
}
|
||||
|
||||
}
|
28
EDA Viewer/Singleton/IBackground.cs
Normal file
28
EDA Viewer/Singleton/IBackground.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using EDAViewer.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Shared;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
|
||||
namespace EDAViewer.Singleton
|
||||
{
|
||||
|
||||
public interface IBackground : Models.IBackground, IDisposable
|
||||
{
|
||||
|
||||
void ClearMessage();
|
||||
void SendStatusOk();
|
||||
string Message { get; }
|
||||
bool IsPrimaryInstance();
|
||||
void SetIsPrimaryInstance();
|
||||
void ClearIsPrimaryInstance();
|
||||
string WorkingDirectory { get; }
|
||||
List<Exception> Exceptions { get; }
|
||||
void Update(ILogger<object> logger);
|
||||
string GetCountDirectory(string verb);
|
||||
void LogPathCleanUpByWeek(string server, bool isEDA = false, bool isNA = false);
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user