PropertyGroup Condition

BarcodeController
This commit is contained in:
Mike Phares 2023-08-01 14:12:05 -07:00
parent 71753964ac
commit c6782d1cb3
9 changed files with 138 additions and 56 deletions

View File

@ -17,6 +17,7 @@
"lsid",
"messa",
"messv",
"NETFRAMEWORK",
"NOPAUSE",
"PDFC",
"PDSF",

View File

@ -1,10 +1,7 @@
#if SelfHost
using System;
using System.Globalization;
using System.IO;
using System.Text.Json;
using System.Threading.Tasks;
#if NETFRAMEWORK && NET48
using Adaptation.FileHandlers.TIBCO.Transport;
using System.Web.Http;
using System.Web.Http.Results;
namespace Adaptation.FileHandlers.MoveAllFiles.ApiController;
@ -15,50 +12,20 @@ public class BarcodeController : System.Web.Http.ApiController
#nullable enable
#pragma warning disable CA1822
public string Get()
public OkNegotiatedContentResult<string> Get()
#pragma warning restore CA1822
{
string results = "record";
return results;
}
private static string? GetJson(System.Net.Http.HttpContent? httpContent)
{
string? result;
if (httpContent is null)
result = null;
else
{
Task<string> task = httpContent.ReadAsStringAsync();
task.Wait();
result = task.Result;
}
return result;
}
private static void Write(string barcodeHostFileShare, string cellInstanceConnectionName, Notification notification)
{
DateTime dateTime = DateTime.Now;
Calendar calendar = new CultureInfo("en-US").Calendar;
string weekOfYear = $"{dateTime:yyyy}_Week_{calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday):00}";
string directory = Path.Combine(barcodeHostFileShare, weekOfYear, dateTime.ToString("yyyy-MM-dd_HH"));
if (!Directory.Exists(directory))
_ = Directory.CreateDirectory(directory);
File.WriteAllText(Path.Combine(directory, $"{cellInstanceConnectionName}.csv"), notification.LastScanServiceResultValue);
string result = "record";
return Ok(result);
}
[Route("{id}")]
#pragma warning disable CA1822
public void Post(string id)
public JsonResult<PostReplay?> Post(string id)
#pragma warning restore CA1822
{
string? json = GetJson(Request.Content);
if (json is not null)
{
Notification? notification = JsonSerializer.Deserialize<Notification>(json);
if (notification is not null)
Write(FileRead.BarcodeHostFileShare, id, notification.Value);
}
PostReplay? postReplay = BarcodeHelper.Post(id, Request.Content);
return Json(postReplay);
}
}

View File

@ -0,0 +1,77 @@
using Adaptation.FileHandlers.TIBCO.Transport;
using System;
using System.Globalization;
using System.IO;
using System.Text.Json;
using System.Threading.Tasks;
namespace Adaptation.FileHandlers.MoveAllFiles.ApiController;
public class BarcodeHelper
{
#nullable enable
private static string? GetJson(System.Net.Http.HttpContent? httpContent)
{
string? result;
if (httpContent is null)
result = null;
else
{
Task<string> task = httpContent.ReadAsStringAsync();
task.Wait();
result = task.Result;
}
return result;
}
private static void Write(string barcodeHostFileShare, string cellInstanceConnectionName, Notification notification)
{
DateTime dateTime = DateTime.Now;
Calendar calendar = new CultureInfo("en-US").Calendar;
string weekOfYear = $"{dateTime:yyyy}_Week_{calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday):00}";
string directory = Path.Combine(barcodeHostFileShare, weekOfYear, dateTime.ToString("yyyy-MM-dd_HH"));
if (!Directory.Exists(directory))
_ = Directory.CreateDirectory(directory);
File.WriteAllText(Path.Combine(directory, $"{cellInstanceConnectionName}.csv"), notification.LastScanServiceResultValue);
}
private static Job GetJob(string lsl2SQLConnectionString, string metrologyFileShare, string barcodeHostFileShare, string id, Notification notification)
{
Job result;
string lastScan = notification.LastScanServiceResultValue.Length < 3 || notification.LastScanServiceResultValue[1] is not 't' and not 'T' || notification.LastScanServiceResultValue[0] != '1' ? notification.LastScanServiceResultValue : notification.LastScanServiceResultValue.Substring(2);
string json = string.Concat("{\"Area\": \"Si\", \"EquipmentType\": \"MET08THFTIRQS408M\", \"MesEntity\": \"", id, "\", \"Sequence\": \"", notification.KeyPressEvent.DateTime.Ticks, "\", \"MID\": \"-", lastScan, "-\", \"Recipe\": \"Recipe\"}");
result = new(lsl2SQLConnectionString, metrologyFileShare, barcodeHostFileShare, json);
return result;
}
internal static PostReplay? Post(string id, System.Net.Http.HttpContent? httpContent)
{
PostReplay? result;
string? json = GetJson(httpContent);
if (json is null)
result = null;
else
{
Notification? notification = JsonSerializer.Deserialize<Notification>(json);
if (notification is null)
result = null;
else
{
const string hyphen = "-";
Write(TIBCO.FileRead.BarcodeHostFileShare, id, notification.Value);
Job job = GetJob(TIBCO.FileRead.LSL2SQLConnectionString, TIBCO.FileRead.MetrologyFileShare, TIBCO.FileRead.BarcodeHostFileShare, id, notification.Value);
string mid = job.SpecName == hyphen || job.ProcessSpecName == hyphen ? $"{job.ProcessType}" : $"{job.ProcessType}.{job.SpecName}.{job.ProcessSpecName}";
try
{
// https://oi-prod-ec-api.mes.infineon.com/api/oiWizard/materials/rds/
}
catch (Exception) { }
result = new(job, mid, job.RecipeName);
}
}
return result;
}
}

View File

@ -2,6 +2,7 @@ namespace Adaptation.FileHandlers.MoveAllFiles.ApiController;
public readonly struct Notification
{
public KeyPressEvent KeyPressEvent { get; }
public string LastScanServiceResultValue { get; }

View File

@ -0,0 +1,20 @@
using Adaptation.FileHandlers.TIBCO.Transport;
namespace Adaptation.FileHandlers.MoveAllFiles.ApiController;
public class PostReplay
{
public Job Job { get; }
public string MId { get; }
public string Recipe { get; }
[System.Text.Json.Serialization.JsonConstructor]
public PostReplay(Job job, string mid, string recipe)
{
Job = job;
MId = mid;
Recipe = recipe;
}
}

View File

@ -7,7 +7,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
#if SelfHost
#if NETFRAMEWORK && NET48
using System.Web.Http;
using System.Web.Http.SelfHost;
#endif
@ -20,12 +20,10 @@ public class FileRead : Shared.FileRead, IFileRead
#nullable enable
private long? _TickOffset;
#if SelfHost
#if NETFRAMEWORK && NET48
private readonly HttpSelfHostServer? _HttpSelfHostServer;
#endif
public const string BarcodeHostFileShare = @"\\messv02ecc1.ec.local\EC_Metrology_Si\BarcodeHost\API"; // GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "BarcodeHost.FileShare");
public FileRead(ISMTP smtp, Dictionary<string, string> fileParameter, string cellInstanceName, int? connectionCount, 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(), false, smtp, fileParameter, cellInstanceName, connectionCount, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, staticRuns, useCyclicalForDescription, isEAFHosted: connectionCount is null)
{
@ -38,7 +36,7 @@ public class FileRead : Shared.FileRead, IFileRead
throw new Exception(cellInstanceConnectionName);
if (_IsDuplicator)
throw new Exception(cellInstanceConnectionName);
#if SelfHost
#if NETFRAMEWORK && NET48
if (!_IsEAFHosted)
_HttpSelfHostServer = null;
else
@ -127,7 +125,6 @@ public class FileRead : Shared.FileRead, IFileRead
_TickOffset ??= new FileInfo(reportFullPath).LastWriteTime.Ticks - dateTime.Ticks;
_Logistics = new Logistics(this, _TickOffset.Value, reportFullPath, useSplitForMID: true);
SetFileParameterLotIDToLogisticsMID();
return results;
}

View File

@ -15,8 +15,11 @@ public class FileRead : Shared.FileRead, IFileRead
#nullable enable
public const string BarcodeHostFileShare = @"\\messv02ecc1.ec.local\EC_Metrology_Si\BarcodeHost\API";
public const string MetrologyFileShare = @"\\messv02ecc1.ec.local\EC_Metrology_Si\WorkMaterialOut\API";
public const string LSL2SQLConnectionString = @"Data Source=10.95.128.28\\PROD1,53959;Initial Catalog=LSL2SQL;Persist Security Info=True;User ID=srpadmin;Password=0okm9ijn;";
private long? _TickOffset;
private readonly string _BarcodeHostFileShare;
public FileRead(ISMTP smtp, Dictionary<string, string> fileParameter, string cellInstanceName, int? connectionCount, 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(), false, smtp, fileParameter, cellInstanceName, connectionCount, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, staticRuns, useCyclicalForDescription, isEAFHosted: connectionCount is null)
@ -31,21 +34,27 @@ public class FileRead : Shared.FileRead, IFileRead
if (!_IsDuplicator)
throw new Exception(cellInstanceConnectionName);
string metrologyFileShare = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "Metrology.FileShare");
_BarcodeHostFileShare = @"\\messv02ecc1.ec.local\EC_Metrology_Si\BarcodeHost\API"; // GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "BarcodeHost.FileShare");
if (metrologyFileShare != MetrologyFileShare)
throw new NotSupportedException($"Update configuration for [{nameof(MetrologyFileShare)}]");
string barcodeHostFileShare = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "BarcodeHost.FileShare");
if (barcodeHostFileShare != BarcodeHostFileShare)
throw new NotSupportedException($"Update configuration for [{nameof(BarcodeHostFileShare)}]");
string lsl2SQLConnectionString = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, "ConnectionString.LSL2SQL");
if (lsl2SQLConnectionString != LSL2SQLConnectionString)
throw new NotSupportedException($"Update configuration for [{nameof(LSL2SQLConnectionString)}]");
ModelObjectParameterDefinition[] tibcoParameters = GetProperties(cellInstanceConnectionName, modelObjectParameters, "TIBCO.");
string tibcoParameterChannel = GetPropertyValue(cellInstanceConnectionName, tibcoParameters, "TIBCO.IFX_CHANNEL");
string tibcoParameterSubject = GetPropertyValue(cellInstanceConnectionName, tibcoParameters, "TIBCO.IFX_SUBJECT");
string tibcoParameterSubjectPrefix = GetPropertyValue(cellInstanceConnectionName, tibcoParameters, "TIBCO.IFX_SUBJECT_PREFIX");
string tibcoParameterConfigurationLocation = GetPropertyValue(cellInstanceConnectionName, tibcoParameters, "TIBCO.IFX_CONFIGURATION_LOCATION");
string tibcoParameterConfigurationLocationCopy = GetPropertyValue(cellInstanceConnectionName, tibcoParameters, "TIBCO.IFX_CONFIGURATION_LOCATION_LOCAL_COPY");
if (!Directory.Exists(metrologyFileShare))
throw new Exception($"Unable to access file-share <{metrologyFileShare}>");
if (!Directory.Exists(_BarcodeHostFileShare))
throw new Exception($"Unable to access file-share <{_BarcodeHostFileShare}>");
if (!Directory.Exists(MetrologyFileShare))
throw new Exception($"Unable to access file-share <{MetrologyFileShare}>");
if (!Directory.Exists(BarcodeHostFileShare))
throw new Exception($"Unable to access file-share <{BarcodeHostFileShare}>");
if (_IsEAFHosted)
{
Transport.Main.Initialize(smtp, cellInstanceName, fileConnectorConfiguration, lsl2SQLConnectionString, metrologyFileShare, _BarcodeHostFileShare);
Transport.Main.Initialize(smtp, cellInstanceName, fileConnectorConfiguration, LSL2SQLConnectionString, MetrologyFileShare, BarcodeHostFileShare);
if (!string.IsNullOrEmpty(fileConnectorConfiguration.SourceFileLocation))
_ = Transport.Main.Setup(useSleep: true, setIfxTransport: true, tibcoParameterChannel, tibcoParameterSubjectPrefix, tibcoParameterConfigurationLocation, tibcoParameterConfigurationLocationCopy, tibcoParameterSubject);
else

View File

@ -43,7 +43,6 @@
<PackageReference Include="IKVM.OpenJDK.XML.API" Version="7.2.4630.5"><NoWarn>NU1701</NoWarn></PackageReference>
<PackageReference Include="IKVM.Runtime" Version="7.2.4630.5"><NoWarn>NU1701</NoWarn></PackageReference>
<PackageReference Include="Instances" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNet.WebApi.SelfHost" Version="5.2.9" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />

View File

@ -48,6 +48,9 @@
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFrameworkVersion)' == 'v4.8' ">
<DefineConstants>NETFRAMEWORK;NET20;NET35;NET40;NET45;NET451;NET452;NET46;NET461;NET462;NET47;NET471;NET472;NET48;$(DefineConstants)</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
@ -103,10 +106,12 @@
<Compile Include="Adaptation\FileHandlers\Dummy\FileRead.cs" />
<Compile Include="Adaptation\FileHandlers\IQSSi\FileRead.cs" />
<Compile Include="Adaptation\FileHandlers\MoveAllFiles\ApiController\BarcodeController.cs" />
<Compile Include="Adaptation\FileHandlers\MoveAllFiles\ApiController\BarcodeHelper.cs" />
<Compile Include="Adaptation\FileHandlers\MoveAllFiles\ApiController\EventCode.cs" />
<Compile Include="Adaptation\FileHandlers\MoveAllFiles\ApiController\KeyPressEvent.cs" />
<Compile Include="Adaptation\FileHandlers\MoveAllFiles\ApiController\KeyState.cs" />
<Compile Include="Adaptation\FileHandlers\MoveAllFiles\ApiController\Notification.cs" />
<Compile Include="Adaptation\FileHandlers\MoveAllFiles\ApiController\PostReplay.cs" />
<Compile Include="Adaptation\FileHandlers\MoveAllFiles\FileRead.cs" />
<Compile Include="Adaptation\FileHandlers\MoveMatchingFiles\FileRead.cs" />
<Compile Include="Adaptation\FileHandlers\OpenInsightMetrologyViewerAttachments\FileRead.cs" />
@ -179,6 +184,12 @@
<PackageReference Include="Infineon.EAF.Runtime">
<Version>2.49.2</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNet.WebApi.SelfHost">
<Version>5.2.7</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNet.WebApi.Core">
<Version>5.2.7</Version>
</PackageReference>
<PackageReference Include="System.Text.Json">
<Version>6.0.3</Version>
</PackageReference>