2023-01-24

This commit is contained in:
2023-01-24 08:45:13 -07:00
commit 660b89c129
146 changed files with 16122 additions and 0 deletions

View File

@ -0,0 +1,129 @@
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 title,
string epiLine,
string area,
string systemS,
string priSort,
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;
Title = title;
EpiLine = epiLine;
Area = area;
SystemS = systemS;
PriSort = priSort;
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;
}
[JsonPropertyName("Req ")]
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; }
public string Title { 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; }
[JsonPropertyName("Pri Sort")]
public string PriSort { get; set; } // { init; get; }
public string Priority { get; set; } // { init; get; }
public string Status { get; set; } // { init; get; }
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; }
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

@ -0,0 +1,127 @@
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.Linq;
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, 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(), true, smtp, fileParameter, cellInstanceName, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, staticRuns, useCyclicalForDescription, isEAFHosted)
{
_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.Any())
throw new Exception(string.Concat("B) No Data - ", dateTime.Ticks));
string json = iProcessData.Details[0].ToString();
string fileName = Path.Combine(_FileConnectorConfiguration.TargetFileLocation, $"{_SheetName}.json");
if (File.Exists(fileName))
{
File.Delete(fileName);
Thread.Sleep(500);
}
File.WriteAllText(fileName, json);
results = iProcessData.GetResults(this, _Logistics, results.Item4);
}
return results;
}
}

View File

@ -0,0 +1,141 @@
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 = string.Concat(@object);
if (value.Contains("\""))
value = value.Replace("\"", "\\\"");
if (value.Contains("\n"))
value = value.Replace("\n", "<br />");
name = table.Columns[j].ColumnName.ToString();
if (name == ",")
name = "Title";
if (name.Contains("\""))
name = name.Replace("\"", "\\\"");
if (name.Contains("\n"))
name = name.Replace("\n", "<br />");
_ = jsonString.Append('"').Append(name).Append("\":").Append('"').Append(value).Append('"');
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 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);
FIBacklogMesa[]? fIBacklogMesaCollection = JsonSerializer.Deserialize<FIBacklogMesa[]>(json, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true });
if (fIBacklogMesaCollection is null || !fIBacklogMesaCollection.Any())
throw new NullReferenceException();
json = JsonSerializer.Serialize(fIBacklogMesaCollection, new JsonSerializerOptions() { WriteIndented = true });
_Details.Add(json);
}
}