This commit is contained in:
2024-09-07 10:04:57 -07:00
parent 390090729b
commit 2301a9a9ee
31 changed files with 1121 additions and 1913 deletions

View File

@ -1,130 +0,0 @@
using System.Text.Json.Serialization;
namespace Adaptation.FileHandlers.ConvertExcelToJson;
public class FIBacklogMesa
{
[JsonConstructor]
public FIBacklogMesa(string req,
string submitted,
string requestor,
string assignedTo,
string secondResource,
string subject,
string epiLine,
string area,
string systemS,
string priority,
string status,
string definition,
string updates,
string estEffortDays,
string commitDate,
string reCommitDate,
string uATAsOf,
string cmpDate,
string f20,
string f21,
string f22,
string f23,
string f24,
string f25,
string f26,
string f27,
string f28,
string f29,
string f30,
string f31,
string f32,
string f33)
{
Req = req;
Submitted = submitted;
Requestor = requestor;
AssignedTo = assignedTo;
SecondResource = secondResource;
Subject = subject;
EpiLine = epiLine;
Area = area;
SystemS = systemS;
Priority = priority;
Status = status;
Definition = definition;
Updates = updates;
EstEffortDays = estEffortDays;
CommitDate = commitDate;
ReCommitDate = reCommitDate;
UATAsOf = uATAsOf;
CMPDate = cmpDate;
F20 = f20;
F21 = f21;
F22 = f22;
F23 = f23;
F24 = f24;
F25 = f25;
F26 = f26;
F27 = f27;
F28 = f28;
F29 = f29;
F30 = f30;
F31 = f31;
F32 = f32;
F33 = f33;
}
public string Req { get; set; } // { init; get; }
public string Submitted { get; set; } // { init; get; }
public string Requestor { get; set; } // { init; get; }
[JsonPropertyName("Assigned To")]
public string AssignedTo { get; set; } // { init; get; }
[JsonPropertyName("Second Resource")]
public string SecondResource { get; set; } // { init; get; }
[JsonPropertyName("Subject - from Requestor")]
public string Subject { get; set; } // { init; get; }
[JsonPropertyName("Epi Line")]
public string EpiLine { get; set; } // { init; get; }
public string Area { get; set; } // { init; get; }
[JsonPropertyName("System(s)")]
public string SystemS { get; set; } // { init; get; }
public string Priority { get; set; } // { init; get; }
public string Status { get; set; } // { init; get; }
[JsonPropertyName("Definition - from FI")]
public string Definition { get; set; } // { init; get; }
public string Updates { get; set; } // { init; get; }
[JsonPropertyName("Est Effort _(days)")]
public string EstEffortDays { get; set; } // { init; get; }
[JsonPropertyName("Commit Date")]
public string CommitDate { get; set; } // { init; get; }
[JsonPropertyName("Re-Commit Date")]
public string ReCommitDate { get; set; } // { init; get; }
[JsonPropertyName("UAT as of")]
public string UATAsOf { get; set; } // { init; get; }
[JsonPropertyName("CMP _Date")]
public string CMPDate { get; set; } // { init; get; }
public string F20 { get; set; } // { init; get; }
public string F21 { get; set; } // { init; get; }
public string F22 { get; set; } // { init; get; }
public string F23 { get; set; } // { init; get; }
public string F24 { get; set; } // { init; get; }
public string F25 { get; set; } // { init; get; }
public string F26 { get; set; } // { init; get; }
public string F27 { get; set; } // { init; get; }
public string F28 { get; set; } // { init; get; }
public string F29 { get; set; } // { init; get; }
public string F30 { get; set; } // { init; get; }
public string F31 { get; set; } // { init; get; }
public string F32 { get; set; } // { init; get; }
public string F33 { get; set; } // { init; get; }
}

View File

@ -1,128 +0,0 @@
using Adaptation.Eaf.Management.ConfigurationData.CellAutomation;
using Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration;
using Adaptation.Shared;
using Adaptation.Shared.Duplicator;
using Adaptation.Shared.Methods;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Threading;
namespace Adaptation.FileHandlers.ConvertExcelToJson;
public class FileRead : Shared.FileRead, IFileRead
{
private long? _TickOffset;
private readonly string _SheetName;
public FileRead(ISMTP smtp, Dictionary<string, string> fileParameter, string cellInstanceName, int? connectionCount, string cellInstanceConnectionName, FileConnectorConfiguration fileConnectorConfiguration, string equipmentTypeName, string parameterizedModelObjectDefinitionType, IList<ModelObjectParameterDefinition> modelObjectParameters, string equipmentDictionaryName, Dictionary<string, List<long>> dummyRuns, Dictionary<long, List<string>> staticRuns, bool useCyclicalForDescription, bool isEAFHosted) :
base(new Description(), false, smtp, fileParameter, cellInstanceName, connectionCount, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, staticRuns, useCyclicalForDescription, isEAFHosted: connectionCount is null)
{
_MinFileLength = 10;
_NullData = string.Empty;
_Logistics = new(this);
if (_FileParameter is null)
throw new Exception(cellInstanceConnectionName);
if (_ModelObjectParameterDefinitions is null)
throw new Exception(cellInstanceConnectionName);
if (_IsDuplicator)
throw new Exception(cellInstanceConnectionName);
_SheetName = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, string.Concat("CellInstance.", cellInstanceName, ".Excel.SheetName"));
}
void IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, Exception exception) => Move(extractResults);
void IFileRead.WaitForThread() => WaitForThread(thread: null, threadExceptions: null);
string IFileRead.GetEventDescription()
{
string result = _Description.GetEventDescription();
return result;
}
List<string> IFileRead.GetHeaderNames()
{
List<string> results = _Description.GetHeaderNames();
return results;
}
string[] IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, string to, string from, string resolvedFileLocation, Exception exception)
{
string[] results = Move(extractResults, to, from, resolvedFileLocation, exception);
return results;
}
JsonProperty[] IFileRead.GetDefault()
{
JsonProperty[] results = _Description.GetDefault(this, _Logistics);
return results;
}
Dictionary<string, string> IFileRead.GetDisplayNamesJsonElement()
{
Dictionary<string, string> results = _Description.GetDisplayNamesJsonElement(this);
return results;
}
List<IDescription> IFileRead.GetDescriptions(IFileRead fileRead, List<Test> tests, IProcessData processData)
{
List<IDescription> results = _Description.GetDescriptions(fileRead, _Logistics, tests, processData);
return results;
}
Tuple<string, Test[], JsonElement[], List<FileInfo>> IFileRead.GetExtractResult(string reportFullPath, string eventName)
{
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
if (string.IsNullOrEmpty(eventName))
throw new Exception();
_ReportFullPath = reportFullPath;
DateTime dateTime = DateTime.Now;
results = GetExtractResult(reportFullPath, dateTime);
if (results.Item3 is null)
results = new Tuple<string, Test[], JsonElement[], List<FileInfo>>(results.Item1, Array.Empty<Test>(), JsonSerializer.Deserialize<JsonElement[]>("[]"), results.Item4);
if (results.Item3.Length > 0 && _IsEAFHosted)
WritePDSF(this, results.Item3);
UpdateLastTicksDuration(DateTime.Now.Ticks - dateTime.Ticks);
return results;
}
Tuple<string, Test[], JsonElement[], List<FileInfo>> IFileRead.ReExtract()
{
Tuple<string, Test[], JsonElement[], List<FileInfo>> results;
List<string> headerNames = _Description.GetHeaderNames();
Dictionary<string, string> keyValuePairs = _Description.GetDisplayNamesJsonElement(this);
results = ReExtract(this, headerNames, keyValuePairs);
return results;
}
private Tuple<string, Test[], JsonElement[], List<FileInfo>> GetExtractResult(string reportFullPath, DateTime dateTime)
{
Tuple<string, Test[], JsonElement[], List<FileInfo>> results = new(string.Empty, null, null, new List<FileInfo>());
_TickOffset ??= new FileInfo(reportFullPath).LastWriteTime.Ticks - dateTime.Ticks;
_Logistics = new Logistics(this, _TickOffset.Value, reportFullPath, useSplitForMID: true);
SetFileParameterLotIDToLogisticsMID();
if (_Logistics.FileInfo.Length < _MinFileLength)
results.Item4.Add(_Logistics.FileInfo);
else
{
IProcessData iProcessData = new ProcessData(this, _Logistics, results.Item4, _SheetName);
if (iProcessData.Details.Count == 0)
throw new Exception(string.Concat("B) No Data - ", dateTime.Ticks));
string json = iProcessData.Details[0].ToString();
string fileName = Path.Combine(_FileConnectorConfiguration.TargetFileLocation, $"{Path.GetFileNameWithoutExtension(reportFullPath)} - {_SheetName}{_FileConnectorConfiguration.TargetFileName}");
if (File.Exists(fileName))
{
if (_IsEAFHosted)
File.Delete(fileName);
Thread.Sleep(500);
}
if (_IsEAFHosted)
File.WriteAllText(fileName, json);
results = iProcessData.GetResults(this, _Logistics, results.Item4);
}
return results;
}
}

View File

@ -1,177 +0,0 @@
using Adaptation.Shared;
using Adaptation.Shared.Methods;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
namespace Adaptation.FileHandlers.ConvertExcelToJson;
public class ProcessData : IProcessData
{
private readonly List<object> _Details;
List<object> Shared.Properties.IProcessData.Details => _Details;
public ProcessData(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, string sheetName)
{
fileInfoCollection.Clear();
_Details = new List<object>();
Parse(fileRead, logistics, fileInfoCollection, sheetName);
}
string IProcessData.GetCurrentReactor(IFileRead fileRead, Logistics logistics, Dictionary<string, string> reactors) =>
throw new Exception(string.Concat("See ", nameof(Parse)));
Tuple<string, Test[], JsonElement[], List<FileInfo>> IProcessData.GetResults(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection) =>
new(logistics.Logistics1[0], Array.Empty<Test>(), Array.Empty<JsonElement>(), fileInfoCollection);
#nullable enable
/// <summary>
/// https://social.msdn.microsoft.com/Forums/en-US/2e030743-5d66-4e53-bbff-bb2eee0cbc9b/readingwriting-excel-without-excel?forum=Vsexpressvcs
/// </summary>
private static DataTable GetSheet(string file, string selectSql)
{
DataTable results = new();
#if Linux
()("Built on Linux!");
#elif OSX
()("Built on macOS!");
#elif Windows || !NETCORE
#pragma warning disable CA1416
for (int i = 0; i < int.MaxValue; i++)
{
try
{
OleDbConnectionStringBuilder connectionStringBuilder = new()
{
Provider = "Microsoft.ACE.OLEDB.12.0",
DataSource = file
};
connectionStringBuilder.Add("Extended Properties", "Excel 12.0 Xml;HDR=YES;IMEX=1;ReadOnly=1;");
using OleDbConnection connection = new(connectionStringBuilder.ConnectionString);
connection.Open();
using (OleDbDataAdapter adapter = new(selectSql, connection))
adapter.Fill(results);
connection.Close();
break;
}
catch (Exception)
{
if (i > 3) //2019-12-28 - 001
throw;
System.Threading.Thread.Sleep(1000);
}
#pragma warning restore CA1416
}
#else
()("Built in unknown!");
#endif
return results;
}
public static string DataTableToJSON(DataTable table)
{
string name;
string value;
object @object;
StringBuilder jsonString = new();
if (table.Rows.Count > 0)
{
_ = jsonString.Append('[');
for (int i = 0; i < table.Rows.Count; i++)
{
_ = jsonString.Append('{');
for (int j = 0; j < table.Columns.Count; j++)
{
@object = table.Rows[i][j];
if (@object is null)
value = string.Empty;
else
value = JsonSerializer.Serialize(@object.ToString());
if (value.Contains("\\n"))
value = value.Replace("\\n", "<br>");
if (value.Contains("\\t"))
value = value.Replace("\\t", " ");
name = JsonSerializer.Serialize(table.Columns[j].ColumnName.ToString().Trim());
if (name.Contains("\\n"))
name = name.Replace("\\n", "<br>");
if (name.Contains("\\t"))
name = name.Replace("\\t", " ");
_ = jsonString.Append(name).Append(':').Append(value);
if (j < table.Columns.Count - 1)
_ = jsonString.Append(',');
}
if (i == table.Rows.Count - 1)
_ = jsonString.Append('}');
else
_ = jsonString.Append("},");
}
_ = jsonString.Append(']');
}
return jsonString.ToString();
}
private static List<FIBacklogMesa> Parse(IFileRead fileRead, JsonElement[] jsonElements)
{
string key;
string json;
FIBacklogMesa? fiBacklogMesa;
JsonProperty[] jsonProperties;
List<FIBacklogMesa> fiBacklogMesaCollection = new();
foreach (JsonElement jsonElement in jsonElements)
{
if (jsonElement.ValueKind != JsonValueKind.Object)
continue;
jsonProperties = jsonElement.EnumerateObject().ToArray();
if (jsonProperties.Length < 2)
continue;
key = jsonProperties[0].Value.ToString();
if (string.IsNullOrEmpty(key))
continue;
json = jsonElement.ToString();
if (!fileRead.IsEAFHosted)
File.WriteAllText(".json", json);
fiBacklogMesa = JsonSerializer.Deserialize<FIBacklogMesa>(json);
if (fiBacklogMesa is null)
throw new NullReferenceException();
fiBacklogMesaCollection.Add(fiBacklogMesa);
}
return fiBacklogMesaCollection;
}
private void Parse(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, string sheet)
{
if (fileRead is null)
throw new NullReferenceException();
if (fileInfoCollection is null)
throw new NullReferenceException();
string selectSql = string.Concat("SELECT * FROM [", sheet, "$]");
DataTable dataTable = GetSheet(logistics.ReportFullPath, selectSql);
if (dataTable.Rows.Count == 0)
throw new Exception("No rows");
string json = DataTableToJSON(dataTable);
if (!fileRead.IsEAFHosted)
File.WriteAllText(".json", json);
JsonElement[]? jsonElements = JsonSerializer.Deserialize<JsonElement[]>(json, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true });
if (jsonElements is null || jsonElements.Length == 0)
throw new NullReferenceException();
if (!fileRead.ReportFullPath.Contains("Backlog"))
json = JsonSerializer.Serialize(jsonElements, new JsonSerializerOptions() { WriteIndented = true });
else
{
List<FIBacklogMesa> fiBacklogMesaCollection = Parse(fileRead, jsonElements);
json = JsonSerializer.Serialize(from l in fiBacklogMesaCollection orderby l.Req.Length, l.Req select l, new JsonSerializerOptions() { WriteIndented = true });
}
if (!fileRead.IsEAFHosted)
File.WriteAllText(".json", json);
_Details.Add(json);
}
}