Assembly Version
WS Result bug fix and Nuget bump, PSN, Reactor and Extra RDS rule OpenInsightApi and testRunTitle serializerValue
This commit is contained in:
@ -3,6 +3,7 @@ using System;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
@ -29,7 +30,12 @@ public class FromIQS
|
||||
.AppendLine(" pl.f_name pl_name, ")
|
||||
.AppendLine(" pd.f_name pd_name, ")
|
||||
.AppendLine(" td.f_test td_test, ")
|
||||
.AppendLine(" td.f_name td_name ")
|
||||
.AppendLine(" td.f_name td_name, ")
|
||||
.AppendLine(" (select count(ev.f_evnt) ")
|
||||
.AppendLine(" from [spcepiworld].[dbo].[evnt_inf] ev ")
|
||||
.AppendLine(" where ev.f_prcs = rd.f_prcs ")
|
||||
.AppendLine(" and ev.f_part = pd.f_part ")
|
||||
.AppendLine(" and ev.f_sgtm = se.f_sgtm) ev_count ")
|
||||
.AppendLine(" from [spcepiworld].[dbo].[sgrp_ext] se ")
|
||||
.AppendLine(" join [spcepiworld].[dbo].[prcs_dat] rd ")
|
||||
.AppendLine(" on se.f_prcs = rd.f_prcs ")
|
||||
@ -67,9 +73,10 @@ public class FromIQS
|
||||
return stringBuilder;
|
||||
}
|
||||
|
||||
internal static (long?, string) GetCommandText(string connectionString, Logistics logistics, Stratus.Description description, long breakAfter, long preWait)
|
||||
internal static (long?, int?, string) GetCommandText(string connectionString, Logistics logistics, Stratus.Description description, long breakAfter, long preWait)
|
||||
{
|
||||
string dateTime;
|
||||
int? count = null;
|
||||
string commandText;
|
||||
long? result = null;
|
||||
string dateFormat = Stratus.Description.GetDateFormat();
|
||||
@ -113,10 +120,92 @@ public class FromIQS
|
||||
{
|
||||
result = subGroupId;
|
||||
commandText = GetCommandText(logistics, description, dateTime, subGroupId);
|
||||
if (jsonProperties.Any() && jsonProperties[10].Name == "ev_count" && int.TryParse(jsonProperties[10].Value.ToString(), out int evCount))
|
||||
count = evCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
return new(result, commandText);
|
||||
return new(result, count, commandText);
|
||||
}
|
||||
|
||||
private static string GetJson(Logistics logistics, string logisticLines, Stratus.Description description)
|
||||
{
|
||||
string result;
|
||||
StringBuilder stringBuilder = new();
|
||||
var @object = new
|
||||
{
|
||||
description.MesEntity,
|
||||
description.Employee,
|
||||
description.Layer,
|
||||
description.PSN,
|
||||
description.RDS,
|
||||
description.Reactor,
|
||||
description.Recipe,
|
||||
description.Zone,
|
||||
logistics.DateTimeFromSequence.Ticks
|
||||
};
|
||||
string[] pair;
|
||||
string safeValue;
|
||||
string[] segments;
|
||||
string serializerValue;
|
||||
foreach (string line in logisticLines.Split(new string[] { Environment.NewLine }, StringSplitOptions.None))
|
||||
{
|
||||
segments = line.Split('\t');
|
||||
if (segments.Length < 2)
|
||||
continue;
|
||||
segments = segments[1].Split(';');
|
||||
_ = stringBuilder.Append('{');
|
||||
foreach (string segment in segments)
|
||||
{
|
||||
pair = segment.Split('=');
|
||||
if (pair.Length != 2 || pair[0].Length < 3)
|
||||
continue;
|
||||
serializerValue = JsonSerializer.Serialize(pair[1]);
|
||||
safeValue = serializerValue.Substring(1, serializerValue.Length - 2);
|
||||
_ = stringBuilder.Append('"').Append(pair[0].Substring(2)).Append('"').Append(':').Append('"').Append(safeValue).Append('"').Append(',');
|
||||
}
|
||||
if (stringBuilder.Length > 0)
|
||||
_ = stringBuilder.Remove(stringBuilder.Length - 1, 1);
|
||||
_ = stringBuilder.Append('}').Append(',');
|
||||
}
|
||||
if (stringBuilder.Length > 0)
|
||||
_ = stringBuilder.Remove(stringBuilder.Length - 1, 1);
|
||||
_ = stringBuilder.Append(']').Append('}');
|
||||
_ = stringBuilder.Insert(0, ",\"Logistics\":[");
|
||||
string json = JsonSerializer.Serialize(@object);
|
||||
_ = stringBuilder.Insert(0, json.Substring(0, json.Length - 1));
|
||||
JsonElement? jsonElement = JsonSerializer.Deserialize<JsonElement>(stringBuilder.ToString());
|
||||
result = jsonElement is null ? "{}" : JsonSerializer.Serialize(jsonElement, new JsonSerializerOptions { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static void Save(string openInsightApiECDirectory, string openInsightApiIFXDirectory, Logistics logistics, string reportFullPath, string logisticLines, Stratus.Description description, string lines, long? subGroupId, string weekOfYear)
|
||||
{
|
||||
string fileName = Path.GetFileName(reportFullPath);
|
||||
string json = GetJson(logistics, logisticLines, description);
|
||||
string? ecPathRoot = Path.GetPathRoot(openInsightApiECDirectory);
|
||||
string? ifxPathRoot = Path.GetPathRoot(openInsightApiIFXDirectory);
|
||||
bool ecExists = ecPathRoot is not null && Directory.Exists(ecPathRoot);
|
||||
bool ifxExists = ifxPathRoot is not null && Directory.Exists(ifxPathRoot);
|
||||
string weekYear = $"{logistics.DateTimeFromSequence:yyyy}_Week_{weekOfYear}";
|
||||
string ecDirectory = Path.Combine(openInsightApiECDirectory, weekYear, $"-{description.PSN}", $"-{description.Reactor}", $"-{description.RDS}", $"-{subGroupId}");
|
||||
string ifxDirectory = Path.Combine(openInsightApiIFXDirectory, weekYear, $"-{description.PSN}", $"-{description.Reactor}", $"-{description.RDS}", $"-{subGroupId}");
|
||||
if (ecExists && !Directory.Exists(ecDirectory))
|
||||
_ = Directory.CreateDirectory(ecDirectory);
|
||||
if (ifxExists && !Directory.Exists(ifxDirectory))
|
||||
_ = Directory.CreateDirectory(ifxDirectory);
|
||||
if (ecExists)
|
||||
File.Copy(reportFullPath, Path.Combine(ecDirectory, fileName));
|
||||
if (ifxExists)
|
||||
File.Copy(reportFullPath, Path.Combine(ifxDirectory, fileName));
|
||||
if (ecExists)
|
||||
File.WriteAllText(Path.Combine(ecDirectory, $"{logistics.DateTimeFromSequence.Ticks}.txt"), lines);
|
||||
if (ifxExists)
|
||||
File.WriteAllText(Path.Combine(ifxDirectory, $"{logistics.DateTimeFromSequence.Ticks}.txt"), lines);
|
||||
if (ecExists)
|
||||
File.WriteAllText(Path.Combine(ecDirectory, $"{logistics.DateTimeFromSequence.Ticks}.json"), json);
|
||||
if (ifxExists)
|
||||
File.WriteAllText(Path.Combine(ifxDirectory, $"{logistics.DateTimeFromSequence.Ticks}.json"), json);
|
||||
}
|
||||
|
||||
#nullable disable
|
||||
|
Reference in New Issue
Block a user