|
|
|
@ -264,7 +264,7 @@ public class Background : Models.Properties.IBackground, IBackground, IDisposabl
|
|
|
|
|
if (!addFile && fileName.Length > ticksLength)
|
|
|
|
|
{
|
|
|
|
|
MatchCollection matches = regex.Matches(fileName);
|
|
|
|
|
foreach (Match match in matches)
|
|
|
|
|
foreach (Match match in matches.Cast<Match>())
|
|
|
|
|
{
|
|
|
|
|
if (_Stop)
|
|
|
|
|
break;
|
|
|
|
@ -525,7 +525,7 @@ public class Background : Models.Properties.IBackground, IBackground, IDisposabl
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Stream ToStream(string @this)
|
|
|
|
|
private static Stream ToStream(string @this)
|
|
|
|
|
{
|
|
|
|
|
MemoryStream? stream = new();
|
|
|
|
|
StreamWriter? writer = new(stream);
|
|
|
|
@ -535,7 +535,7 @@ public class Background : Models.Properties.IBackground, IBackground, IDisposabl
|
|
|
|
|
return stream;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private T? ParseXML<T>(string @this, bool throwExceptions) where T : class
|
|
|
|
|
private static T? ParseXML<T>(string @this, bool throwExceptions) where T : class
|
|
|
|
|
{
|
|
|
|
|
object? result = null;
|
|
|
|
|
try
|
|
|
|
@ -554,13 +554,8 @@ public class Background : Models.Properties.IBackground, IBackground, IDisposabl
|
|
|
|
|
return result as T;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DataCollectionPlans(AppSettings appSettings, string edaDataCollectionPlansLastRun, string cSharpFormat, string oracleFormat)
|
|
|
|
|
private void EvaluateRows(string workingDirectory, Dictionary<string, Dictionary<ModuleInstanceTypeName, List<List<object>>>> rows)
|
|
|
|
|
{
|
|
|
|
|
object _Lock = new();
|
|
|
|
|
bool _ShuttingDown = false;
|
|
|
|
|
bool dev = appSettings.Server.Contains("_ec_");
|
|
|
|
|
Dictionary<string, Dictionary<ModuleInstanceTypeName, List<List<object>>>> rows = new();
|
|
|
|
|
//
|
|
|
|
|
//int moduleinstancetypename = 0;
|
|
|
|
|
int unitname = 1;
|
|
|
|
|
//int modulename = 2;
|
|
|
|
@ -571,243 +566,247 @@ public class Background : Models.Properties.IBackground, IBackground, IDisposabl
|
|
|
|
|
int containermodifieddate = 7;
|
|
|
|
|
int containerconfiguration = 8;
|
|
|
|
|
int configurationmodifieddate = 9;
|
|
|
|
|
//
|
|
|
|
|
string csv;
|
|
|
|
|
string? xml;
|
|
|
|
|
string json;
|
|
|
|
|
string text;
|
|
|
|
|
string html;
|
|
|
|
|
Common common;
|
|
|
|
|
string emptyAPC;
|
|
|
|
|
string fileName;
|
|
|
|
|
object _Lock = new();
|
|
|
|
|
string? modifiedDate;
|
|
|
|
|
string edaObjectFile;
|
|
|
|
|
string goldDirectory;
|
|
|
|
|
string replace = "$$$";
|
|
|
|
|
string edaObjectDirectory;
|
|
|
|
|
DateTime lastModifiedDate;
|
|
|
|
|
string objectTypeDirectory;
|
|
|
|
|
string workingDirectory = string.Concat(@"\\", appSettings.Server, @"\EC_EDA");
|
|
|
|
|
// ()
|
|
|
|
|
DateTime containerModifiedDate;
|
|
|
|
|
PDSFConfiguration? configuration;
|
|
|
|
|
DateTime configurationModifiedDate;
|
|
|
|
|
JsonSerializerOptions jsonSerializerOptions = new() { WriteIndented = true };
|
|
|
|
|
foreach (KeyValuePair<string, Dictionary<ModuleInstanceTypeName, List<List<object>>>> databaseElement in rows)
|
|
|
|
|
{
|
|
|
|
|
object @object;
|
|
|
|
|
string? @string;
|
|
|
|
|
int fieldCount;
|
|
|
|
|
List<object> row;
|
|
|
|
|
string decrypted;
|
|
|
|
|
string connectionName;
|
|
|
|
|
string connectionString;
|
|
|
|
|
StringBuilder sql = new();
|
|
|
|
|
Array objectTypes = Enum.GetValues(typeof(ModuleInstanceTypeName));
|
|
|
|
|
List<Tuple<string, string>> connections = new();
|
|
|
|
|
if (dev)
|
|
|
|
|
if (_Stop)
|
|
|
|
|
break;
|
|
|
|
|
emptyAPC = string.Concat(workingDirectory, @"\", databaseElement.Key, @"\EmptyAPC.xlsx");
|
|
|
|
|
foreach (KeyValuePair<ModuleInstanceTypeName, List<List<object>>> tableNameElement in databaseElement.Value)
|
|
|
|
|
{
|
|
|
|
|
connectionName = @"DEV";
|
|
|
|
|
connectionString = 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 = 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 = 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)
|
|
|
|
|
if (_Stop)
|
|
|
|
|
break;
|
|
|
|
|
rows.Add(connection.Item1, new Dictionary<ModuleInstanceTypeName, List<List<object>>>());
|
|
|
|
|
foreach (ModuleInstanceTypeName objectType in objectTypes)
|
|
|
|
|
objectTypeDirectory = string.Concat(workingDirectory, @"\", databaseElement.Key, @"\", tableNameElement.Key);
|
|
|
|
|
foreach (List<object> rowItem in tableNameElement.Value)
|
|
|
|
|
{
|
|
|
|
|
if (_ShuttingDown)
|
|
|
|
|
if (_Stop)
|
|
|
|
|
break;
|
|
|
|
|
if (string.IsNullOrEmpty(edaDataCollectionPlansLastRun))
|
|
|
|
|
//foreach (var item in rowItem)
|
|
|
|
|
// Print(item.ToString());
|
|
|
|
|
//if (!rowItem[containername].ToString().Contains("Plan_Pdsf_Health_Cp2Mg"))
|
|
|
|
|
// if (!rowItem[unitname].ToString().Contains("HGCV1") || !rowItem[containername].ToString().Contains("Plan_Pdsf"))
|
|
|
|
|
// continue;
|
|
|
|
|
modifiedDate = rowItem[containermodifieddate].ToString();
|
|
|
|
|
if (string.IsNullOrEmpty(modifiedDate))
|
|
|
|
|
continue;
|
|
|
|
|
containerModifiedDate = DateTime.Parse(modifiedDate);
|
|
|
|
|
modifiedDate = rowItem[configurationmodifieddate].ToString();
|
|
|
|
|
if (string.IsNullOrEmpty(modifiedDate))
|
|
|
|
|
continue;
|
|
|
|
|
configurationModifiedDate = DateTime.Parse(modifiedDate);
|
|
|
|
|
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();
|
|
|
|
|
if (string.IsNullOrEmpty(xml))
|
|
|
|
|
continue;
|
|
|
|
|
lock (_Lock)
|
|
|
|
|
{
|
|
|
|
|
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(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(sql.ToString(), oracleConnection);
|
|
|
|
|
using Oracle.ManagedDataAccess.Client.OracleDataReader oracleDataReader = oracleCommand.ExecuteReader();
|
|
|
|
|
fieldCount = oracleDataReader.FieldCount;
|
|
|
|
|
while (oracleDataReader.Read())
|
|
|
|
|
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 (configuration is null)
|
|
|
|
|
continue;
|
|
|
|
|
common.Update(configuration);
|
|
|
|
|
json = JsonSerializer.Serialize(configuration, configuration.GetType(), jsonSerializerOptions);
|
|
|
|
|
if (common?.UnitName is null)
|
|
|
|
|
continue;
|
|
|
|
|
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 = 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 = 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 = 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 = 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 = 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 = 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))
|
|
|
|
|
{
|
|
|
|
|
if (_ShuttingDown)
|
|
|
|
|
break;
|
|
|
|
|
row = new List<object>();
|
|
|
|
|
for (int c = 0; c < fieldCount; c++)
|
|
|
|
|
{
|
|
|
|
|
@object = oracleDataReader.GetValue(c);
|
|
|
|
|
row.Add(@object);
|
|
|
|
|
if (@object is null)
|
|
|
|
|
continue;
|
|
|
|
|
@string = @object.ToString();
|
|
|
|
|
//if (@string.Length < 128)
|
|
|
|
|
// _Log.Debug(@string);
|
|
|
|
|
}
|
|
|
|
|
rows[connection.Item1][objectType].Add(row);
|
|
|
|
|
File.Copy(emptyAPC, fileName);
|
|
|
|
|
try
|
|
|
|
|
{ File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); }
|
|
|
|
|
catch (Exception) { }
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (rows.Any())
|
|
|
|
|
{
|
|
|
|
|
string csv;
|
|
|
|
|
string? xml;
|
|
|
|
|
string json;
|
|
|
|
|
string text;
|
|
|
|
|
string html;
|
|
|
|
|
Common common;
|
|
|
|
|
string emptyAPC;
|
|
|
|
|
string fileName;
|
|
|
|
|
string? modifiedDate;
|
|
|
|
|
string edaObjectFile;
|
|
|
|
|
string goldDirectory;
|
|
|
|
|
string replace = "$$$";
|
|
|
|
|
string edaObjectDirectory;
|
|
|
|
|
DateTime lastModifiedDate;
|
|
|
|
|
DateTime containerModifiedDate;
|
|
|
|
|
PDSFConfiguration? configuration;
|
|
|
|
|
DateTime configurationModifiedDate;
|
|
|
|
|
JsonSerializerOptions jsonSerializerOptions = new() { 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;
|
|
|
|
|
modifiedDate = rowItem[containermodifieddate].ToString();
|
|
|
|
|
if (string.IsNullOrEmpty(modifiedDate))
|
|
|
|
|
if (!common.StoragePaths.Any())
|
|
|
|
|
continue;
|
|
|
|
|
containerModifiedDate = DateTime.Parse(modifiedDate);
|
|
|
|
|
modifiedDate = rowItem[configurationmodifieddate].ToString();
|
|
|
|
|
if (string.IsNullOrEmpty(modifiedDate))
|
|
|
|
|
continue;
|
|
|
|
|
configurationModifiedDate = DateTime.Parse(modifiedDate);
|
|
|
|
|
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();
|
|
|
|
|
if (string.IsNullOrEmpty(xml))
|
|
|
|
|
continue;
|
|
|
|
|
//continue;
|
|
|
|
|
lock (_Lock)
|
|
|
|
|
foreach (string? storagePath in common.StoragePaths)
|
|
|
|
|
{
|
|
|
|
|
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 (configuration is null)
|
|
|
|
|
if (string.IsNullOrEmpty(storagePath) || !Directory.Exists(Path.GetPathRoot(storagePath)))
|
|
|
|
|
continue;
|
|
|
|
|
common.Update(configuration);
|
|
|
|
|
json = JsonSerializer.Serialize(configuration, configuration.GetType(), jsonSerializerOptions);
|
|
|
|
|
if (common?.UnitName is null)
|
|
|
|
|
if (Directory.Exists(storagePath))
|
|
|
|
|
continue;
|
|
|
|
|
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 = 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 = 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 = 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 = 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 = 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 = 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) { }
|
|
|
|
|
}
|
|
|
|
|
if (!common.StoragePaths.Any())
|
|
|
|
|
continue;
|
|
|
|
|
foreach (string? storagePath in common.StoragePaths)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(storagePath) || !Directory.Exists(Path.GetPathRoot(storagePath)))
|
|
|
|
|
continue;
|
|
|
|
|
if (Directory.Exists(storagePath))
|
|
|
|
|
continue;
|
|
|
|
|
_ = Directory.CreateDirectory(storagePath);
|
|
|
|
|
}
|
|
|
|
|
_ = Directory.CreateDirectory(storagePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{ Directory.SetLastWriteTime(objectTypeDirectory, DateTime.Now); }
|
|
|
|
|
catch (Exception) { }
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{ Directory.SetLastWriteTime(objectTypeDirectory, DateTime.Now); }
|
|
|
|
|
catch (Exception) { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DataCollectionPlans(AppSettings appSettings, string edaDataCollectionPlansLastRun, string cSharpFormat, string oracleFormat)
|
|
|
|
|
{
|
|
|
|
|
int fieldCount;
|
|
|
|
|
object @object;
|
|
|
|
|
string? @string;
|
|
|
|
|
List<object> row;
|
|
|
|
|
string decrypted;
|
|
|
|
|
string connectionName;
|
|
|
|
|
string connectionString;
|
|
|
|
|
StringBuilder sql = new();
|
|
|
|
|
string objectTypeDirectory;
|
|
|
|
|
bool dev = appSettings.Server.Contains("_ec_");
|
|
|
|
|
List<Tuple<string, string>> connections = new();
|
|
|
|
|
Array objectTypes = Enum.GetValues(typeof(ModuleInstanceTypeName));
|
|
|
|
|
string workingDirectory = string.Concat(@"\\", appSettings.Server, @"\EC_EDA");
|
|
|
|
|
Dictionary<string, Dictionary<ModuleInstanceTypeName, List<List<object>>>> rows = new();
|
|
|
|
|
if (dev)
|
|
|
|
|
{
|
|
|
|
|
connectionName = @"DEV";
|
|
|
|
|
connectionString = 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 = 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 = 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 (_Stop)
|
|
|
|
|
break;
|
|
|
|
|
rows.Add(connection.Item1, new Dictionary<ModuleInstanceTypeName, List<List<object>>>());
|
|
|
|
|
foreach (ModuleInstanceTypeName objectType in objectTypes)
|
|
|
|
|
{
|
|
|
|
|
if (_Stop)
|
|
|
|
|
break;
|
|
|
|
|
if (string.IsNullOrEmpty(edaDataCollectionPlansLastRun))
|
|
|
|
|
{
|
|
|
|
|
objectTypeDirectory = Path.Combine(workingDirectory, connection.Item1, objectType.ToString());
|
|
|
|
|
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(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(sql.ToString(), oracleConnection);
|
|
|
|
|
using Oracle.ManagedDataAccess.Client.OracleDataReader oracleDataReader = oracleCommand.ExecuteReader();
|
|
|
|
|
fieldCount = oracleDataReader.FieldCount;
|
|
|
|
|
while (oracleDataReader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (_Stop)
|
|
|
|
|
break;
|
|
|
|
|
row = new List<object>();
|
|
|
|
|
for (int c = 0; c < fieldCount; c++)
|
|
|
|
|
{
|
|
|
|
|
@object = oracleDataReader.GetValue(c);
|
|
|
|
|
row.Add(@object);
|
|
|
|
|
if (@object is null)
|
|
|
|
|
continue;
|
|
|
|
|
@string = @object.ToString();
|
|
|
|
|
//if (@string.Length < 128)
|
|
|
|
|
// _Log.Debug(@string);
|
|
|
|
|
}
|
|
|
|
|
rows[connection.Item1][objectType].Add(row);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (rows.Any())
|
|
|
|
|
EvaluateRows(workingDirectory, rows);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|