v2.47.1 - Ready to test IQS query

This commit is contained in:
2022-12-02 14:22:13 -07:00
parent 6f92f8fcfc
commit 335dd5011f
46 changed files with 775 additions and 199 deletions

View File

@ -17,6 +17,7 @@ public class FileRead : Shared.FileRead, IFileRead
{
private string _LastLines;
private readonly string _IqsConnectionString;
private readonly string _OpenInsightFilePattern;
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) :
@ -32,6 +33,7 @@ public class FileRead : Shared.FileRead, IFileRead
if (!_IsDuplicator)
throw new Exception(cellInstanceConnectionName);
_LastLines = string.Empty;
_IqsConnectionString = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "IQS.ConnectionString");
_OpenInsightFilePattern = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "OpenInsight.FilePattern");
}
@ -167,27 +169,32 @@ public class FileRead : Shared.FileRead, IFileRead
{
if (dateTime == DateTime.MinValue)
{ }
if (!tests.Any())
bool isDummyRun = false;
List<(Shared.Properties.IScopeInfo, string)> collection = new();
string successDirectory = _FileConnectorConfiguration.AlternateTargetFolder;
string parentParent = GetParentParent(_FileConnectorConfiguration.SourceFileLocation);
if (parentParent.Contains(_CellInstanceName))
parentParent = Path.GetDirectoryName(parentParent);
string duplicateDirectory = Path.Combine(parentParent, "Data");
if (!descriptions.Any() || !tests.Any())
_LastLines = string.Empty;
else
{
bool isDummyRun = false;
Tuple<string, string> lines = GetLines(_Logistics, descriptions);
string check = lines.Item1.Replace(lines.Item2, "$Date$");
ScopeInfo scopeInfo = new(tests[0], _OpenInsightFilePattern);
List<(Shared.Properties.IScopeInfo, string)> tuples = new();
if (string.IsNullOrEmpty(_LastLines) || check != _LastLines)
tuples.Add(new(scopeInfo, lines.Item1));
bool save = string.IsNullOrEmpty(_LastLines) || check != _LastLines;
if (save && !string.IsNullOrEmpty(check))
collection.Add(new(new ScopeInfo(tests[0], _OpenInsightFilePattern), lines.Item1));
_LastLines = check;
string successDirectory = _FileConnectorConfiguration.AlternateTargetFolder;
string parentParent = GetParentParent(_FileConnectorConfiguration.SourceFileLocation);
if (parentParent.Contains(_CellInstanceName))
parentParent = Path.GetDirectoryName(parentParent);
string duplicateDirectory = Path.Combine(parentParent, "Data");
_ = FromIQS.GetCommandText(_IqsConnectionString, _Logistics, descriptions[0]);
// string commandText = FromIQS.GetCommandText(_IqsConnectionString, _Logistics, descriptions[0]);
// if (save && !string.IsNullOrEmpty(commandText))
// collection.Add(new(new ScopeInfo(tests[0], _OpenInsightFilePattern), commandText));
if (!Directory.Exists(duplicateDirectory))
_ = Directory.CreateDirectory(duplicateDirectory);
string duplicateFile = Path.Combine(duplicateDirectory, Path.GetFileName(reportFullPath));
WaitForFileConsumption(dateTime, isDummyRun, successDirectory, duplicateDirectory, tuples, duplicateFile);
if (_IsEAFHosted && _FileConnectorConfiguration.FileScanningIntervalInSeconds > 0)
WaitForFileConsumption(dateTime, descriptions, isDummyRun, successDirectory, duplicateDirectory, collection, duplicateFile);
}
}

View File

@ -0,0 +1,103 @@
using Adaptation.Shared;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.Json;
namespace Adaptation.FileHandlers.OpenInsight;
public class FromIQS
{
#nullable enable
private static string GetCommandText(Logistics logistics, txt.Description description, string dateTime, string? sid)
{
StringBuilder result = new();
_ = result
.AppendLine(" select ")
.AppendLine(" se.f_sgrp se_sgrp, ")
.AppendLine(" se.f_sgtm se_sgtm, ")
.AppendLine(" se.f_tsno se_tsno, ")
.AppendLine(" se.f_val se_val, ")
.AppendLine(" rd.f_name rd_name, ")
.AppendLine(" jd.f_name jd_name, ")
.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(" from [spcepiworld].[dbo].[sgrp_ext] se ")
.AppendLine(" join [spcepiworld].[dbo].[prcs_dat] rd ")
.AppendLine(" on se.f_prcs = rd.f_prcs ")
.AppendLine(" join [spcepiworld].[dbo].[job_dat] jd ")
.AppendLine(" on se.f_job = jd.f_job ")
.AppendLine(" join [spcepiworld].[dbo].[part_lot] pl ")
.AppendLine(" on se.f_lot = pl.f_lot ")
.AppendLine(" join [spcepiworld].[dbo].[part_dat] pd ")
.AppendLine(" on se.f_part = pd.f_part ")
.AppendLine(" join [spcepiworld].[dbo].[test_dat] td ")
.AppendLine(" on se.f_test = td.f_test ")
.AppendLine(" where se.f_flag = 0 ");
if (!string.IsNullOrEmpty(sid))
_ = result.Append(" and se.f_sgrp = ").Append(sid).AppendLine(" ");
_ = result
.Append(" and rd.f_name = '").Append(description.Reactor).AppendLine("' ")
.Append(" and pd.f_name = '").Append(description.PSN).AppendLine("' ")
.AppendLine(" and jd.f_name in ('SP1') ")
.Append(" and jd.f_name = '").Append(logistics.MesEntity).AppendLine("' ")
.Append(" and pl.f_name = '").Append(description.RDS).AppendLine("' ")
.Append(" and dateadd(HH, -7, (dateadd(SS, convert(bigint, se.f_sgtm), '19700101'))) = '").Append(dateTime).AppendLine("' ")
.AppendLine(" for json path ");
return result.ToString();
}
private static StringBuilder GetForJsonPath(string connectionString, string commandText)
{
StringBuilder stringBuilder = new();
using SqlConnection sqlConnection = new(connectionString);
sqlConnection.Open();
using SqlCommand sqlCommand = new(commandText, sqlConnection);
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess);
while (sqlDataReader.Read())
_ = stringBuilder.Append(sqlDataReader.GetString(0));
return stringBuilder;
}
internal static string GetCommandText(string connectionString, Logistics logistics, txt.Description description)
{
string result;
string dateTime;
string dateFormat = txt.Description.GetDateFormat();
if (DateTime.TryParseExact(description.Date, dateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateTimeParsed))
dateTime = dateTimeParsed.ToString("yyyy-MM-dd HH:mm:ss");
else if (DateTime.TryParse(description.Date, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTimeParsed))
dateTime = dateTimeParsed.ToString("yyyy-MM-dd HH:mm:ss");
else
dateTime = logistics.DateTimeFromSequence.ToString("yyyy-MM-dd HH:mm:ss");
string commandText = GetCommandText(logistics, description, dateTime, sid: null);
StringBuilder stringBuilder = GetForJsonPath(connectionString, commandText);
if (stringBuilder.Length == 0)
result = commandText;
else
{
JsonElement[]? jsonElements = JsonSerializer.Deserialize<JsonElement[]>(stringBuilder.ToString());
if (jsonElements is null || !jsonElements.Any() || jsonElements[0].ValueKind != JsonValueKind.Object)
result = commandText;
else
{
JsonProperty[] jsonProperties = jsonElements[0].EnumerateObject().ToArray();
if (!jsonProperties.Any() || jsonProperties[0].Name != "se_sgrp")
result = commandText;
else
result = GetCommandText(logistics, description, dateTime, sid: jsonProperties[0].Value.ToString());
}
}
return result;
}
#nullable disable
}