v2.47.1 - ISQ query in OI file name

This commit is contained in:
Mike Phares 2022-12-06 08:22:00 -07:00
parent 6a63632bc7
commit c4bf1dcf21
6 changed files with 84 additions and 30 deletions

16
Adaptation/.vscode/Reactor.js vendored Normal file
View File

@ -0,0 +1,16 @@
// (self.length != 0) ?
// self :
// (getContextData('2', 'cds.PROCESS_JOBID', '') == '-') ?
// self :
// getContextData('2', 'cds.PROCESS_JOBID', '')
getValue(self, self.length, $('dcp.TENCOR1/pcl/MesEntity', ''), $('dcp.TENCOR1/pcl/asdf', ''), getContextData('2', 'cds.PROCESS_JOBID', ''));
function getValue(value, length, mesEntity, recipe, processJobId) {
if (recipe.toUpperCase() === 'adsf')
return mesEntity;
else if (length !== 0 || processJobId === '-')
return value;
else
return processJobId;
}

16
Adaptation/.vscode/psn.js vendored Normal file
View File

@ -0,0 +1,16 @@
// (self.length != 0) ?
// self :
// (getContextData('2', 'cds.PRODUCT', '') == '-') ?
// self :
// getContextData('2', 'cds.PRODUCT', '')
getValue(self, self.length, getContextData('2', 'cds.PRODUCT', ''), $('dcp.TENCOR1/pcl/asdf', ''));
function getValue(value, length, product, recipe) {
if (recipe.toUpperCase() === 'asdf')
return 'asdf';
else if (length !== 0 || product === '-')
return value;
else
return product;
}

View File

@ -245,13 +245,16 @@ public class FileRead : Shared.FileRead, IFileRead
if (descriptions.Any() && tests.Any()) if (descriptions.Any() && tests.Any())
{ {
string lines = GetLines(_Logistics, descriptions); string lines = GetLines(_Logistics, descriptions);
;
if (!string.IsNullOrEmpty(lines)) if (!string.IsNullOrEmpty(lines))
collection.Add(new(new ScopeInfo(tests[0], _OpenInsightFilePattern), lines)); {
_ = FromIQS.GetCommandText(_IqsConnectionString, _Logistics, descriptions[0]); long breakAfter = dateTime.AddSeconds(_BreakAfterSeconds).Ticks;
// string commandText = FromIQS.GetCommandText(_IqsConnectionString, _Logistics, descriptions[0]); long preWait = _FileConnectorConfiguration?.FileHandleWaitTime is null ? dateTime.AddMilliseconds(1234).Ticks : dateTime.AddMilliseconds(_FileConnectorConfiguration.FileHandleWaitTime.Value).Ticks;
// if (!string.IsNullOrEmpty(commandText)) (long? subGroupId, string _) = FromIQS.GetCommandText(_BreakAfterSeconds, _IqsConnectionString, _Logistics, descriptions[0], breakAfter, preWait);
// collection.Add(new(new ScopeInfo(tests[0], _OpenInsightFilePattern), commandText)); if (subGroupId is null)
collection.Add(new(new ScopeInfo(tests[0], _OpenInsightFilePattern), lines));
else
collection.Add(new(new ScopeInfo(tests[0], $"{subGroupId.Value}_{_OpenInsightFilePattern}"), lines));
}
} }
if (_IsEAFHosted && _FileConnectorConfiguration.FileScanningIntervalInSeconds > 0) if (_IsEAFHosted && _FileConnectorConfiguration.FileScanningIntervalInSeconds > 0)
WaitForFileConsumption(dateTime, descriptions, isDummyRun, successDirectory, duplicateDirectory, collection, duplicateFile); WaitForFileConsumption(dateTime, descriptions, isDummyRun, successDirectory, duplicateDirectory, collection, duplicateFile);

View File

@ -1,10 +1,12 @@
using Adaptation.Shared; using Adaptation.Shared;
using System; using System;
using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Threading;
namespace Adaptation.FileHandlers.OpenInsight; namespace Adaptation.FileHandlers.OpenInsight;
@ -13,7 +15,7 @@ public class FromIQS
#nullable enable #nullable enable
private static string GetCommandText(Logistics logistics, pcl.Description description, string dateTime, string? sid) private static string GetCommandText(Logistics logistics, pcl.Description description, string dateTime, long? subGroupId)
{ {
StringBuilder result = new(); StringBuilder result = new();
_ = result _ = result
@ -40,8 +42,8 @@ public class FromIQS
.AppendLine(" join [spcepiworld].[dbo].[test_dat] td ") .AppendLine(" join [spcepiworld].[dbo].[test_dat] td ")
.AppendLine(" on se.f_test = td.f_test ") .AppendLine(" on se.f_test = td.f_test ")
.AppendLine(" where se.f_flag = 0 "); .AppendLine(" where se.f_flag = 0 ");
if (!string.IsNullOrEmpty(sid)) if (subGroupId is not null)
_ = result.Append(" and se.f_sgrp = ").Append(sid).AppendLine(" "); _ = result.Append(" and se.f_sgrp = ").Append(subGroupId).AppendLine(" ");
_ = result _ = result
.Append(" and rd.f_name = '").Append(description.Reactor).AppendLine("' ") .Append(" and rd.f_name = '").Append(description.Reactor).AppendLine("' ")
.Append(" and pd.f_name = '").Append(description.PSN).AppendLine("' ") .Append(" and pd.f_name = '").Append(description.PSN).AppendLine("' ")
@ -56,21 +58,20 @@ public class FromIQS
private static StringBuilder GetForJsonPath(string connectionString, string commandText) private static StringBuilder GetForJsonPath(string connectionString, string commandText)
{ {
StringBuilder stringBuilder = new(); StringBuilder stringBuilder = new();
using (SqlConnection sqlConnection = new(connectionString)) using SqlConnection sqlConnection = new(connectionString);
{ sqlConnection.Open();
sqlConnection.Open(); using SqlCommand sqlCommand = new(commandText, sqlConnection);
using SqlCommand sqlCommand = new(commandText, sqlConnection); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess);
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess); while (sqlDataReader.Read())
while (sqlDataReader.Read()) _ = stringBuilder.Append(sqlDataReader.GetString(0));
_ = stringBuilder.Append(sqlDataReader.GetString(0));
}
return stringBuilder; return stringBuilder;
} }
internal static string GetCommandText(string connectionString, Logistics logistics, pcl.Description description) internal static (long?, string) GetCommandText(long breakAfterSeconds, string connectionString, Logistics logistics, pcl.Description description, long breakAfter, long preWait)
{ {
string result;
string dateTime; string dateTime;
string commandText;
long? result = null;
string dateFormat = pcl.Description.GetDateFormat(); string dateFormat = pcl.Description.GetDateFormat();
if (DateTime.TryParseExact(description.Date, dateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateTimeParsed)) if (DateTime.TryParseExact(description.Date, dateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateTimeParsed))
dateTime = dateTimeParsed.ToString("yyyy-MM-dd HH:mm:ss"); dateTime = dateTimeParsed.ToString("yyyy-MM-dd HH:mm:ss");
@ -78,25 +79,43 @@ public class FromIQS
dateTime = dateTimeParsed.ToString("yyyy-MM-dd HH:mm:ss"); dateTime = dateTimeParsed.ToString("yyyy-MM-dd HH:mm:ss");
else else
dateTime = logistics.DateTimeFromSequence.ToString("yyyy-MM-dd HH:mm:ss"); dateTime = logistics.DateTimeFromSequence.ToString("yyyy-MM-dd HH:mm:ss");
string commandText = GetCommandText(logistics, description, dateTime, sid: null); commandText = GetCommandText(logistics, description, dateTime, subGroupId: null);
StringBuilder stringBuilder = GetForJsonPath(connectionString, commandText); for (short i = 0; i < short.MaxValue; i++)
{
if (DateTime.Now.Ticks > preWait)
break;
Thread.Sleep(100);
}
StringBuilder stringBuilder = new();
for (short z = 0; z < short.MaxValue; z++)
{
stringBuilder = GetForJsonPath(connectionString, commandText);
if (stringBuilder.Length > 0)
break;
if (DateTime.Now.Ticks > breakAfter)
throw new Exception($"After {breakAfterSeconds} seconds, didn't find sub group id!");
Thread.Sleep(250);
}
if (stringBuilder.Length == 0) if (stringBuilder.Length == 0)
result = commandText; commandText = stringBuilder.ToString();
else else
{ {
JsonElement[]? jsonElements = JsonSerializer.Deserialize<JsonElement[]>(stringBuilder.ToString()); JsonElement[]? jsonElements = JsonSerializer.Deserialize<JsonElement[]>(stringBuilder.ToString());
if (jsonElements is null || !jsonElements.Any() || jsonElements[0].ValueKind != JsonValueKind.Object) if (jsonElements is null || !jsonElements.Any() || jsonElements[0].ValueKind != JsonValueKind.Object)
result = commandText; commandText = stringBuilder.ToString();
else else
{ {
JsonProperty[] jsonProperties = jsonElements[0].EnumerateObject().ToArray(); JsonProperty[] jsonProperties = jsonElements[0].EnumerateObject().ToArray();
if (!jsonProperties.Any() || jsonProperties[0].Name != "se_sgrp") if (!jsonProperties.Any() || jsonProperties[0].Name != "se_sgrp" || !long.TryParse(jsonProperties[0].Value.ToString(), out long subGroupId))
result = commandText; commandText = stringBuilder.ToString();
else else
result = GetCommandText(logistics, description, dateTime, sid: jsonProperties[0].Value.ToString()); {
result = subGroupId;
commandText = GetCommandText(logistics, description, dateTime, subGroupId);
}
} }
} }
return result; return new(result, commandText);
} }
#nullable disable #nullable disable

View File

@ -327,7 +327,7 @@ public class FileRead : Properties.IFileRead
{ {
if (DateTime.Now.Ticks > preWait) if (DateTime.Now.Ticks > preWait)
break; break;
Thread.Sleep(500); Thread.Sleep(100);
} }
if (!moreThanAnHour) if (!moreThanAnHour)
{ {
@ -373,7 +373,7 @@ public class FileRead : Properties.IFileRead
} }
throw new Exception(string.Concat("After {", _BreakAfterSeconds, "} seconds, right side of {", sourceDirectoryCloaking, "} didn't consume file(s) ", stringBuilder)); throw new Exception(string.Concat("After {", _BreakAfterSeconds, "} seconds, right side of {", sourceDirectoryCloaking, "} didn't consume file(s) ", stringBuilder));
} }
Thread.Sleep(500); Thread.Sleep(250);
} }
} }
} }

View File

@ -40,7 +40,7 @@ public class PCL : LoggingUnitTesting, IDisposable
public void TestDateTime() public void TestDateTime()
{ {
DateTime dateTime = DateTime.Now; DateTime dateTime = DateTime.Now;
Assert.IsTrue(dateTime.ToString("MM/dd/yyyy hh:mm:ss tt") == dateTime.ToString()); Assert.IsTrue(dateTime.ToString("M/d/yyyy h:mm:ss tt") == dateTime.ToString());
} }
[TestMethod] [TestMethod]