v2.47.1 - ISQ query in OI file name

This commit is contained in:
Mike Phares 2022-12-06 08:43:58 -07:00
parent 6e09172646
commit f6c6d9855e
3 changed files with 44 additions and 20 deletions

View File

@ -147,11 +147,15 @@ public class FileRead : Shared.FileRead, IFileRead
{
string lines = GetLines(descriptions);
if (!string.IsNullOrEmpty(lines))
collection.Add(new(new ScopeInfo(tests[0], _OpenInsightFilePattern), lines));
_ = FromIQS.GetCommandText(_IqsConnectionString, _Logistics, descriptions[0]);
// string commandText = FromIQS.GetCommandText(_IqsConnectionString, _Logistics, descriptions[0]);
// if (!string.IsNullOrEmpty(commandText))
// collection.Add(new(new ScopeInfo(tests[0], _OpenInsightFilePattern), commandText));
{
long breakAfter = dateTime.AddSeconds(_BreakAfterSeconds).Ticks;
long preWait = _FileConnectorConfiguration?.FileHandleWaitTime is null ? dateTime.AddMilliseconds(1234).Ticks : dateTime.AddMilliseconds(_FileConnectorConfiguration.FileHandleWaitTime.Value).Ticks;
(long? subGroupId, string _) = FromIQS.GetCommandText(_BreakAfterSeconds, _IqsConnectionString, _Logistics, descriptions[0], breakAfter, preWait);
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)
WaitForFileConsumption(dateTime, descriptions, isDummyRun, successDirectory, duplicateDirectory, collection, duplicateFile);

View File

@ -6,6 +6,7 @@ using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading;
namespace Adaptation.FileHandlers.OpenInsight;
@ -14,7 +15,7 @@ public class FromIQS
#nullable enable
private static string GetCommandText(Logistics logistics, Stratus.Description description, string dateTime, string? sid)
private static string GetCommandText(Logistics logistics, Stratus.Description description, string dateTime, long? subGroupId)
{
StringBuilder result = new();
_ = result
@ -41,8 +42,8 @@ public class FromIQS
.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(" ");
if (subGroupId is not null)
_ = result.Append(" and se.f_sgrp = ").Append(subGroupId).AppendLine(" ");
_ = result
.Append(" and rd.f_name = '").Append(description.Reactor).AppendLine("' ")
.Append(" and pd.f_name = '").Append(description.PSN).AppendLine("' ")
@ -66,10 +67,11 @@ public class FromIQS
return stringBuilder;
}
internal static string GetCommandText(string connectionString, Logistics logistics, Stratus.Description description)
internal static (long?, string) GetCommandText(long breakAfterSeconds, string connectionString, Logistics logistics, Stratus.Description description, long breakAfter, long preWait)
{
string result;
string dateTime;
string commandText;
long? result = null;
string dateFormat = Stratus.Description.GetDateFormat();
if (DateTime.TryParseExact(description.Date, dateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateTimeParsed))
dateTime = dateTimeParsed.ToString("yyyy-MM-dd HH:mm:ss");
@ -77,25 +79,43 @@ public class FromIQS
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);
commandText = GetCommandText(logistics, description, dateTime, subGroupId: null);
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)
result = commandText;
commandText = stringBuilder.ToString();
else
{
JsonElement[]? jsonElements = JsonSerializer.Deserialize<JsonElement[]>(stringBuilder.ToString());
if (jsonElements is null || !jsonElements.Any() || jsonElements[0].ValueKind != JsonValueKind.Object)
result = commandText;
commandText = stringBuilder.ToString();
else
{
JsonProperty[] jsonProperties = jsonElements[0].EnumerateObject().ToArray();
if (!jsonProperties.Any() || jsonProperties[0].Name != "se_sgrp")
result = commandText;
if (!jsonProperties.Any() || jsonProperties[0].Name != "se_sgrp" || !long.TryParse(jsonProperties[0].Value.ToString(), out long subGroupId))
commandText = stringBuilder.ToString();
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

View File

@ -327,7 +327,7 @@ public class FileRead : Properties.IFileRead
{
if (DateTime.Now.Ticks > preWait)
break;
Thread.Sleep(500);
Thread.Sleep(100);
}
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));
}
Thread.Sleep(500);
Thread.Sleep(250);
}
}
}