MET08DDUPSFS6420 - v2.43.4 - Builtin MonA, Run with layer and

1T
This commit is contained in:
Mike Phares 2022-09-13 09:02:32 -07:00
parent f8ca86e5a0
commit ba0a3d65d1
11 changed files with 516 additions and 9 deletions

View File

@ -4,7 +4,7 @@
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": 10724
"processId": 20888
}
]
}

View File

@ -39,7 +39,8 @@
"titleBar.activeBackground": "#5c277c",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveBackground": "#5c277c99",
"titleBar.inactiveForeground": "#e7e7e799"
"titleBar.inactiveForeground": "#e7e7e799",
"commandCenter.border": "#e7e7e799"
},
"peacock.color": "#5c277c",
"cSpell.enabled": false

View File

@ -271,8 +271,11 @@ public class ProcessData : IProcessData
}
else
{
employee = string.Empty;
// Remove illegal characters \/:*?"<>| found in the Lot.
lot = Regex.Replace(text, @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]", "_").Split('\r')[0].Split('\n')[0];
if (lot.StartsWith("1T") || lot.StartsWith("1t"))
lot = lot.Substring(2);
string[] segments = lot.Split('-');
if (segments.Length == 0)
reactor = defaultReactor;
@ -290,11 +293,7 @@ public class ProcessData : IProcessData
if (segments.Length <= 2)
psn = defaultPSN;
else
psn = segments[2];
if (segments.Length <= 3)
employee = string.Empty;
else
employee = segments[3];
psn = segments[2].Split('.')[0];
}
result = new(employee, lot, psn, rds, reactor);
return result;

View File

@ -0,0 +1,20 @@
using System;
using System.Net;
namespace Infineon.Monitoring.MonA;
#nullable disable
#pragma warning disable SYSLIB0014
public class ExtWebClient : WebClient
{
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest webRequest = base.GetWebRequest(address);
if (webRequest != null)
webRequest.PreAuthenticate = PreAuthenticate;
return webRequest;
}
public bool PreAuthenticate { get; set; }
}

View File

@ -0,0 +1,167 @@
using System;
namespace Infineon.Monitoring.MonA;
public interface IMonIn
{
string SendStatus(string site, string resource, string stateName, State state);
string SendStatus(
string site,
DateTime timeStamp,
string resource,
string stateName,
State state);
string SendStatus(
string site,
string resource,
string stateName,
State state,
string description);
string SendStatus(
string site,
DateTime timeStamp,
string resource,
string stateName,
State state,
string description);
string SendStatus(
string site,
string resource,
string subresource,
string stateName,
State state);
string SendStatus(
string site,
DateTime timeStamp,
string resource,
string subresource,
string stateName,
State state);
string SendStatus(
string site,
string resource,
string subresource,
string stateName,
State state,
string description);
string SendStatus(
string site,
DateTime? timeStamp,
string resource,
string subresource,
string stateName,
State state,
string description);
string SendPerformanceMessage(
string site,
string resource,
string performanceName,
double value);
string SendPerformanceMessage(
string site,
DateTime? timeStamp,
string resource,
string performanceName,
double value);
string SendPerformanceMessage(
string site,
string resource,
string performanceName,
double value,
string description);
string SendPerformanceMessage(
string site,
DateTime? timeStamp,
string resource,
string performanceName,
double value,
string description);
string SendPerformanceMessage(
string site,
DateTime? timeStamp,
string resource,
string performanceName,
double value,
int? interval);
string SendPerformanceMessage(
string site,
string resource,
DateTime? timeStamp,
string performanceName,
double value,
string unit);
string SendPerformanceMessage(
string site,
DateTime? timeStamp,
string resource,
string performanceName,
double value,
string unit,
int? interval);
string SendPerformanceMessage(
string site,
string resource,
string subresource,
string performanceName,
double value);
string SendPerformanceMessage(
string site,
DateTime? timeStamp,
string resource,
string subresource,
string performanceName,
double value);
string SendPerformanceMessage(
string site,
string resource,
string subresource,
string performanceName,
double value,
string description);
string SendPerformanceMessage(
string site,
DateTime? timeStamp,
string resource,
string subresource,
string performanceName,
double value,
int? interval);
string SendPerformanceMessage(
string site,
DateTime? timeStamp,
string resource,
string subresource,
string performanceName,
double value,
string unit);
string SendPerformanceMessage(
string site,
DateTime? timeStamp,
string resource,
string subresource,
string performanceName,
double value,
string description,
string unit,
int? interval);
}

View File

@ -0,0 +1,292 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net;
using System.Text;
namespace Infineon.Monitoring.MonA;
public class MonIn : IMonIn, IDisposable
{
private static readonly DateTime _Utc1970DateTime = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
public const string MonInUrl = "http://moninhttp.{0}.infineon.com/input/text";
private static readonly Dictionary<string, MonIn> _Instances = new();
private readonly ExtWebClient _WebClient;
private readonly string _MonInUrl;
private static CultureInfo _CultureInfo;
public static MonIn GetInstance(string url = "http://moninhttp.{0}.infineon.com/input/text")
{
MonIn instance;
if (_Instances.ContainsKey(url))
{
instance = _Instances[url];
}
else
{
lock (_Instances)
{
if (!_Instances.ContainsKey(url))
{
instance = new MonIn(url);
_Instances.Add(url, instance);
}
else
instance = _Instances[url];
}
}
return instance;
}
private MonIn(string url)
{
_WebClient = new ExtWebClient();
_WebClient.Headers[HttpRequestHeader.ContentType] = "application/text";
_WebClient.Encoding = Encoding.UTF8;
_CultureInfo = new CultureInfo("en-US");
_MonInUrl = url;
}
public void SetBasicAuthentication(string username, string password)
{
_WebClient.PreAuthenticate = true;
_WebClient.Headers[HttpRequestHeader.Authorization] = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password));
}
public string SendStatus(string site, string resource, string stateName, State state) => SendStatus(site, new DateTime?(), resource, string.Empty, stateName, state, string.Empty);
public string SendStatus(
string site,
DateTime timeStamp,
string resource,
string stateName,
State state) => SendStatus(site, new DateTime?(timeStamp), resource, string.Empty, stateName, state, string.Empty);
public string SendStatus(
string site,
string resource,
string stateName,
State state,
string description) => SendStatus(site, new DateTime?(), resource, string.Empty, stateName, state, description);
public string SendStatus(
string site,
DateTime timeStamp,
string resource,
string stateName,
State state,
string description) => SendStatus(site, new DateTime?(timeStamp), resource, string.Empty, stateName, state, description);
public string SendStatus(
string site,
string resource,
string subresource,
string stateName,
State state) => SendStatus(site, new DateTime?(), resource, subresource, stateName, state, string.Empty);
public string SendStatus(
string site,
DateTime timeStamp,
string resource,
string subresource,
string stateName,
State state) => SendStatus(site, new DateTime?(timeStamp), resource, subresource, stateName, state, string.Empty);
public string SendStatus(
string site,
string resource,
string subresource,
string stateName,
State state,
string description) => SendStatus(site, new DateTime?(), resource, subresource, stateName, state, description);
public string SendStatus(
string site,
DateTime? timeStamp,
string resource,
string subresource,
string stateName,
State state,
string description)
{
string statusMessage = CreateStatusMessage(site, timeStamp, resource, subresource, stateName, state.ToString(), description);
lock (_WebClient)
return _WebClient.UploadString(string.Format(_MonInUrl, site), statusMessage);
}
public string SendPerformanceMessage(
string site,
string resource,
string performanceName,
double value) => SendPerformanceMessage(site, new DateTime?(), resource, string.Empty, performanceName, value, string.Empty, string.Empty, new int?());
public string SendPerformanceMessage(
string site,
DateTime? timeStamp,
string resource,
string performanceName,
double value) => SendPerformanceMessage(site, timeStamp, resource, string.Empty, performanceName, value, string.Empty, string.Empty, new int?());
public string SendPerformanceMessage(
string site,
string resource,
string performanceName,
double value,
string description) => SendPerformanceMessage(site, new DateTime?(), resource, string.Empty, performanceName, value, description, string.Empty, new int?());
public string SendPerformanceMessage(
string site,
DateTime? timeStamp,
string resource,
string performanceName,
double value,
string description) => SendPerformanceMessage(site, timeStamp, resource, string.Empty, performanceName, value, description, string.Empty, new int?());
public string SendPerformanceMessage(
string site,
DateTime? timeStamp,
string resource,
string performanceName,
double value,
int? interval) => SendPerformanceMessage(site, timeStamp, resource, string.Empty, performanceName, value, string.Empty, string.Empty, interval);
public string SendPerformanceMessage(
string site,
string resource,
DateTime? timeStamp,
string performanceName,
double value,
string unit) => SendPerformanceMessage(site, timeStamp, resource, string.Empty, performanceName, value, string.Empty, unit, new int?());
public string SendPerformanceMessage(
string site,
DateTime? timeStamp,
string resource,
string performanceName,
double value,
string unit,
int? interval) => SendPerformanceMessage(site, timeStamp, resource, string.Empty, performanceName, value, string.Empty, unit, interval);
public string SendPerformanceMessage(
string site,
string resource,
string subresource,
string performanceName,
double value) => SendPerformanceMessage(site, new DateTime?(), resource, subresource, performanceName, value, string.Empty, string.Empty, new int?());
public string SendPerformanceMessage(
string site,
DateTime? timeStamp,
string resource,
string subresource,
string performanceName,
double value) => SendPerformanceMessage(site, timeStamp, resource, subresource, performanceName, value, string.Empty, string.Empty, new int?());
public string SendPerformanceMessage(
string site,
string resource,
string subresource,
string performanceName,
double value,
string description) => SendPerformanceMessage(site, new DateTime?(), resource, subresource, performanceName, value, description, string.Empty, new int?());
public string SendPerformanceMessage(
string site,
DateTime? timeStamp,
string resource,
string subresource,
string performanceName,
double value,
int? interval) => SendPerformanceMessage(site, timeStamp, resource, subresource, performanceName, value, string.Empty, string.Empty, interval);
public string SendPerformanceMessage(
string site,
DateTime? timeStamp,
string resource,
string subresource,
string performanceName,
double value,
string unit) => SendPerformanceMessage(site, timeStamp, resource, subresource, performanceName, value, string.Empty, unit, new int?());
public string SendPerformanceMessage(
string site,
DateTime? timeStamp,
string resource,
string subresource,
string performanceName,
double value,
string description,
string unit,
int? interval)
{
string performanceMessage = CreatePerformanceMessage(site, timeStamp, resource, subresource, performanceName, value, description, unit, interval);
lock (_WebClient)
return _WebClient.UploadString(string.Format(_MonInUrl, site), performanceMessage);
}
private static string CreateStatusMessage(
string site,
DateTime? timeStamp,
string resource,
string subresource,
string stateName,
string state,
string description)
{
StringBuilder stringBuilder = new();
if (string.IsNullOrEmpty(subresource))
_ = stringBuilder.AppendFormat(_CultureInfo, "> {0} {1} \"{2}\" \"{3}\" {4} \n{5}", site.Trim(), timeStamp.HasValue ? GetDateTimeNowAsPosix(timeStamp.Value) : (object)"now", resource.Trim(), stateName.Trim(), state.Trim(), description.Trim());
else
_ = stringBuilder.AppendFormat(_CultureInfo, "> {0} {1} \"{2}\" \"{3}\" \"{4}\" {5} \n{6}", site.Trim(), timeStamp.HasValue ? GetDateTimeNowAsPosix(timeStamp.Value) : (object)"now", resource.Trim(), subresource.Trim(), stateName.Trim(), state.Trim(), description.Trim());
return stringBuilder.ToString();
}
private static string CreatePerformanceMessage(
string site,
DateTime? timeStamp,
string resource,
string subresource,
string performanceName,
double value,
string description,
string unit,
int? interval)
{
StringBuilder stringBuilder = new();
if (string.IsNullOrEmpty(subresource))
{
if (unit.Equals(string.Empty) && !interval.HasValue)
_ = stringBuilder.AppendFormat(_CultureInfo, "> {0} {1} \"{2}\" \"{3}\" {4} \n{5}", site.Trim(), timeStamp.HasValue ? GetDateTimeNowAsPosix(timeStamp.Value) : (object)"now", resource.Trim(), performanceName.Trim(), value, description.Trim());
else
_ = stringBuilder.AppendFormat(_CultureInfo, "> {0} {1} \"{2}\" \"{3}\" {4} {5} {{interval={6}, unit={7}}}\n", site.Trim(), timeStamp.HasValue ? GetDateTimeNowAsPosix(timeStamp.Value) : (object)"now", resource.Trim(), performanceName.Trim(), value, description.Trim(), interval.HasValue ? interval.Value.ToString() : (object)string.Empty, unit.Trim());
}
else if (unit.Equals(string.Empty) && !interval.HasValue)
_ = stringBuilder.AppendFormat(_CultureInfo, "> {0} {1} \"{2}\" \"{3}\" \"{4}\" {5} \n{6}", site.Trim(), timeStamp.HasValue ? GetDateTimeNowAsPosix(timeStamp.Value) : (object)"now", resource.Trim(), subresource.Trim(), performanceName.Trim(), value, description.Trim());
else
_ = stringBuilder.AppendFormat(_CultureInfo, "> {0} {1} \"{2}\" \"{3}\" \"{4}\" {5} {6} {{interval={7}, unit={8}}}\n", site.Trim(), timeStamp.HasValue ? GetDateTimeNowAsPosix(timeStamp.Value) : (object)"now", resource.Trim(), subresource.Trim(), performanceName.Trim(), value, description.Trim(), interval.HasValue ? interval.Value.ToString() : (object)string.Empty, unit.Trim());
return stringBuilder.ToString();
}
private static string GetDateTimeNowAsPosix(DateTime timeStamp)
{
if (timeStamp > DateTime.Now)
timeStamp = DateTime.Now;
return ((int)timeStamp.ToUniversalTime().Subtract(_Utc1970DateTime).TotalSeconds).ToString(CultureInfo.InvariantCulture);
}
public void Dispose()
{
KeyValuePair<string, MonIn> keyValuePair = new();
foreach (KeyValuePair<string, MonIn> instance in _Instances)
{
if (instance.Value == this)
{
keyValuePair = instance;
break;
}
}
_ = _Instances.Remove(keyValuePair.Key);
_WebClient?.Dispose();
}
}

View File

@ -0,0 +1,11 @@
namespace Infineon.Monitoring.MonA;
public enum State
{
Up,
Ok,
Warning,
Critical,
Down,
Unknown,
}

View File

@ -15,6 +15,7 @@
</PropertyGroup>
<PropertyGroup>
<VSTestLogger>trx</VSTestLogger>
<VSTestCollect>XPlat Code Coverage</VSTestCollect>
<VSTestResultsDirectory>../../../../MET08DDUPSFS6420/05_TestResults/TestResults</VSTestResultsDirectory>
</PropertyGroup>
<PropertyGroup>
@ -62,7 +63,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FFMpegCore" Version="4.8.0" />
<PackageReference Include="Infineon.Monitoring.MonA" Version="3.0.0" />
<PackageReference Include="Infineon.Yoda" Version="5.4.1" />
<PackageReference Include="Instances" Version="2.0.0" />
<PackageReference Include="RoboSharp" Version="1.2.7" />

View File

@ -1250,12 +1250,13 @@ public class AdaptationTesting : ISMTP
if (!fileRead.IsDuplicator)
{
Assert.IsFalse(string.IsNullOrEmpty(extractResult?.Item1));
Assert.IsTrue(extractResult.Item3.Length > 0, "extractResult Array Length check!");
Assert.IsNotNull(extractResult.Item3);
Assert.IsNotNull(extractResult.Item4);
if (!validatePDSF)
_ = GetLogisticsColumnsAndBody(fileRead, logistics, extractResult, new(string.Empty, Array.Empty<string>(), Array.Empty<string>()));
else
{
Assert.IsTrue(extractResult.Item3.Length > 0, "extractResult Array Length check!");
Tuple<string, string[], string[]> pdsf = GetLogisticsColumnsAndBody(variables[2], variables[4]);
Tuple<string, string[], string[]> pdsfNew = GetLogisticsColumnsAndBody(fileRead, logistics, extractResult, pdsf);
CompareSave(variables[5], pdsf, pdsfNew);

View File

@ -56,11 +56,21 @@ public class PCL : LoggingUnitTesting, IDisposable
Assert.IsTrue(descriptor.Reactor is "00");
Assert.IsTrue(descriptor.RDS is "123456");
Assert.IsTrue(descriptor.PSN is "0000");
descriptor = FileHandlers.pcl.ProcessData.GetDescriptor("1T123456");
Assert.IsTrue(descriptor.Reactor is "00");
Assert.IsTrue(descriptor.RDS is "123456");
Assert.IsTrue(descriptor.PSN is "0000");
descriptor = FileHandlers.pcl.ProcessData.GetDescriptor("MP");
Assert.IsTrue(descriptor.Reactor is "00");
Assert.IsTrue(descriptor.RDS is "000000");
Assert.IsTrue(descriptor.PSN is "0000");
Assert.IsTrue(descriptor.Employee is "MP");
descriptor = FileHandlers.pcl.ProcessData.GetDescriptor("12-123456-1234.2-1");
Assert.IsTrue(descriptor.Reactor is "12");
Assert.IsTrue(descriptor.RDS is "123456");
Assert.IsTrue(descriptor.PSN is "1234");
// Assert.IsTrue(descriptor.Layer is "2");
// Assert.IsTrue(descriptor.Zone is "1");
LoggingUnitTesting.Logger.LogInformation(string.Concat(methodBase.Name, " - Exit"));
}

View File

@ -124,6 +124,12 @@
<Compile Include="Adaptation\Ifx\Eaf\EquipmentConnector\File\Component\FilePathGenerator.cs" />
<Compile Include="Adaptation\Ifx\Eaf\EquipmentConnector\File\Configuration\FileConnectorConfiguration.cs" />
<Compile Include="Adaptation\Ifx\Eaf\EquipmentConnector\File\SelfDescription\FileConnectorParameterTypeDefinitionProvider.cs" />
<Compile Include="Adaptation\Infineon\Monitoring\MonA\ExtWebClient.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Adaptation\Infineon\Monitoring\MonA\IMonIn.cs" />
<Compile Include="Adaptation\Infineon\Monitoring\MonA\MonIn.cs" />
<Compile Include="Adaptation\Infineon\Monitoring\MonA\State.cs" />
<Compile Include="Adaptation\PeerGroup\GCL\Annotations\NotNullAttribute.cs" />
<Compile Include="Adaptation\PeerGroup\GCL\SecsDriver\HsmsConnectionMode.cs" />
<Compile Include="Adaptation\PeerGroup\GCL\SecsDriver\HsmsSessionMode.cs" />