diff --git a/Common/CommonConsole/Program.cs b/Common/CommonConsole/Program.cs index 768adfd7..478b0e74 100644 --- a/Common/CommonConsole/Program.cs +++ b/Common/CommonConsole/Program.cs @@ -1,14 +1,10 @@ namespace CommonConsole { - using System.Text; - public class Program { public static void Main() { - var bytes = new byte[] { 0x43, 0x6F, 0x72, 0x64, 0x6F, 0x6E, 0x65, 0x6C, 0x20, 0x31, 0x2E, 0x35, 0x36, 0x00, 0x4E, 0xE4 }; - System.Console.WriteLine(Encoding.ASCII.GetString(bytes)); } } } \ No newline at end of file diff --git a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/CordonelDbContext.cs b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/CordonelDbContext.cs index 1784f7d2..d2001e81 100644 --- a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/CordonelDbContext.cs +++ b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/CordonelDbContext.cs @@ -1,5 +1,6 @@ namespace LaaProduction.Data.Cordonel { + using LaaPackages.Features.Cordonel; using LaaPackages.SqlClient; using LaaProduction.Data.Cordonel.Interfaces; using LaaProduction.Data.Cordonel.Models; @@ -30,5 +31,91 @@ public ISpecialRequirementsRepository SpecialRequirements { get; } public IStandardRequirementRepository StandardRequirements { get; } + + public CordonelAppsDictionary GetLatestAppsWithValues(Object pcbid, CordonelAppsDictionary appsDictionary) + { + var pcbidString = pcbid?.ToString(); + + this.SqlConnection + .CreateCommand($@" + SELECT x.Id + , CONVERT(VARBINARY(MAX), REPLACE(ISNULL(x.Address, '00'), '-', ''), 2) AS Address + , CONVERT(VARBINARY(MAX), REPLACE(REPLACE(ISNULL(x.Value, '00'), 'NULL', '00'), '-', ''), 2) AS Value + FROM (SELECT gmh.ID AS Id + , gmh.Address + , gmh.Value + , ROW_NUMBER() OVER (PARTITION BY gmh.Address ORDER BY gmh.date DESC) AS Row + FROM GenesisMeterRegisterHistory AS gmh + WHERE gmh.PcbId = @{nameof(pcbidString)}) AS x + WHERE x.Row = 1 + ORDER BY x.Address") + .SetParameter(nameof(pcbidString), pcbidString) + .ExecuteReader(reader => + { + var addressBytes = reader.GetValue(1); + + if (addressBytes?.Length == 2) + { + var appId = addressBytes[0]; + var registerId = addressBytes[1]; + var register = appsDictionary[appId][registerId]; + + register.HistoryId = reader.GetValue(0); + register.Value = reader.GetValue(2); + } + }); + + return appsDictionary; + } + + public GenesisFlowModel GetLatestGenesisFlowValues(Object pcbid) + => this.SqlConnection + .CreateCommand($@" + SELECT TOP 1 + ID + , PcbId + , CalFactor1 + , CalFactor2 + , CalFactor3 + , ZeroOffset1 + , ZeroOffset2 + , ZeroOffset3 + , FirstHitUpdatePeriod + , FirstHitShift + , FirstHitPercent1 + , FirstHitPercent2 + , FirstHitPercent3 + , ToFTempOffset1 + , ToFTempOffset2 + , ToFTempOffset3 + , MeterSize + , date + , successful + FROM CordonelMeterCalibrationResults + WHERE PcbId = @{nameof(pcbid)} + ORDER BY date DESC") + .SetParameter(nameof(pcbid), pcbid?.ToString()) + .FirstOrDefault(reader => new GenesisFlowModel + { + Id = reader.GetValue(0), + PcbId = reader.GetValue(1), + CalFactor1 = reader.GetValue(2), + CalFactor2 = reader.GetValue(3), + CalFactor3 = reader.GetValue(4), + ZeroOffset1 = reader.GetValue(5), + ZeroOffset2 = reader.GetValue(6), + ZeroOffset3 = reader.GetValue(7), + FirstHitUpdatePeriod = reader.GetValue(8), + FirstHitShift = reader.GetValue(9), + FirstHitPercent1 = reader.GetValue(10), + FirstHitPercent2 = reader.GetValue(11), + FirstHitPercent3 = reader.GetValue(12), + ToFTempOffset1 = reader.GetValue(13), + ToFTempOffset2 = reader.GetValue(14), + ToFTempOffset3 = reader.GetValue(15), + MeterSize = reader.GetValue(16), + Date = reader.GetValue(17), + Successful = reader.GetValue(18), + }); } } diff --git a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/LaaProduction.Data.Cordonel.csproj b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/LaaProduction.Data.Cordonel.csproj index 5011ba29..92ad2059 100644 --- a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/LaaProduction.Data.Cordonel.csproj +++ b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/LaaProduction.Data.Cordonel.csproj @@ -72,6 +72,7 @@ + diff --git a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Models/GenesisFlowModel.cs b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Models/GenesisFlowModel.cs new file mode 100644 index 00000000..b4478774 --- /dev/null +++ b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Models/GenesisFlowModel.cs @@ -0,0 +1,147 @@ +namespace LaaProduction.Data.Cordonel.Models +{ + using LaaPackages.Features.Cordonel; + + using System; + using System.Collections.Generic; + using System.Linq.Expressions; + using System.Reflection; + + public class GenesisFlowModel + { + public Int32 Id { get; set; } + + public String PcbId { get; set; } + + public Int32 CalFactor1 { get; set; } + + public Int32 CalFactor2 { get; set; } + + public Int32 CalFactor3 { get; set; } + + public Int32 ZeroOffset1 { get; set; } + + public Int32 ZeroOffset2 { get; set; } + + public Int32 ZeroOffset3 { get; set; } + + public Int32 FirstHitUpdatePeriod { get; set; } + + public Int32 FirstHitShift { get; set; } + + public Int32 FirstHitPercent1 { get; set; } + + public Int32 FirstHitPercent2 { get; set; } + + public Int32 FirstHitPercent3 { get; set; } + + public Int32 ToFTempOffset1 { get; set; } + + public Int32 ToFTempOffset2 { get; set; } + + public Int32 ToFTempOffset3 { get; set; } + + public Int32 MeterSize { get; set; } + + public DateTime Date { get; set; } + + public Boolean Successful { get; set; } + + public IEnumerable> IsEquals(CordonelAppsDictionary appsDictionary) + { + if (!this.Successful) + { + yield return new KeyValuePair(this.PcbId, "Genesis flow is not successful."); + } + + var genesisFlow = appsDictionary[Apps.GENESISFLOW]; + var calFactor1 = genesisFlow[GENESISFLOW.CalFactor1].GetValue(); + var calFactor2 = genesisFlow[GENESISFLOW.CalFactor2].GetValue(); + var calFactor3 = genesisFlow[GENESISFLOW.CalFactor3].GetValue(); + var zeroOffset1 = genesisFlow[GENESISFLOW.ZeroOffset1].GetValue(); + var zeroOffset2 = genesisFlow[GENESISFLOW.ZeroOffset2].GetValue(); + var zeroOffset3 = genesisFlow[GENESISFLOW.ZeroOffset3].GetValue(); + var firstHitUpdatePeriod = genesisFlow[GENESISFLOW.FirstHitUpdatePeriod].GetValue(); + var firstHitShift = genesisFlow[GENESISFLOW.FirstHitShift].GetValue(); + var firstHitPercent1 = genesisFlow[GENESISFLOW.FirstHitPercent1].GetValue(); + var firstHitPercent2 = genesisFlow[GENESISFLOW.FirstHitPercent2].GetValue(); + var firstHitPercent3 = genesisFlow[GENESISFLOW.FirstHitPercent3].GetValue(); + var toFTempOffset1 = genesisFlow[GENESISFLOW.ToFTempOffset1].GetValue(); + var toFTempOffset2 = genesisFlow[GENESISFLOW.ToFTempOffset2].GetValue(); + var toFTempOffset3 = genesisFlow[GENESISFLOW.ToFTempOffset3].GetValue(); + + yield return this.ErrorIf(x => x.CalFactor1 != calFactor1); + yield return this.ErrorIf(x => x.CalFactor2 != calFactor2); + yield return this.ErrorIf(x => x.CalFactor3 != calFactor3); + yield return this.ErrorIf(x => x.ZeroOffset1 != zeroOffset1); + yield return this.ErrorIf(x => x.ZeroOffset2 != zeroOffset2); + yield return this.ErrorIf(x => x.ZeroOffset3 != zeroOffset3); + yield return this.ErrorIf(x => x.FirstHitUpdatePeriod != firstHitUpdatePeriod); + yield return this.ErrorIf(x => x.FirstHitShift != firstHitShift); + yield return this.ErrorIf(x => x.FirstHitPercent1 != firstHitPercent1); + yield return this.ErrorIf(x => x.FirstHitPercent2 != firstHitPercent2); + yield return this.ErrorIf(x => x.FirstHitPercent3 != firstHitPercent3); + yield return this.ErrorIf(x => x.ToFTempOffset1 != toFTempOffset1); + yield return this.ErrorIf(x => x.ToFTempOffset2 != toFTempOffset2); + yield return this.ErrorIf(x => x.ToFTempOffset3 != toFTempOffset3); + } + + public IEnumerable> IsZeroFlowEquals(CordonelAppsDictionary appsDictionary) + { + if (!this.Successful) + { + yield return new KeyValuePair(this.PcbId, "Genesis flow is not successful."); + } + + var genesisFlow = appsDictionary[Apps.GENESISFLOW]; + var zeroOffset1 = genesisFlow[GENESISFLOW.ZeroOffset1].GetValue(); + var zeroOffset2 = genesisFlow[GENESISFLOW.ZeroOffset2].GetValue(); + var zeroOffset3 = genesisFlow[GENESISFLOW.ZeroOffset3].GetValue(); + + yield return this.ErrorIf(x => x.ZeroOffset1 != zeroOffset1); + yield return this.ErrorIf(x => x.ZeroOffset2 != zeroOffset2); + yield return this.ErrorIf(x => x.ZeroOffset3 != zeroOffset3); + } + + public IEnumerable> IsCalibrationEquals(CordonelAppsDictionary appsDictionary) + { + if (!this.Successful) + { + yield return new KeyValuePair(this.PcbId, "Genesis flow is not successful."); + } + + var genesisFlow = appsDictionary[Apps.GENESISFLOW]; + var calFactor1 = genesisFlow[GENESISFLOW.CalFactor1].GetValue(); + var calFactor2 = genesisFlow[GENESISFLOW.CalFactor2].GetValue(); + var calFactor3 = genesisFlow[GENESISFLOW.CalFactor3].GetValue(); + + yield return this.ErrorIf(x => x.CalFactor1 != calFactor1); + yield return this.ErrorIf(x => x.CalFactor2 != calFactor2); + yield return this.ErrorIf(x => x.CalFactor3 != calFactor3); + } + + private KeyValuePair ErrorIf(Expression> expression) + { + var succeeded = expression.Compile().Invoke(this); + + if (!succeeded) + { + var binaryExpression = expression.Body as BinaryExpression; + var leftMember = binaryExpression?.Left as MemberExpression; + var leftPropertyInfo = leftMember?.Member as PropertyInfo; + var name = leftPropertyInfo.Name; + var valueL = leftPropertyInfo.GetValue(this); + var valueR = Expression + .Lambda(binaryExpression?.Right) + ?.Compile() + ?.DynamicInvoke(); + + return new KeyValuePair(this.PcbId, $"Calibration result compared to register value: {name} - {valueL} != {valueR}."); + } + else + { + return new KeyValuePair(); + } + } + } +} diff --git a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Repositories/EOLProgressRepository.cs b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Repositories/EOLProgressRepository.cs index fd8e01a5..40a81aaa 100644 --- a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Repositories/EOLProgressRepository.cs +++ b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Repositories/EOLProgressRepository.cs @@ -196,8 +196,8 @@ return deleted; } - - public IEnumerable> RunSentinel(EOLProgressModel model, CordonelAppsDictionary cordonelApps) + + public IEnumerable> RunSentinel(EOLProgressModel model, CordonelAppsDictionary appsDictionary) { if (model is null) { @@ -249,34 +249,7 @@ yield break; } - this.sqlConnection - .CreateCommand($@" - SELECT x.Id - , CONVERT(VARBINARY(MAX), REPLACE(ISNULL(x.Address, '00'), '-', ''), 2) AS Address - , CONVERT(VARBINARY(MAX), REPLACE(REPLACE(ISNULL(x.Value, '00'), 'NULL', '00'), '-', ''), 2) AS Value - FROM (SELECT gmh.ID AS Id - , gmh.Address - , gmh.Value - , ROW_NUMBER() OVER (PARTITION BY gmh.Address ORDER BY gmh.date DESC) AS Row - FROM GenesisMeterRegisterHistory AS gmh - WHERE gmh.PcbId = @{nameof(pcbidString)}) AS x - WHERE x.Row = 1 - ORDER BY x.Address") - .SetParameter(nameof(pcbidString), pcbidString) - .ExecuteReader(reader => - { - var addressBytes = reader.GetValue(1); - - if (addressBytes?.Length == 2) - { - var appId = addressBytes[0]; - var registerId = addressBytes[1]; - var register = cordonelApps[appId][registerId]; - - register.HistoryId = reader.GetValue(0); - register.Value = reader.GetValue(2); - } - }); + appsDictionary = this.dbContext.GetLatestAppsWithValues(pcbidString, appsDictionary); var meterSize = default(Byte); var hasRadio = default(Boolean); @@ -314,7 +287,7 @@ hasRadio = reader.GetValue(1); }); - var meterSizeRegister = cordonelApps[Apps.GENESISFLOW][GENESISFLOW.MeterSize]; + var meterSizeRegister = appsDictionary[Apps.GENESISFLOW][GENESISFLOW.MeterSize]; if (meterSizeRegister.IsEquals(meterSize)) { @@ -322,6 +295,21 @@ yield break; } + var genesisFlow = this.dbContext.GetLatestGenesisFlowValues(pcbidString); + var genesisFlowComparisonErrors = genesisFlow + .IsEquals(appsDictionary) + .Where(x => String.IsNullOrWhiteSpace(x.Key)); + + if (genesisFlowComparisonErrors?.Any() == true) + { + foreach (var error in genesisFlowComparisonErrors) + { + yield return error; + } + + yield break; + } + if (hasRadio) { var radioCheckId = model.RadioCheckId; @@ -398,7 +386,7 @@ if (UInt16.TryParse(lutCrcString, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var lutCRCValue)) { - var lutCRCRegister = cordonelApps[Apps.GENESISFLOW][GENESISFLOW.LookupFileCrc]; + var lutCRCRegister = appsDictionary[Apps.GENESISFLOW][GENESISFLOW.LookupFileCrc]; if (!lutCRCRegister.IsEquals(lutCRCValue)) { @@ -414,7 +402,7 @@ yield break; } - if (!this.CheckBatteryAndLifeTime(cordonelApps, requirements)) + if (!this.CheckBatteryAndLifeTime(appsDictionary, requirements)) { yield break; } diff --git a/LaaProductionWeb/LaaPackages b/LaaProductionWeb/LaaPackages index 2bcec981..0bd11ec9 160000 --- a/LaaProductionWeb/LaaPackages +++ b/LaaProductionWeb/LaaPackages @@ -1 +1 @@ -Subproject commit 2bcec981f7f692e716154e9211f14c3ee4fd70c3 +Subproject commit 0bd11ec9087e6fa3a47cb0d3e65af2846c184b1b diff --git a/LaaProductionWeb/LaaProduction.Console/LaaProduction.Console.csproj b/LaaProductionWeb/LaaProduction.Console/LaaProduction.Console.csproj index 91a9df1e..f44e7731 100644 --- a/LaaProductionWeb/LaaProduction.Console/LaaProduction.Console.csproj +++ b/LaaProductionWeb/LaaProduction.Console/LaaProduction.Console.csproj @@ -44,6 +44,7 @@ + ..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll diff --git a/LaaProductionWeb/LaaProduction.Console/Program.cs b/LaaProductionWeb/LaaProduction.Console/Program.cs index 306278da..cc45b91a 100644 --- a/LaaProductionWeb/LaaProduction.Console/Program.cs +++ b/LaaProductionWeb/LaaProduction.Console/Program.cs @@ -1,12 +1,29 @@ namespace LaaProduction.Console { using System; + using System.Net; + using System.Net.Http; public class Program { + const string URL_PATTERN = "https://nodes.sms-esaap.com/keygenproxy/api/v2/keys/devices?orderNumber={0}&radioaddress={1}"; + const string X_NODE_TOKEN_HEADER = "X-Node-Token"; + const string X_NODE_TOKEN = "d5b8c0b2-81f6-4421-80d0-44eb2093e616"; + public static void Main(String[] args) { - Console.WriteLine(typeof(Program).Namespace); + using (var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, String.Format(URL_PATTERN, 3233972, 10309029807))) + { + httpRequestMessage.Headers.Add(X_NODE_TOKEN_HEADER, X_NODE_TOKEN); + + ServicePointManager.Expect100Continue = true; + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; + + using (var httpResponseMessage = new HttpClient().SendAsync(httpRequestMessage).Result) + { + var content = httpResponseMessage?.Content?.ReadAsStringAsync()?.Result?.Trim('"'); + } + } } } } \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/API/Cordonel/EOLProgressController.cs b/LaaProductionWeb/LaaProductionWeb/API/Cordonel/EOLProgressController.cs index 34efe9f8..a94c52b9 100644 --- a/LaaProductionWeb/LaaProductionWeb/API/Cordonel/EOLProgressController.cs +++ b/LaaProductionWeb/LaaProductionWeb/API/Cordonel/EOLProgressController.cs @@ -55,12 +55,7 @@ return this.BadRequest(); } - var apps = WebApiApplication - .GetService() - .Get(request => - { - request.SetPath("/MeterProcessState/api/ConfigurationJson"); - }).Value ?? new CordonelAppsDictionary(); + var apps = this.GetConfigurationJson(); var errors = this.dbcontext.EOLProgress.RunSentinel(eol, apps); if (errors?.Count() > 0) @@ -116,5 +111,61 @@ return this.Json(actualEOLProgressModel); } + + [HttpGet] + [Route("Check/ZeroFlow/{pcbId}")] + public IHttpActionResult CheckZeroFlow(Int32 pcbid) + { + var apps = this.GetConfigurationJson(); + apps = this.dbcontext.GetLatestAppsWithValues(pcbid, apps); + var genesisFlow = this.dbcontext.GetLatestGenesisFlowValues(pcbid); + + foreach (var kvp in genesisFlow.IsZeroFlowEquals(apps)) + { + if (!String.IsNullOrWhiteSpace(kvp.Key)) + { + this.ModelState.AddModelError(kvp.Key, kvp.Value); + } + } + + if (!this.ModelState.IsValid) + { + return this.BadRequest(); + } + + return this.Ok(); + } + + [HttpGet] + [Route("Check/Calibration/{pcbId}")] + public IHttpActionResult CheckCalibration(Int32 pcbid) + { + var apps = this.GetConfigurationJson(); + apps = this.dbcontext.GetLatestAppsWithValues(pcbid, apps); + var genesisFlow = this.dbcontext.GetLatestGenesisFlowValues(pcbid); + + foreach (var kvp in genesisFlow.IsCalibrationEquals(apps)) + { + if (!String.IsNullOrWhiteSpace(kvp.Key)) + { + this.ModelState.AddModelError(kvp.Key, kvp.Value); + } + } + + if (!this.ModelState.IsValid) + { + return this.BadRequest(); + } + + return this.Ok(); + } + + private CordonelAppsDictionary GetConfigurationJson() + => WebApiApplication + .GetService() + .Get(request => + { + request.SetPath("/MeterProcessState/api/ConfigurationJson"); + }).Value ?? new CordonelAppsDictionary(); } } \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/API/Search/SearchController.cs b/LaaProductionWeb/LaaProductionWeb/API/Search/SearchController.cs new file mode 100644 index 00000000..29c4d68b --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/API/Search/SearchController.cs @@ -0,0 +1,43 @@ +namespace LaaProductionWeb.API.Search +{ + using LaaPackages.SqlClient; + using LaaProductionWeb.App_Infrastructure; + + using System; + using System.Web.Http; + + [AuthorizeBearer] + [RoutePrefix("api/search")] + public class SearchController : ApiController + { + private readonly SqlConnection sqlConnection; + + public SearchController() => this.sqlConnection = WebApiApplication.GetService(); + + [HttpGet] + [Route("pono/eregister/address/{address}")] + public IHttpActionResult PonoByEregisterRadioAddress(Int64 address) + { + var pono = this.sqlConnection + .CreateCommand($@" + SELECT DISTINCT TOP 1 + aap.FertigungsauftragNr + FROM eRegister AS er + JOIN AuftragPositionSerienNr As aps + ON er.Seriennummer = aps.SerienNr + JOIN AlleAuftragPositionen AS aap + ON aps.AuftragNr = aap.AuftragNr + AND aps.PositionNr = aap.PositionNr + WHERE er.Adresse = @{nameof(address)}") + .SetParameter(nameof(address), address) + .FirstOrDefault(x => x.GetValue(0)); + + if (pono is null) + { + return this.BadRequest(); + } + + return this.Ok(pono); + } + } +} diff --git a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/RoutePrefixes.cs b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/RoutePrefixes.cs index dd42b5ee..dc6970ce 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/RoutePrefixes.cs +++ b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/RoutePrefixes.cs @@ -32,6 +32,8 @@ namespace LaaProductionWeb.App_Infrastructure public const String API_PRODUCTION_VFM = "api/production/vfm"; + public const String API_SEARCH_SEARCH = "api/search/search"; + public const String API_SEARCH_WILDCARD = "api/search/wildcard"; } } diff --git a/LaaProductionWeb/LaaProductionWeb/Controllers/SearchController.cs b/LaaProductionWeb/LaaProductionWeb/Controllers/SearchController.cs index 54b02f4e..268e5f25 100644 --- a/LaaProductionWeb/LaaProductionWeb/Controllers/SearchController.cs +++ b/LaaProductionWeb/LaaProductionWeb/Controllers/SearchController.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Linq; using System.Net; + using System.Net.Http; using System.Web.Mvc; using Hash256 = System.Security.Cryptography.SHA256; @@ -141,8 +142,6 @@ { fields = WebUtility.UrlEncode(String.Join(",", model.Fields.Where(x => x.Value).Select(x => x.Key))); } - - // http://10.49.40.25/MeterProcessState/api/FinalCheck/GetEncryptionKey?PcbID=45451 var filter = new { model.Token, fields }; var results = this.http @@ -166,7 +165,7 @@ } [HttpGet] - public String FS(String pcbid) + public String FS(String token, Boolean ispcb = false) { var userId = this.User?.Identity?.Name; var email = this.ordersService.GetUserEmail(userId); @@ -180,14 +179,55 @@ try { - var http = WebApiApplication.GetService(); - var _result = http.Get(request => request - .SetPath($"/MeterProcessState/api/FinalCheck/GetEncryptionKey") - .SetQueryParameter(nameof(pcbid), pcbid)); - - if (_result.Succeeded) + if (ispcb) { - result = _result.Value?.ToUpper(); + var _result = this.http + .Get(request => request + .SetPath($"/MeterProcessState/api/FinalCheck/GetEncryptionKey") + .SetQueryParameter(nameof(token), token)); + + if (_result.Succeeded) + { + result = _result.Value?.ToUpper(); + } + } + else + { + const String UrlFormat = "https://nodes.sms-esaap.com/keygenproxy/api/v2/keys/devices?orderNumber={0}&radioaddress={1}"; + const String XNodeTokenHeaderName = "X-Node-Token"; + const String XNodeTokenHeaderValue = "d5b8c0b2-81f6-4421-80d0-44eb2093e616"; + + var ponr = this.http + .SetBearer(this.bearer) + .Get(request => request + .SetPath($"api/search/pono/eregister/address/{token}")) + .Value; + + using (var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, String.Format(UrlFormat, ponr, token))) + { + httpRequestMessage.Headers.Add(XNodeTokenHeaderName, XNodeTokenHeaderValue); + + var expect100Continue = ServicePointManager.Expect100Continue; + var securityProtokol = ServicePointManager.SecurityProtocol; + + ServicePointManager.Expect100Continue = true; + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; + + using (var httpResponseMessage = new HttpClient().SendAsync(httpRequestMessage).Result) + { + if (httpResponseMessage.IsSuccessStatusCode) + { + result = httpResponseMessage.Content?.ReadAsStringAsync()?.Result?.Trim('"'); + } + else + { + result = httpResponseMessage.StatusCode.ToString(); + } + } + + ServicePointManager.Expect100Continue = expect100Continue; + ServicePointManager.SecurityProtocol = securityProtokol; + } } } catch (Exception e) @@ -202,7 +242,7 @@ request.SetPath(RoutePrefixes.API_SEND.ToURL("email")); request.SetJsonBody(new SendModel { - Body = $"MitarbeiterNr: {userId} => PcbID: {pcbid}", + Body = $"MitarbeiterNr: {userId} => PcbID: {token}", CC = new String[] { "Roland.Drabesch@xylem.com", "Stoyan.Zlatev@xylem.com" }, IPAddress = HttpContext.Request.UserHostAddress, IsHtml = false, @@ -215,7 +255,7 @@ }); }); } - catch (Exception e) + catch (Exception e) // http://sla12iis01.emea.sensus.net/LaaProductionWeb/Search/Passwords { this.http.Post(request => { diff --git a/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj b/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj index b4c01bbb..f23bc973 100644 --- a/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj +++ b/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj @@ -210,6 +210,7 @@ + diff --git a/LaaProductionWeb/LaaProductionWeb/Views/Search/Passwords.cshtml b/LaaProductionWeb/LaaProductionWeb/Views/Search/Passwords.cshtml index fd2ba950..3b42dae2 100644 --- a/LaaProductionWeb/LaaProductionWeb/Views/Search/Passwords.cshtml +++ b/LaaProductionWeb/LaaProductionWeb/Views/Search/Passwords.cshtml @@ -68,6 +68,10 @@ { @kvp.Value } + else if (kvp.Key.Equals("ErRadioAddress", StringComparison.OrdinalIgnoreCase)) + { + @kvp.Value + } else { @kvp.Value @@ -165,9 +169,9 @@ fs_modal.classList.add('show'); } - function td_clicked(pcbid) { + function td_clicked(token) { loader.style.display = 'flex'; - fetch(`@this.Url.Action("FS", "Search")?pcbid=${pcbid}`) + fetch(`@this.Url.Action("FS", "Search")?token=${token}`) .then(response => response.text()) .then(function (text) { loader.style.display = 'none'; diff --git a/LaaProductionWeb/LaaProductionWeb/web.config b/LaaProductionWeb/LaaProductionWeb/web.config index 2856a359..6f328779 100644 --- a/LaaProductionWeb/LaaProductionWeb/web.config +++ b/LaaProductionWeb/LaaProductionWeb/web.config @@ -6,8 +6,8 @@ - - + +