diff --git a/src/AasCore.Aas3_0/AasCore.Aas3_0.csproj b/src/AasCore.Aas3_0/AasCore.Aas3_0.csproj index 96a86a8a9..5fa15e746 100644 --- a/src/AasCore.Aas3_0/AasCore.Aas3_0.csproj +++ b/src/AasCore.Aas3_0/AasCore.Aas3_0.csproj @@ -1,25 +1,25 @@  - - net6.0 - enable - Debug;Release;DebugSlow - AnyCPU - 8 + + net6.0 + enable + Debug;Release;DebugSlow + AnyCPU + 8 - AasCore.Aas3_0 - 1.0.0-rc1 - Marko Ristin - - An SDK for manipulating, verifying and de/serializing Asset Administration Shells. - - https://github.com/aas-core-works/aas-core3.0-csharp.git - git - Copyright (c) 2023 Marko Ristin - https://raw.githubusercontent.com/aas-core-works/aas-core3.0-csharp/main/LICENSE - https://github.com/aas-core-works/aas-core3.0-csharp - aas;asset administration shell;iiot;industry internet of things;industrie 4.0;i4.0 - - - - + AasCore.Aas3_0 + 1.0.0-rc1 + Marko Ristin + + An SDK for manipulating, verifying and de/serializing Asset Administration Shells. + + https://github.com/aas-core-works/aas-core3.0-csharp.git + git + Copyright (c) 2023 Marko Ristin + https://raw.githubusercontent.com/aas-core-works/aas-core3.0-csharp/main/LICENSE + https://github.com/aas-core-works/aas-core3.0-csharp + aas;asset administration shell;iiot;industry internet of things;industrie 4.0;i4.0 + + + + diff --git a/src/AasSecurity/AasSecurity.csproj b/src/AasSecurity/AasSecurity.csproj index c14647253..718a33cd1 100644 --- a/src/AasSecurity/AasSecurity.csproj +++ b/src/AasSecurity/AasSecurity.csproj @@ -1,17 +1,17 @@ - - net6.0 - enable - enable - + + net6.0 + enable + enable + - - - + + + - - - + + + diff --git a/src/AasSecurity/SecurityService.cs b/src/AasSecurity/SecurityService.cs index 80d165c2f..76c6ba225 100644 --- a/src/AasSecurity/SecurityService.cs +++ b/src/AasSecurity/SecurityService.cs @@ -117,7 +117,7 @@ public AuthenticationTicket AuthenticateRequest(HttpContext context, string rout if (user.Contains('@')) { string[] split = user.Split('@'); - domain = split[1]; + domain = split[ 1 ]; } if (domain != null && domain.Equals(securityRight.Name)) @@ -241,25 +241,25 @@ public AuthenticationTicket AuthenticateRequest(HttpContext context, string rout { case "authorization": { - var token = headers[key]; + var token = headers[ key ]; if (token != null) { string[] split = token.Split(new Char[] {' ', '\t'}); - if (split[0].ToLower().Equals("bearer")) + if (split[ 0 ].ToLower().Equals("bearer")) { - _logger.LogDebug($"Received bearer token {split[1]}"); - bearerToken = split[1]; + _logger.LogDebug($"Received bearer token {split[ 1 ]}"); + bearerToken = split[ 1 ]; } - else if (split[0].ToLower().Equals("basic") && bearerToken == null) + else if (split[ 0 ].ToLower().Equals("basic") && bearerToken == null) { try { if (Program.secretStringAPI != null) { - var credentialBytes = Convert.FromBase64String(split[1]); + var credentialBytes = Convert.FromBase64String(split[ 1 ]); var credentials = Encoding.UTF8.GetString(credentialBytes).Split(new[] {':'}, 2); - string u = credentials[0]; - string p = credentials[1]; + string u = credentials[ 0 ]; + string p = credentials[ 1 ]; Console.WriteLine("Received username+password http header = " + u + " : " + p); if (u == "secret") @@ -275,7 +275,7 @@ public AuthenticationTicket AuthenticateRequest(HttpContext context, string rout } } - string username = CheckUserPW(split[1]); + string username = CheckUserPW(split[ 1 ]); if (username != null) { user = username; @@ -292,7 +292,7 @@ public AuthenticationTicket AuthenticateRequest(HttpContext context, string rout } case "email": { - var token = headers[key]; + var token = headers[ key ]; if (token != null) { _logger.LogDebug($"Received email token from header: {token}"); @@ -312,7 +312,7 @@ public AuthenticationTicket AuthenticateRequest(HttpContext context, string rout { case "s": { - string secretQuery = queries["s"]!; + string secretQuery = queries[ "s" ]!; if (!secretQuery.IsNullOrEmpty()) { _logger.LogDebug($"Received token of type s: {secretQuery}"); @@ -329,7 +329,7 @@ public AuthenticationTicket AuthenticateRequest(HttpContext context, string rout } case "bearer": { - var token = queries[key]; + var token = queries[ key ]; if (token != null) { _logger.LogDebug($"Received token of type bear {token}"); @@ -340,7 +340,7 @@ public AuthenticationTicket AuthenticateRequest(HttpContext context, string rout } case "email": { - var token = queries[key]; + var token = queries[ key ]; if (token != null) { _logger.LogDebug($"Received token of type email {token}"); @@ -352,7 +352,7 @@ public AuthenticationTicket AuthenticateRequest(HttpContext context, string rout } case "_up": { - var token = queries[key]; + var token = queries[ key ]; if (token != null) { _logger.LogDebug($"Received token of type username-password {token}"); @@ -382,8 +382,8 @@ private string CheckUserPW(string userPW64) { var credentialBytes = Convert.FromBase64String(userPW64); var credentials = Encoding.UTF8.GetString(credentialBytes).Split(new[] {':'}, 2); - string username = credentials[0]; - string password = credentials[1]; + string username = credentials[ 0 ]; + string password = credentials[ 1 ]; var found = GlobalSecurityVariables.SecurityUsernamePassword.TryGetValue(username, out string storedPassword); if (found) @@ -675,7 +675,7 @@ private static bool CheckAccessLevelForOperation(string currentRole, string oper { if (securityRole.SemanticId == "*" || (submodel.SemanticId != null && submodel.SemanticId.Keys != null && submodel.SemanticId.Keys.Count != 0)) { - if (securityRole.SemanticId == "*" || (securityRole.SemanticId.ToLower() == submodel.SemanticId?.Keys?[0].Value.ToLower())) + if (securityRole.SemanticId == "*" || (securityRole.SemanticId.ToLower() == submodel.SemanticId?.Keys?[ 0 ].Value.ToLower())) { if (securityRole.Kind == KindOfPermissionEnum.Allow) { @@ -814,11 +814,11 @@ private static bool MatchApiOperation(string apiOperation, string operation) { for (int i = 0; i < apiOpSplit.Length; i++) { - if (apiOpSplit[i].Equals(opSplit[i])) + if (apiOpSplit[ i ].Equals(opSplit[ i ])) { match = true; } - else if (apiOpSplit[i].StartsWith("{")) + else if (apiOpSplit[ i ].StartsWith("{")) { continue; } diff --git a/src/AasxCsharpLibrary/AasxCsharpLibrary.csproj b/src/AasxCsharpLibrary/AasxCsharpLibrary.csproj index 1e76f10a7..9ea97f7af 100644 --- a/src/AasxCsharpLibrary/AasxCsharpLibrary.csproj +++ b/src/AasxCsharpLibrary/AasxCsharpLibrary.csproj @@ -1,51 +1,51 @@  - - net6.0 - Library - AdminShellNS - false - - - false - - - TRACE;UseAasxCompatibilityModels - - - false - - - - - - - PreserveNewest - - - - - Designer - PreserveNewest - - - Designer - PreserveNewest - - - Designer - PreserveNewest - - - - - - - - - - - - - - + + net6.0 + Library + AdminShellNS + false + + + false + + + TRACE;UseAasxCompatibilityModels + + + false + + + + + + + PreserveNewest + + + + + Designer + PreserveNewest + + + Designer + PreserveNewest + + + Designer + PreserveNewest + + + + + + + + + + + + + + diff --git a/src/AasxCsharpLibrary/AdminShellPackageEnv.cs b/src/AasxCsharpLibrary/AdminShellPackageEnv.cs index 3855edfe8..6f28f5771 100644 --- a/src/AasxCsharpLibrary/AdminShellPackageEnv.cs +++ b/src/AasxCsharpLibrary/AdminShellPackageEnv.cs @@ -626,7 +626,7 @@ private void AssignDefaultThumbnailPath() { if (_aasEnv.AssetAdministrationShells.Count > 0) { - _aasEnv.AssetAdministrationShells[0].AssetInformation.DefaultThumbnail = new Resource(thumbUri.OriginalString); + _aasEnv.AssetAdministrationShells[ 0 ].AssetInformation.DefaultThumbnail = new Resource(thumbUri.OriginalString); } } } @@ -980,7 +980,7 @@ public bool SaveAs(string fn, bool writeFreshly = false, SerializationFormat pre // create, as not existing var frn = "aasenv-with-no-id"; if (_aasEnv.AssetAdministrationShells.Count > 0) - frn = _aasEnv.AssetAdministrationShells[0].GetFriendlyName() ?? frn; + frn = _aasEnv.AssetAdministrationShells[ 0 ].GetFriendlyName() ?? frn; var aas_spec_fn = "/aasx/#/#.aas"; if (prefFmt == SerializationFormat.Json) aas_spec_fn += ".json"; diff --git a/src/AasxCsharpLibrary/Extensions/ExtendConceptDescription.cs b/src/AasxCsharpLibrary/Extensions/ExtendConceptDescription.cs index 57fb28e1e..875457058 100644 --- a/src/AasxCsharpLibrary/Extensions/ExtendConceptDescription.cs +++ b/src/AasxCsharpLibrary/Extensions/ExtendConceptDescription.cs @@ -28,9 +28,7 @@ public static EmbeddedDataSpecification SetIEC61360Spec(this ConceptDescription string[] definition = null ) { - var eds = new EmbeddedDataSpecification( - new Reference(ReferenceTypes.ExternalReference, - new List {ExtendIDataSpecificationContent.GetKeyForIec61360()}), + var eds = new EmbeddedDataSpecification(new Reference(ReferenceTypes.ExternalReference, new List {ExtendIDataSpecificationContent.GetKeyForIec61360()}), new DataSpecificationIec61360( ExtendLangStringSet.CreateManyPreferredNamesFromStringArray(preferredNames), new List {new LangStringShortNameTypeIec61360("EN?", shortName)}, diff --git a/src/AasxCsharpLibrary/Extensions/ExtendIReferable.cs b/src/AasxCsharpLibrary/Extensions/ExtendIReferable.cs index a2f7f8ce4..9482529c3 100644 --- a/src/AasxCsharpLibrary/Extensions/ExtendIReferable.cs +++ b/src/AasxCsharpLibrary/Extensions/ExtendIReferable.cs @@ -585,7 +585,7 @@ public static void MigrateV20QualifiersToExtensions(this IReferable rf) // now move these for (int i = 0; i < toMove.Count; i++) { - var q = toMove[i]; + var q = toMove[ i ]; var ext = new Extension( name: q.Type, semanticId: q.SemanticId, valueType: q.ValueType, value: q.Value); diff --git a/src/AasxCsharpLibrary/Extensions/ExtendISubmodelElement.cs b/src/AasxCsharpLibrary/Extensions/ExtendISubmodelElement.cs index 200b2f47f..38e3a11da 100644 --- a/src/AasxCsharpLibrary/Extensions/ExtendISubmodelElement.cs +++ b/src/AasxCsharpLibrary/Extensions/ExtendISubmodelElement.cs @@ -615,7 +615,7 @@ public static IReferable FindReferableByReference( // over all wrappers foreach (var smw in submodelElements) - if (smw != null && smw.IdShort.Equals(keys[keyIndex].Value, StringComparison.OrdinalIgnoreCase)) + if (smw != null && smw.IdShort.Equals(keys[ keyIndex ].Value, StringComparison.OrdinalIgnoreCase)) { // match on this level. Did we find a leaf element? if ((keyIndex + 1) >= keys.Count) diff --git a/src/AasxServerAspNetCore/AasxServerAspNetCore.csproj b/src/AasxServerAspNetCore/AasxServerAspNetCore.csproj index 51ef6d88c..c9cd7f7a7 100644 --- a/src/AasxServerAspNetCore/AasxServerAspNetCore.csproj +++ b/src/AasxServerAspNetCore/AasxServerAspNetCore.csproj @@ -1,32 +1,32 @@ - - net6.0 - enable - enable - - - false - + + net6.0 + enable + enable + + + false + - - - - - + + + + + - - - - + + + + - - - Always - - - Always - - + + + Always + + + Always + + diff --git a/src/AasxServerBlazor/AasxServerBlazor.csproj b/src/AasxServerBlazor/AasxServerBlazor.csproj index 109a6a7a9..3e0946ff9 100644 --- a/src/AasxServerBlazor/AasxServerBlazor.csproj +++ b/src/AasxServerBlazor/AasxServerBlazor.csproj @@ -1,86 +1,90 @@  - - net6.0 - en-US;de-DE - + + net6.0 + en-US;de-DE + - - DEBUG;TRACE;UseAasxCompatibilityModels - portable - true - + + DEBUG;TRACE;UseAasxCompatibilityModels + portable + true + - - false - + + false + - - - + + + - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + - - - - - - - - - - + + + + + + + + + + - + + + + + - - - PreserveNewest - + + + PreserveNewest + - - PreserveNewest - - + + PreserveNewest + + - - - Always - - + + + Always + + - - - - - - - - - - - + + + + + + + + + + + - - - - + + + + - - - PreserveNewest - - + + + PreserveNewest + + diff --git a/src/AasxServerStandardBib/AasxHttpContextHelper.cs b/src/AasxServerStandardBib/AasxHttpContextHelper.cs index 195f6eae2..249c8af48 100644 --- a/src/AasxServerStandardBib/AasxHttpContextHelper.cs +++ b/src/AasxServerStandardBib/AasxHttpContextHelper.cs @@ -55,7 +55,7 @@ public class AasxHttpContextHelper public bool PathEndsWith(string path, string tag) { - return path.Trim().ToLower().TrimEnd(new char[] {'/'}).EndsWith(tag); + return path.Trim().ToLower().TrimEnd(new[] {'/'}).EndsWith(tag); } public bool PathEndsWith(Grapevine.Interfaces.Server.IHttpContext context, string tag) @@ -92,14 +92,14 @@ public List CreateHandlesFromQueryString(System.Co try { var k = kr.Trim().ToLower(); - var v = queryStrings[k]; + var v = queryStrings[ k ]; if (k.StartsWith("q") && k.Length > 1 && v.Contains(',')) { var vl = v.Split(','); if (vl.Length == 2) { //var id = new IIdentifiable(vl[1]); - var id = vl[1]; + var id = vl[ 1 ]; var h = new AasxHttpHandleIdentification(id, "@" + k); res.Add(h); } @@ -132,15 +132,15 @@ public List CreateHandlesFromRawUrl(string rawUrl) // try make a Regex wonder, again var m = Regex.Match(query, @"(\s*([^&]+)(&|))+"); - if (m.Success && m.Groups.Count >= 3 && m.Groups[2].Captures != null) - foreach (var cp in m.Groups[2].Captures) + if (m.Success && m.Groups.Count >= 3 && m.Groups[ 2 ].Captures != null) + foreach (var cp in m.Groups[ 2 ].Captures) { var m2 = Regex.Match(cp.ToString(), @"\s*(\w+)\s*=\s*([^,]+),(.+)$"); if (m2.Success && m2.Groups.Count >= 4) { - var k = m2.Groups[1].ToString(); - var idt = m2.Groups[2].ToString(); - var ids = m2.Groups[3].ToString(); + var k = m2.Groups[ 1 ].ToString(); + var idt = m2.Groups[ 2 ].ToString(); + var ids = m2.Groups[ 3 ].ToString(); //var id = new IIdentifiable(ids); var id = ids; @@ -172,11 +172,11 @@ public FindAasReturn FindAAS(string aasid, System.Collections.Specialized.NameVa if (i > Packages.Length) return null; - if (Packages[i] == null || Packages[i].AasEnv == null || Packages[i].AasEnv.AssetAdministrationShells == null - || Packages[i].AasEnv.AssetAdministrationShells.Count < 1) + if (Packages[ i ] == null || Packages[ i ].AasEnv == null || Packages[ i ].AasEnv.AssetAdministrationShells == null + || Packages[ i ].AasEnv.AssetAdministrationShells.Count < 1) return null; - findAasReturn.aas = Packages[i].AasEnv.AssetAdministrationShells[0]; + findAasReturn.aas = Packages[ i ].AasEnv.AssetAdministrationShells[ 0 ]; findAasReturn.iPackage = i; } else @@ -184,18 +184,18 @@ public FindAasReturn FindAAS(string aasid, System.Collections.Specialized.NameVa // Name if (aasid == "id") { - findAasReturn.aas = Packages[0].AasEnv.AssetAdministrationShells[0]; + findAasReturn.aas = Packages[ 0 ].AasEnv.AssetAdministrationShells[ 0 ]; findAasReturn.iPackage = 0; } else { for (int i = 0; i < Packages.Length; i++) { - if (Packages[i] != null) + if (Packages[ i ] != null) { - if (Packages[i].AasEnv.AssetAdministrationShells[0].IdShort == aasid) + if (Packages[ i ].AasEnv.AssetAdministrationShells[ 0 ].IdShort == aasid) { - findAasReturn.aas = Packages[i].AasEnv.AssetAdministrationShells[0]; + findAasReturn.aas = Packages[ i ].AasEnv.AssetAdministrationShells[ 0 ]; findAasReturn.iPackage = i; break; } @@ -231,7 +231,7 @@ public IReference FindSubmodelRefWithinAas(FindAasReturn findAasReturn, string s string rawUrl = null) { // trivial - if (Packages[findAasReturn.iPackage] == null || Packages[findAasReturn.iPackage].AasEnv == null || findAasReturn.aas == null || smid == null || smid.Trim() == "") + if (Packages[ findAasReturn.iPackage ] == null || Packages[ findAasReturn.iPackage ].AasEnv == null || findAasReturn.aas == null || smid == null || smid.Trim() == "") return null; // via handle @@ -248,7 +248,7 @@ public IReference FindSubmodelRefWithinAas(FindAasReturn findAasReturn, string s } else { - var sm = this.Packages[findAasReturn.iPackage].AasEnv.FindSubmodel(smref); + var sm = this.Packages[ findAasReturn.iPackage ].AasEnv.FindSubmodel(smref); if (sm != null && sm.IdShort != null && sm.IdShort.Trim().ToLower() == smid.Trim().ToLower()) return smref; } @@ -262,20 +262,20 @@ public ISubmodel FindSubmodelWithinAas(FindAasReturn findAasReturn, string smid, string rawUrl = null) { // trivial - if (Packages[findAasReturn.iPackage] == null || Packages[findAasReturn.iPackage].AasEnv == null || findAasReturn.aas == null || smid == null || smid.Trim() == "") + if (Packages[ findAasReturn.iPackage ] == null || Packages[ findAasReturn.iPackage ].AasEnv == null || findAasReturn.aas == null || smid == null || smid.Trim() == "") return null; // via handle var specialHandles = this.CreateHandlesFromRawUrl(rawUrl); var handleId = IdRefHandleStore.ResolveSpecific(smid, specialHandles); if (handleId != null && handleId.identification != null) - return Packages[findAasReturn.iPackage].AasEnv.FindSubmodelById(handleId.identification); + return Packages[ findAasReturn.iPackage ].AasEnv.FindSubmodelById(handleId.identification); // no, iterate & find foreach (var smref in findAasReturn.aas.Submodels) { - var sm = this.Packages[findAasReturn.iPackage].AasEnv.FindSubmodel(smref); + var sm = this.Packages[ findAasReturn.iPackage ].AasEnv.FindSubmodel(smref); if (sm != null && sm.IdShort != null && sm.IdShort.Trim().ToLower() == smid.Trim().ToLower()) return sm; } @@ -301,11 +301,11 @@ public ISubmodel FindSubmodelWithinAas(string aasid, string smid, System.Collect if (i > Packages.Length) return null; - if (Packages[i] == null || Packages[i].AasEnv == null || Packages[i].AasEnv.AssetAdministrationShells == null - || Packages[i].AasEnv.AssetAdministrationShells.Count < 1) + if (Packages[ i ] == null || Packages[ i ].AasEnv == null || Packages[ i ].AasEnv.AssetAdministrationShells == null + || Packages[ i ].AasEnv.AssetAdministrationShells.Count < 1) return null; - aas = Packages[i].AasEnv.AssetAdministrationShells[0]; + aas = Packages[ i ].AasEnv.AssetAdministrationShells[ 0 ]; iPackage = i; } else @@ -313,18 +313,18 @@ public ISubmodel FindSubmodelWithinAas(string aasid, string smid, System.Collect // Name if (aasid == "id") { - aas = Packages[0].AasEnv.AssetAdministrationShells[0]; + aas = Packages[ 0 ].AasEnv.AssetAdministrationShells[ 0 ]; iPackage = 0; } else { for (int i = 0; i < Packages.Length; i++) { - if (Packages[i] != null) + if (Packages[ i ] != null) { - if (Packages[i].AasEnv.AssetAdministrationShells[0].IdShort == aasid) + if (Packages[ i ].AasEnv.AssetAdministrationShells[ 0 ].IdShort == aasid) { - aas = Packages[i].AasEnv.AssetAdministrationShells[0]; + aas = Packages[ i ].AasEnv.AssetAdministrationShells[ 0 ]; iPackage = i; break; } @@ -340,7 +340,7 @@ public ISubmodel FindSubmodelWithinAas(string aasid, string smid, System.Collect foreach (var smref in aas.Submodels) { - var sm = this.Packages[iPackage].AasEnv.FindSubmodel(smref); + var sm = this.Packages[ iPackage ].AasEnv.FindSubmodel(smref); if (sm != null && sm.IdShort != null && sm.IdShort.Trim().ToLower() == smid.Trim().ToLower()) return sm; } @@ -353,17 +353,17 @@ public ISubmodel FindSubmodelWithinAas(string aasid, string smid, System.Collect public ISubmodel FindSubmodelWithoutAas(string smid, System.Collections.Specialized.NameValueCollection queryStrings = null, string rawUrl = null) { // trivial - if (Packages[0] == null || Packages[0].AasEnv == null || smid == null || smid.Trim() == "") + if (Packages[ 0 ] == null || Packages[ 0 ].AasEnv == null || smid == null || smid.Trim() == "") return null; // via handle var specialHandles = this.CreateHandlesFromRawUrl(rawUrl); var handleId = IdRefHandleStore.ResolveSpecific(smid, specialHandles); if (handleId != null && handleId.identification != null) - return Packages[0].AasEnv.FindSubmodelById(handleId.identification); + return Packages[ 0 ].AasEnv.FindSubmodelById(handleId.identification); // no, iterate & find - foreach (var sm in this.Packages[0].AasEnv.Submodels) + foreach (var sm in this.Packages[ 0 ].AasEnv.Submodels) { if (sm != null && sm.IdShort != null && sm.IdShort.Trim().ToLower() == smid.Trim().ToLower()) return sm; @@ -377,17 +377,17 @@ public IConceptDescription FindCdWithoutAas(FindAasReturn findAasReturn, string string rawUrl = null) { // trivial - if (Packages[findAasReturn.iPackage] == null || Packages[findAasReturn.iPackage].AasEnv == null || findAasReturn.aas == null || cdid == null || cdid.Trim() == "") + if (Packages[ findAasReturn.iPackage ] == null || Packages[ findAasReturn.iPackage ].AasEnv == null || findAasReturn.aas == null || cdid == null || cdid.Trim() == "") return null; // via handle var specialHandles = this.CreateHandlesFromRawUrl(rawUrl); var handleId = IdRefHandleStore.ResolveSpecific(cdid, specialHandles); if (handleId != null && handleId.identification != null) - return Packages[findAasReturn.iPackage].AasEnv.FindConceptDescriptionById(handleId.identification); + return Packages[ findAasReturn.iPackage ].AasEnv.FindConceptDescriptionById(handleId.identification); // no, iterate & find - foreach (var cd in Packages[findAasReturn.iPackage].AasEnv.ConceptDescriptions) + foreach (var cd in Packages[ findAasReturn.iPackage ].AasEnv.ConceptDescriptions) { if (cd.IdShort != null && cd.IdShort.Trim().ToLower() == cdid.Trim().ToLower()) return cd; @@ -423,7 +423,7 @@ public FindSubmodelElementResult FindSubmodelElement(IReferable parent, List= 0 && jsonld[k] != '}' && jsonld[k] != ']') + while (k >= 0 && jsonld[ k ] != '}' && jsonld[ k ] != ']') { k--; } @@ -668,15 +668,15 @@ public static string makeJsonLD(string json, int count) protected static void SendJsonResponse(Grapevine.Interfaces.Server.IHttpContext context, object obj, IContractResolver contractResolver = null) { var queryString = context.Request.QueryString; - string refresh = queryString["refresh"]; + string refresh = queryString[ "refresh" ]; if (refresh != null && refresh != "") { context.Response.Headers.Remove("Refresh"); context.Response.Headers.Add("Refresh", refresh); } - string jsonld = queryString["jsonld"]; - string vc = queryString["vc"]; + string jsonld = queryString[ "jsonld" ]; + string vc = queryString[ "vc" ]; var settings = new JsonSerializerSettings(); if (contractResolver != null) @@ -744,11 +744,11 @@ protected static void SendJsonResponse(Grapevine.Interfaces.Server.IHttpContext { if (kvp.Key.Equals("AAS")) { - value["AAS"] = Jsonization.Serialize.ToJsonObject((AssetAdministrationShell) kvp.Value); + value[ "AAS" ] = Jsonization.Serialize.ToJsonObject((AssetAdministrationShell) kvp.Value); } else if (kvp.Key.Equals("Asset")) { - value["AssetInformation"] = Jsonization.Serialize.ToJsonObject((AssetInformation) kvp.Value); + value[ "AssetInformation" ] = Jsonization.Serialize.ToJsonObject((AssetInformation) kvp.Value); } } @@ -769,7 +769,7 @@ protected static void SendJsonResponse(Grapevine.Interfaces.Server.IHttpContext protected static void SendTextResponse(Grapevine.Interfaces.Server.IHttpContext context, string txt, string mimeType = null) { var queryString = context.Request.QueryString; - string refresh = queryString["refresh"]; + string refresh = queryString[ "refresh" ]; if (refresh != null && refresh != "") { context.Response.Headers.Remove("Refresh"); @@ -875,7 +875,7 @@ public void EvalGetAasEnv(IHttpContext context, string aasid) res.confirm = "Authorization = " + accessrights; } - if (this.Packages[0] == null || this.Packages[0].AasEnv == null) + if (this.Packages[ 0 ] == null || this.Packages[ 0 ].AasEnv == null) { context.Response.SendResponse(HttpStatusCode.InternalServerError, $"Error accessing internal data structures."); return; @@ -893,7 +893,7 @@ public void EvalGetAasEnv(IHttpContext context, string aasid) AasCore.Aas3_0.Environment copyenv = new AasCore.Aas3_0.Environment(); try { - var sourceEnvironment = Packages[findAasReturn.iPackage].AasEnv; + var sourceEnvironment = Packages[ findAasReturn.iPackage ].AasEnv; var aasList = new List() {findAasReturn.aas}; copyenv = copyenv.CreateFromExistingEnvironment(sourceEnvironment, aasList); } @@ -963,7 +963,7 @@ public void EvalGetAasThumbnail(IHttpContext context, string aasid) res.confirm = "Authorization = " + accessrights; } - if (this.Packages[0] == null) + if (this.Packages[ 0 ] == null) { context.Response.SendResponse(HttpStatusCode.InternalServerError, $"Error accessing internal data structures."); return; @@ -980,7 +980,7 @@ public void EvalGetAasThumbnail(IHttpContext context, string aasid) // access the thumbnail // Note: in this version, the thumbnail is not specific to the AAS, but maybe in later versions ;-) Uri thumbUri = null; - var thumbStream = this.Packages[findAasReturn.iPackage].GetLocalThumbnailStream(ref thumbUri); + var thumbStream = this.Packages[ findAasReturn.iPackage ].GetLocalThumbnailStream(ref thumbUri); if (thumbStream == null) { context.Response.SendResponse(HttpStatusCode.NotFound, $"No thumbnail available in package."); @@ -1044,13 +1044,13 @@ public void EvalPutAas(IHttpContext context) int emptyPackageIndex = -1; for (int envi = 0; envi < this.Packages.Length; envi++) { - if (this.Packages[envi] != null) + if (this.Packages[ envi ] != null) { - var existingAas = this.Packages[envi].AasEnv.FindAasById(aas.Id); + var existingAas = this.Packages[ envi ].AasEnv.FindAasById(aas.Id); if (existingAas != null) { - this.Packages[envi].AasEnv.AssetAdministrationShells.Remove(existingAas); - this.Packages[envi].AasEnv.AssetAdministrationShells.Add(aas); + this.Packages[ envi ].AasEnv.AssetAdministrationShells.Remove(existingAas); + this.Packages[ envi ].AasEnv.AssetAdministrationShells.Add(aas); SendTextResponse(context, "OK (update, index=" + envi + ")"); return; } @@ -1067,8 +1067,8 @@ public void EvalPutAas(IHttpContext context) if (emptyPackageAvailable) { - this.Packages[emptyPackageIndex] = new AdminShellPackageEnv(); - this.Packages[emptyPackageIndex].AasEnv.AssetAdministrationShells.Add(aas); + this.Packages[ emptyPackageIndex ] = new AdminShellPackageEnv(); + this.Packages[ emptyPackageIndex ].AasEnv.AssetAdministrationShells.Add(aas); SendTextResponse(context, "OK (new, index=" + emptyPackageIndex + ")"); return; } @@ -1173,7 +1173,7 @@ public void EvalPutAasxOnServer(IHttpContext context) string aasIdShort = ""; try { - aasIdShort = aasEnv.AasEnv.AssetAdministrationShells[0].IdShort; + aasIdShort = aasEnv.AasEnv.AssetAdministrationShells[ 0 ].IdShort; } catch (Exception ex) { @@ -1188,10 +1188,10 @@ public void EvalPutAasxOnServer(IHttpContext context) { for (int envi = 0; envi < this.Packages.Length; envi++) { - if (this.Packages[envi] == null) + if (this.Packages[ envi ] == null) { - this.Packages[envi] = aasEnv; - Program.envFileName[envi] = file.path; + this.Packages[ envi ] = aasEnv; + Program.envFileName[ envi ] = file.path; context.Response.StatusCode = HttpStatusCode.Ok; SendTextResponse(context, "OK (new, index=" + envi + ")"); return; @@ -1204,8 +1204,8 @@ public void EvalPutAasxOnServer(IHttpContext context) } else { - Packages[findAasReturn.iPackage] = aasEnv; - Program.envFileName[findAasReturn.iPackage] = file.path; + Packages[ findAasReturn.iPackage ] = aasEnv; + Program.envFileName[ findAasReturn.iPackage ] = file.path; context.Response.StatusCode = HttpStatusCode.Ok; SendTextResponse(context, "OK (update, index=" + findAasReturn.iPackage + ")"); return; @@ -1259,8 +1259,8 @@ public void EvalPutAasxToFilesystem(IHttpContext context, string aasid) { try { - Packages[findAasReturn.iPackage].SaveAs(file.path, false, AdminShellPackageEnv.SerializationFormat.Json, null); - Program.envFileName[findAasReturn.iPackage] = file.path; + Packages[ findAasReturn.iPackage ].SaveAs(file.path, false, AdminShellPackageEnv.SerializationFormat.Json, null); + Program.envFileName[ findAasReturn.iPackage ] = file.path; context.Response.StatusCode = HttpStatusCode.Ok; SendTextResponse(context, "OK (saved)"); return; @@ -1286,7 +1286,7 @@ public void EvalPutAasxReplacePackage(IHttpContext context, string aasid) { accessrights = SecurityCheck(context, ref index); - var aas = Program.env[aasInfo.iPackage].AasEnv.AssetAdministrationShells[0]; + var aas = Program.env[ aasInfo.iPackage ].AasEnv.AssetAdministrationShells[ 0 ]; if (!checkAccessRights(context, accessrights, "/aasx", "UPDATE", "", "aas", aas)) { return; @@ -1325,7 +1325,7 @@ public void EvalPutAasxReplacePackage(IHttpContext context, string aasid) } */ - var packFn = Packages[packIndex].Filename; + var packFn = Packages[ packIndex ].Filename; Console.WriteLine($"Will replace AASX package on server: {packFn}"); // make temp file @@ -1347,7 +1347,7 @@ public void EvalPutAasxReplacePackage(IHttpContext context, string aasid) try { // free to overwrite - Packages[packIndex].Close(); + Packages[ packIndex ].Close(); // copy to back (rename experienced to be more error-prone) System.IO.File.Copy(packFn, packFn + ".bak", overwrite: true); @@ -1362,7 +1362,7 @@ public void EvalPutAasxReplacePackage(IHttpContext context, string aasid) try { // replace loaded original when saving - packFn = Program.envFileName[packIndex]; + packFn = Program.envFileName[ packIndex ]; Console.WriteLine($"Replace original AASX package on server: {packFn}"); // copy into same location @@ -1371,7 +1371,7 @@ public void EvalPutAasxReplacePackage(IHttpContext context, string aasid) // open again var newAasx = new AdminShellPackageEnv(packFn, true); if (newAasx != null) - Packages[packIndex] = newAasx; + Packages[ packIndex ] = newAasx; else { context.Response.SendResponse(HttpStatusCode.BadRequest, $"Cannot load new package {packFn} for replacing via PUT. Aborting."); @@ -1399,14 +1399,14 @@ public void EvalGetAasxByAssetId(IHttpContext context) { string path = context.Request.PathInfo; string[] split = path.Split('/'); - string node = split[2]; - string assetId = split[3].ToUpper(); + string node = split[ 2 ]; + string assetId = split[ 3 ].ToUpper(); for (int envi = 0; envi < Packages.Length; envi++) { - if (this.Packages[envi] != null) + if (this.Packages[ envi ] != null) { - foreach (var aas in this.Packages[envi].AasEnv.AssetAdministrationShells) + foreach (var aas in this.Packages[ envi ].AasEnv.AssetAdministrationShells) { if (aas.AssetInformation != null) { @@ -1434,7 +1434,7 @@ public void EvalGetAasxByAssetId(IHttpContext context) System.IO.Stream s = null; try { - s = Program.env[envi].GetLocalThumbnailStream(); + s = Program.env[ envi ].GetLocalThumbnailStream(); } catch { @@ -1510,7 +1510,7 @@ public void EvalDeleteAasAndAsset(IHttpContext context, string aasid, bool delet } // datastructure update - if (this.Packages[0] == null || this.Packages[0].AasEnv == null || this.Packages[0].AasEnv.AssetAdministrationShells == null) + if (this.Packages[ 0 ] == null || this.Packages[ 0 ].AasEnv == null || this.Packages[ 0 ].AasEnv.AssetAdministrationShells == null) { context.Response.SendResponse(HttpStatusCode.InternalServerError, $"Error accessing internal data structures."); return; @@ -1530,11 +1530,11 @@ public void EvalDeleteAasAndAsset(IHttpContext context, string aasid, bool delet // delete context.Server.Logger.Debug($"Deleting AdministrationShell with IdShort {findAasReturn.aas.IdShort ?? "--"} and id {findAasReturn.aas.Id?.ToString() ?? "--"}"); - this.Packages[findAasReturn.iPackage].AasEnv.AssetAdministrationShells.Remove(findAasReturn.aas); + this.Packages[ findAasReturn.iPackage ].AasEnv.AssetAdministrationShells.Remove(findAasReturn.aas); - if (this.Packages[findAasReturn.iPackage].AasEnv.AssetAdministrationShells.Count == 0) + if (this.Packages[ findAasReturn.iPackage ].AasEnv.AssetAdministrationShells.Count == 0) { - this.Packages[findAasReturn.iPackage] = null; + this.Packages[ findAasReturn.iPackage ] = null; } else { @@ -1586,7 +1586,7 @@ public void EvalGetAssetLinks(IHttpContext context, string assetid) var handle = IdRefHandleStore.ResolveSpecific(assetid, specialHandles); if (handle != null && handle.identification != null) { - foreach (var aas in this.Packages[0].AasEnv.AssetAdministrationShells) + foreach (var aas in this.Packages[ 0 ].AasEnv.AssetAdministrationShells) if (aas.AssetInformation != null && (aas.AssetInformation.GlobalAssetId.Equals(handle.identification))) { dynamic o = new ExpandoObject(); @@ -1597,7 +1597,7 @@ public void EvalGetAssetLinks(IHttpContext context, string assetid) } else { - foreach (var aas in this.Packages[0].AasEnv.AssetAdministrationShells) + foreach (var aas in this.Packages[ 0 ].AasEnv.AssetAdministrationShells) if (aas.IdShort != null && aas.IdShort.Trim() != "" && aas.IdShort.Trim().ToLower() == assetid.Trim().ToLower()) { dynamic o = new ExpandoObject(); @@ -1817,7 +1817,7 @@ public void EvalGetSubmodels(IHttpContext context, string aasid) // get all submodels foreach (var smref in findAasReturn.aas.Submodels) { - var sm = this.Packages[findAasReturn.iPackage].AasEnv.FindSubmodel(smref); + var sm = this.Packages[ findAasReturn.iPackage ].AasEnv.FindSubmodel(smref); if (sm != null) { //res.Add(new GetSubmodelsItem(sm, sm.kind.kind)); @@ -1894,8 +1894,8 @@ public void EvalPutSubmodel(IHttpContext context, string aasid) } // datastructure update - if (this.Packages[findAasReturn.iPackage] == null || - this.Packages[findAasReturn.iPackage].AasEnv == null /*|| this.Packages[findAasReturn.iPackage].AasEnv.Assets == null*/) + if (this.Packages[ findAasReturn.iPackage ] == null || + this.Packages[ findAasReturn.iPackage ].AasEnv == null /*|| this.Packages[findAasReturn.iPackage].AasEnv.Assets == null*/) { context.Response.SendResponse(HttpStatusCode.InternalServerError, $"Error accessing internal data structures."); return; @@ -1903,16 +1903,16 @@ public void EvalPutSubmodel(IHttpContext context, string aasid) // add Submodel context.Server.Logger.Debug($"Adding Submodel with IdShort {submodel.IdShort ?? "--"} and id {submodel.Id?.ToString() ?? "--"}"); - var existingSm = this.Packages[findAasReturn.iPackage].AasEnv.FindSubmodelById(submodel.Id); + var existingSm = this.Packages[ findAasReturn.iPackage ].AasEnv.FindSubmodelById(submodel.Id); if (existingSm != null) { - int indexOfExistingSm = this.Packages[findAasReturn.iPackage].AasEnv.Submodels.IndexOf(existingSm); - this.Packages[findAasReturn.iPackage].AasEnv.Submodels.RemoveAt(indexOfExistingSm); - this.Packages[findAasReturn.iPackage].AasEnv.Submodels.Insert(indexOfExistingSm, submodel); + int indexOfExistingSm = this.Packages[ findAasReturn.iPackage ].AasEnv.Submodels.IndexOf(existingSm); + this.Packages[ findAasReturn.iPackage ].AasEnv.Submodels.RemoveAt(indexOfExistingSm); + this.Packages[ findAasReturn.iPackage ].AasEnv.Submodels.Insert(indexOfExistingSm, submodel); } else { - this.Packages[findAasReturn.iPackage].AasEnv.Submodels.Add(submodel); + this.Packages[ findAasReturn.iPackage ].AasEnv.Submodels.Add(submodel); } // add SubmodelRef to AAS @@ -1982,7 +1982,7 @@ public void EvalDeleteSubmodel(IHttpContext context, string aasid, string smid) if (sm != null) { context.Server.Logger.Debug($"Removing Submodel {smid} from data structures."); - this.Packages[findAasReturn.iPackage].AasEnv.Submodels.Remove(sm); + this.Packages[ findAasReturn.iPackage ].AasEnv.Submodels.Remove(sm); } // simple OK @@ -2063,7 +2063,7 @@ public void EvalGetSubmodelContentsAsTable(IHttpContext context, string aasid, s } // AAS ENV - if (this.Packages[0] == null || this.Packages[0].AasEnv == null) + if (this.Packages[ 0 ] == null || this.Packages[ 0 ].AasEnv == null) { context.Response.SendResponse(HttpStatusCode.InternalServerError, $"Error accessing internal data structures."); return; @@ -2111,7 +2111,7 @@ public void EvalGetSubmodelContentsAsTable(IHttpContext context, string aasid, s // try find a concept description if (sme.SemanticId != null) { - var cd = this.Packages[0].AasEnv.FindConceptDescriptionByReference(sme.SemanticId); + var cd = this.Packages[ 0 ].AasEnv.FindConceptDescriptionByReference(sme.SemanticId); if (cd != null) { // TODO (jtikekar, 2023-09-04): Temporarily commented @@ -2300,7 +2300,7 @@ private List EvalGetSubmodelElementsProperty_EvalValues( var path = new List(); path.Add("" + smep?.IdShort); for (int i = pars.Count - 1; i >= 0; i--) - path.Insert(0, "" + pars[i].IdShort); + path.Insert(0, "" + pars[ i ].IdShort); dynamic tuple = new ExpandoObject(); tuple.path = path; @@ -2414,7 +2414,7 @@ public void EvalGetSubmodelElementsFile(IHttpContext context, string aasid, stri } // access - var packageStream = this.Packages[0].GetLocalStreamFromPackage(smef.Value); + var packageStream = this.Packages[ 0 ].GetLocalStreamFromPackage(smef.Value); if (packageStream == null) { context.Response.SendResponse(HttpStatusCode.NotFound, $"No file contents available in package."); @@ -2489,7 +2489,7 @@ public void EvalPutSubmodelElementContents(IHttpContext context, string aasid, s // Check query parameter bool first = false; var queryString = context.Request.QueryString; - string f = queryString["first"]; + string f = queryString[ "first" ]; if (f != null && f != "") { first = true; @@ -2713,7 +2713,7 @@ public void EvalInvokeSubmodelElementOperation(IHttpContext context, string aasi { numGivenInputArgs = input.Count; for (int i = 0; i < numGivenInputArgs; i++) - inputArguments[i] = input[i]; + inputArguments[ i ] = input[ i ]; } } catch (Exception ex) @@ -2734,7 +2734,7 @@ public void EvalInvokeSubmodelElementOperation(IHttpContext context, string aasi if (smep.FindQualifierOfType("DEMO") != null) { for (int i = 0; i < Math.Min(numExpectedInputArgs, numExpectedOutputArgs); i++) - outputArguments[i] = "CALC on " + inputArguments[i]; + outputArguments[ i ] = "CALC on " + inputArguments[ i ]; } // return as little dynamic object @@ -2774,7 +2774,7 @@ public void EvalGetAllCds(IHttpContext context, string aasid) // create a new, filtered AasEnv // (this is expensive, but delivers us with a list of CDs which are in relation to the respective AAS) var copyenv = new AasCore.Aas3_0.Environment(); - copyenv = copyenv.CreateFromExistingEnvironment(this.Packages[findAasReturn.iPackage].AasEnv, + copyenv = copyenv.CreateFromExistingEnvironment(this.Packages[ findAasReturn.iPackage ].AasEnv, filterForAas: new List(new AssetAdministrationShell[] {(AssetAdministrationShell) findAasReturn.aas})); // get all CDs and describe them @@ -2859,10 +2859,10 @@ public void EvalDeleteSpecificCd(IHttpContext context, string aasid, string cdid // delete ?! var deleted = false; - if (this.Packages[findAasReturn.iPackage] != null && this.Packages[findAasReturn.iPackage].AasEnv != null && - this.Packages[findAasReturn.iPackage].AasEnv.ConceptDescriptions.Contains(cd)) + if (this.Packages[ findAasReturn.iPackage ] != null && this.Packages[ findAasReturn.iPackage ].AasEnv != null && + this.Packages[ findAasReturn.iPackage ].AasEnv.ConceptDescriptions.Contains(cd)) { - this.Packages[findAasReturn.iPackage].AasEnv.ConceptDescriptions.Remove(cd); + this.Packages[ findAasReturn.iPackage ].AasEnv.ConceptDescriptions.Remove(cd); deleted = true; } @@ -3024,13 +3024,13 @@ public void EvalGetAuthenticateGuest(IHttpContext context) // string with real random numbers Byte[] barray = new byte[100]; rngCsp.GetBytes(barray); - sessionRandom[sessionCount] = Convert.ToBase64String(barray); + sessionRandom[ sessionCount ] = Convert.ToBase64String(barray); dynamic res = new ExpandoObject(); var payload = new Dictionary() { {"sessionID", sessionCount}, - {"sessionRandom", sessionRandom[sessionCount]} + {"sessionRandom", sessionRandom[ sessionCount ]} }; System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); @@ -3041,8 +3041,8 @@ public void EvalGetAuthenticateGuest(IHttpContext context) withAuthentification = true; - sessionUserType[sessionCount] = 'G'; - sessionUserName[sessionCount] = "guest"; + sessionUserType[ sessionCount ] = 'G'; + sessionUserName[ sessionCount ] = "guest"; sessionCount++; if (sessionCount >= 100) { @@ -3086,7 +3086,7 @@ public void EvalPostAuthenticateUser(IHttpContext context) for (int i = 0; i < userCount; i++) { - if (user == securityUserName[i] && password == securityUserPassword[i]) + if (user == securityUserName[ i ] && password == securityUserPassword[ i ]) { userFound = true; break; @@ -3104,12 +3104,12 @@ public void EvalPostAuthenticateUser(IHttpContext context) // string with real random numbers Byte[] barray = new byte[100]; rngCsp.GetBytes(barray); - sessionRandom[sessionCount] = Convert.ToBase64String(barray); + sessionRandom[ sessionCount ] = Convert.ToBase64String(barray); var payload = new Dictionary() { {"sessionID", sessionCount}, - {"sessionRandom", sessionRandom[sessionCount]} + {"sessionRandom", sessionRandom[ sessionCount ]} }; System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); @@ -3118,8 +3118,8 @@ public void EvalPostAuthenticateUser(IHttpContext context) Console.WriteLine("SessionID: " + sessionCount); Console.WriteLine("sessionRandom: " + token); - sessionUserType[sessionCount] = 'U'; - sessionUserName[sessionCount] = user; + sessionUserType[ sessionCount ] = 'U'; + sessionUserName[ sessionCount ] = user; sessionCount++; if (sessionCount >= 100) { @@ -3140,10 +3140,10 @@ public void EvalPostAuthenticateCert1(IHttpContext context) Console.WriteLine(); Console.WriteLine("Security 2 Server: /AuthenticateCert1"); // POST token with user - sessionUserType[sessionCount] = ' '; - sessionUserName[sessionCount] = ""; - sessionRandom[sessionCount] = ""; - sessionChallenge[sessionCount] = ""; + sessionUserType[ sessionCount ] = ' '; + sessionUserName[ sessionCount ] = ""; + sessionRandom[ sessionCount ] = ""; + sessionChallenge[ sessionCount ] = ""; bool error = false; @@ -3159,7 +3159,7 @@ public void EvalPostAuthenticateCert1(IHttpContext context) token = parsed.SelectToken("token").Value(); var headers = Jose.JWT.Headers(token); - string x5c = headers["x5c"].ToString(); + string x5c = headers[ "x5c" ].ToString(); if (x5c != "") { @@ -3175,7 +3175,7 @@ public void EvalPostAuthenticateCert1(IHttpContext context) string[] x5c64 = JsonConvert.DeserializeObject(x5c); X509Certificate2Collection xcc = new X509Certificate2Collection(); - Byte[] certFileBytes = Convert.FromBase64String(x5c64[0]); + Byte[] certFileBytes = Convert.FromBase64String(x5c64[ 0 ]); string fileCert = "./temp/" + user + ".cer"; System.IO.File.WriteAllBytes(fileCert, certFileBytes); Console.WriteLine("Security 2.1b Server: " + fileCert + " received"); @@ -3193,7 +3193,7 @@ public void EvalPostAuthenticateCert1(IHttpContext context) for (int i = 1; i < x5c64.Length; i++) { - var cert = new X509Certificate2(Convert.FromBase64String(x5c64[i])); + var cert = new X509Certificate2(Convert.FromBase64String(x5c64[ i ])); Console.WriteLine("Security 2.1c Certificate in Chain: " + cert.Subject); if (cert.Subject != cert.Issuer) { @@ -3281,7 +3281,7 @@ public void EvalPostAuthenticateCert1(IHttpContext context) rngCsp.GetBytes(barray); Console.WriteLine("Security 2.3 Server: Create session unique challenge by real random"); - sessionChallenge[sessionCount] = Convert.ToBase64String(barray); + sessionChallenge[ sessionCount ] = Convert.ToBase64String(barray); } if (error) @@ -3292,15 +3292,15 @@ public void EvalPostAuthenticateCert1(IHttpContext context) } Console.WriteLine("sessionID: " + sessionCount); - Console.WriteLine("session challenge: " + sessionChallenge[sessionCount]); + Console.WriteLine("session challenge: " + sessionChallenge[ sessionCount ]); - sessionUserType[sessionCount] = 'T'; - sessionUserName[sessionCount] = user; - sessionUserPulicKey[sessionCount] = publicKey; + sessionUserType[ sessionCount ] = 'T'; + sessionUserName[ sessionCount ] = user; + sessionUserPulicKey[ sessionCount ] = publicKey; withAuthentification = true; - res.challenge = sessionChallenge[sessionCount]; + res.challenge = sessionChallenge[ sessionCount ]; context.Response.StatusCode = HttpStatusCode.Ok; SendJsonResponse(context, res); @@ -3311,7 +3311,7 @@ public void EvalPostAuthenticateCert2(IHttpContext context) Console.WriteLine(); Console.WriteLine("Security 3 Server: /AuthenticateCert2"); // POST token with user - sessionRandom[sessionCount] = ""; + sessionRandom[ sessionCount ] = ""; bool error = false; @@ -3334,7 +3334,7 @@ public void EvalPostAuthenticateCert2(IHttpContext context) error = true; } - if (challenge != sessionChallenge[sessionCount] || sessionChallenge[sessionCount] == null || sessionChallenge[sessionCount] == "") + if (challenge != sessionChallenge[ sessionCount ] || sessionChallenge[ sessionCount ] == null || sessionChallenge[ sessionCount ] == "") { error = true; } @@ -3343,7 +3343,7 @@ public void EvalPostAuthenticateCert2(IHttpContext context) { try { - publicKey = sessionUserPulicKey[sessionCount]; + publicKey = sessionUserPulicKey[ sessionCount ]; Jose.JWT.Decode(token, publicKey, JwsAlgorithm.RS256); // signed by user key? Console.WriteLine("Security 3.1 Server: Validate challenge signature with publicKey"); @@ -3362,7 +3362,7 @@ public void EvalPostAuthenticateCert2(IHttpContext context) Byte[] barray = new byte[100]; rngCsp.GetBytes(barray); Console.WriteLine("Security 3.2 Server: Create session unique bearerToken signed by real random"); - sessionRandom[sessionCount] = Convert.ToBase64String(barray); + sessionRandom[ sessionCount ] = Convert.ToBase64String(barray); var payload = new Dictionary() { @@ -3372,7 +3372,7 @@ public void EvalPostAuthenticateCert2(IHttpContext context) try { var enc = new System.Text.ASCIIEncoding(); - token = Jose.JWT.Encode(payload, enc.GetBytes(sessionRandom[sessionCount]), JwsAlgorithm.HS256); + token = Jose.JWT.Encode(payload, enc.GetBytes(sessionRandom[ sessionCount ]), JwsAlgorithm.HS256); Console.WriteLine("Security 3.3 Server: Sign sessionID by server sessionRandom"); } catch @@ -3389,7 +3389,7 @@ public void EvalPostAuthenticateCert2(IHttpContext context) } Console.WriteLine("sessionID: " + sessionCount); - Console.WriteLine("session random: " + sessionRandom[sessionCount]); + Console.WriteLine("session random: " + sessionRandom[ sessionCount ]); Console.WriteLine("session bearerToken: " + token); sessionCount++; @@ -3461,20 +3461,20 @@ public static bool checkAccessLevelWithError(out string error, string currentRol if (objPath == "") { int iRole = 0; - while (securityRole != null && iRole < securityRole.Count && securityRole[iRole].name != null) + while (securityRole != null && iRole < securityRole.Count && securityRole[ iRole ].name != null) { - if (aasOrSubmodel == "aas" && securityRole[iRole].objType == "aas") + if (aasOrSubmodel == "aas" && securityRole[ iRole ].objType == "aas") /* (aasOrSubmodel == "submodel" && securityRole[iRole].objType == "sm")) */ { - if (objectAasOrSubmodel != null && securityRole[iRole].objReference == objectAasOrSubmodel && - securityRole[iRole].permission == neededRights) + if (objectAasOrSubmodel != null && securityRole[ iRole ].objReference == objectAasOrSubmodel && + securityRole[ iRole ].permission == neededRights) { - if ((securityRole[iRole].condition == "" && securityRole[iRole].name == currentRole) || - (securityRole[iRole].condition == "not" && securityRole[iRole].name != currentRole)) + if ((securityRole[ iRole ].condition == "" && securityRole[ iRole ].name == currentRole) || + (securityRole[ iRole ].condition == "not" && securityRole[ iRole ].name != currentRole)) { - if (securityRole[iRole].kind == "allow") + if (securityRole[ iRole ].kind == "allow") return true; - if (securityRole[iRole].kind == "deny") + if (securityRole[ iRole ].kind == "deny") { error = "DENY AAS " + (objectAasOrSubmodel as AssetAdministrationShell).Id; return false; @@ -3483,14 +3483,14 @@ public static bool checkAccessLevelWithError(out string error, string currentRol } } - if (securityRole[iRole].name == currentRole && securityRole[iRole].objType == "api" && - securityRole[iRole].permission == neededRights) + if (securityRole[ iRole ].name == currentRole && securityRole[ iRole ].objType == "api" && + securityRole[ iRole ].permission == neededRights) { - if (securityRole[iRole].apiOperation == "*" || securityRole[iRole].apiOperation == operation) + if (securityRole[ iRole ].apiOperation == "*" || securityRole[ iRole ].apiOperation == operation) { - if (securityRole[iRole].permission == neededRights) + if (securityRole[ iRole ].permission == neededRights) { - return checkPolicy(out error, securityRole[iRole], out getPolicy); + return checkPolicy(out error, securityRole[ iRole ], out getPolicy); } } } @@ -3517,7 +3517,7 @@ public static bool checkAccessLevelWithError(out string error, string currentRol { if (role.semanticId == "*" || (s.SemanticId != null && s.SemanticId.Keys != null && s.SemanticId.Keys.Count != 0)) { - if (role.semanticId == "*" || (role.semanticId.ToLower() == s.SemanticId.Keys[0].Value.ToLower())) + if (role.semanticId == "*" || (role.semanticId.ToLower() == s.SemanticId.Keys[ 0 ].Value.ToLower())) { if (role.kind == "allow") { @@ -3740,7 +3740,7 @@ public static bool checkPolicy(out string error, securityRoleClass sr, out strin { try { - using (System.IO.Stream s = Program.env[sr.usageEnvIndex].GetLocalStreamFromPackage(fPolicy.Value)) + using (System.IO.Stream s = Program.env[ sr.usageEnvIndex ].GetLocalStreamFromPackage(fPolicy.Value)) using (SHA256 mySHA256 = SHA256.Create()) { if (s != null) @@ -3823,14 +3823,14 @@ static string checkUserPW(string userPW64) { var credentialBytes = Convert.FromBase64String(userPW64); var credentials = Encoding.UTF8.GetString(credentialBytes).Split(new[] {':'}, 2); - string username = credentials[0]; - string password = credentials[1]; + string username = credentials[ 0 ]; + string password = credentials[ 1 ]; int userCount = securityUserName.Count; for (int i = 0; i < userCount; i++) { - if (username == securityUserName[i] && password == securityUserPassword[i]) + if (username == securityUserName[ i ] && password == securityUserPassword[ i ]) { return (username); } @@ -3884,7 +3884,7 @@ public static string SecurityCheckWithPolicy(NameValueCollection queryString, Na // check for secret - string s = queryString["s"]; + string s = queryString[ "s" ]; if (s != null && s != "") { if (Program.secretStringAPI != null) @@ -3904,28 +3904,28 @@ public static string SecurityCheckWithPolicy(NameValueCollection queryString, Na // string headers = request.Headers.ToString(); // Check bearer token - token = headers["Authorization"]; + token = headers[ "Authorization" ]; if (token != null) { split = token.Split(new Char[] {' ', '\t'}); - if (split[0] != null) + if (split[ 0 ] != null) { - if (split[0].ToLower() == "bearer") + if (split[ 0 ].ToLower() == "bearer") { - Console.WriteLine("Received bearer token = " + split[1]); - bearerToken = split[1]; + Console.WriteLine("Received bearer token = " + split[ 1 ]); + bearerToken = split[ 1 ]; } - if (bearerToken == null && split[0].ToLower() == "basic") + if (bearerToken == null && split[ 0 ].ToLower() == "basic") { try { if (Program.secretStringAPI != null) { - var credentialBytes = Convert.FromBase64String(split[1]); + var credentialBytes = Convert.FromBase64String(split[ 1 ]); var credentials = Encoding.UTF8.GetString(credentialBytes).Split(new[] {':'}, 2); - string u = credentials[0]; - string p = credentials[1]; + string u = credentials[ 0 ]; + string p = credentials[ 1 ]; Console.WriteLine("Received username+password http header = " + u + " : " + p); if (u == "secret") @@ -3940,7 +3940,7 @@ public static string SecurityCheckWithPolicy(NameValueCollection queryString, Na } } - string username = checkUserPW(split[1]); + string username = checkUserPW(split[ 1 ]); if (username != null) { user = username; @@ -3963,7 +3963,7 @@ public static string SecurityCheckWithPolicy(NameValueCollection queryString, Na bearerToken = split[1]; } */ - bearerToken = queryString["bearer"]; + bearerToken = queryString[ "bearer" ]; } if (bearerToken == null) @@ -3972,7 +3972,7 @@ public static string SecurityCheckWithPolicy(NameValueCollection queryString, Na } // Check email token - token = headers["Email"]; + token = headers[ "Email" ]; if (token != null) { Console.WriteLine("Received Email token = " + token); @@ -3981,7 +3981,7 @@ public static string SecurityCheckWithPolicy(NameValueCollection queryString, Na } // Check email query string - token = queryString["Email"]; + token = queryString[ "Email" ]; if (token != null) { Console.WriteLine("Received Email query string = " + token); @@ -3990,7 +3990,7 @@ public static string SecurityCheckWithPolicy(NameValueCollection queryString, Na } // Username+password query string - token = queryString["_up"]; + token = queryString[ "_up" ]; if (token != null) { try @@ -4108,11 +4108,11 @@ public static string SecurityCheckWithPolicy(NameValueCollection queryString, Na int i = 0; for (i = 0; i < certList.Count; i++) { - if (certList[i].userName == user) + if (certList[ i ].userName == user) { - if (certList[i].certificate != null) - certList[i].certificate.Dispose(); - certList[i].certificate = x509; + if (certList[ i ].certificate != null) + certList[ i ].certificate.Dispose(); + certList[ i ].certificate = x509; break; } } @@ -4135,9 +4135,9 @@ public static string SecurityCheckWithPolicy(NameValueCollection queryString, Na int i = 0; for (i = 0; i < certList.Count; i++) { - if (certList[i].userName == user) + if (certList[ i ].userName == user) { - x509 = certList[i].certificate; + x509 = certList[ i ].certificate; break; } } @@ -4176,12 +4176,12 @@ public static string SecurityCheckWithPolicy(NameValueCollection queryString, Na { for (int i = 0; i < rightsCount; i++) { - if (securityRights[i].name.Contains("@")) // email address + if (securityRights[ i ].name.Contains("@")) // email address { - if (user == securityRights[i].name) + if (user == securityRights[ i ].name) { // accessrights = securityRightsValue[i]; - accessrights = securityRights[i].role; + accessrights = securityRights[ i ].role; return accessrights; } } @@ -4190,19 +4190,19 @@ public static string SecurityCheckWithPolicy(NameValueCollection queryString, Na for (int i = 0; i < rightsCount; i++) { - if (!securityRights[i].name.Contains("@")) // domain name only or non email + if (!securityRights[ i ].name.Contains("@")) // domain name only or non email { string u = user; if (user.Contains("@")) { string[] splitUser = user.Split('@'); - u = splitUser[1]; // domain only + u = splitUser[ 1 ]; // domain only } - if (u == securityRights[i].name) + if (u == securityRights[ i ].name) { // accessrights = securityRightsValue[i]; - accessrights = securityRights[i].role; + accessrights = securityRights[ i ].role; return accessrights; } } @@ -4232,7 +4232,7 @@ public static string SecurityCheckWithPolicy(NameValueCollection queryString, Na { string payload = null; - switch (sessionUserType[id]) + switch (sessionUserType[ id ]) { case 'G': case 'U': @@ -4301,9 +4301,9 @@ public void EvalGetListAAS(IHttpContext context, bool withasset = false) for (int i = 0; i < aascount; i++) { - if (AasxServer.Program.env[i] != null) + if (AasxServer.Program.env[ i ] != null) { - var aas = AasxServer.Program.env[i].AasEnv.AssetAdministrationShells[0]; + var aas = AasxServer.Program.env[ i ].AasEnv.AssetAdministrationShells[ 0 ]; string IdShort = aas.IdShort; string aasRights = "NONE"; if (securityRightsAAS != null && securityRightsAAS.Count != 0) @@ -4322,7 +4322,7 @@ public void EvalGetListAAS(IHttpContext context, bool withasset = false) string s = i.ToString() + " : " + IdShort + " : " + aas.Id + " : " - + AasxServer.Program.envFileName[i]; + + AasxServer.Program.envFileName[ i ]; if (withasset) { //var asset = Program.env[i].AasEnv.FindAsset(aas.assetRef); @@ -4406,7 +4406,7 @@ public void EvalGetAASX(IHttpContext context, int fileIndex) res.confirm = "Authorization = " + accessrights; */ - var aas = Program.env[fileIndex].AasEnv.AssetAdministrationShells[0]; + var aas = Program.env[ fileIndex ].AasEnv.AssetAdministrationShells[ 0 ]; if (!checkAccessRights(context, accessrights, "/aasx", "READ", "", "aas", aas)) { return; @@ -4428,14 +4428,14 @@ public void EvalGetAASX(IHttpContext context, int fileIndex) lock (Program.changeAasxFile) { - string fname = "./temp/" + Path.GetFileName(Program.envFileName[fileIndex]); - Program.env[fileIndex].SaveAs(fname); + string fname = "./temp/" + Path.GetFileName(Program.envFileName[ fileIndex ]); + Program.env[ fileIndex ].SaveAs(fname); // return as FILE FileStream packageStream = System.IO.File.OpenRead(fname); context.Response.StatusCode = HttpStatusCode.Ok; SendStreamResponse(context, packageStream, - Path.GetFileName(AasxServer.Program.envFileName[fileIndex])); + Path.GetFileName(AasxServer.Program.envFileName[ fileIndex ])); packageStream.Close(); // Reload @@ -4493,7 +4493,7 @@ public void EvalGetAASX2(IHttpContext context, int fileIndex) res.confirm = "Authorization = " + accessrights; - Byte[] binaryFile = System.IO.File.ReadAllBytes(AasxServer.Program.envFileName[fileIndex]); + Byte[] binaryFile = System.IO.File.ReadAllBytes(AasxServer.Program.envFileName[ fileIndex ]); string binaryBase64 = Convert.ToBase64String(binaryFile); string payload = "{ \"file\" : \" " + binaryBase64 + " \" }"; @@ -4501,7 +4501,7 @@ public void EvalGetAASX2(IHttpContext context, int fileIndex) System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); string fileToken = Jose.JWT.Encode(payload, enc.GetBytes(secretString), JwsAlgorithm.HS256); - res.fileName = Path.GetFileName(AasxServer.Program.envFileName[fileIndex]); + res.fileName = Path.GetFileName(AasxServer.Program.envFileName[ fileIndex ]); res.fileData = fileToken; context.Response.StatusCode = HttpStatusCode.Ok; @@ -4530,7 +4530,7 @@ public void EvalGetFile(IHttpContext context, int envIndex, string filePath) context.Response.StatusCode = HttpStatusCode.Ok; string fname = Path.GetFileName(filePath); - var s = Program.env[envIndex].GetLocalStreamFromPackage(filePath); + var s = Program.env[ envIndex ].GetLocalStreamFromPackage(filePath); SendStreamResponse(context, s, fname); } @@ -4621,10 +4621,10 @@ public static void securityInit() for (int i = 0; i < aascount; i++) { - var env = AasxServer.Program.env[i]; + var env = AasxServer.Program.env[ i ]; if (env != null) { - var aas = env.AasEnv.AssetAdministrationShells[0]; + var aas = env.AasEnv.AssetAdministrationShells[ 0 ]; if (aas.Submodels != null && aas.Submodels.Count > 0) { foreach (var smr in aas.Submodels) @@ -4649,7 +4649,7 @@ public static void securityInit() int countSme = sm.SubmodelElements.Count; for (int iSme = 0; iSme < countSme; iSme++) { - var sme = sm.SubmodelElements[iSme]; + var sme = sm.SubmodelElements[ iSme ]; if (sme is Property) continue; var smec = sme as SubmodelElementCollection; @@ -4659,7 +4659,7 @@ public static void securityInit() case "authenticationServer": for (int iSmec = 0; iSmec < countSmec; iSmec++) { - var sme2 = smec.Value[iSmec]; + var sme2 = smec.Value[ iSmec ]; switch (sme2.IdShort) { case "endpoint": @@ -4674,17 +4674,17 @@ public static void securityInit() var f = sme2 as AasCore.Aas3_0.File; serverCertfileNames = new string[1]; serverCerts = new X509Certificate2[1]; - var s = Program.env[i].GetLocalStreamFromPackage(f.Value, init: true); + var s = Program.env[ i ].GetLocalStreamFromPackage(f.Value, init: true); if (s != null) { using (var m = new MemoryStream()) { s.CopyTo(m); var b = m.GetBuffer(); - serverCerts[0] = new X509Certificate2(b); + serverCerts[ 0 ] = new X509Certificate2(b); string[] split = f.Value.Split('/'); - serverCertfileNames[0] = split[3]; - Console.WriteLine("Loaded auth server certifcate: " + serverCertfileNames[0]); + serverCertfileNames[ 0 ] = split[ 3 ]; + Console.WriteLine("Loaded auth server certifcate: " + serverCertfileNames[ 0 ]); } } @@ -4698,13 +4698,13 @@ public static void securityInit() for (int iSmec = 0; iSmec < countSmec; iSmec++) { - var smec2 = smec.Value[iSmec] as SubmodelElementCollection; + var smec2 = smec.Value[ iSmec ] as SubmodelElementCollection; int countSmec2 = smec2.Value.Count; List subjects = new List(); for (int iSmec2 = 0; iSmec2 < countSmec2; iSmec2++) { - var smec3 = smec2.Value[iSmec2] as SubmodelElementCollection; + var smec3 = smec2.Value[ iSmec2 ] as SubmodelElementCollection; int countSmec3 = smec3.Value.Count; switch (smec3.IdShort) @@ -4712,7 +4712,7 @@ public static void securityInit() case "subjects": for (int iSmec3 = 0; iSmec3 < countSmec3; iSmec3++) { - var p = smec3.Value[iSmec3] as Property; + var p = smec3.Value[ iSmec3 ] as Property; switch (p.IdShort) { case "emailDomain": @@ -4729,7 +4729,7 @@ public static void securityInit() case "roles": for (int iSmec3 = 0; iSmec3 < countSmec3; iSmec3++) { - var p = smec3.Value[iSmec3] as Property; + var p = smec3.Value[ iSmec3 ] as Property; foreach (var s in subjects) { securityRightsClass sr = new securityRightsClass(); @@ -4748,7 +4748,7 @@ public static void securityInit() case "basicAuth": for (int iSmec = 0; iSmec < countSmec; iSmec++) { - if (smec.Value[iSmec] is Property p) + if (smec.Value[ iSmec ] is Property p) { securityUserName.Add(p.IdShort); securityUserPassword.Add(p.Value); @@ -4772,14 +4772,14 @@ public static void securityInit() int countSme = smc4.Value.Count; for (int iSme = 0; iSme < countSme; iSme++) { - var sme = smc4.Value[iSme]; // actual rule + var sme = smc4.Value[ iSme ]; // actual rule var smc5 = sme as SubmodelElementCollection; var smc6 = smc5?.FindFirstIdShortAs("targetSubjectAttributes"); List role = new List(); int iRole = 0; while (smc6?.Value.Count > iRole) { - if (smc6?.Value[iRole] is Property rp) + if (smc6?.Value[ iRole ] is Property rp) { role.Add(rp); } @@ -4788,7 +4788,7 @@ public static void securityInit() } smc6 = smc5?.FindFirstIdShortAs("permissionsPerObject"); - var smc7 = smc6?.Value[0] as SubmodelElementCollection; + var smc7 = smc6?.Value[ 0 ] as SubmodelElementCollection; var objProp = smc7?.FindFirstIdShortAs("object"); var objRef = smc7?.FindFirstIdShortAs("object"); object aasObject = null; @@ -4805,7 +4805,7 @@ public static void securityInit() Property kind = null; for (int iSmc8 = 0; iSmc8 < countSmc8; iSmc8++) { - var sme9 = smc8.Value[iSmc8]; + var sme9 = smc8.Value[ iSmc8 ]; if (sme9 is Property) kind = sme9 as Property; if (sme9 is ReferenceElement) @@ -4834,8 +4834,8 @@ public static void securityInit() if (r.IdShort.Contains(":")) { split = r.IdShort.Split(':'); - src.condition = split[0].ToLower(); - src.name = split[1]; + src.condition = split[ 0 ].ToLower(); + src.name = split[ 1 ]; } else { @@ -4850,22 +4850,22 @@ public static void securityInit() if (value.Contains("api")) { split = value.Split(':'); - if (split[0] == "api") + if (split[ 0 ] == "api") { - src.objType = split[0]; - src.apiOperation = split[1]; + src.objType = split[ 0 ]; + src.apiOperation = split[ 1 ]; } } if (value.Contains("semanticid")) { split = value.Split(':'); - if (split[0] == "semanticid") + if (split[ 0 ] == "semanticid") { - src.objType = split[0]; - src.semanticId = split[1]; + src.objType = split[ 0 ]; + src.semanticId = split[ 1 ]; for (int j = 2; j < split.Length; j++) - src.semanticId += ":" + split[j]; + src.semanticId += ":" + split[ j ]; } } } @@ -4930,8 +4930,8 @@ public static void serverCertsInit() for (int i = 0; i < serverCertfileNames.Length; i++) { - serverCerts[i] = new X509Certificate2(serverCertfileNames[i]); - Console.WriteLine("Loaded auth server certifcate: " + Path.GetFileName(serverCertfileNames[i])); + serverCerts[ i ] = new X509Certificate2(serverCertfileNames[ i ]); + Console.WriteLine("Loaded auth server certifcate: " + Path.GetFileName(serverCertfileNames[ i ])); } } } @@ -4942,9 +4942,9 @@ public static X509Certificate2 serverCertFind(string authServerName) { for (int i = 0; i < serverCertfileNames.Length; i++) { - if (Path.GetFileName(serverCertfileNames[i]) == authServerName + ".cer") + if (Path.GetFileName(serverCertfileNames[ i ]) == authServerName + ".cer") { - return serverCerts[i]; + return serverCerts[ i ]; } } } @@ -5007,8 +5007,8 @@ public void EvalPutCd(IHttpContext context, string aasid) } // datastructure update - if (this.Packages[findAasReturn.iPackage] == null || - this.Packages[findAasReturn.iPackage].AasEnv == null /*|| this.Packages[findAasReturn.iPackage].AasEnv.Assets == null*/) + if (this.Packages[ findAasReturn.iPackage ] == null || + this.Packages[ findAasReturn.iPackage ].AasEnv == null /*|| this.Packages[findAasReturn.iPackage].AasEnv.Assets == null*/) { context.Response.SendResponse(HttpStatusCode.InternalServerError, $"Error accessing internal data structures."); return; @@ -5016,10 +5016,10 @@ public void EvalPutCd(IHttpContext context, string aasid) // add Submodel context.Server.Logger.Debug($"Adding ConceptDescription with IdShort {cd.IdShort ?? "--"} and id {cd.Id?.ToString() ?? "--"}"); - var existingCd = this.Packages[findAasReturn.iPackage].AasEnv.FindConceptDescriptionById(cd.Id); + var existingCd = this.Packages[ findAasReturn.iPackage ].AasEnv.FindConceptDescriptionById(cd.Id); if (existingCd != null) - this.Packages[findAasReturn.iPackage].AasEnv.ConceptDescriptions.Remove(existingCd); - this.Packages[findAasReturn.iPackage].AasEnv.ConceptDescriptions.Add(cd); + this.Packages[ findAasReturn.iPackage ].AasEnv.ConceptDescriptions.Remove(existingCd); + this.Packages[ findAasReturn.iPackage ].AasEnv.ConceptDescriptions.Add(cd); // simple OK Program.signalNewData(2); diff --git a/src/AasxServerStandardBib/AasxRestServer.cs b/src/AasxServerStandardBib/AasxRestServer.cs index e1f14a67d..c13135a6c 100644 --- a/src/AasxServerStandardBib/AasxRestServer.cs +++ b/src/AasxServerStandardBib/AasxRestServer.cs @@ -56,7 +56,7 @@ static string translateURL(string url) return url; } - [RestResource] + [ RestResource ] public class TestResource { public static List listofRepositories = new List(); @@ -71,7 +71,7 @@ public static void initListOfRepositories() int aascount = AasxServer.Program.env.Length; for (int i = 0; i < aascount; i++) { - var env = AasxServer.Program.env[i]; + var env = AasxServer.Program.env[ i ]; if (env?.AasEnv?.AssetAdministrationShells == null) continue; @@ -106,8 +106,8 @@ public static void initListOfRepositories() } // query - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/queryregistry/([^/]+)(/|)$")] - [RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/queryregistry/(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/queryregistry/([^/]+)(/|)$") ] + [ RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/queryregistry/(/|)$") ] public IHttpContext Queryregistry(IHttpContext context) { allowCORS(context); @@ -186,20 +186,20 @@ private static bool comp(string op, string left, string right) right = right.Substring(1, rightlen - 2); right = right.Replace("><", " "); var split = right.Split(' '); - if (split.Count() == 3 && split[0] == "right") + if (split.Count() == 3 && split[ 0 ] == "right") { - if (left.Contains(split[1])) + if (left.Contains(split[ 1 ])) { - right = split[2]; + right = split[ 2 ]; rightlen = right.Length; - int found = left.IndexOf(split[1]); - found += split[1].Length; + int found = left.IndexOf(split[ 1 ]); + found += split[ 1 ].Length; string l = ""; - while (char.IsWhiteSpace(left[found]) && found < leftlen - 1) + while (char.IsWhiteSpace(left[ found ]) && found < leftlen - 1) found++; - while (char.IsDigit(left[found]) && found < leftlen - 1) + while (char.IsDigit(left[ found ]) && found < leftlen - 1) { - l += left[found]; + l += left[ found ]; found++; } @@ -366,19 +366,19 @@ public static string runQueryRegistryOnly(string query, string restPayload, Subm error = true; else { - if (split[0] != "SELECT:") + if (split[ 0 ] != "SELECT:") error = true; // if (split[1] != "aas" && split[1] != "submodel") // error = true; - if (split[2] != "FROM:") + if (split[ 2 ] != "FROM:") error = true; - if (split[3] != "registry") + if (split[ 3 ] != "registry") error = true; - if (split[4] != "WHERE:") + if (split[ 4 ] != "WHERE:") error = true; - if (split[5] != "submodelelement" && split[5] != "submodel" && split[5] != "aas") + if (split[ 5 ] != "submodelelement" && split[ 5 ] != "submodel" && split[ 5 ] != "aas") error = true; - if (split[6] != "AND" && split[6] != "OR") + if (split[ 6 ] != "AND" && split[ 6 ] != "OR") error = true; } @@ -399,9 +399,9 @@ public static string runQueryRegistryOnly(string query, string restPayload, Subm result += "registry endpoint " + AasxServer.Program.externalBlazor + "\n"; - var sSplit = split[1].Split(' '); - string select = sSplit[0]; - string selectParameters = split[1].Substring(select.Length); + var sSplit = split[ 1 ].Split(' '); + string select = sSplit[ 0 ]; + string selectParameters = split[ 1 ].Substring(select.Length); string whereAasCondition = ""; string whereSmCondition = ""; string whereSmeCondition = ""; @@ -409,25 +409,25 @@ public static string runQueryRegistryOnly(string query, string restPayload, Subm List whereSmOperations = new List(); List whereSmeOperations = new List(); - if (split[5] == "aas") + if (split[ 5 ] == "aas") { - whereAasCondition = split[6].ToLower(); + whereAasCondition = split[ 6 ].ToLower(); for (int i = 7; i < split.Length; i++) - whereAasOperations.Add(split[i]); + whereAasOperations.Add(split[ i ]); } - if (split[5] == "submodel") + if (split[ 5 ] == "submodel") { - whereSmCondition = split[6].ToLower(); + whereSmCondition = split[ 6 ].ToLower(); for (int i = 7; i < split.Length; i++) - whereSmOperations.Add(split[i]); + whereSmOperations.Add(split[ i ]); } - if (split[5] == "submodelelement") + if (split[ 5 ] == "submodelelement") { - whereSmeCondition = split[6].ToLower(); + whereSmeCondition = split[ 6 ].ToLower(); for (int i = 7; i < split.Length; i++) - whereSmeOperations.Add(split[i]); + whereSmeOperations.Add(split[ i ]); } int totalFound = 0; @@ -491,9 +491,9 @@ public static string runQueryRegistryOnly(string query, string restPayload, Subm split = wo.Split(' '); if (split.Length == 3) { - attr = split[0]; - op = split[1]; - attrValue = split[2].Replace("\"", ""); + attr = split[ 0 ]; + op = split[ 1 ]; + attrValue = split[ 2 ].Replace("\"", ""); } string compare = ""; @@ -595,9 +595,9 @@ public static string runQueryRegistryOnly(string query, string restPayload, Subm split = wo.Split(' '); if (split.Length == 3) { - attr = split[0]; - op = split[1]; - attrValue = split[2].Replace("\"", ""); + attr = split[ 0 ]; + op = split[ 1 ]; + attrValue = split[ 2 ].Replace("\"", ""); } string compare = ""; @@ -648,7 +648,7 @@ public static string runQueryRegistryOnly(string query, string restPayload, Subm { while (iLevel < level.Count) { - var sme = level[iLevel]; + var sme = level[ iLevel ]; int conditionsTrue = 0; foreach (var wo in whereSmeOperations) @@ -659,9 +659,9 @@ public static string runQueryRegistryOnly(string query, string restPayload, Subm split = wo.Split(' '); if (split.Length == 3) { - attr = split[0]; - op = split[1]; - attrValue = split[2].Replace("\"", ""); + attr = split[ 0 ]; + op = split[ 1 ]; + attrValue = split[ 2 ].Replace("\"", ""); } string compare = ""; @@ -676,7 +676,7 @@ public static string runQueryRegistryOnly(string query, string restPayload, Subm break; case "%semanticid": if (sme.SemanticId != null && sme.SemanticId.Keys != null && sme.SemanticId.Keys.Count != 0) - compare = sme.SemanticId.Keys[0].Value; + compare = sme.SemanticId.Keys[ 0 ].Value; break; } @@ -713,8 +713,8 @@ public static string runQueryRegistryOnly(string query, string restPayload, Subm { for (int iMlp = 0; iMlp < mlp.Value.Count; iMlp++) { - result += " [" + mlp.Value[iMlp].Language + "]" + - mlp.Value[iMlp].Text; + result += " [" + mlp.Value[ iMlp ].Language + "]" + + mlp.Value[ iMlp ].Text; } } } @@ -730,7 +730,7 @@ public static string runQueryRegistryOnly(string query, string restPayload, Subm depth++; string smcSemanticId = ""; if (smc2.SemanticId != null && smc2.SemanticId.Keys != null && smc2.SemanticId.Keys.Count != 0) - smcSemanticId = smc2.SemanticId.Keys[0].Value; + smcSemanticId = smc2.SemanticId.Keys[ 0 ].Value; level = smc2.Value; iLevel = 0; continue; @@ -742,9 +742,9 @@ public static string runQueryRegistryOnly(string query, string restPayload, Subm depth--; if (depth >= 0) { - level = stack[depth]; + level = stack[ depth ]; stack.RemoveAt(depth); - iLevel = iStack[depth]; + iLevel = iStack[ depth ]; iStack.RemoveAt(depth); } } @@ -949,16 +949,16 @@ public static string runQuery(string query, string restPayload) { case "select:": var sSplit = s.Split(' '); - select = sSplit[0]; + select = sSplit[ 0 ]; selectParameters = s.Substring(select.Length); break; case "from:": var fromsplit = sp.Split(' '); - from = fromsplit[0].ToLower(); + from = fromsplit[ 0 ].ToLower(); if (from == "aas" || from == "submodel") { if (fromsplit.Length == 2) - fromId = fromsplit[1].Replace("\"", ""); + fromId = fromsplit[ 1 ].Replace("\"", ""); } break; @@ -1046,7 +1046,7 @@ public static string runQuery(string query, string restPayload) for (int i = 0; i < aascount; i++) { int foundInAas = 0; - var env = AasxServer.Program.env[i]; + var env = AasxServer.Program.env[ i ]; if (env?.AasEnv?.AssetAdministrationShells == null) continue; @@ -1078,9 +1078,9 @@ public static string runQuery(string query, string restPayload) split = wo.Split(' '); if (split.Length == 3) { - attr = split[0]; - op = split[1]; - attrValue = split[2]; + attr = split[ 0 ]; + op = split[ 1 ]; + attrValue = split[ 2 ]; } string compare = ""; @@ -1170,7 +1170,7 @@ public static string runQuery(string query, string restPayload) string smSemanticId = ""; if (sm.SemanticId != null && sm.SemanticId.Keys != null && sm.SemanticId.Keys.Count != 0) - smSemanticId = sm.SemanticId.Keys[0].Value; + smSemanticId = sm.SemanticId.Keys[ 0 ].Value; int foundInSubmodel = 0; if (whereSmCondition != "" && accessSubmodel) @@ -1184,9 +1184,9 @@ public static string runQuery(string query, string restPayload) split = wo.Split(' '); if (split.Length == 3) { - attr = split[0]; - op = split[1]; - attrValue = split[2]; + attr = split[ 0 ]; + op = split[ 1 ]; + attrValue = split[ 2 ]; string compare = ""; switch (attr) @@ -1200,7 +1200,7 @@ public static string runQuery(string query, string restPayload) case "%semanticid": compare = ""; if (sm.SemanticId != null && sm.SemanticId.Keys != null && sm.SemanticId.Keys.Count != 0) - compare = sm.SemanticId.Keys[0].Value; + compare = sm.SemanticId.Keys[ 0 ].Value; break; } @@ -1275,7 +1275,7 @@ public static string runQuery(string query, string restPayload) { while (iLevel < level.Count) { - var sme = level[iLevel]; + var sme = level[ iLevel ]; // check, if access to submodelelement is allowed string _path = sm.IdShort + "."; @@ -1298,9 +1298,9 @@ public static string runQuery(string query, string restPayload) split = wo.Split(' '); if (split.Length == 3) { - attr = split[0]; - op = split[1]; - attrValue = split[2]; + attr = split[ 0 ]; + op = split[ 1 ]; + attrValue = split[ 2 ]; } string compare = ""; @@ -1315,7 +1315,7 @@ public static string runQuery(string query, string restPayload) break; case "%semanticid": if (sme.SemanticId != null && sme.SemanticId.Keys != null && sme.SemanticId.Keys.Count != 0) - compare = sme.SemanticId.Keys[0].Value; + compare = sme.SemanticId.Keys[ 0 ].Value; break; case "%path": attrValue = attrValue.Replace(".", "/"); @@ -1378,8 +1378,8 @@ public static string runQuery(string query, string restPayload) { for (int iMlp = 0; iMlp < mlp.Value.Count; iMlp++) { - result += " [" + mlp.Value[iMlp].Language + "]" + - mlp.Value[iMlp].Text; + result += " [" + mlp.Value[ iMlp ].Language + "]" + + mlp.Value[ iMlp ].Text; } } } @@ -1388,7 +1388,7 @@ public static string runQuery(string query, string restPayload) if (selectParameters.Contains("%semanticid")) { if (sme.SemanticId != null && sme.SemanticId.Keys != null && sme.SemanticId.Keys.Count != 0) - result += " " + sme.SemanticId.Keys[0].Value; + result += " " + sme.SemanticId.Keys[ 0 ].Value; } if (selectParameters.Contains("%path")) @@ -1443,7 +1443,7 @@ public static string runQuery(string query, string restPayload) path += smc.IdShort + "/"; string smcSemanticId = ""; if (smc.SemanticId != null && smc.SemanticId.Keys != null && smc.SemanticId.Keys.Count != 0) - smcSemanticId = smc.SemanticId.Keys[0].Value; + smcSemanticId = smc.SemanticId.Keys[ 0 ].Value; semanticIdPath += smcSemanticId + "."; level = smc.Value; iLevel = 0; @@ -1456,13 +1456,13 @@ public static string runQuery(string query, string restPayload) depth--; if (depth >= 0) { - level = stack[depth]; + level = stack[ depth ]; stack.RemoveAt(depth); - iLevel = iStack[depth]; + iLevel = iStack[ depth ]; iStack.RemoveAt(depth); - path = pathStack[depth]; + path = pathStack[ depth ]; pathStack.RemoveAt(depth); - semanticIdPath = semanticIdPathStack[depth]; + semanticIdPath = semanticIdPathStack[ depth ]; semanticIdPathStack.RemoveAt(depth); } } @@ -1492,7 +1492,7 @@ public static string runQuery(string query, string restPayload) if (selectParameters.Contains("%semanticid")) { if (sm.SemanticId != null && sm.SemanticId.Keys != null && sm.SemanticId.Keys.Count != 0) - result += " " + sm.SemanticId.Keys[0].Value; + result += " " + sm.SemanticId.Keys[ 0 ].Value; } result += "\n"; @@ -1572,7 +1572,7 @@ public static string runQuery(string query, string restPayload) { int foundInAas = 0; - var aasDB = aasDBList[i]; + var aasDB = aasDBList[ i ]; AssetAdministrationShell aas = new AssetAdministrationShell( id: aasDB.AasId, idShort: aasDB.Idshort, @@ -1606,9 +1606,9 @@ public static string runQuery(string query, string restPayload) split = wo.Split(' '); if (split.Length == 3) { - attr = split[0]; - op = split[1]; - attrValue = split[2]; + attr = split[ 0 ]; + op = split[ 1 ]; + attrValue = split[ 2 ]; } string compare = ""; @@ -1697,7 +1697,7 @@ public static string runQuery(string query, string restPayload) string smSemanticId = ""; if (sm.SemanticId != null && sm.SemanticId.Keys != null && sm.SemanticId.Keys.Count != 0) - smSemanticId = sm.SemanticId.Keys[0].Value; + smSemanticId = sm.SemanticId.Keys[ 0 ].Value; int foundInSubmodel = 0; if (whereSmCondition != "" && accessSubmodel) @@ -1711,9 +1711,9 @@ public static string runQuery(string query, string restPayload) split = wo.Split(' '); if (split.Length == 3) { - attr = split[0]; - op = split[1]; - attrValue = split[2]; + attr = split[ 0 ]; + op = split[ 1 ]; + attrValue = split[ 2 ]; string compare = ""; switch (attr) @@ -1727,7 +1727,7 @@ public static string runQuery(string query, string restPayload) case "%semanticid": compare = ""; if (sm.SemanticId != null && sm.SemanticId.Keys != null && sm.SemanticId.Keys.Count != 0) - compare = sm.SemanticId.Keys[0].Value; + compare = sm.SemanticId.Keys[ 0 ].Value; break; } @@ -1802,7 +1802,7 @@ public static string runQuery(string query, string restPayload) { while (iLevel < level.Count) { - var sme = level[iLevel]; + var sme = level[ iLevel ]; // check, if access to submodelelement is allowed string _path = sm.IdShort + "."; @@ -1825,9 +1825,9 @@ public static string runQuery(string query, string restPayload) split = wo.Split(' '); if (split.Length == 3) { - attr = split[0]; - op = split[1]; - attrValue = split[2]; + attr = split[ 0 ]; + op = split[ 1 ]; + attrValue = split[ 2 ]; } string compare = ""; @@ -1842,7 +1842,7 @@ public static string runQuery(string query, string restPayload) break; case "%semanticid": if (sme.SemanticId != null && sme.SemanticId.Keys != null && sme.SemanticId.Keys.Count != 0) - compare = sme.SemanticId.Keys[0].Value; + compare = sme.SemanticId.Keys[ 0 ].Value; break; case "%path": attrValue = attrValue.Replace(".", "/"); @@ -1905,8 +1905,8 @@ public static string runQuery(string query, string restPayload) { for (int iMlp = 0; iMlp < mlp.Value.Count; iMlp++) { - result += " [" + mlp.Value[iMlp].Language + "]" + - mlp.Value[iMlp].Text; + result += " [" + mlp.Value[ iMlp ].Language + "]" + + mlp.Value[ iMlp ].Text; } } } @@ -1915,7 +1915,7 @@ public static string runQuery(string query, string restPayload) if (selectParameters.Contains("%semanticid")) { if (sme.SemanticId != null && sme.SemanticId.Keys != null && sme.SemanticId.Keys.Count != 0) - result += " " + sme.SemanticId.Keys[0].Value; + result += " " + sme.SemanticId.Keys[ 0 ].Value; } if (selectParameters.Contains("%path")) @@ -1970,7 +1970,7 @@ public static string runQuery(string query, string restPayload) path += smc.IdShort + "/"; string smcSemanticId = ""; if (smc.SemanticId != null && smc.SemanticId.Keys != null && smc.SemanticId.Keys.Count != 0) - smcSemanticId = smc.SemanticId.Keys[0].Value; + smcSemanticId = smc.SemanticId.Keys[ 0 ].Value; semanticIdPath += smcSemanticId + "."; level = smc.Value; iLevel = 0; @@ -1983,13 +1983,13 @@ public static string runQuery(string query, string restPayload) depth--; if (depth >= 0) { - level = stack[depth]; + level = stack[ depth ]; stack.RemoveAt(depth); - iLevel = iStack[depth]; + iLevel = iStack[ depth ]; iStack.RemoveAt(depth); - path = pathStack[depth]; + path = pathStack[ depth ]; pathStack.RemoveAt(depth); - semanticIdPath = semanticIdPathStack[depth]; + semanticIdPath = semanticIdPathStack[ depth ]; semanticIdPathStack.RemoveAt(depth); } } @@ -2019,7 +2019,7 @@ public static string runQuery(string query, string restPayload) if (selectParameters.Contains("%semanticid")) { if (sm.SemanticId != null && sm.SemanticId.Keys != null && sm.SemanticId.Keys.Count != 0) - result += " " + sm.SemanticId.Keys[0].Value; + result += " " + sm.SemanticId.Keys[ 0 ].Value; } result += "\n"; @@ -2091,8 +2091,8 @@ public static string runQuery(string query, string restPayload) } // query - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/query/([^/]+)(/|)$")] - [RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/query/(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/query/([^/]+)(/|)$") ] + [ RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/query/(/|)$") ] public IHttpContext Query(IHttpContext context) { allowCORS(context); @@ -2111,8 +2111,8 @@ public IHttpContext Query(IHttpContext context) } // exit application - [RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/exit/([^/]+)(/|)$")] - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/exit/([^/]+)(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/exit/([^/]+)(/|)$") ] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/exit/([^/]+)(/|)$") ] public IHttpContext Exit(IHttpContext context) { string restPath = context.Request.PathInfo; @@ -2151,8 +2151,8 @@ public IHttpContext Exit(IHttpContext context) } // set secret string to write to API - [RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/secret/([^/]+)/([^/]+)(/|)$")] - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/secret/([^/]+)/([^/]+)(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/secret/([^/]+)/([^/]+)(/|)$") ] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/secret/([^/]+)/([^/]+)(/|)$") ] public IHttpContext Secret(IHttpContext context) { string requestSecret1 = null; @@ -2165,8 +2165,8 @@ public IHttpContext Secret(IHttpContext context) string[] split = restPath.Split('/'); if (split.Count() == 2) { - requestSecret1 = split[0]; - requestSecret2 = split[1]; + requestSecret1 = split[ 0 ]; + requestSecret2 = split[ 1 ]; } if (System.IO.File.Exists("SECRET.DAT")) @@ -2231,7 +2231,7 @@ void sendJson(IHttpContext context, object o) context.Response.SendResponse(buffer); } - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/data4(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/data4(/|)$") ] public IHttpContext GetData4(IHttpContext context) { varInt1++; @@ -2330,9 +2330,9 @@ public static void add(IReferable o, string op, ISubmodel rootSubmodel, ulong ch o.IdShort = path; */ deletedList.Add(new DeletedListItem() {sm = rootSubmodel, rf = o}); - if (deletedList.Count > 1000 && deletedList[0].rf != null) + if (deletedList.Count > 1000 && deletedList[ 0 ].rf != null) { - olderDeletedTimeStamp = deletedList[0].rf.TimeStamp; + olderDeletedTimeStamp = deletedList[ 0 ].rf.TimeStamp; deletedList.RemoveAt(0); } } @@ -2342,7 +2342,7 @@ public static void add(IReferable o, string op, ISubmodel rootSubmodel, ulong ch public static string posttimeseriesPayload = ""; - [RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/posttimeseries(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/posttimeseries(/|)$") ] public IHttpContext posttimeseries(IHttpContext context) { Console.WriteLine("posttimeseries:"); @@ -2356,7 +2356,7 @@ public IHttpContext posttimeseries(IHttpContext context) return context; } - [RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/calculatecfp/aas/([^/]+)(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/calculatecfp/aas/([^/]+)(/|)$") ] public IHttpContext calculatecfp(IHttpContext context) { string restPath = context.Request.PathInfo; @@ -2367,11 +2367,11 @@ public IHttpContext calculatecfp(IHttpContext context) { // specific AAS string[] split = restPath.Split('/'); - if (split[2] == "aas") + if (split[ 2 ] == "aas") { try { - if (!int.TryParse(split[3], out aasIndex)) + if (!int.TryParse(split[ 3 ], out aasIndex)) aasIndex = -1; if (aasIndex >= 0) { @@ -2397,18 +2397,18 @@ public IHttpContext calculatecfp(IHttpContext context) private static bool _setAllParentsExecuted = false; - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/geteventmessages(/|)$")] - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/geteventmessages/values(/|)$")] - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/geteventmessages/time/([^/]+)(/|)$")] - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/geteventmessages/deltasecs/(\\d+)(/|)$")] - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/geteventmessages/aas/([^/]+)(/|)$")] - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/geteventmessages/aas/([^/]+)/values(/|)$")] - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/geteventmessages/aas/([^/]+)/time/([^/]+)(/|)$")] - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/geteventmessages/aas/([^/]+)/deltasecs/(\\d+)(/|)$")] - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/aas/([^/]+)/geteventmessages(/|)$")] - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/aas/([^/]+)/geteventmessages/values(/|)$")] - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/aas/([^/]+)/geteventmessages/time/([^/]+)(/|)$")] - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/aas/([^/]+)/geteventmessages/deltasecs/(\\d+)(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/geteventmessages(/|)$") ] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/geteventmessages/values(/|)$") ] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/geteventmessages/time/([^/]+)(/|)$") ] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/geteventmessages/deltasecs/(\\d+)(/|)$") ] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/geteventmessages/aas/([^/]+)(/|)$") ] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/geteventmessages/aas/([^/]+)/values(/|)$") ] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/geteventmessages/aas/([^/]+)/time/([^/]+)(/|)$") ] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/geteventmessages/aas/([^/]+)/deltasecs/(\\d+)(/|)$") ] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/aas/([^/]+)/geteventmessages(/|)$") ] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/aas/([^/]+)/geteventmessages/values(/|)$") ] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/aas/([^/]+)/geteventmessages/time/([^/]+)(/|)$") ] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/aas/([^/]+)/geteventmessages/deltasecs/(\\d+)(/|)$") ] public IHttpContext GetEventMessages(IHttpContext context) { // @@ -2425,11 +2425,11 @@ public IHttpContext GetEventMessages(IHttpContext context) { // specific AAS string[] split = restPath.Split('/'); - if (split[2] == "aas") + if (split[ 2 ] == "aas") { try { - if (!int.TryParse(split[3], out aasIndex)) + if (!int.TryParse(split[ 3 ], out aasIndex)) aasIndex = -1; if (aasIndex >= 0) { @@ -2438,7 +2438,7 @@ public IHttpContext GetEventMessages(IHttpContext context) { if (i != 2 && i != 3) { - restPath += "/" + split[i]; + restPath += "/" + split[ i ]; } } } @@ -2448,11 +2448,11 @@ public IHttpContext GetEventMessages(IHttpContext context) } } - if (split[1] == "aas") + if (split[ 1 ] == "aas") { try { - if (!int.TryParse(split[2], out aasIndex)) + if (!int.TryParse(split[ 2 ], out aasIndex)) aasIndex = -1; if (aasIndex >= 0) { @@ -2461,7 +2461,7 @@ public IHttpContext GetEventMessages(IHttpContext context) { if (i != 1 && i != 2) { - restPath += "/" + split[i]; + restPath += "/" + split[ i ]; } } } @@ -2537,7 +2537,7 @@ public IHttpContext GetEventMessages(IHttpContext context) if (aasIndex >= 0 && i != aasIndex) continue; - var env = AasxServer.Program.env[i]; + var env = AasxServer.Program.env[ i ]; if (env?.AasEnv?.AssetAdministrationShells == null) continue; @@ -2768,7 +2768,7 @@ static void GetEventMsgRecurseDiff( int i = 0; while (i < smec.Value.Count) { - var sme2 = smec.Value[i]; + var sme2 = smec.Value[ i ]; if (sme2.TimeStamp != smec.TimeStamp) { deeper = true; @@ -2786,7 +2786,7 @@ static void GetEventMsgRecurseDiff( int i = 0; while (i < smec.Value.Count) { - var sme2 = smec.Value[i]; + var sme2 = smec.Value[ i ]; GetEventMsgRecurseDiff( mode, plStruct, plUpdate, @@ -2848,7 +2848,7 @@ public static void SendJsonResponse(Grapevine.Interfaces.Server.IHttpContext con var length = buffer.Length; var queryString = context.Request.QueryString; - string refresh = queryString["refresh"]; + string refresh = queryString[ "refresh" ]; if (refresh != null && refresh != "") { context.Response.Headers.Remove("Refresh"); @@ -2931,22 +2931,22 @@ private static void addEntry(bool diffJson, ref string diffText, ref List= 0) { @@ -3043,7 +3043,7 @@ public IHttpContext GetDiff(IHttpContext context) { if (i != 2 && i != 3) { - restPath += "/" + split[i]; + restPath += "/" + split[ i ]; } } } @@ -3063,7 +3063,7 @@ public IHttpContext GetDiff(IHttpContext context) for (int imode = 0; imode < modes.Length; imode++) { - string mode = modes[imode]; + string mode = modes[ imode ]; if (mode == "DELETE") { @@ -3104,10 +3104,10 @@ public IHttpContext GetDiff(IHttpContext context) if (aasIndex >= 0 && i != aasIndex) continue; - var env = AasxServer.Program.env[i]; + var env = AasxServer.Program.env[ i ]; if (env != null) { - var aas = env.AasEnv.AssetAdministrationShells[0]; + var aas = env.AasEnv.AssetAdministrationShells[ 0 ]; if (aas.Submodels != null && aas.Submodels.Count > 0) { DateTime diffTimeStamp = new(); @@ -3255,7 +3255,7 @@ static void checkDiff(bool diffJson, ref string diffText, ref List di // get authserver - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/authserver(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/authserver(/|)$") ] public IHttpContext GetAuthserver(IHttpContext context) { var txt = AasxServer.Program.redirectServer; @@ -3269,7 +3269,7 @@ public IHttpContext GetAuthserver(IHttpContext context) } // Basic AAS + Asset - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/aas/(id|([^/]+))(|/core|/complete|/thumbnail|/aasenv|/aasenvjson)(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/aas/(id|([^/]+))(|/core|/complete|/thumbnail|/aasenv|/aasenvjson)(/|)$") ] public IHttpContext GetAasAndAsset(IHttpContext context) { if (context.Request.PathInfo.Contains("geteventmessages")) @@ -3282,55 +3282,55 @@ public IHttpContext GetAasAndAsset(IHttpContext context) { if (helper.PathEndsWith(context, "thumbnail")) { - helper.EvalGetAasThumbnail(context, m.Groups[1].ToString()); + helper.EvalGetAasThumbnail(context, m.Groups[ 1 ].ToString()); } else if (helper.PathEndsWith(context, "aasenv") || helper.PathEndsWith(context, "aasenvjson")) { - helper.EvalGetAasEnv(context, m.Groups[1].ToString()); + helper.EvalGetAasEnv(context, m.Groups[ 1 ].ToString()); } else { var complete = helper.PathEndsWith(context, "complete"); - helper.EvalGetAasAndAsset(context, m.Groups[1].ToString(), complete: complete); + helper.EvalGetAasAndAsset(context, m.Groups[ 1 ].ToString(), complete: complete); } } return context; } - [RestRoute(HttpMethod = HttpMethod.PUT, PathInfo = "^/aas(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.PUT, PathInfo = "^/aas(/|)$") ] public IHttpContext PutAas(IHttpContext context) { helper.EvalPutAas(context); return context; } - [RestRoute(HttpMethod = HttpMethod.PUT, PathInfo = "^/aasx/server(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.PUT, PathInfo = "^/aasx/server(/|)$") ] public IHttpContext PutAasxOnServer(IHttpContext context) { helper.EvalPutAasxOnServer(context); return context; } - [RestRoute(HttpMethod = HttpMethod.PUT, PathInfo = "^/aasx/filesystem/([^/]+)(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.PUT, PathInfo = "^/aasx/filesystem/([^/]+)(/|)$") ] public IHttpContext PutAasxToFileSystem(IHttpContext context) { var m = helper.PathInfoRegexMatch(MethodBase.GetCurrentMethod(), context.Request.PathInfo); if (m.Success && m.Groups.Count >= 2) { - helper.EvalPutAasxToFilesystem(context, m.Groups[1].ToString()); + helper.EvalPutAasxToFilesystem(context, m.Groups[ 1 ].ToString()); } return context; } - [RestRoute(HttpMethod = HttpMethod.DELETE, PathInfo = "^/aas/([^/]+)(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.DELETE, PathInfo = "^/aas/([^/]+)(/|)$") ] public IHttpContext DeleteAasAndAsset(IHttpContext context) { var m = helper.PathInfoRegexMatch(MethodBase.GetCurrentMethod(), context.Request.PathInfo); if (m.Success && m.Groups.Count >= 2) { - helper.EvalDeleteAasAndAsset(context, m.Groups[1].ToString(), deleteAsset: true); + helper.EvalDeleteAasAndAsset(context, m.Groups[ 1 ].ToString(), deleteAsset: true); } return context; @@ -3338,14 +3338,14 @@ public IHttpContext DeleteAasAndAsset(IHttpContext context) // Handles - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/handles/identification(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/handles/identification(/|)$") ] public IHttpContext GetHandlesIdentification(IHttpContext context) { helper.EvalGetHandlesIdentification(context); return context; } - [RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/handles/identification(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/handles/identification(/|)$") ] public IHttpContext PostHandlesIdentification(IHttpContext context) { helper.EvalPostHandlesIdentification(context); @@ -3354,7 +3354,7 @@ public IHttpContext PostHandlesIdentification(IHttpContext context) // Authenticate - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/authenticateGuest(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/authenticateGuest(/|)$") ] public IHttpContext GetAuthenticate(IHttpContext context) { helper.EvalGetAuthenticateGuest(context); @@ -3363,21 +3363,21 @@ public IHttpContext GetAuthenticate(IHttpContext context) // Authenticate User - [RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/authenticateUser(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/authenticateUser(/|)$") ] public IHttpContext PostAuthenticateUser(IHttpContext context) { helper.EvalPostAuthenticateUser(context); return context; } - [RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/authenticateCert1(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/authenticateCert1(/|)$") ] public IHttpContext PostAuthenticateCert1(IHttpContext context) { helper.EvalPostAuthenticateCert1(context); return context; } - [RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/authenticateCert2(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/authenticateCert2(/|)$") ] public IHttpContext PostAuthenticateCert2(IHttpContext context) { helper.EvalPostAuthenticateCert2(context); @@ -3386,7 +3386,7 @@ public IHttpContext PostAuthenticateCert2(IHttpContext context) // Server - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/server/profile(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/server/profile(/|)$") ] public IHttpContext GetServerProfile(IHttpContext context) { helper.EvalGetServerProfile(context); @@ -3394,8 +3394,8 @@ public IHttpContext GetServerProfile(IHttpContext context) } // OZ - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/server/listaas(/|)$")] - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/server/listasset(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/server/listaas(/|)$") ] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/server/listasset(/|)$") ] public IHttpContext GetServerAASX(IHttpContext context) { if (context.Request.PathInfo.Contains("listasset")) @@ -3410,32 +3410,32 @@ public IHttpContext GetServerAASX(IHttpContext context) return context; } - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = @"^/assetid/(\d+)(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = @"^/assetid/(\d+)(/|)$") ] public IHttpContext AssetId(IHttpContext context) { var m = helper.PathInfoRegexMatch(MethodBase.GetCurrentMethod(), context.Request.PathInfo); if (m.Success && m.Groups.Count >= 2) { - helper.EvalAssetId(context, Int32.Parse(m.Groups[1].ToString())); + helper.EvalAssetId(context, Int32.Parse(m.Groups[ 1 ].ToString())); } return context; } - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = @"^/server/getaasx/(\d+)(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = @"^/server/getaasx/(\d+)(/|)$") ] public IHttpContext GetAASX(IHttpContext context) { var m = helper.PathInfoRegexMatch(MethodBase.GetCurrentMethod(), context.Request.PathInfo); if (m.Success && m.Groups.Count >= 2) { - helper.EvalGetAASX(context, Int32.Parse(m.Groups[1].ToString())); + helper.EvalGetAASX(context, Int32.Parse(m.Groups[ 1 ].ToString())); return context; } return context; } - [RestRoute(HttpMethod = HttpMethod.PUT, PathInfo = @"^/server/getaasx/(\d+)(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.PUT, PathInfo = @"^/server/getaasx/(\d+)(/|)$") ] public IHttpContext PutAASX(IHttpContext context) { var m = helper.PathInfoRegexMatch(MethodBase.GetCurrentMethod(), context.Request.PathInfo); @@ -3458,7 +3458,7 @@ public IHttpContext PutAASX(IHttpContext context) else { // here goes the official code - helper.EvalPutAasxReplacePackage(context, m.Groups[1].ToString()); + helper.EvalPutAasxReplacePackage(context, m.Groups[ 1 ].ToString()); } return context; @@ -3467,40 +3467,40 @@ public IHttpContext PutAASX(IHttpContext context) return context; } - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = @"^/server/getaasxbyassetid/([^/]+)(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = @"^/server/getaasxbyassetid/([^/]+)(/|)$") ] public IHttpContext GetAASX2ByAssetId(IHttpContext context) { helper.EvalGetAasxByAssetId(context); return context; } - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = @"^/server/getaasx2/(\d+)(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = @"^/server/getaasx2/(\d+)(/|)$") ] public IHttpContext GetAASX2(IHttpContext context) { var m = helper.PathInfoRegexMatch(MethodBase.GetCurrentMethod(), context.Request.PathInfo); if (m.Success && m.Groups.Count >= 2) { - helper.EvalGetAASX2(context, Int32.Parse(m.Groups[1].ToString())); + helper.EvalGetAASX2(context, Int32.Parse(m.Groups[ 1 ].ToString())); return context; } return context; } - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = @"^/server/getfile/(\d+)/(([^/]+)/){0,99}([^/]+)$")] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = @"^/server/getfile/(\d+)/(([^/]+)/){0,99}([^/]+)$") ] public IHttpContext GetFile(IHttpContext context) { int index = -1; string path = ""; string[] split = context.Request.PathInfo.Split(new Char[] {'/'}); - if (split[1].ToLower() == "server" && split[2].ToLower() == "getfile") + if (split[ 1 ].ToLower() == "server" && split[ 2 ].ToLower() == "getfile") { - index = Int32.Parse(split[3]); + index = Int32.Parse(split[ 3 ]); int i = 4; while (i < split.Length) { - path += "/" + split[i]; + path += "/" + split[ i ]; i++; } } @@ -3512,32 +3512,32 @@ public IHttpContext GetFile(IHttpContext context) // Assets - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/assets/([^/]+)(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/assets/([^/]+)(/|)$") ] public IHttpContext GetAssets(IHttpContext context) { var m = helper.PathInfoRegexMatch(MethodBase.GetCurrentMethod(), context.Request.PathInfo); if (m.Success && m.Groups.Count >= 2) { - helper.EvalGetAssetLinks(context, m.Groups[1].ToString()); + helper.EvalGetAssetLinks(context, m.Groups[ 1 ].ToString()); } return context; } - [RestRoute(HttpMethod = HttpMethod.PUT, PathInfo = "^/assets(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.PUT, PathInfo = "^/assets(/|)$") ] public IHttpContext PutAssets(IHttpContext context) { helper.EvalPutAsset(context); return context; } - [RestRoute(HttpMethod = HttpMethod.PUT, PathInfo = "^/aas/(id|([^/]+))/asset(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.PUT, PathInfo = "^/aas/(id|([^/]+))/asset(/|)$") ] public IHttpContext PutAssetsToAas(IHttpContext context) { var m = helper.PathInfoRegexMatch(MethodBase.GetCurrentMethod(), context.Request.PathInfo); if (m.Success && m.Groups.Count >= 2) { - helper.EvalPutAssetToAas(context, m.Groups[1].ToString()); + helper.EvalPutAssetToAas(context, m.Groups[ 1 ].ToString()); } return context; @@ -3545,37 +3545,37 @@ public IHttpContext PutAssetsToAas(IHttpContext context) // List of Submodels - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/aas/(id|([^/]+))/submodels(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/aas/(id|([^/]+))/submodels(/|)$") ] public IHttpContext GetSubmodels(IHttpContext context) { var m = helper.PathInfoRegexMatch(MethodBase.GetCurrentMethod(), context.Request.PathInfo); if (m.Success && m.Groups.Count >= 2) { - helper.EvalGetSubmodels(context, m.Groups[1].ToString()); + helper.EvalGetSubmodels(context, m.Groups[ 1 ].ToString()); } return context; } - [RestRoute(HttpMethod = HttpMethod.PUT, PathInfo = "^/aas/(id|([^/]+))/submodels(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.PUT, PathInfo = "^/aas/(id|([^/]+))/submodels(/|)$") ] public IHttpContext PutSubmodel(IHttpContext context) { var m = helper.PathInfoRegexMatch(MethodBase.GetCurrentMethod(), context.Request.PathInfo); if (m.Success && m.Groups.Count >= 2) { - helper.EvalPutSubmodel(context, m.Groups[1].ToString()); + helper.EvalPutSubmodel(context, m.Groups[ 1 ].ToString()); } return context; } - [RestRoute(HttpMethod = HttpMethod.DELETE, PathInfo = "^/aas/(id|([^/]+))/submodels/([^/]+)(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.DELETE, PathInfo = "^/aas/(id|([^/]+))/submodels/([^/]+)(/|)$") ] public IHttpContext DeleteSubmodel(IHttpContext context) { var m = helper.PathInfoRegexMatch(MethodBase.GetCurrentMethod(), context.Request.PathInfo); if (m.Success && m.Groups.Count >= 4) { - helper.EvalDeleteSubmodel(context, m.Groups[1].ToString(), m.Groups[3].ToString()); + helper.EvalDeleteSubmodel(context, m.Groups[ 1 ].ToString(), m.Groups[ 3 ].ToString()); } return context; @@ -3583,14 +3583,14 @@ public IHttpContext DeleteSubmodel(IHttpContext context) // Contents of a Submodel - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/aas/(id|([^/]+))/submodels/([^/]+)(|/core|/deep|/complete|/values)(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/aas/(id|([^/]+))/submodels/([^/]+)(|/core|/deep|/complete|/values)(/|)$") ] public IHttpContext GetSubmodelContents(IHttpContext context) { var m = helper.PathInfoRegexMatch(MethodBase.GetCurrentMethod(), context.Request.PathInfo); if (m.Success && m.Groups.Count >= 4) { - var aasid = m.Groups[1].ToString(); - var smid = m.Groups[3].ToString(); + var aasid = m.Groups[ 1 ].ToString(); + var smid = m.Groups[ 3 ].ToString(); if (helper.PathEndsWith(context, "values")) { @@ -3607,13 +3607,13 @@ public IHttpContext GetSubmodelContents(IHttpContext context) return context; } - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/aas/(id|([^/]+))/submodels/([^/]+)/table(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/aas/(id|([^/]+))/submodels/([^/]+)/table(/|)$") ] public IHttpContext GetSubmodelContentsAsTable(IHttpContext context) { var m = helper.PathInfoRegexMatch(MethodBase.GetCurrentMethod(), context.Request.PathInfo); if (m.Success && m.Groups.Count >= 4) { - helper.EvalGetSubmodelContentsAsTable(context, m.Groups[1].ToString(), m.Groups[3].ToString()); + helper.EvalGetSubmodelContentsAsTable(context, m.Groups[ 1 ].ToString(), m.Groups[ 3 ].ToString()); } return context; @@ -3621,21 +3621,21 @@ public IHttpContext GetSubmodelContentsAsTable(IHttpContext context) // Contents of SubmodelElements - [RestRoute(HttpMethod = HttpMethod.GET, + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = - "^/aas/(id|([^/]+))/submodels/([^/]+)/submodel/submodelElements(/([^/]+)){1,99}?(|/core|/complete|/deep|/file|/blob|/events|/values/value)(/|)$")] // BaSyx-Style - [RestRoute(HttpMethod = HttpMethod.GET, - PathInfo = "^/aas/(id|([^/]+))/submodels/([^/]+)/elements(/([^/]+)){1,99}?(|/core|/complete|/deep|/file|/blob|/events|/values|/value)(/|)$")] + "^/aas/(id|([^/]+))/submodels/([^/]+)/submodel/submodelElements(/([^/]+)){1,99}?(|/core|/complete|/deep|/file|/blob|/events|/values/value)(/|)$") ] // BaSyx-Style + [ RestRoute(HttpMethod = HttpMethod.GET, + PathInfo = "^/aas/(id|([^/]+))/submodels/([^/]+)/elements(/([^/]+)){1,99}?(|/core|/complete|/deep|/file|/blob|/events|/values|/value)(/|)$") ] public IHttpContext GetSubmodelElementsContents(IHttpContext context) { var m = helper.PathInfoRegexMatch(MethodBase.GetCurrentMethod(), context.Request.PathInfo.Replace("submodel/submodelElements", "elements")); - if (m.Success && m.Groups.Count >= 6 && m.Groups[5].Captures != null && m.Groups[5].Captures.Count >= 1) + if (m.Success && m.Groups.Count >= 6 && m.Groups[ 5 ].Captures != null && m.Groups[ 5 ].Captures.Count >= 1) { - var aasid = m.Groups[1].ToString(); - var smid = m.Groups[3].ToString(); + var aasid = m.Groups[ 1 ].ToString(); + var smid = m.Groups[ 3 ].ToString(); var elemids = new List(); - for (int i = 0; i < m.Groups[5].Captures.Count; i++) - elemids.Add(m.Groups[5].Captures[i].ToString()); + for (int i = 0; i < m.Groups[ 5 ].Captures.Count; i++) + elemids.Add(m.Groups[ 5 ].Captures[ i ].ToString()); // special case?? if (helper.PathEndsWith(context, "file")) @@ -3673,17 +3673,17 @@ public IHttpContext GetSubmodelElementsContents(IHttpContext context) return context; } - [RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/aas/(id|([^/]+))/submodels/([^/]+)/elements(/([^/]+)){1,99}?/invoke(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "^/aas/(id|([^/]+))/submodels/([^/]+)/elements(/([^/]+)){1,99}?/invoke(/|)$") ] public IHttpContext PostSubmodelElementsContents(IHttpContext context) { var m = helper.PathInfoRegexMatch(MethodBase.GetCurrentMethod(), context.Request.PathInfo); - if (m.Success && m.Groups.Count >= 6 && m.Groups[5].Captures != null && m.Groups[5].Captures.Count >= 1) + if (m.Success && m.Groups.Count >= 6 && m.Groups[ 5 ].Captures != null && m.Groups[ 5 ].Captures.Count >= 1) { - var aasid = m.Groups[1].ToString(); - var smid = m.Groups[3].ToString(); + var aasid = m.Groups[ 1 ].ToString(); + var smid = m.Groups[ 3 ].ToString(); var elemids = new List(); - for (int i = 0; i < m.Groups[5].Captures.Count; i++) - elemids.Add(m.Groups[5].Captures[i].ToString()); + for (int i = 0; i < m.Groups[ 5 ].Captures.Count; i++) + elemids.Add(m.Groups[ 5 ].Captures[ i ].ToString()); // special case?? if (helper.PathEndsWith(context, "invoke")) @@ -3695,18 +3695,18 @@ public IHttpContext PostSubmodelElementsContents(IHttpContext context) return context; } - [RestRoute(HttpMethod = HttpMethod.PUT, PathInfo = "^/aas/(id|([^/]+))/submodels/([^/]+)/elements(/([^/]+)){0,99}?(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.PUT, PathInfo = "^/aas/(id|([^/]+))/submodels/([^/]+)/elements(/([^/]+)){0,99}?(/|)$") ] public IHttpContext PutSubmodelElementsContents(IHttpContext context) { var m = helper.PathInfoRegexMatch(MethodBase.GetCurrentMethod(), context.Request.PathInfo); if (m.Success && m.Groups.Count >= 6) { - var aasid = m.Groups[1].ToString(); - var smid = m.Groups[3].ToString(); + var aasid = m.Groups[ 1 ].ToString(); + var smid = m.Groups[ 3 ].ToString(); var elemids = new List(); - if (m.Groups[5].Captures != null) - for (int i = 0; i < m.Groups[5].Captures.Count; i++) - elemids.Add(m.Groups[5].Captures[i].ToString()); + if (m.Groups[ 5 ].Captures != null) + for (int i = 0; i < m.Groups[ 5 ].Captures.Count; i++) + elemids.Add(m.Groups[ 5 ].Captures[ i ].ToString()); helper.EvalPutSubmodelElementContents(context, aasid, smid, elemids.ToArray()); } @@ -3715,7 +3715,7 @@ public IHttpContext PutSubmodelElementsContents(IHttpContext context) } //An OPTIONS preflight call is made by browser before calling actual PUT - [RestRoute(HttpMethod = HttpMethod.OPTIONS, PathInfo = "^/aas/(id|([^/]+))/submodels/([^/]+)/elements(/([^/]+)){0,99}?(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.OPTIONS, PathInfo = "^/aas/(id|([^/]+))/submodels/([^/]+)/elements(/([^/]+)){0,99}?(/|)$") ] public IHttpContext OptionsSubmodelElementsContents(IHttpContext context) { SendJsonResponse(context, new Object()); //returning just an empty object @@ -3723,18 +3723,18 @@ public IHttpContext OptionsSubmodelElementsContents(IHttpContext context) } - [RestRoute(HttpMethod = HttpMethod.DELETE, PathInfo = "^/aas/(id|([^/]+))/submodels/([^/]+)/elements(/([^/]+)){0,99}?(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.DELETE, PathInfo = "^/aas/(id|([^/]+))/submodels/([^/]+)/elements(/([^/]+)){0,99}?(/|)$") ] public IHttpContext DeleteSubmodelElementsContents(IHttpContext context) { var m = helper.PathInfoRegexMatch(MethodBase.GetCurrentMethod(), context.Request.PathInfo); if (m.Success && m.Groups.Count >= 6) { - var aasid = m.Groups[1].ToString(); - var smid = m.Groups[3].ToString(); + var aasid = m.Groups[ 1 ].ToString(); + var smid = m.Groups[ 3 ].ToString(); var elemids = new List(); - if (m.Groups[5].Captures != null) - for (int i = 0; i < m.Groups[5].Captures.Count; i++) - elemids.Add(m.Groups[5].Captures[i].ToString()); + if (m.Groups[ 5 ].Captures != null) + for (int i = 0; i < m.Groups[ 5 ].Captures.Count; i++) + elemids.Add(m.Groups[ 5 ].Captures[ i ].ToString()); helper.EvalDeleteSubmodelElementContents(context, aasid, smid, elemids.ToArray()); } @@ -3744,49 +3744,49 @@ public IHttpContext DeleteSubmodelElementsContents(IHttpContext context) // concept descriptions - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/aas/(id|([^/]+))/cds(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/aas/(id|([^/]+))/cds(/|)$") ] public IHttpContext GetCds(IHttpContext context) { var m = helper.PathInfoRegexMatch(MethodBase.GetCurrentMethod(), context.Request.PathInfo); if (m.Success && m.Groups.Count >= 2) { - helper.EvalGetAllCds(context, m.Groups[1].ToString()); + helper.EvalGetAllCds(context, m.Groups[ 1 ].ToString()); } return context; } - [RestRoute(HttpMethod = HttpMethod.PUT, PathInfo = "^/aas/(id|([^/]+))/cds(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.PUT, PathInfo = "^/aas/(id|([^/]+))/cds(/|)$") ] public IHttpContext PutConceptDescription(IHttpContext context) { var m = helper.PathInfoRegexMatch(MethodBase.GetCurrentMethod(), context.Request.PathInfo); if (m.Success && m.Groups.Count >= 2) { - helper.EvalPutCd(context, m.Groups[1].ToString()); + helper.EvalPutCd(context, m.Groups[ 1 ].ToString()); } return context; } - [RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/aas/(id|([^/]+))/cds/([^/]+)(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "^/aas/(id|([^/]+))/cds/([^/]+)(/|)$") ] public IHttpContext GetSpecificCd(IHttpContext context) { var m = helper.PathInfoRegexMatch(MethodBase.GetCurrentMethod(), context.Request.PathInfo); if (m.Success && m.Groups.Count >= 4) { - helper.EvalGetCdContents(context, m.Groups[1].ToString(), m.Groups[3].ToString()); + helper.EvalGetCdContents(context, m.Groups[ 1 ].ToString(), m.Groups[ 3 ].ToString()); } return context; } - [RestRoute(HttpMethod = HttpMethod.DELETE, PathInfo = "^/aas/(id|([^/]+))/cds/([^/]+)(/|)$")] + [ RestRoute(HttpMethod = HttpMethod.DELETE, PathInfo = "^/aas/(id|([^/]+))/cds/([^/]+)(/|)$") ] public IHttpContext DeleteSpecificCd(IHttpContext context) { var m = helper.PathInfoRegexMatch(MethodBase.GetCurrentMethod(), context.Request.PathInfo); if (m.Success && m.Groups.Count >= 4) { - helper.EvalDeleteSpecificCd(context, m.Groups[1].ToString(), m.Groups[3].ToString()); + helper.EvalDeleteSpecificCd(context, m.Groups[ 1 ].ToString(), m.Groups[ 3 ].ToString()); } return context; diff --git a/src/AasxServerStandardBib/AasxServerStandardBib.csproj b/src/AasxServerStandardBib/AasxServerStandardBib.csproj index 197db5179..c474a660c 100644 --- a/src/AasxServerStandardBib/AasxServerStandardBib.csproj +++ b/src/AasxServerStandardBib/AasxServerStandardBib.csproj @@ -1,66 +1,66 @@  - - - net6.0 - en-US;de-DE - ef550880-6a5f-4e0c-b634-8284f1dc5445 - + + + net6.0 + en-US;de-DE + ef550880-6a5f-4e0c-b634-8284f1dc5445 + - - false - + + false + - - TRACE;UseAasxCompatibilityModels - portable - true - - - - + + TRACE;UseAasxCompatibilityModels + portable + true + + + + - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - - - - + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + - - - Always - - - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - + + + Always + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + diff --git a/src/AasxServerStandardBib/SecurityClient.cs b/src/AasxServerStandardBib/SecurityClient.cs index cb3555bd3..dde5af27d 100644 --- a/src/AasxServerStandardBib/SecurityClient.cs +++ b/src/AasxServerStandardBib/SecurityClient.cs @@ -102,10 +102,10 @@ public static void taskInit() for (int i = 0; i < aascount; i++) { - var env = AasxServer.Program.env[i]; + var env = AasxServer.Program.env[ i ]; if (env != null) { - var aas = env.AasEnv.AssetAdministrationShells[0]; + var aas = env.AasEnv.AssetAdministrationShells[ 0 ]; if (aas.Submodels != null && aas.Submodels.Count > 0) { foreach (var smr in aas.Submodels) @@ -119,7 +119,7 @@ public static void taskInit() countSme = sm.SubmodelElements.Count; for (int iSme = 0; iSme < countSme; iSme++) { - var sme = sm.SubmodelElements[iSme]; + var sme = sm.SubmodelElements[ iSme ]; if (sme is SubmodelElementCollection smec) { var nextTask = new AasxTask(); @@ -130,7 +130,7 @@ public static void taskInit() int countSmec = smec.Value.Count; for (int iSmec = 0; iSmec < countSmec; iSmec++) { - var sme2 = smec.Value[iSmec]; + var sme2 = smec.Value[ iSmec ]; var idShort = sme2.IdShort.ToLower(); switch (idShort) @@ -186,7 +186,7 @@ static void runOperations(SubmodelElementCollection smec, int envIndex, DateTime int countSmec = smec.Value.Count; for (int iSmec = 0; iSmec < countSmec; iSmec++) { - var sme2 = smec.Value[iSmec]; + var sme2 = smec.Value[ iSmec ]; if (sme2 is Operation op) { @@ -246,7 +246,7 @@ static void operation_authenticate(Operation op, int envIndex, DateTime timeStam var inputRef = input.Value; if (!(inputRef is ReferenceElement)) return; - var refElement = Program.env[envIndex].AasEnv.FindReferableByReference((inputRef as ReferenceElement).Value); + var refElement = Program.env[ envIndex ].AasEnv.FindReferableByReference((inputRef as ReferenceElement).Value); if (refElement is SubmodelElementCollection re) smec = re; } @@ -254,7 +254,7 @@ static void operation_authenticate(Operation op, int envIndex, DateTime timeStam int countSmec = smec.Value.Count; for (int iSmec = 0; iSmec < countSmec; iSmec++) { - var sme2 = smec.Value[iSmec]; + var sme2 = smec.Value[ iSmec ]; var idShort = sme2.IdShort.ToLower(); switch (idShort) @@ -377,7 +377,7 @@ static bool createAccessToken(int envIndex, Property authServerEndPoint, AasCore Stream s = null; try { - s = AasxServer.Program.env[envIndex].GetLocalStreamFromPackage(authServerCertificate.Value, access: FileAccess.Read); + s = AasxServer.Program.env[ envIndex ].GetLocalStreamFromPackage(authServerCertificate.Value, access: FileAccess.Read); } catch { @@ -404,7 +404,7 @@ static bool createAccessToken(int envIndex, Property authServerEndPoint, AasCore Stream s2 = null; try { - s2 = AasxServer.Program.env[envIndex].GetLocalStreamFromPackage(clientCertificate.Value, access: FileAccess.Read); + s2 = AasxServer.Program.env[ envIndex ].GetLocalStreamFromPackage(clientCertificate.Value, access: FileAccess.Read); } catch { @@ -443,7 +443,7 @@ static bool createAccessToken(int envIndex, Property authServerEndPoint, AasCore for (int i = 0; i < xc.Count; i++) { xce.MoveNext(); - X509Base64[--j] = Convert.ToBase64String(xce.Current.GetRawCertData()); + X509Base64[ --j ] = Convert.ToBase64String(xce.Current.GetRawCertData()); // X509Base64[--j] = Base64UrlEncoder.Encode(xce.Current.GetRawCertData()); } @@ -454,12 +454,12 @@ static bool createAccessToken(int envIndex, Property authServerEndPoint, AasCore string email = ""; string subject = certificate.Subject; var split = subject.Split(new Char[] {','}); - if (split[0] != "") + if (split[ 0 ] != "") { - var split2 = split[0].Split(new Char[] {'='}); - if (split2[0] == "E") + var split2 = split[ 0 ].Split(new Char[] {'='}); + if (split2[ 0 ] == "E") { - email = split2[1]; + email = split2[ 1 ]; } } @@ -643,7 +643,7 @@ static void operation_get_put(Operation op, int envIndex, DateTime timeStamp) if (inputRef is ReferenceElement) { - var refElement = Program.env[envIndex].AasEnv.FindReferableByReference((inputRef as ReferenceElement).Value); + var refElement = Program.env[ envIndex ].AasEnv.FindReferableByReference((inputRef as ReferenceElement).Value); if (refElement is SubmodelElementCollection) smec = refElement as SubmodelElementCollection; if (refElement is Submodel) @@ -698,7 +698,7 @@ static void operation_get_put(Operation op, int envIndex, DateTime timeStamp) if (outputRef is ReferenceElement) { - var refElement = Program.env[envIndex].AasEnv.FindReferableByReference((outputRef as ReferenceElement).Value); + var refElement = Program.env[ envIndex ].AasEnv.FindReferableByReference((outputRef as ReferenceElement).Value); if (refElement is SubmodelElementCollection) smec = refElement as SubmodelElementCollection; if (refElement is Submodel) @@ -728,7 +728,7 @@ static void operation_get_put(Operation op, int envIndex, DateTime timeStamp) int countSmec = smec.Value.Count; for (int iSmec = 0; iSmec < countSmec; iSmec++) { - var sme2 = smec.Value[iSmec]; + var sme2 = smec.Value[ iSmec ]; var idShort = sme2.IdShort.ToLower(); switch (idShort) @@ -831,13 +831,13 @@ static void operation_get_put(Operation op, int envIndex, DateTime timeStamp) Task task = null; string diffPath = ""; var splitPath = path.Value.Split('/'); - string aasPath = splitPath[0]; + string aasPath = splitPath[ 0 ]; string subPath = ""; int i = 1; string pre = ""; while (i < splitPath.Length) { - subPath += pre + splitPath[i]; + subPath += pre + splitPath[ i ]; pre = "."; i++; } @@ -865,11 +865,11 @@ static void operation_get_put(Operation op, int envIndex, DateTime timeStamp) { opName = "get"; requestPath = endPoint.Value + "/aas/" + aasPath + - "/submodels/" + splitPath[1] + "/elements"; + "/submodels/" + splitPath[ 1 ] + "/elements"; i = 2; while (i < splitPath.Length) { - requestPath += "/" + splitPath[i]; + requestPath += "/" + splitPath[ i ]; i++; } @@ -879,7 +879,7 @@ static void operation_get_put(Operation op, int envIndex, DateTime timeStamp) { last = DateTime.Parse(lastDiff.Value).ToUniversalTime(); requestPath = endPoint.Value + - "/diffjson/aas/" + splitPath[0] + + "/diffjson/aas/" + splitPath[ 0 ] + "?path=" + subPath; requestPath += "."; // to avoid wrong data by prefix only requestPath += "&time=" + lastDiff.Value; @@ -1048,20 +1048,20 @@ static void operation_get_put(Operation op, int envIndex, DateTime timeStamp) continue; receiveSubmodel.Id = elementSubmodel.Id; - var aas = Program.env[envIndex].AasEnv.FindAasWithSubmodelId(elementSubmodel.Id); + var aas = Program.env[ envIndex ].AasEnv.FindAasWithSubmodelId(elementSubmodel.Id); // datastructure update - if (Program.env == null || Program.env[envIndex].AasEnv == null /*|| Program.env[envIndex].AasEnv.Assets == null*/) + if (Program.env == null || Program.env[ envIndex ].AasEnv == null /*|| Program.env[envIndex].AasEnv.Assets == null*/) continue; // add Submodel - var existingSm = Program.env[envIndex].AasEnv.FindSubmodelById(elementSubmodel.Id); + var existingSm = Program.env[ envIndex ].AasEnv.FindSubmodelById(elementSubmodel.Id); if (existingSm != null) - Program.env[envIndex].AasEnv.Submodels.Remove(existingSm); - Program.env[envIndex].AasEnv.Submodels.Add(receiveSubmodel); + Program.env[ envIndex ].AasEnv.Submodels.Remove(existingSm); + Program.env[ envIndex ].AasEnv.Submodels.Add(receiveSubmodel); for (int s = 0; s < aas.Submodels.Count; s++) { - if (aas.Submodels[s].Keys[0].Value == existingSm.Id) + if (aas.Submodels[ s ].Keys[ 0 ].Value == existingSm.Id) { aas.Submodels.RemoveAt(s); break; @@ -1093,11 +1093,11 @@ static void operation_get_put(Operation op, int envIndex, DateTime timeStamp) if (splitPath.Length < 2) continue; requestPath = endPoint.Value + "/aas/" + aasPath + - "/submodels/" + splitPath[0] + "/elements"; + "/submodels/" + splitPath[ 0 ] + "/elements"; i = 1; while (i < splitPath.Length) { - requestPath += "/" + splitPath[i]; + requestPath += "/" + splitPath[ i ]; i++; } @@ -1285,7 +1285,7 @@ static void operation_get_put(Operation op, int envIndex, DateTime timeStamp) if (elementCollection.Value.Count == 1) { - if (elementCollection.Value[0] is SubmodelElementCollection smc) + if (elementCollection.Value[ 0 ] is SubmodelElementCollection smc) { if (smc.IdShort == "latestData") { @@ -1349,7 +1349,7 @@ static void operation_get_put(Operation op, int envIndex, DateTime timeStamp) { if (opName == "putdiff") { - var sme = diffCollection.Value[i]; + var sme = diffCollection.Value[ i ]; if (!(sme is SubmodelElementCollection)) continue; elementCollection = sme as SubmodelElementCollection; @@ -1482,7 +1482,7 @@ static void operation_limitCount(Operation op, int envIndex, DateTime timeStamp) if (inputRef is ReferenceElement) { - var refElement = Program.env[envIndex].AasEnv.FindReferableByReference((inputRef as ReferenceElement).Value); + var refElement = Program.env[ envIndex ].AasEnv.FindReferableByReference((inputRef as ReferenceElement).Value); if (refElement is SubmodelElementCollection) smec = refElement as SubmodelElementCollection; } @@ -1515,7 +1515,7 @@ static void operation_limitCount(Operation op, int envIndex, DateTime timeStamp) int i = 0; while (i < collection.Value.Count) { - if (pre == collection.Value[i].IdShort.Substring(0, pre.Length)) + if (pre == collection.Value[ i ].IdShort.Substring(0, pre.Length)) preCount++; i++; } @@ -1523,9 +1523,9 @@ static void operation_limitCount(Operation op, int envIndex, DateTime timeStamp) i = 0; while (preCount > count && i < collection.Value.Count) { - if (pre == collection.Value[i].IdShort.Substring(0, pre.Length)) + if (pre == collection.Value[ i ].IdShort.Substring(0, pre.Length)) { - IReferable r = collection.Value[i]; + IReferable r = collection.Value[ i ]; var sm = r.GetParentSubmodel(); AasxRestServerLibrary.AasxRestServer.TestResource.eventMessage.add( r, "Remove", sm, (ulong) timeStamp.Ticks); @@ -1615,10 +1615,10 @@ public static bool createCfpTree(int envIndex, DateTime timeStamp) for (int i = 0; i < aascount; i++) { - env = AasxServer.Program.env[i]; + env = AasxServer.Program.env[ i ]; if (env != null) { - var aas = env.AasEnv.AssetAdministrationShells[0]; + var aas = env.AasEnv.AssetAdministrationShells[ 0 ]; // if (aas.IdShort != "ZveiControlCabinetAas - EXTERNAL") // continue; @@ -1628,15 +1628,15 @@ public static bool createCfpTree(int envIndex, DateTime timeStamp) // foreach (var smr in aas.Submodels) for (int j = 0; j < aas.Submodels.Count; j++) { - var smr = aas.Submodels[j]; + var smr = aas.Submodels[ j ]; var sm = env.AasEnv.FindSubmodel(smr); if (sm != null && sm.IdShort != null) { if (sm.IdShort.Contains("BillOfMaterial")) { - if (sm.Extensions != null && sm.Extensions.Count != 0 && sm.Extensions[0].Name == "endpoint") + if (sm.Extensions != null && sm.Extensions.Count != 0 && sm.Extensions[ 0 ].Name == "endpoint") { - var requestPath = sm.Extensions[0].Value; + var requestPath = sm.Extensions[ 0 ].Value; string queryPara = ""; string userPW = ""; @@ -1666,8 +1666,8 @@ public static bool createCfpTree(int envIndex, DateTime timeStamp) if (userPW != "") client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", userPW); string clientToken = ""; - if (sm.Extensions != null && sm.Extensions.Count > 1 && sm.Extensions[1].Name == "clientToken") - clientToken = sm.Extensions[1].Value; + if (sm.Extensions != null && sm.Extensions.Count > 1 && sm.Extensions[ 1 ].Name == "clientToken") + clientToken = sm.Extensions[ 1 ].Value; if (clientToken != "") client.SetBearerToken(clientToken); @@ -1744,10 +1744,10 @@ public static bool createCfpTree(int envIndex, DateTime timeStamp) // Collect data from all AAS into cfpNode(s) for (int i = 0; i < aascount; i++) { - env = AasxServer.Program.env[i]; + env = AasxServer.Program.env[ i ]; if (env != null) { - var aas = env.AasEnv.AssetAdministrationShells[0]; + var aas = env.AasEnv.AssetAdministrationShells[ 0 ]; //var assetId = aas.assetRef.Keys[0].Value; var assetId = aas.AssetInformation.GlobalAssetId; @@ -2218,7 +2218,7 @@ public static void operation_calculate_cfp(Operation op, int envIndex, DateTime } else { - parent = stack[sp]; + parent = stack[ sp ]; if (parent.cradleToGateCombination != null) { Property p = node.cradleToGateModule; @@ -2312,7 +2312,7 @@ public static void operation_calculate_cfp(Operation op, int envIndex, DateTime } parent = null; - node = stack[sp]; + node = stack[ sp ]; stack.RemoveAt(sp); sp--; } @@ -2322,7 +2322,7 @@ public static void operation_calculate_cfp(Operation op, int envIndex, DateTime // Interate children stack.Add(node); sp++; - node = node.children[node.iChild++]; + node = node.children[ node.iChild++ ]; } } @@ -2344,7 +2344,7 @@ static void saveAASXtoTemp() { if (!Program.withDb) { - string fn = Program.envFileName[envi]; + string fn = Program.envFileName[ envi ]; if (fn != null && fn != "") { @@ -2354,9 +2354,9 @@ static void saveAASXtoTemp() lock (Program.changeAasxFile) { Console.WriteLine("SAVE TEMP: " + fn); - Program.env[envi].SaveAs("./temp/" + fn, true); + Program.env[ envi ].SaveAs("./temp/" + fn, true); DateTime timeStamp = DateTime.Now; - foreach (var submodel in Program.env[envi].AasEnv.Submodels) + foreach (var submodel in Program.env[ envi ].AasEnv.Submodels) { submodel.TimeStampCreate = timeStamp; submodel.SetTimeStamp(timeStamp); @@ -2370,14 +2370,14 @@ static void saveAASXtoTemp() } else { - if (Program.env[envi] != null && Program.env[envi].getWrite()) + if (Program.env[ envi ] != null && Program.env[ envi ].getWrite()) { lock (Program.changeAasxFile) { - var aasList = Program.env[envi].AasEnv.AssetAdministrationShells; + var aasList = Program.env[ envi ].AasEnv.AssetAdministrationShells; var aasIds = aasList.Select(x => x.Id).ToList(); - var submodelList = Program.env[envi].AasEnv.Submodels; + var submodelList = Program.env[ envi ].AasEnv.Submodels; var submodelIds = submodelList.Select(x => x.Id).ToList(); Dictionary aasToDeleteAASXNumsDic; @@ -2405,17 +2405,17 @@ static void saveAASXtoTemp() long assxNum = 0; if (aasToDeleteAASXNumsDic.ContainsKey(aas.Id)) { - assxNum = aasToDeleteAASXNumsDic[aas.Id]; + assxNum = aasToDeleteAASXNumsDic[ aas.Id ]; } - VisitorAASX.LoadAASInDB(db, aas, assxNum, Program.env[envi]); + VisitorAASX.LoadAASInDB(db, aas, assxNum, Program.env[ envi ]); } db.SaveChanges(); } //Program.saveEnv(envi); - Program.env[envi].setWrite(false); + Program.env[ envi ].setWrite(false); newData = true; } } @@ -2460,7 +2460,7 @@ public static void tasksCyclic() bool taskRun = false; for (int i = 0; i < taskList.Count; i++) { - var t = taskList[i]; + var t = taskList[ i ]; if (t.taskType?.Value.ToLower() == "cyclic") { if (t.nextExecution > timeStamp) diff --git a/src/AasxServerStandardBib/Services/AdminShellPackageEnvironmentService.cs b/src/AasxServerStandardBib/Services/AdminShellPackageEnvironmentService.cs index 08b5078cb..e38f26265 100644 --- a/src/AasxServerStandardBib/Services/AdminShellPackageEnvironmentService.cs +++ b/src/AasxServerStandardBib/Services/AdminShellPackageEnvironmentService.cs @@ -40,10 +40,10 @@ private bool EmptyPackageAvailable(out int emptyPackageIndex) for (int envi = 0; envi < _packages.Length; envi++) { - if (_packages[envi] == null) + if (_packages[ envi ] == null) { emptyPackageIndex = envi; - _packages[emptyPackageIndex] = new AdminShellPackageEnv(); + _packages[ emptyPackageIndex ] = new AdminShellPackageEnv(); return true; } } @@ -53,7 +53,7 @@ private bool EmptyPackageAvailable(out int emptyPackageIndex) public void setWrite(int packageIndex, bool status) { - _packages[packageIndex].setWrite(status); + _packages[ packageIndex ].setWrite(status); } #endregion @@ -64,12 +64,12 @@ public IAssetAdministrationShell CreateAssetAdministrationShell(IAssetAdministra { if (EmptyPackageAvailable(out int emptyPackageIndex)) { - _packages[emptyPackageIndex].AasEnv.AssetAdministrationShells.Add(body); + _packages[ emptyPackageIndex ].AasEnv.AssetAdministrationShells.Add(body); var timeStamp = DateTime.UtcNow; body.TimeStampCreate = timeStamp; body.SetTimeStamp(timeStamp); Program.signalNewData(2); - return _packages[emptyPackageIndex].AasEnv.AssetAdministrationShells[0]; //Considering it is the first AAS being added to empty package. + return _packages[ emptyPackageIndex ].AasEnv.AssetAdministrationShells[ 0 ]; //Considering it is the first AAS being added to empty package. } else { @@ -81,15 +81,15 @@ public void DeleteAssetAdministrationShell(int packageIndex, IAssetAdministratio { if (aas != null && packageIndex != -1) { - bool deleted = (bool) (_packages[packageIndex].AasEnv?.AssetAdministrationShells.Remove(aas)); + bool deleted = (bool) (_packages[ packageIndex ].AasEnv?.AssetAdministrationShells.Remove(aas)); if (deleted) { _logger.LogDebug($"Deleted Asset Administration Shell with id {aas.Id}"); //if no more shells in the environment, then remove the environment // TODO (jtikekar, 2023-09-04): what about submodels and concept descriptions for the same environment - if (_packages[packageIndex].AasEnv.AssetAdministrationShells.Count == 0) + if (_packages[ packageIndex ].AasEnv.AssetAdministrationShells.Count == 0) { - _packages[packageIndex] = null; + _packages[ packageIndex ] = null; } Program.signalNewData(2); @@ -172,9 +172,9 @@ public void UpdateAssetAdministrationShellById(IAssetAdministrationShell body, s var aas = GetAssetAdministrationShellById(aasIdentifier, out int packageIndex); if (aas != null && packageIndex != -1) { - var aasIndex = _packages[packageIndex].AasEnv.AssetAdministrationShells.IndexOf(aas); - _packages[packageIndex].AasEnv.AssetAdministrationShells.Remove(aas); - _packages[packageIndex].AasEnv.AssetAdministrationShells.Insert(aasIndex, body); + var aasIndex = _packages[ packageIndex ].AasEnv.AssetAdministrationShells.IndexOf(aas); + _packages[ packageIndex ].AasEnv.AssetAdministrationShells.Remove(aas); + _packages[ packageIndex ].AasEnv.AssetAdministrationShells.Insert(aasIndex, body); var timeStamp = DateTime.UtcNow; body.TimeStampCreate = timeStamp; body.SetTimeStamp(timeStamp); @@ -186,18 +186,18 @@ public void UpdateAssetAdministrationShellById(IAssetAdministrationShell body, s public void DeleteAssetInformationThumbnail(int packageIndex, IResource defaultThumbnail) { - _packages[packageIndex].DeleteAssetInformationThumbnail(defaultThumbnail); + _packages[ packageIndex ].DeleteAssetInformationThumbnail(defaultThumbnail); Program.signalNewData(0); } public Stream GetAssetInformationThumbnail(int packageIndex) { - return _packages[packageIndex].GetLocalThumbnailStream(); + return _packages[ packageIndex ].GetLocalThumbnailStream(); } public void UpdateAssetInformationThumbnail(IResource defaultThumbnail, Stream fileContent, int packageIndex) { - _packages[packageIndex].EmbeddAssetInformationThumbnail(defaultThumbnail, fileContent); + _packages[ packageIndex ].EmbeddAssetInformationThumbnail(defaultThumbnail, fileContent); Program.signalNewData(0); } @@ -210,12 +210,12 @@ public void DeleteSubmodelById(string submodelIdentifier) var submodel = GetSubmodelById(submodelIdentifier, out int packageIndex); if (submodel != null && packageIndex != -1) { - foreach (var aas in _packages[packageIndex].AasEnv.AssetAdministrationShells) + foreach (var aas in _packages[ packageIndex ].AasEnv.AssetAdministrationShells) { _aasService.Value.DeleteSubmodelReferenceById(aas.Id, submodelIdentifier); } - _packages[packageIndex].AasEnv.Submodels.Remove(submodel); + _packages[ packageIndex ].AasEnv.Submodels.Remove(submodel); _logger.LogDebug($"Deleted submodel with id {submodelIdentifier}."); AasxServer.Program.signalNewData(1); } @@ -240,7 +240,7 @@ public void DeleteSupplementaryFileInPackage(string submodelIdentifier, string f _ = GetSubmodelById(submodelIdentifier, out int packageIndex); if (packageIndex != -1) { - _packages[packageIndex].DeleteSupplementaryFile(filePath); + _packages[ packageIndex ].DeleteSupplementaryFile(filePath); } } @@ -297,7 +297,7 @@ public void DeleteConceptDescriptionById(string cdIdentifier) if ((conceptDescription != null) && (packageIndex != -1)) { - _packages[packageIndex].AasEnv.ConceptDescriptions.Remove(conceptDescription); + _packages[ packageIndex ].AasEnv.ConceptDescriptions.Remove(conceptDescription); _logger.LogDebug($"Delete ConceptDescription with id {cdIdentifier}"); AasxServer.Program.signalNewData(1); } @@ -371,12 +371,12 @@ public IConceptDescription CreateConceptDescription(IConceptDescription body) { if (EmptyPackageAvailable(out int emptyPackageIndex)) { - _packages[emptyPackageIndex].AasEnv.ConceptDescriptions.Add(body); + _packages[ emptyPackageIndex ].AasEnv.ConceptDescriptions.Add(body); var timeStamp = DateTime.UtcNow; body.TimeStampCreate = timeStamp; body.SetTimeStamp(timeStamp); Program.signalNewData(2); - return _packages[emptyPackageIndex].AasEnv.ConceptDescriptions[0]; //Considering it is the first AAS being added to empty package. + return _packages[ emptyPackageIndex ].AasEnv.ConceptDescriptions[ 0 ]; //Considering it is the first AAS being added to empty package. } else { @@ -389,9 +389,9 @@ public void UpdateConceptDescriptionById(IConceptDescription body, string cdIden var conceptDescription = GetConceptDescriptionById(cdIdentifier, out int packageIndex); if (conceptDescription != null && packageIndex != -1) { - var cdIndex = _packages[packageIndex].AasEnv.ConceptDescriptions.IndexOf(conceptDescription); - _packages[packageIndex].AasEnv.ConceptDescriptions.Remove(conceptDescription); - _packages[packageIndex].AasEnv.ConceptDescriptions.Insert(cdIndex, body); + var cdIndex = _packages[ packageIndex ].AasEnv.ConceptDescriptions.IndexOf(conceptDescription); + _packages[ packageIndex ].AasEnv.ConceptDescriptions.Remove(conceptDescription); + _packages[ packageIndex ].AasEnv.ConceptDescriptions.Insert(cdIndex, body); var timeStamp = DateTime.UtcNow; body.TimeStampCreate = timeStamp; body.SetTimeStamp(timeStamp); @@ -406,7 +406,7 @@ public Stream GetFileFromPackage(string submodelIdentifier, string fileName) if (!string.IsNullOrEmpty(fileName)) { var _ = GetSubmodelById(submodelIdentifier, out int packageIndex); - return _packages[packageIndex].GetLocalStreamFromPackage(fileName); + return _packages[ packageIndex ].GetLocalStreamFromPackage(fileName); } else { @@ -420,9 +420,9 @@ public void ReplaceAssetAdministrationShellById(string aasIdentifier, IAssetAdmi var aas = GetAssetAdministrationShellById(aasIdentifier, out int packageIndex); if (aas != null && packageIndex != -1) { - var existingIndex = _packages[packageIndex].AasEnv.AssetAdministrationShells.IndexOf(aas); - _packages[packageIndex].AasEnv.AssetAdministrationShells.Remove(aas); - _packages[packageIndex].AasEnv.AssetAdministrationShells.Insert(existingIndex, newAas); + var existingIndex = _packages[ packageIndex ].AasEnv.AssetAdministrationShells.IndexOf(aas); + _packages[ packageIndex ].AasEnv.AssetAdministrationShells.Remove(aas); + _packages[ packageIndex ].AasEnv.AssetAdministrationShells.Insert(existingIndex, newAas); var timeStamp = DateTime.UtcNow; newAas.TimeStampCreate = timeStamp; newAas.SetTimeStamp(timeStamp); @@ -435,9 +435,9 @@ public void ReplaceSubmodelById(string submodelIdentifier, ISubmodel newSubmodel var submodel = GetSubmodelById(submodelIdentifier, out int packageIndex); if (submodel != null && packageIndex != -1) { - var existingIndex = _packages[packageIndex].AasEnv.Submodels.IndexOf(submodel); - _packages[packageIndex].AasEnv.Submodels.Remove(submodel); - _packages[packageIndex].AasEnv.Submodels.Insert(existingIndex, newSubmodel); + var existingIndex = _packages[ packageIndex ].AasEnv.Submodels.IndexOf(submodel); + _packages[ packageIndex ].AasEnv.Submodels.Remove(submodel); + _packages[ packageIndex ].AasEnv.Submodels.Insert(existingIndex, newSubmodel); var timeStamp = DateTime.UtcNow; newSubmodel.TimeStampCreate = timeStamp; newSubmodel.SetParentAndTimestamp(timeStamp); @@ -519,7 +519,7 @@ public ISubmodel CreateSubmodel(ISubmodel newSubmodel, string aasIdentifier = nu newSubmodel.SetAllParents(DateTime.UtcNow); aas.Submodels ??= new List(); aas.Submodels.Add(newSubmodel.GetReference()); - _packages[packageIndex].AasEnv.Submodels.Add(newSubmodel); + _packages[ packageIndex ].AasEnv.Submodels.Add(newSubmodel); var timeStamp = DateTime.UtcNow; aas.SetTimeStamp(timeStamp); newSubmodel.TimeStampCreate = timeStamp; @@ -531,12 +531,12 @@ public ISubmodel CreateSubmodel(ISubmodel newSubmodel, string aasIdentifier = nu if (EmptyPackageAvailable(out int emptyPackageIndex)) { - _packages[emptyPackageIndex].AasEnv.Submodels.Add(newSubmodel); + _packages[ emptyPackageIndex ].AasEnv.Submodels.Add(newSubmodel); var timeStamp = DateTime.UtcNow; newSubmodel.TimeStampCreate = timeStamp; newSubmodel.SetTimeStamp(timeStamp); Program.signalNewData(2); - return _packages[emptyPackageIndex].AasEnv.Submodels[0]; //Considering it is the first AAS being added to empty package. + return _packages[ emptyPackageIndex ].AasEnv.Submodels[ 0 ]; //Considering it is the first AAS being added to empty package. } else { @@ -547,7 +547,7 @@ public ISubmodel CreateSubmodel(ISubmodel newSubmodel, string aasIdentifier = nu public Task ReplaceSupplementaryFileInPackage(string submodelIdentifier, string sourceFile, string targetFile, string contentType, MemoryStream fileContent) { var submodel = GetSubmodelById(submodelIdentifier, out int packageIndex); - return _packages[packageIndex].ReplaceSupplementaryFileInPackageAsync(sourceFile, targetFile, contentType, fileContent); + return _packages[ packageIndex ].ReplaceSupplementaryFileInPackageAsync(sourceFile, targetFile, contentType, fileContent); } #endregion diff --git a/src/AasxServerStandardBib/Services/SubmodelService.cs b/src/AasxServerStandardBib/Services/SubmodelService.cs index 47a2bde71..ad05ac594 100644 --- a/src/AasxServerStandardBib/Services/SubmodelService.cs +++ b/src/AasxServerStandardBib/Services/SubmodelService.cs @@ -61,7 +61,7 @@ private ISubmodelElement GetSubmodelElementByPath(IReferable parent, string idSh if (idShorts.Count == 1) { - return parent.FindSubmodelElementByIdShort((string) idShorts[0]); + return parent.FindSubmodelElementByIdShort((string) idShorts[ 0 ]); } foreach (var idShortObject in idShorts) @@ -85,7 +85,7 @@ private ISubmodelElement GetSubmodelElementByPath(IReferable parent, string idSh { try { - output = smeList.Value?[idShortInt]; + output = smeList.Value?[ idShortInt ]; } catch (ArgumentOutOfRangeException ex) { diff --git a/src/AasxServerStandardBib/entityFW.cs b/src/AasxServerStandardBib/entityFW.cs index 8a193d869..15f0aaf5b 100644 --- a/src/AasxServerStandardBib/entityFW.cs +++ b/src/AasxServerStandardBib/entityFW.cs @@ -50,7 +50,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder options) throw new Exception("No Configuration!"); } - connectionString = _con["DatabaseConnection:ConnectionString"]; + connectionString = _con[ "DatabaseConnection:ConnectionString" ]; if (connectionString != null) { if (connectionString.Contains("$DATAPATH")) @@ -62,14 +62,14 @@ protected override void OnConfiguring(DbContextOptionsBuilder options) string dbUser = System.Environment.GetEnvironmentVariable("DATABASE_PASSWORD"); for (int i = 0; i < Params.Length; i++) { - if (Params[i].Contains("Username") && dbUser != null) + if (Params[ i ].Contains("Username") && dbUser != null) { - Params[i] = "Username=" + dbUser; + Params[ i ] = "Username=" + dbUser; } - if (Params[i].Contains("Password") && dbPassword != null) + if (Params[ i ].Contains("Password") && dbPassword != null) { - Params[i] = "Password=" + dbPassword; + Params[ i ] = "Password=" + dbPassword; } } @@ -156,7 +156,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder options) } else { - var connectionString = _con["DatabaseConnection:ConnectionString"]; + var connectionString = _con[ "DatabaseConnection:ConnectionString" ]; if (connectionString.Contains("$DATAPATH")) connectionString = connectionString.Replace("$DATAPATH", AasxHttpContextHelper.DataPath); options.UseSqlite(connectionString); @@ -174,7 +174,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder options) } else { - var connectionString = _con["DatabaseConnection:ConnectionString"]; + var connectionString = _con[ "DatabaseConnection:ConnectionString" ]; if (connectionString.Contains("$DATAPATH")) connectionString = connectionString.Replace("$DATAPATH", AasxHttpContextHelper.DataPath); options.UseNpgsql(connectionString); @@ -191,7 +191,7 @@ public class DbConfigSet public long SMECount { get; set; } } - [Index(nameof(AASXNum))] + [ Index(nameof(AASXNum)) ] public class AASXSet { public int Id { get; set; } @@ -199,7 +199,7 @@ public class AASXSet public string AASX { get; set; } } - [Index(nameof(AasNum))] + [ Index(nameof(AasNum)) ] public class AasSet { public int Id { get; set; } @@ -211,7 +211,7 @@ public class AasSet public string AssetKind { get; set; } } - [Index(nameof(SubmodelNum))] + [ Index(nameof(SubmodelNum)) ] public class SubmodelSet { public int Id { get; set; } @@ -223,8 +223,8 @@ public class SubmodelSet public string SemanticId { get; set; } } - [Index(nameof(SubmodelNum))] - [Index(nameof(SMENum))] + [ Index(nameof(SubmodelNum)) ] + [ Index(nameof(SMENum)) ] public class SMESet { public int Id { get; set; } @@ -319,7 +319,7 @@ public static List getValueList(List smesets) } } - [Index(nameof(ParentSMENum))] + [ Index(nameof(ParentSMENum)) ] public class IntValue { public int Id { get; set; } @@ -339,7 +339,7 @@ public StringValue asStringValue() } } - [Index(nameof(ParentSMENum))] + [ Index(nameof(ParentSMENum)) ] public class StringValue { public int Id { get; set; } @@ -348,7 +348,7 @@ public class StringValue public string Annotation { get; set; } } - [Index(nameof(ParentSMENum))] + [ Index(nameof(ParentSMENum)) ] public class DoubleValue { public int Id { get; set; } @@ -1145,8 +1145,8 @@ private void getValue(ISubmodelElement sme, long smeNum, out string vt, out stri { var mlpval = new StringValue() { - Annotation = ls[i].Language, - Value = ls[i].Text, + Annotation = ls[ i ].Language, + Value = ls[ i ].Text, ParentSMENum = smeNum }; _db.Add(mlpval); @@ -1191,7 +1191,7 @@ private long collectSMEData(ISubmodelElement sme) long smeNum = ++_dbConfig.SMECount; long pn = 0; if (_parentNum.Count > 0) - pn = _parentNum[_parentNum.Count - 1]; + pn = _parentNum[ _parentNum.Count - 1 ]; var semanticId = sme.SemanticId.GetAsIdentifier(); if (semanticId == null) semanticId = ""; diff --git a/src/DataTransferObjects/DataTransferObjects.csproj b/src/DataTransferObjects/DataTransferObjects.csproj index 77c8c8b3f..d53464475 100644 --- a/src/DataTransferObjects/DataTransferObjects.csproj +++ b/src/DataTransferObjects/DataTransferObjects.csproj @@ -1,17 +1,17 @@  - - net6.0 - enable - enable - + + net6.0 + enable + enable + - - false - + + false + - - - + + + diff --git a/src/ExampleClient/ExampleClient.csproj b/src/ExampleClient/ExampleClient.csproj index 5082f9ad6..a8d330362 100644 --- a/src/ExampleClient/ExampleClient.csproj +++ b/src/ExampleClient/ExampleClient.csproj @@ -1,19 +1,19 @@ - - Exe - net6.0 - enable - enable - + + Exe + net6.0 + enable + enable + - - - + + + - - - - + + + + diff --git a/src/IO.Swagger.Lib.V3/Controllers/ConceptDescriptionRepositoryAPIApi.cs b/src/IO.Swagger.Lib.V3/Controllers/ConceptDescriptionRepositoryAPIApi.cs index b2d617b92..106fdc5e9 100644 --- a/src/IO.Swagger.Lib.V3/Controllers/ConceptDescriptionRepositoryAPIApi.cs +++ b/src/IO.Swagger.Lib.V3/Controllers/ConceptDescriptionRepositoryAPIApi.cs @@ -29,8 +29,8 @@ namespace IO.Swagger.Controllers /// /// /// - [Authorize(AuthenticationSchemes = "AasSecurityAuth")] - [ApiController] + [ Authorize(AuthenticationSchemes = "AasSecurityAuth") ] + [ ApiController ] public class ConceptDescriptionRepositoryAPIApiController : ControllerBase { private readonly IAppLogger _logger; @@ -61,16 +61,16 @@ public ConceptDescriptionRepositoryAPIApiController(IAppLoggerNot Found /// Internal Server Error /// Default error handling for unmentioned status codes - [HttpDelete] - [Route("/concept-descriptions/{cdIdentifier}")] - [ValidateModelState] - [SwaggerOperation("DeleteConceptDescriptionById")] - [SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")] - [SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")] - [SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")] - [SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")] - [SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")] - public virtual IActionResult DeleteConceptDescriptionById([FromRoute] [Required] string cdIdentifier) + [ HttpDelete ] + [ Route("/concept-descriptions/{cdIdentifier}") ] + [ ValidateModelState ] + [ SwaggerOperation("DeleteConceptDescriptionById") ] + [ SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.") ] + [ SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden") ] + [ SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found") ] + [ SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error") ] + [ SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes") ] + public virtual IActionResult DeleteConceptDescriptionById([ FromRoute ] [ Required ] string cdIdentifier) { var decodedCdIdentifier = _decoderService.Decode("cdIdentifier", cdIdentifier); @@ -94,18 +94,18 @@ public virtual IActionResult DeleteConceptDescriptionById([FromRoute] [Required] /// Forbidden /// Internal Server Error /// Default error handling for unmentioned status codes - [HttpGet] - [Route("/concept-descriptions")] - [ValidateModelState] - [SwaggerOperation("GetAllConceptDescriptions")] + [ HttpGet ] + [ Route("/concept-descriptions") ] + [ ValidateModelState ] + [ SwaggerOperation("GetAllConceptDescriptions") ] //[SwaggerResponse(statusCode: 200, type: typeof(GetConceptDescriptionsResult), description: "Requested Concept Descriptions")] - [SwaggerResponse(statusCode: 200, type: typeof(List), description: "Requested Concept Descriptions")] - [SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")] - [SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")] - [SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")] - [SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")] - public virtual IActionResult GetAllConceptDescriptions([FromQuery] string idShort, [FromQuery] string isCaseOf, [FromQuery] string dataSpecificationRef, - [FromQuery] int? limit, [FromQuery] string cursor) + [ SwaggerResponse(statusCode: 200, type: typeof(List), description: "Requested Concept Descriptions") ] + [ SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.") ] + [ SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden") ] + [ SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error") ] + [ SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes") ] + public virtual IActionResult GetAllConceptDescriptions([ FromQuery ] string idShort, [ FromQuery ] string isCaseOf, [ FromQuery ] string dataSpecificationRef, + [ FromQuery ] int? limit, [ FromQuery ] string cursor) { _logger.LogInformation($"Received request to get all the concept descriptions."); var reqIsCaseOf = _jsonQueryDeserializer.DeserializeReference("isCaseOf", isCaseOf); @@ -139,17 +139,17 @@ public virtual IActionResult GetAllConceptDescriptions([FromQuery] string idShor /// Not Found /// Internal Server Error /// Default error handling for unmentioned status codes - [HttpGet] - [Route("/concept-descriptions/{cdIdentifier}")] - [ValidateModelState] - [SwaggerOperation("GetConceptDescriptionById")] - [SwaggerResponse(statusCode: 200, type: typeof(ConceptDescription), description: "Requested Concept Description")] - [SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")] - [SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")] - [SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")] - [SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")] - [SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")] - public virtual IActionResult GetConceptDescriptionById([FromRoute] [Required] string cdIdentifier) + [ HttpGet ] + [ Route("/concept-descriptions/{cdIdentifier}") ] + [ ValidateModelState ] + [ SwaggerOperation("GetConceptDescriptionById") ] + [ SwaggerResponse(statusCode: 200, type: typeof(ConceptDescription), description: "Requested Concept Description") ] + [ SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.") ] + [ SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden") ] + [ SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found") ] + [ SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error") ] + [ SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes") ] + public virtual IActionResult GetConceptDescriptionById([ FromRoute ] [ Required ] string cdIdentifier) { var decodedCdIdentifier = _decoderService.Decode("cdIdentifier", cdIdentifier); @@ -180,19 +180,19 @@ public virtual IActionResult GetConceptDescriptionById([FromRoute] [Required] st /// Conflict, a resource which shall be created exists already. Might be thrown if a Submodel or SubmodelElement with the same ShortId is contained in a POST request. /// Internal Server Error /// Default error handling for unmentioned status codes - [HttpPost] - [Route("/concept-descriptions")] - [ValidateModelState] - [SwaggerOperation("PostConceptDescription")] - [SwaggerResponse(statusCode: 201, type: typeof(ConceptDescription), description: "Concept Description created successfully")] - [SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")] - [SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")] - [SwaggerResponse(statusCode: 409, type: typeof(Result), + [ HttpPost ] + [ Route("/concept-descriptions") ] + [ ValidateModelState ] + [ SwaggerOperation("PostConceptDescription") ] + [ SwaggerResponse(statusCode: 201, type: typeof(ConceptDescription), description: "Concept Description created successfully") ] + [ SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.") ] + [ SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden") ] + [ SwaggerResponse(statusCode: 409, type: typeof(Result), description: - "Conflict, a resource which shall be created exists already. Might be thrown if a Submodel or SubmodelElement with the same ShortId is contained in a POST request.")] - [SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")] - [SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")] - public virtual IActionResult PostConceptDescription([FromBody] ConceptDescription body) + "Conflict, a resource which shall be created exists already. Might be thrown if a Submodel or SubmodelElement with the same ShortId is contained in a POST request.") ] + [ SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error") ] + [ SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes") ] + public virtual IActionResult PostConceptDescription([ FromBody ] ConceptDescription body) { var output = _cdService.CreateConceptDescription(body); @@ -210,16 +210,16 @@ public virtual IActionResult PostConceptDescription([FromBody] ConceptDescriptio /// Not Found /// Internal Server Error /// Default error handling for unmentioned status codes - [HttpPut] - [Route("/concept-descriptions/{cdIdentifier}")] - [ValidateModelState] - [SwaggerOperation("PutConceptDescriptionById")] - [SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")] - [SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")] - [SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")] - [SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")] - [SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")] - public virtual IActionResult PutConceptDescriptionById([FromBody] ConceptDescription body, [FromRoute] [Required] string cdIdentifier) + [ HttpPut ] + [ Route("/concept-descriptions/{cdIdentifier}") ] + [ ValidateModelState ] + [ SwaggerOperation("PutConceptDescriptionById") ] + [ SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.") ] + [ SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden") ] + [ SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found") ] + [ SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error") ] + [ SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes") ] + public virtual IActionResult PutConceptDescriptionById([ FromBody ] ConceptDescription body, [ FromRoute ] [ Required ] string cdIdentifier) { var decodedCdId = _decoderService.Decode("cdIdentifier", cdIdentifier); diff --git a/src/IO.Swagger.Lib.V3/IO.Swagger.Lib.V3.csproj b/src/IO.Swagger.Lib.V3/IO.Swagger.Lib.V3.csproj index 8270939b5..19118d141 100644 --- a/src/IO.Swagger.Lib.V3/IO.Swagger.Lib.V3.csproj +++ b/src/IO.Swagger.Lib.V3/IO.Swagger.Lib.V3.csproj @@ -1,33 +1,33 @@ - - IO.Swagger - IO.Swagger - net6.0 - true - true - IO.Swagger.Lib.V3 - IO.Swagger - Library - - - false - - - - - - - - - - - - - - - - - - - + + IO.Swagger + IO.Swagger + net6.0 + true + true + IO.Swagger.Lib.V3 + IO.Swagger + Library + + + false + + + + + + + + + + + + + + + + + + + diff --git a/src/IO.Swagger.Lib.V3/Models/BaseOperationResult.cs b/src/IO.Swagger.Lib.V3/Models/BaseOperationResult.cs index 786d99bd6..c9130a745 100644 --- a/src/IO.Swagger.Lib.V3/Models/BaseOperationResult.cs +++ b/src/IO.Swagger.Lib.V3/Models/BaseOperationResult.cs @@ -24,21 +24,21 @@ namespace IO.Swagger.Models /// /// /// - [DataContract] + [ DataContract ] public partial class BaseOperationResult : Result, IEquatable { /// /// Gets or Sets ExecutionState /// - [DataMember(Name = "executionState")] + [ DataMember(Name = "executionState") ] public ExecutionState ExecutionState { get; set; } /// /// Gets or Sets Success /// - [DataMember(Name = "success")] + [ DataMember(Name = "success") ] public bool? Success { get; set; } /// diff --git a/src/IO.Swagger.Lib.V3/Models/Message.cs b/src/IO.Swagger.Lib.V3/Models/Message.cs index b6e0c5287..c784b3812 100644 --- a/src/IO.Swagger.Lib.V3/Models/Message.cs +++ b/src/IO.Swagger.Lib.V3/Models/Message.cs @@ -19,77 +19,77 @@ namespace IO.Swagger.Models /// /// /// - [DataContract] + [ DataContract ] public partial class Message : IEquatable { /// /// Gets or Sets Code /// - [StringLength(32, MinimumLength = 1)] - [DataMember(Name = "code")] + [ StringLength(32, MinimumLength = 1) ] + [ DataMember(Name = "code") ] public string Code { get; set; } /// /// Gets or Sets CorrelationId /// - [StringLength(128, MinimumLength = 1)] - [DataMember(Name = "correlationId")] + [ StringLength(128, MinimumLength = 1) ] + [ DataMember(Name = "correlationId") ] public string CorrelationId { get; set; } /// /// Gets or Sets MessageType /// - [JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] + [ JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter)) ] public enum MessageTypeEnum { /// /// Enum UndefinedEnum for Undefined /// - [EnumMember(Value = "Undefined")] UndefinedEnum = 0, + [ EnumMember(Value = "Undefined") ] UndefinedEnum = 0, /// /// Enum InfoEnum for Info /// - [EnumMember(Value = "Info")] InfoEnum = 1, + [ EnumMember(Value = "Info") ] InfoEnum = 1, /// /// Enum WarningEnum for Warning /// - [EnumMember(Value = "Warning")] WarningEnum = 2, + [ EnumMember(Value = "Warning") ] WarningEnum = 2, /// /// Enum ErrorEnum for Error /// - [EnumMember(Value = "Error")] ErrorEnum = 3, + [ EnumMember(Value = "Error") ] ErrorEnum = 3, /// /// Enum ExceptionEnum for Exception /// - [EnumMember(Value = "Exception")] ExceptionEnum = 4 + [ EnumMember(Value = "Exception") ] ExceptionEnum = 4 } /// /// Gets or Sets MessageType /// - [DataMember(Name = "messageType")] + [ DataMember(Name = "messageType") ] public MessageTypeEnum? MessageType { get; set; } /// /// Gets or Sets Text /// - [DataMember(Name = "text")] + [ DataMember(Name = "text") ] public string Text { get; set; } /// /// Gets or Sets Timestamp /// - [RegularExpression( - "/^-?(([1-9][0-9][0-9][0-9]+)|(0[0-9][0-9][0-9]))-((0[1-9])|(1[0-2]))-((0[1-9])|([12][0-9])|(3[01]))T(((([01][0-9])|(2[0-3])):[0-5][0-9]:([0-5][0-9])(\\.[0-9]+)?)|24:00:00(\\.0+)?)(Z|\\+00:00|-00:00)$/")] - [DataMember(Name = "timestamp")] + [ RegularExpression( + "/^-?(([1-9][0-9][0-9][0-9]+)|(0[0-9][0-9][0-9]))-((0[1-9])|(1[0-2]))-((0[1-9])|([12][0-9])|(3[01]))T(((([01][0-9])|(2[0-3])):[0-5][0-9]:([0-5][0-9])(\\.[0-9]+)?)|24:00:00(\\.0+)?)(Z|\\+00:00|-00:00)$/") ] + [ DataMember(Name = "timestamp") ] public string Timestamp { get; set; } /// diff --git a/src/IO.Swagger.Lib.V3/Models/Result.cs b/src/IO.Swagger.Lib.V3/Models/Result.cs index ff0a7ee55..db61b13e2 100644 --- a/src/IO.Swagger.Lib.V3/Models/Result.cs +++ b/src/IO.Swagger.Lib.V3/Models/Result.cs @@ -20,14 +20,14 @@ namespace IO.Swagger.Models /// /// /// - [DataContract] + [ DataContract ] public partial class Result : IEquatable { /// /// Gets or Sets Messages /// - [DataMember(Name = "messages")] + [ DataMember(Name = "messages") ] public List Messages { get; set; } /// diff --git a/src/IO.Swagger.Registry.Lib.V3/Attributes/ValidateModelStateAttribute.cs b/src/IO.Swagger.Registry.Lib.V3/Attributes/ValidateModelStateAttribute.cs index 877abe8ca..3435d13c2 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Attributes/ValidateModelStateAttribute.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Attributes/ValidateModelStateAttribute.cs @@ -27,7 +27,7 @@ public override void OnActionExecuting(ActionExecutingContext context) object args = null; if (context.ActionArguments.ContainsKey(parameter.Name)) { - args = context.ActionArguments[parameter.Name]; + args = context.ActionArguments[ parameter.Name ]; } ValidateAttributes(parameter, args, context.ModelState); @@ -58,4 +58,4 @@ private void ValidateAttributes(ParameterInfo parameter, object args, ModelState } } } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Controllers/AssetAdministrationShellRegistryAPIApi.cs b/src/IO.Swagger.Registry.Lib.V3/Controllers/AssetAdministrationShellRegistryAPIApi.cs index 4962db7c1..e76058ad3 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Controllers/AssetAdministrationShellRegistryAPIApi.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Controllers/AssetAdministrationShellRegistryAPIApi.cs @@ -7,6 +7,7 @@ * Contact: info@idtwin.org * Generated by: https://github.com/swagger-api/swagger-codegen.git */ + using AasxServer; using AasxServerStandardBib.Logging; using IO.Swagger.Lib.V3.Interfaces; @@ -27,7 +28,7 @@ namespace IO.Swagger.Controllers /// /// /// - [ApiController] + [ ApiController ] public class AssetAdministrationShellRegistryAPIApiController : ControllerBase { private readonly IAppLogger _logger; @@ -36,7 +37,8 @@ public class AssetAdministrationShellRegistryAPIApiController : ControllerBase private readonly IRegistryInitializerService _registryInitializerService; private readonly IAasDescriptorPaginationService _paginationService; - public AssetAdministrationShellRegistryAPIApiController(IAppLogger logger, IBase64UrlDecoderService decoderService, IAasRegistryService aasRegistryService, IRegistryInitializerService registryInitializerService, IAasDescriptorPaginationService paginationService) + public AssetAdministrationShellRegistryAPIApiController(IAppLogger logger, IBase64UrlDecoderService decoderService, + IAasRegistryService aasRegistryService, IRegistryInitializerService registryInitializerService, IAasDescriptorPaginationService paginationService) { _logger = logger; _decoderService = decoderService; @@ -44,6 +46,7 @@ public AssetAdministrationShellRegistryAPIApiController(IAppLogger /// Deletes an Asset Administration Shell Descriptor, i.e. de-registers an AAS /// @@ -53,15 +56,15 @@ public AssetAdministrationShellRegistryAPIApiController(IAppLoggerNot Found /// Internal Server Error /// Default error handling for unmentioned status codes - [HttpDelete] - [Route("/shell-descriptors/{aasIdentifier}")] - [ValidateModelState] - [SwaggerOperation("DeleteAssetAdministrationShellDescriptorById")] - [SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")] - [SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")] - [SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")] - [SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")] - public virtual IActionResult DeleteAssetAdministrationShellDescriptorById([FromRoute][Required] byte[] aasIdentifier) + [ HttpDelete ] + [ Route("/shell-descriptors/{aasIdentifier}") ] + [ ValidateModelState ] + [ SwaggerOperation("DeleteAssetAdministrationShellDescriptorById") ] + [ SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.") ] + [ SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found") ] + [ SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error") ] + [ SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes") ] + public virtual IActionResult DeleteAssetAdministrationShellDescriptorById([ FromRoute ] [ Required ] byte[] aasIdentifier) { //TODO: Uncomment the next line to return response 204 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(204); @@ -91,15 +94,16 @@ public virtual IActionResult DeleteAssetAdministrationShellDescriptorById([FromR /// Not Found /// Internal Server Error /// Default error handling for unmentioned status codes - [HttpDelete] - [Route("/shell-descriptors/{aasIdentifier}/submodel-descriptors/{submodelIdentifier}")] - [ValidateModelState] - [SwaggerOperation("DeleteSubmodelDescriptorByIdThroughSuperpath")] - [SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")] - [SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")] - [SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")] - [SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")] - public virtual IActionResult DeleteSubmodelDescriptorByIdThroughSuperpath([FromRoute][Required] string aasIdentifier, [FromRoute][Required] string submodelIdentifier) + [ HttpDelete ] + [ Route("/shell-descriptors/{aasIdentifier}/submodel-descriptors/{submodelIdentifier}") ] + [ ValidateModelState ] + [ SwaggerOperation("DeleteSubmodelDescriptorByIdThroughSuperpath") ] + [ SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.") ] + [ SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found") ] + [ SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error") ] + [ SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes") ] + public virtual IActionResult DeleteSubmodelDescriptorByIdThroughSuperpath([ FromRoute ] [ Required ] string aasIdentifier, + [ FromRoute ] [ Required ] string submodelIdentifier) { //TODO: Uncomment the next line to return response 204 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(204); @@ -131,16 +135,17 @@ public virtual IActionResult DeleteSubmodelDescriptorByIdThroughSuperpath([FromR /// Forbidden /// Internal Server Error /// Default error handling for unmentioned status codes - [HttpGet] - [Route("/shell-descriptors")] - [ValidateModelState] - [SwaggerOperation("GetAllAssetAdministrationShellDescriptors")] - [SwaggerResponse(statusCode: 200, type: typeof(List), description: "Requested Asset Administration Shell Descriptors")] - [SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")] - [SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")] - [SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")] - [SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")] - public virtual IActionResult GetAllAssetAdministrationShellDescriptors([FromQuery] int? limit, [FromQuery] string cursor, [FromQuery] string assetKind, [FromQuery] string assetType) + [ HttpGet ] + [ Route("/shell-descriptors") ] + [ ValidateModelState ] + [ SwaggerOperation("GetAllAssetAdministrationShellDescriptors") ] + [ SwaggerResponse(statusCode: 200, type: typeof(List), description: "Requested Asset Administration Shell Descriptors") ] + [ SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.") ] + [ SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden") ] + [ SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error") ] + [ SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes") ] + public virtual IActionResult GetAllAssetAdministrationShellDescriptors([ FromQuery ] int? limit, [ FromQuery ] string cursor, [ FromQuery ] string assetKind, + [ FromQuery ] string assetType) { // TODO (jtikekar, 2023-09-04): AssetType resembles AssetId from old Implementation List assetList = new List(); @@ -192,17 +197,18 @@ public virtual IActionResult GetAllAssetAdministrationShellDescriptors([FromQuer /// Not Found /// Internal Server Error /// Default error handling for unmentioned status codes - [HttpGet] - [Route("/shell-descriptors/{aasIdentifier}/submodel-descriptors")] - [ValidateModelState] - [SwaggerOperation("GetAllSubmodelDescriptorsThroughSuperpath")] - [SwaggerResponse(statusCode: 200, type: typeof(List), description: "Requested Submodel Descriptors")] - [SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")] - [SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")] - [SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")] - [SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")] - [SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")] - public virtual IActionResult GetAllSubmodelDescriptorsThroughSuperpath([FromRoute][Required] string aasIdentifier, [FromQuery] int? limit, [FromQuery] string cursor) + [ HttpGet ] + [ Route("/shell-descriptors/{aasIdentifier}/submodel-descriptors") ] + [ ValidateModelState ] + [ SwaggerOperation("GetAllSubmodelDescriptorsThroughSuperpath") ] + [ SwaggerResponse(statusCode: 200, type: typeof(List), description: "Requested Submodel Descriptors") ] + [ SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.") ] + [ SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden") ] + [ SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found") ] + [ SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error") ] + [ SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes") ] + public virtual IActionResult GetAllSubmodelDescriptorsThroughSuperpath([ FromRoute ] [ Required ] string aasIdentifier, [ FromQuery ] int? limit, + [ FromQuery ] string cursor) { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(200, default(GetSubmodelDescriptorsResult)); @@ -237,17 +243,17 @@ public virtual IActionResult GetAllSubmodelDescriptorsThroughSuperpath([FromRout /// Not Found /// Internal Server Error /// Default error handling for unmentioned status codes - [HttpGet] - [Route("/shell-descriptors/{aasIdentifier}")] - [ValidateModelState] - [SwaggerOperation("GetAssetAdministrationShellDescriptorById")] - [SwaggerResponse(statusCode: 200, type: typeof(AssetAdministrationShellDescriptor), description: "Requested Asset Administration Shell Descriptor")] - [SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")] - [SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")] - [SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")] - [SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")] - [SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")] - public virtual IActionResult GetAssetAdministrationShellDescriptorById([FromRoute][Required] string aasIdentifier) + [ HttpGet ] + [ Route("/shell-descriptors/{aasIdentifier}") ] + [ ValidateModelState ] + [ SwaggerOperation("GetAssetAdministrationShellDescriptorById") ] + [ SwaggerResponse(statusCode: 200, type: typeof(AssetAdministrationShellDescriptor), description: "Requested Asset Administration Shell Descriptor") ] + [ SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.") ] + [ SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden") ] + [ SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found") ] + [ SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error") ] + [ SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes") ] + public virtual IActionResult GetAssetAdministrationShellDescriptorById([ FromRoute ] [ Required ] string aasIdentifier) { var decodedAasIdentifier = _decoderService.Decode("aasIdentifier", aasIdentifier); _logger.LogInformation($"Received request to get the AAS Descriptor by Id"); @@ -273,7 +279,6 @@ public virtual IActionResult GetAssetAdministrationShellDescriptorById([FromRout } } } - } return NotFound(); @@ -290,17 +295,18 @@ public virtual IActionResult GetAssetAdministrationShellDescriptorById([FromRout /// Not Found /// Internal Server Error /// Default error handling for unmentioned status codes - [HttpGet] - [Route("/shell-descriptors/{aasIdentifier}/submodel-descriptors/{submodelIdentifier}")] - [ValidateModelState] - [SwaggerOperation("GetSubmodelDescriptorByIdThroughSuperpath")] - [SwaggerResponse(statusCode: 200, type: typeof(SubmodelDescriptor), description: "Requested Submodel Descriptor")] - [SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")] - [SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")] - [SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")] - [SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")] - [SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")] - public virtual IActionResult GetSubmodelDescriptorByIdThroughSuperpath([FromRoute][Required] string aasIdentifier, [FromRoute][Required] string submodelIdentifier) + [ HttpGet ] + [ Route("/shell-descriptors/{aasIdentifier}/submodel-descriptors/{submodelIdentifier}") ] + [ ValidateModelState ] + [ SwaggerOperation("GetSubmodelDescriptorByIdThroughSuperpath") ] + [ SwaggerResponse(statusCode: 200, type: typeof(SubmodelDescriptor), description: "Requested Submodel Descriptor") ] + [ SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.") ] + [ SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden") ] + [ SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found") ] + [ SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error") ] + [ SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes") ] + public virtual IActionResult GetSubmodelDescriptorByIdThroughSuperpath([ FromRoute ] [ Required ] string aasIdentifier, + [ FromRoute ] [ Required ] string submodelIdentifier) { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(200, default(SubmodelDescriptor)); @@ -333,17 +339,19 @@ public virtual IActionResult GetSubmodelDescriptorByIdThroughSuperpath([FromRout /// Internal Server Error /// Default error handling for unmentioned status codes //TODO (jtikekar, 2023-09-04): Routes are different than old impl - [HttpPost] - [Route("/shell-descriptors")] - [ValidateModelState] - [SwaggerOperation("PostAssetAdministrationShellDescriptor")] - [SwaggerResponse(statusCode: 201, type: typeof(AssetAdministrationShellDescriptor), description: "Asset Administration Shell Descriptor created successfully")] - [SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")] - [SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")] - [SwaggerResponse(statusCode: 409, type: typeof(Result), description: "Conflict, a resource which shall be created exists already. Might be thrown if a Submodel or SubmodelElement with the same ShortId is contained in a POST request.")] - [SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")] - [SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")] - public virtual IActionResult PostAssetAdministrationShellDescriptor([FromBody] AssetAdministrationShellDescriptor body) + [ HttpPost ] + [ Route("/shell-descriptors") ] + [ ValidateModelState ] + [ SwaggerOperation("PostAssetAdministrationShellDescriptor") ] + [ SwaggerResponse(statusCode: 201, type: typeof(AssetAdministrationShellDescriptor), description: "Asset Administration Shell Descriptor created successfully") ] + [ SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.") ] + [ SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden") ] + [ SwaggerResponse(statusCode: 409, type: typeof(Result), + description: + "Conflict, a resource which shall be created exists already. Might be thrown if a Submodel or SubmodelElement with the same ShortId is contained in a POST request.") ] + [ SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error") ] + [ SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes") ] + public virtual IActionResult PostAssetAdministrationShellDescriptor([ FromBody ] AssetAdministrationShellDescriptor body) { var timestamp = DateTime.UtcNow; @@ -377,19 +385,20 @@ public virtual IActionResult PostAssetAdministrationShellDescriptor([FromBody] A /// Conflict, a resource which shall be created exists already. Might be thrown if a Submodel or SubmodelElement with the same ShortId is contained in a POST request. /// Internal Server Error /// Default error handling for unmentioned status codes - - [HttpPost] - [Route("/shell-descriptors/{aasIdentifier}/submodel-descriptors")] - [ValidateModelState] - [SwaggerOperation("PostSubmodelDescriptorThroughSuperpath")] - [SwaggerResponse(statusCode: 201, type: typeof(SubmodelDescriptor), description: "Submodel Descriptor created successfully")] - [SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")] - [SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")] - [SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")] - [SwaggerResponse(statusCode: 409, type: typeof(Result), description: "Conflict, a resource which shall be created exists already. Might be thrown if a Submodel or SubmodelElement with the same ShortId is contained in a POST request.")] - [SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")] - [SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")] - public virtual IActionResult PostSubmodelDescriptorThroughSuperpath([FromBody] SubmodelDescriptor body, [FromRoute][Required] string aasIdentifier) + [ HttpPost ] + [ Route("/shell-descriptors/{aasIdentifier}/submodel-descriptors") ] + [ ValidateModelState ] + [ SwaggerOperation("PostSubmodelDescriptorThroughSuperpath") ] + [ SwaggerResponse(statusCode: 201, type: typeof(SubmodelDescriptor), description: "Submodel Descriptor created successfully") ] + [ SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.") ] + [ SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden") ] + [ SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found") ] + [ SwaggerResponse(statusCode: 409, type: typeof(Result), + description: + "Conflict, a resource which shall be created exists already. Might be thrown if a Submodel or SubmodelElement with the same ShortId is contained in a POST request.") ] + [ SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error") ] + [ SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes") ] + public virtual IActionResult PostSubmodelDescriptorThroughSuperpath([ FromBody ] SubmodelDescriptor body, [ FromRoute ] [ Required ] string aasIdentifier) { //TODO: Uncomment the next line to return response 201 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(201, default(SubmodelDescriptor)); @@ -425,16 +434,17 @@ public virtual IActionResult PostSubmodelDescriptorThroughSuperpath([FromBody] S /// Not Found /// Internal Server Error /// Default error handling for unmentioned status codes - [HttpPut] - [Route("/shell-descriptors/{aasIdentifier}")] - [ValidateModelState] - [SwaggerOperation("PutAssetAdministrationShellDescriptorById")] - [SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")] - [SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")] - [SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")] - [SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")] - [SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")] - public virtual IActionResult PutAssetAdministrationShellDescriptorById([FromBody] AssetAdministrationShellDescriptor body, [FromRoute][Required] byte[] aasIdentifier) + [ HttpPut ] + [ Route("/shell-descriptors/{aasIdentifier}") ] + [ ValidateModelState ] + [ SwaggerOperation("PutAssetAdministrationShellDescriptorById") ] + [ SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.") ] + [ SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden") ] + [ SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found") ] + [ SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error") ] + [ SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes") ] + public virtual IActionResult PutAssetAdministrationShellDescriptorById([ FromBody ] AssetAdministrationShellDescriptor body, + [ FromRoute ] [ Required ] byte[] aasIdentifier) { //TODO: Uncomment the next line to return response 204 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(204); @@ -469,16 +479,17 @@ public virtual IActionResult PutAssetAdministrationShellDescriptorById([FromBody /// Not Found /// Internal Server Error /// Default error handling for unmentioned status codes - [HttpPut] - [Route("/shell-descriptors/{aasIdentifier}/submodel-descriptors/{submodelIdentifier}")] - [ValidateModelState] - [SwaggerOperation("PutSubmodelDescriptorByIdThroughSuperpath")] - [SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")] - [SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")] - [SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")] - [SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")] - [SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")] - public virtual IActionResult PutSubmodelDescriptorByIdThroughSuperpath([FromBody] SubmodelDescriptor body, [FromRoute][Required] string aasIdentifier, [FromRoute][Required] string submodelIdentifier) + [ HttpPut ] + [ Route("/shell-descriptors/{aasIdentifier}/submodel-descriptors/{submodelIdentifier}") ] + [ ValidateModelState ] + [ SwaggerOperation("PutSubmodelDescriptorByIdThroughSuperpath") ] + [ SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.") ] + [ SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden") ] + [ SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found") ] + [ SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error") ] + [ SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes") ] + public virtual IActionResult PutSubmodelDescriptorByIdThroughSuperpath([ FromBody ] SubmodelDescriptor body, [ FromRoute ] [ Required ] string aasIdentifier, + [ FromRoute ] [ Required ] string submodelIdentifier) { //TODO: Uncomment the next line to return response 204 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(204); @@ -501,12 +512,12 @@ public virtual IActionResult PutSubmodelDescriptorByIdThroughSuperpath([FromBody throw new NotImplementedException(); } - [HttpPost] - [Route("/overwrite-shell-descriptors")] - [ValidateModelState] - [SwaggerOperation("PostMultipleAssetAdministrationShellDescriptors")] - [SwaggerResponse(statusCode: 201, type: typeof(List), description: "Asset Administration Shell Descriptors created successfully")] - public virtual IActionResult PostMultipleAssetAdministrationShellDescriptor([FromBody] List body) + [ HttpPost ] + [ Route("/overwrite-shell-descriptors") ] + [ ValidateModelState ] + [ SwaggerOperation("PostMultipleAssetAdministrationShellDescriptors") ] + [ SwaggerResponse(statusCode: 201, type: typeof(List), description: "Asset Administration Shell Descriptors created successfully") ] + public virtual IActionResult PostMultipleAssetAdministrationShellDescriptor([ FromBody ] List body) { var timestamp = DateTime.UtcNow; @@ -515,7 +526,6 @@ public virtual IActionResult PostMultipleAssetAdministrationShellDescriptor([Fro _registryInitializerService.CreateMultipleAssetAdministrationShellDescriptor(body, timestamp); return new ObjectResult("ok"); - } /// @@ -524,14 +534,14 @@ public virtual IActionResult PostMultipleAssetAdministrationShellDescriptor([Fro /// The key-value-pair of an Asset identifier (BASE64-URL-encoded JSON-serialized key-value-pairs) /// An Asset identifier (BASE64-URL-encoded identifier) /// Requested Asset Administration Shell ids - [HttpGet] - [Route("/lookup/shells")] - [ValidateModelState] - [SwaggerOperation("GetAllAssetAdministrationShellIdsByAssetLink")] - [SwaggerResponse(statusCode: 200, type: typeof(List), description: "Requested Asset Administration Shell ids")] + [ HttpGet ] + [ Route("/lookup/shells") ] + [ ValidateModelState ] + [ SwaggerOperation("GetAllAssetAdministrationShellIdsByAssetLink") ] + [ SwaggerResponse(statusCode: 200, type: typeof(List), description: "Requested Asset Administration Shell ids") ] public virtual IActionResult GetAllAssetAdministrationShellIdsByAssetLink( - [FromQuery] List assetIds, - [FromQuery] string assetId) + [ FromQuery ] List assetIds, + [ FromQuery ] string assetId) { try { @@ -545,6 +555,7 @@ public virtual IActionResult GetAllAssetAdministrationShellIdsByAssetLink( assetList.Add(decodedAssetId); } } + // single assetId if (assetId != null && assetId != "") { @@ -587,4 +598,4 @@ public virtual IActionResult GetAllAssetAdministrationShellIdsByAssetLink( } } } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Filters/BasePathFilter.cs b/src/IO.Swagger.Registry.Lib.V3/Filters/BasePathFilter.cs index 9c8584327..ae20b339a 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Filters/BasePathFilter.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Filters/BasePathFilter.cs @@ -32,7 +32,7 @@ public BasePathFilter(string basePath) /// FilterContext public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { - swaggerDoc.Servers.Add(new OpenApiServer() { Url = BasePath }); + swaggerDoc.Servers.Add(new OpenApiServer() {Url = BasePath}); var pathsToModify = swaggerDoc.Paths.Where(p => p.Key.StartsWith(BasePath)).ToList(); @@ -47,4 +47,4 @@ public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) } } } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Filters/GeneratePathParamsValidationFilter.cs b/src/IO.Swagger.Registry.Lib.V3/Filters/GeneratePathParamsValidationFilter.cs index f7265130c..da3947270 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Filters/GeneratePathParamsValidationFilter.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Filters/GeneratePathParamsValidationFilter.cs @@ -24,7 +24,7 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context) { var swaggerParam = operation.Parameters.SingleOrDefault(p => p.Name == par.Name); - var attributes = ((ControllerParameterDescriptor)par.ParameterDescriptor).ParameterInfo.CustomAttributes; + var attributes = ((ControllerParameterDescriptor) par.ParameterDescriptor).ParameterInfo.CustomAttributes; if (attributes != null && attributes.Count() > 0 && swaggerParam != null) { @@ -39,7 +39,7 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context) var regexAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RegularExpressionAttribute)); if (regexAttr != null) { - string regex = (string)regexAttr.ConstructorArguments[0].Value; + string regex = (string) regexAttr.ConstructorArguments[ 0 ].Value; if (swaggerParam is OpenApiParameter) { swaggerParam.Schema.Pattern = regex; @@ -53,21 +53,22 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context) { if (stringLengthAttr.NamedArguments.Count == 1) { - minLenght = (int)stringLengthAttr.NamedArguments.Single(p => p.MemberName == "MinimumLength").TypedValue.Value; + minLenght = (int) stringLengthAttr.NamedArguments.Single(p => p.MemberName == "MinimumLength").TypedValue.Value; } - maxLength = (int)stringLengthAttr.ConstructorArguments[0].Value; + + maxLength = (int) stringLengthAttr.ConstructorArguments[ 0 ].Value; } var minLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(MinLengthAttribute)); if (minLengthAttr != null) { - minLenght = (int)minLengthAttr.ConstructorArguments[0].Value; + minLenght = (int) minLengthAttr.ConstructorArguments[ 0 ].Value; } var maxLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(MaxLengthAttribute)); if (maxLengthAttr != null) { - maxLength = (int)maxLengthAttr.ConstructorArguments[0].Value; + maxLength = (int) maxLengthAttr.ConstructorArguments[ 0 ].Value; } if (swaggerParam is OpenApiParameter) @@ -80,8 +81,8 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context) var rangeAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RangeAttribute)); if (rangeAttr != null) { - int rangeMin = (int)rangeAttr.ConstructorArguments[0].Value; - int rangeMax = (int)rangeAttr.ConstructorArguments[1].Value; + int rangeMin = (int) rangeAttr.ConstructorArguments[ 0 ].Value; + int rangeMax = (int) rangeAttr.ConstructorArguments[ 1 ].Value; if (swaggerParam is OpenApiParameter) { @@ -93,4 +94,4 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context) } } } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Formatters/AasDescriptorRequestFormatter.cs b/src/IO.Swagger.Registry.Lib.V3/Formatters/AasDescriptorRequestFormatter.cs index cc1ee1ad4..df149e46d 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Formatters/AasDescriptorRequestFormatter.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Formatters/AasDescriptorRequestFormatter.cs @@ -53,6 +53,7 @@ public override Task ReadRequestBodyAsync(InputFormatterCo { aasDescList.Add(DescriptorDeserializer.AssetAdministrationShellDescriptorFrom(item)); } + result = aasDescList; } else @@ -63,4 +64,4 @@ public override Task ReadRequestBodyAsync(InputFormatterCo return InputFormatterResult.SuccessAsync(result); } } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Formatters/AasDescriptorResponseFormatter.cs b/src/IO.Swagger.Registry.Lib.V3/Formatters/AasDescriptorResponseFormatter.cs index e41df4fac..f7d5799ca 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Formatters/AasDescriptorResponseFormatter.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Formatters/AasDescriptorResponseFormatter.cs @@ -24,8 +24,8 @@ public static bool IsGenericListOfAasDesc(object o) { var oType = o.GetType(); return oType.IsGenericType && - (oType.GetGenericTypeDefinition() == typeof(List<>) && - (typeof(AssetAdministrationShellDescriptor).IsAssignableFrom(oType.GetGenericArguments()[0]))); + (oType.GetGenericTypeDefinition() == typeof(List<>) && + (typeof(AssetAdministrationShellDescriptor).IsAssignableFrom(oType.GetGenericArguments()[ 0 ]))); } public override bool CanWriteResult(OutputFormatterCanWriteContext context) @@ -71,27 +71,28 @@ public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context) jsonArray.Add(json); } } + JsonObject jsonNode = new JsonObject(); - jsonNode["result"] = jsonArray; + jsonNode[ "result" ] = jsonArray; var pagingMetadata = new JsonObject(); if (cursor != null) { - pagingMetadata["cursor"] = cursor; + pagingMetadata[ "cursor" ] = cursor; } - jsonNode["paging_metadata"] = pagingMetadata; + + jsonNode[ "paging_metadata" ] = pagingMetadata; var writer = new Utf8JsonWriter(response.Body); jsonNode.WriteTo(writer); writer.FlushAsync().GetAwaiter().GetResult(); } else if (IsGenericListOfAasDesc(context.Object)) { - var jsonArray = new JsonArray(); - IList genericList = (IList)context.Object; + IList genericList = (IList) context.Object; List contextObjectType = new List(); foreach (var generic in genericList) { - contextObjectType.Add((AssetAdministrationShellDescriptor)generic); + contextObjectType.Add((AssetAdministrationShellDescriptor) generic); } foreach (var item in contextObjectType) @@ -99,6 +100,7 @@ public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context) var json = DescriptorSerializer.ToJsonObject(item); jsonArray.Add(json); } + var writer = new Utf8JsonWriter(response.Body); jsonArray.WriteTo(writer); writer.FlushAsync().GetAwaiter().GetResult(); @@ -111,4 +113,4 @@ public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context) return Task.FromResult(response); } } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/IO.Swagger.Registry.Lib.V3.csproj b/src/IO.Swagger.Registry.Lib.V3/IO.Swagger.Registry.Lib.V3.csproj index 2f9bf9317..b1f1e4f2e 100644 --- a/src/IO.Swagger.Registry.Lib.V3/IO.Swagger.Registry.Lib.V3.csproj +++ b/src/IO.Swagger.Registry.Lib.V3/IO.Swagger.Registry.Lib.V3.csproj @@ -1,32 +1,32 @@  - - IO.Swagger - IO.Swagger - net6.0 - true - true - IO.Swagger.Registry.Lib.V3 - IO.Swagger.Registry - Library - - - false - - - - - - - - - - - - - - - - - - - + + IO.Swagger + IO.Swagger + net6.0 + true + true + IO.Swagger.Registry.Lib.V3 + IO.Swagger.Registry + Library + + + false + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Interfaces/IAasDescriptorPaginationService.cs b/src/IO.Swagger.Registry.Lib.V3/Interfaces/IAasDescriptorPaginationService.cs index cbbe05bc3..77993fe80 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Interfaces/IAasDescriptorPaginationService.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Interfaces/IAasDescriptorPaginationService.cs @@ -9,4 +9,4 @@ public interface IAasDescriptorPaginationService { AasDescriptorPagedResult GetPaginatedList(List sourceList, PaginationParameters paginationParameters); } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Interfaces/IAasRegistryService.cs b/src/IO.Swagger.Registry.Lib.V3/Interfaces/IAasRegistryService.cs index 96616f2ed..19b43504d 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Interfaces/IAasRegistryService.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Interfaces/IAasRegistryService.cs @@ -9,4 +9,4 @@ public interface IAasRegistryService AssetAdministrationShellDescriptor CreateAasDescriptorFromDB(AasSet aasDB); List GetAllAssetAdministrationShellDescriptors(string assetKind = null, List assetList = null, string aasIdentifier = null); } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Interfaces/IRegistryInitializerService.cs b/src/IO.Swagger.Registry.Lib.V3/Interfaces/IRegistryInitializerService.cs index 2a20fc567..6f8c95732 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Interfaces/IRegistryInitializerService.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Interfaces/IRegistryInitializerService.cs @@ -15,4 +15,4 @@ public interface IRegistryInitializerService List GetRegistryList(); void InitRegistry(List cList, DateTime timestamp, bool initAgain = false); } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Models/AasDescriptorPagedResult.cs b/src/IO.Swagger.Registry.Lib.V3/Models/AasDescriptorPagedResult.cs index a8d9cfc56..73794ed19 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Models/AasDescriptorPagedResult.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Models/AasDescriptorPagedResult.cs @@ -9,4 +9,4 @@ public class AasDescriptorPagedResult public List result { get; set; } public PagedResultPagingMetadata paging_metadata { get; set; } } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Models/AssetAdministrationShellDescriptor.cs b/src/IO.Swagger.Registry.Lib.V3/Models/AssetAdministrationShellDescriptor.cs index a58588a0e..d2f4e8c21 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Models/AssetAdministrationShellDescriptor.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Models/AssetAdministrationShellDescriptor.cs @@ -7,6 +7,7 @@ * Contact: info@idtwin.org * Generated by: https://github.com/swagger-api/swagger-codegen.git */ + using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -20,78 +21,80 @@ namespace IO.Swagger.Registry.Lib.V3.Models /// /// /// - [DataContract] + [ DataContract ] public partial class AssetAdministrationShellDescriptor : Descriptor, IEquatable { /// /// Gets or Sets Administration /// - [DataMember(Name = "administration")] + [ DataMember(Name = "administration") ] public AdministrativeInformation Administration { get; set; } /// /// Gets or Sets AssetKind /// - [DataMember(Name = "assetKind")] + [ DataMember(Name = "assetKind") ] public AssetKind AssetKind { get; set; } /// /// Gets or Sets AssetType /// //[RegularExpression("/^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$/")] - [StringLength(2000, MinimumLength = 1)] - [DataMember(Name = "assetType")] + [ StringLength(2000, MinimumLength = 1) ] + [ DataMember(Name = "assetType") ] public string AssetType { get; set; } /// /// Gets or Sets Endpoints /// - [DataMember(Name = "endpoints")] + [ DataMember(Name = "endpoints") ] public List Endpoints { get; set; } /// /// Gets or Sets GlobalAssetId /// //[RegularExpression("/^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$/")] - [StringLength(2000, MinimumLength = 1)] - [DataMember(Name = "globalAssetId")] + [ StringLength(2000, MinimumLength = 1) ] + [ DataMember(Name = "globalAssetId") ] public string GlobalAssetId { get; set; } /// /// Gets or Sets IdShort /// - [MaxLength(128)] - [DataMember(Name = "idShort")] + [ MaxLength(128) ] + [ DataMember(Name = "idShort") ] public string IdShort { get; set; } /// /// Gets or Sets Id /// - [Required] + [ Required ] //[RegularExpression("/^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$/")] - [StringLength(2000, MinimumLength = 1)] - [DataMember(Name = "id")] + [ StringLength(2000, MinimumLength = 1) ] + [ DataMember(Name = "id") ] public string Id { get; set; } /// /// Gets or Sets SpecificAssetIds /// - [DataMember(Name = "specificAssetIds")] + [ DataMember(Name = "specificAssetIds") ] public List SpecificAssetIds { get; set; } /// /// Gets or Sets SubmodelDescriptors /// - [DataMember(Name = "submodelDescriptors")] + [ DataMember(Name = "submodelDescriptors") ] public List SubmodelDescriptors { get; set; } - public AssetAdministrationShellDescriptor(AdministrativeInformation administration = null, AssetKind assetKind = AssetKind.NotApplicable, string assetType = null, List endpoints = null, string globalAssetId = null, string idShort = null, string id = null, List specificAssetIds = null, List submodelDescriptors = null) + public AssetAdministrationShellDescriptor(AdministrativeInformation administration = null, AssetKind assetKind = AssetKind.NotApplicable, string assetType = null, + List endpoints = null, string globalAssetId = null, string idShort = null, string id = null, List specificAssetIds = null, + List submodelDescriptors = null) { Administration = administration; AssetKind = assetKind; @@ -143,7 +146,7 @@ public override bool Equals(object obj = null) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((AssetAdministrationShellDescriptor)obj); + return obj.GetType() == GetType() && Equals((AssetAdministrationShellDescriptor) obj); } /// @@ -237,6 +240,7 @@ public override int GetHashCode() } #region Operators + #pragma warning disable 1591 public static bool operator ==(AssetAdministrationShellDescriptor left, AssetAdministrationShellDescriptor right) @@ -250,6 +254,7 @@ public override int GetHashCode() } #pragma warning restore 1591 + #endregion Operators } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Models/Descriptor.cs b/src/IO.Swagger.Registry.Lib.V3/Models/Descriptor.cs index 84b1744c6..38150f087 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Models/Descriptor.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Models/Descriptor.cs @@ -7,6 +7,7 @@ * Contact: info@idtwin.org * Generated by: https://github.com/swagger-api/swagger-codegen.git */ + using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -19,28 +20,28 @@ namespace IO.Swagger.Registry.Lib.V3.Models /// /// /// - [DataContract] + [ DataContract ] public partial class Descriptor : IEquatable { /// /// Gets or Sets Description /// - [DataMember(Name = "description")] + [ DataMember(Name = "description") ] public List Description { get; set; } /// /// Gets or Sets DisplayName /// - [DataMember(Name = "displayName")] + [ DataMember(Name = "displayName") ] public List DisplayName { get; set; } /// /// Gets or Sets Extensions /// - [DataMember(Name = "extensions")] + [ DataMember(Name = "extensions") ] public List Extensions { get; set; } /// @@ -76,7 +77,7 @@ public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((Descriptor)obj); + return obj.GetType() == GetType() && Equals((Descriptor) obj); } /// @@ -128,6 +129,7 @@ public override int GetHashCode() } #region Operators + #pragma warning disable 1591 public static bool operator ==(Descriptor left, Descriptor right) @@ -141,6 +143,7 @@ public override int GetHashCode() } #pragma warning restore 1591 + #endregion Operators } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Models/Endpoint.cs b/src/IO.Swagger.Registry.Lib.V3/Models/Endpoint.cs index 2af328003..e9a4040f7 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Models/Endpoint.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Models/Endpoint.cs @@ -7,6 +7,7 @@ * Contact: info@idtwin.org * Generated by: https://github.com/swagger-api/swagger-codegen.git */ + using Newtonsoft.Json; using System; using System.ComponentModel.DataAnnotations; @@ -18,24 +19,22 @@ namespace IO.Swagger.Registry.Lib.V3.Models /// /// /// - [DataContract] + [ DataContract ] public partial class Endpoint : IEquatable { /// /// Gets or Sets _Interface /// - [Required] - - [MaxLength(128)] - [DataMember(Name = "interface")] + [ Required ] + [ MaxLength(128) ] + [ DataMember(Name = "interface") ] public string Interface { get; set; } /// /// Gets or Sets ProtocolInformation /// - [Required] - - [DataMember(Name = "protocolInformation")] + [ Required ] + [ DataMember(Name = "protocolInformation") ] public ProtocolInformation ProtocolInformation { get; set; } public Endpoint(string @interface = null, ProtocolInformation protocolInformation = null) @@ -76,7 +75,7 @@ public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((Endpoint)obj); + return obj.GetType() == GetType() && Equals((Endpoint) obj); } /// @@ -121,6 +120,7 @@ public override int GetHashCode() } #region Operators + #pragma warning disable 1591 public static bool operator ==(Endpoint left, Endpoint right) @@ -134,6 +134,7 @@ public override int GetHashCode() } #pragma warning restore 1591 + #endregion Operators } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Models/Message.cs b/src/IO.Swagger.Registry.Lib.V3/Models/Message.cs index 0049f8c33..1fb57c199 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Models/Message.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Models/Message.cs @@ -7,6 +7,7 @@ * Contact: info@idtwin.org * Generated by: https://github.com/swagger-api/swagger-codegen.git */ + using Newtonsoft.Json; using System; using System.ComponentModel.DataAnnotations; @@ -18,77 +19,76 @@ namespace IO.Swagger.Registry.Lib.V3.Models /// /// /// - [DataContract] + [ DataContract ] public partial class Message : IEquatable { /// /// Gets or Sets Code /// - [StringLength(32, MinimumLength = 1)] - [DataMember(Name = "code")] + [ StringLength(32, MinimumLength = 1) ] + [ DataMember(Name = "code") ] public string Code { get; set; } /// /// Gets or Sets CorrelationId /// - [StringLength(128, MinimumLength = 1)] - [DataMember(Name = "correlationId")] + [ StringLength(128, MinimumLength = 1) ] + [ DataMember(Name = "correlationId") ] public string CorrelationId { get; set; } /// /// Gets or Sets MessageType /// - [JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] + [ JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter)) ] public enum MessageTypeEnum { /// /// Enum UndefinedEnum for Undefined /// - [EnumMember(Value = "Undefined")] - UndefinedEnum = 0, + [ EnumMember(Value = "Undefined") ] UndefinedEnum = 0, + /// /// Enum InfoEnum for Info /// - [EnumMember(Value = "Info")] - InfoEnum = 1, + [ EnumMember(Value = "Info") ] InfoEnum = 1, + /// /// Enum WarningEnum for Warning /// - [EnumMember(Value = "Warning")] - WarningEnum = 2, + [ EnumMember(Value = "Warning") ] WarningEnum = 2, + /// /// Enum ErrorEnum for Error /// - [EnumMember(Value = "Error")] - ErrorEnum = 3, + [ EnumMember(Value = "Error") ] ErrorEnum = 3, + /// /// Enum ExceptionEnum for Exception /// - [EnumMember(Value = "Exception")] - ExceptionEnum = 4 + [ EnumMember(Value = "Exception") ] ExceptionEnum = 4 } /// /// Gets or Sets MessageType /// - [DataMember(Name = "messageType")] + [ DataMember(Name = "messageType") ] public MessageTypeEnum? MessageType { get; set; } /// /// Gets or Sets Text /// - [DataMember(Name = "text")] + [ DataMember(Name = "text") ] public string Text { get; set; } /// /// Gets or Sets Timestamp /// //[RegularExpression("/^-?(([1-9][0-9][0-9][0-9]+)|(0[0-9][0-9][0-9]))-((0[1-9])|(1[0-2]))-((0[1-9])|([12][0-9])|(3[01]))T(((([01][0-9])|(2[0-3])):[0-5][0-9]:([0-5][0-9])(\\.[0-9]+)?)|24:00:00(\\.0+)?)(Z|\\+00:00|-00:00)$/")] - [DataMember(Name = "timestamp")] + [ DataMember(Name = "timestamp") ] public string Timestamp { get; set; } /// @@ -126,7 +126,7 @@ public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((Message)obj); + return obj.GetType() == GetType() && Equals((Message) obj); } /// @@ -192,6 +192,7 @@ public override int GetHashCode() } #region Operators + #pragma warning disable 1591 public static bool operator ==(Message left, Message right) @@ -205,6 +206,7 @@ public override int GetHashCode() } #pragma warning restore 1591 + #endregion Operators } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Models/ProtocolInformation.cs b/src/IO.Swagger.Registry.Lib.V3/Models/ProtocolInformation.cs index ad3d9045a..9591c1513 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Models/ProtocolInformation.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Models/ProtocolInformation.cs @@ -7,6 +7,7 @@ * Contact: info@idtwin.org * Generated by: https://github.com/swagger-api/swagger-codegen.git */ + using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -20,65 +21,65 @@ namespace IO.Swagger.Registry.Lib.V3.Models /// /// /// - [DataContract] + [ DataContract ] public partial class ProtocolInformation : IEquatable { /// /// Gets or Sets Href /// - [Required] - - [MaxLength(2048)] - [DataMember(Name = "href")] + [ Required ] + [ MaxLength(2048) ] + [ DataMember(Name = "href") ] public string Href { get; set; } /// /// Gets or Sets EndpointProtocol /// - [MaxLength(128)] - [DataMember(Name = "endpointProtocol")] + [ MaxLength(128) ] + [ DataMember(Name = "endpointProtocol") ] public string EndpointProtocol { get; set; } /// /// Gets or Sets EndpointProtocolVersion /// - [DataMember(Name = "endpointProtocolVersion")] + [ DataMember(Name = "endpointProtocolVersion") ] public List EndpointProtocolVersion { get; set; } /// /// Gets or Sets Subprotocol /// - [MaxLength(128)] - [DataMember(Name = "subprotocol")] + [ MaxLength(128) ] + [ DataMember(Name = "subprotocol") ] public string Subprotocol { get; set; } /// /// Gets or Sets SubprotocolBody /// - [MaxLength(128)] - [DataMember(Name = "subprotocolBody")] + [ MaxLength(128) ] + [ DataMember(Name = "subprotocolBody") ] public string SubprotocolBody { get; set; } /// /// Gets or Sets SubprotocolBodyEncoding /// - [MaxLength(128)] - [DataMember(Name = "subprotocolBodyEncoding")] + [ MaxLength(128) ] + [ DataMember(Name = "subprotocolBodyEncoding") ] public string SubprotocolBodyEncoding { get; set; } /// /// Gets or Sets SecurityAttributes /// - [DataMember(Name = "securityAttributes")] + [ DataMember(Name = "securityAttributes") ] public List SecurityAttributes { get; set; } - public ProtocolInformation(string href = null, string endpointProtocol = null, List endpointProtocolVersion = null, string subprotocol = null, string subprotocolBody = null, string subprotocolBodyEncoding = null, List securityAttributes = null) + public ProtocolInformation(string href = null, string endpointProtocol = null, List endpointProtocolVersion = null, string subprotocol = null, + string subprotocolBody = null, string subprotocolBodyEncoding = null, List securityAttributes = null) { Href = href; EndpointProtocol = endpointProtocol; @@ -126,7 +127,7 @@ public override bool Equals(object obj = null) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((ProtocolInformation)obj); + return obj.GetType() == GetType() && Equals((ProtocolInformation) obj); } /// @@ -206,6 +207,7 @@ public override int GetHashCode() } #region Operators + #pragma warning disable 1591 public static bool operator ==(ProtocolInformation left, ProtocolInformation right) @@ -219,6 +221,7 @@ public override int GetHashCode() } #pragma warning restore 1591 + #endregion Operators } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Models/ProtocolInformationSecurityAttributes.cs b/src/IO.Swagger.Registry.Lib.V3/Models/ProtocolInformationSecurityAttributes.cs index 778276964..e11c2a22f 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Models/ProtocolInformationSecurityAttributes.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Models/ProtocolInformationSecurityAttributes.cs @@ -7,6 +7,7 @@ * Contact: info@idtwin.org * Generated by: https://github.com/swagger-api/swagger-codegen.git */ + using Newtonsoft.Json; using System; using System.ComponentModel.DataAnnotations; @@ -18,59 +19,57 @@ namespace IO.Swagger.Registry.Lib.V3.Models /// /// /// - [DataContract] + [ DataContract ] public partial class ProtocolInformationSecurityAttributes : IEquatable { /// /// Gets or Sets Type /// - [JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] + [ JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter)) ] public enum TypeEnum { /// /// Enum NONEEnum for NONE /// - [EnumMember(Value = "NONE")] - NONEEnum = 0, + [ EnumMember(Value = "NONE") ] NONEEnum = 0, + /// /// Enum RFCTLSAEnum for RFC_TLSA /// - [EnumMember(Value = "RFC_TLSA")] - RFCTLSAEnum = 1, + [ EnumMember(Value = "RFC_TLSA") ] RFCTLSAEnum = 1, + /// /// Enum W3CDIDEnum for W3C_DID /// - [EnumMember(Value = "W3C_DID")] - W3CDIDEnum = 2 + [ EnumMember(Value = "W3C_DID") ] W3CDIDEnum = 2 } /// /// Gets or Sets Type /// - [Required] - - [DataMember(Name = "type")] + [ Required ] + [ DataMember(Name = "type") ] public TypeEnum? Type { get; set; } /// /// Gets or Sets Key /// - [Required] - - [DataMember(Name = "key")] + [ Required ] + [ DataMember(Name = "key") ] public string Key { get; set; } /// /// Gets or Sets Value /// - [Required] - - [DataMember(Name = "value")] + [ Required ] + [ DataMember(Name = "value") ] public string Value { get; set; } public ProtocolInformationSecurityAttributes(TypeEnum type, string key, string value) { - Type = type; Key = key; Value = value; + Type = type; + Key = key; + Value = value; } /// @@ -106,7 +105,7 @@ public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((ProtocolInformationSecurityAttributes)obj); + return obj.GetType() == GetType() && Equals((ProtocolInformationSecurityAttributes) obj); } /// @@ -158,6 +157,7 @@ public override int GetHashCode() } #region Operators + #pragma warning disable 1591 public static bool operator ==(ProtocolInformationSecurityAttributes left, ProtocolInformationSecurityAttributes right) @@ -171,6 +171,7 @@ public override int GetHashCode() } #pragma warning restore 1591 + #endregion Operators } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Models/Result.cs b/src/IO.Swagger.Registry.Lib.V3/Models/Result.cs index 024b83f51..521b3f477 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Models/Result.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Models/Result.cs @@ -7,6 +7,7 @@ * Contact: info@idtwin.org * Generated by: https://github.com/swagger-api/swagger-codegen.git */ + using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -19,14 +20,14 @@ namespace IO.Swagger.Registry.Lib.V3.Models /// /// /// - [DataContract] + [ DataContract ] public partial class Result : IEquatable { /// /// Gets or Sets Messages /// - [DataMember(Name = "messages")] + [ DataMember(Name = "messages") ] public List Messages { get; set; } /// @@ -60,7 +61,7 @@ public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((Result)obj); + return obj.GetType() == GetType() && Equals((Result) obj); } /// @@ -74,10 +75,9 @@ public bool Equals(Result other) if (ReferenceEquals(this, other)) return true; return - - Messages == other.Messages || - Messages != null && - Messages.SequenceEqual(other.Messages) + Messages == other.Messages || + Messages != null && + Messages.SequenceEqual(other.Messages) ; } @@ -98,6 +98,7 @@ public override int GetHashCode() } #region Operators + #pragma warning disable 1591 public static bool operator ==(Result left, Result right) @@ -111,6 +112,7 @@ public override int GetHashCode() } #pragma warning restore 1591 + #endregion Operators } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Models/SubmodelDescriptor.cs b/src/IO.Swagger.Registry.Lib.V3/Models/SubmodelDescriptor.cs index cf4a0b1ac..91a123f1b 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Models/SubmodelDescriptor.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Models/SubmodelDescriptor.cs @@ -7,6 +7,7 @@ * Contact: info@idtwin.org * Generated by: https://github.com/swagger-api/swagger-codegen.git */ + using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -20,53 +21,52 @@ namespace IO.Swagger.Registry.Lib.V3.Models /// /// /// - [DataContract] + [ DataContract ] public partial class SubmodelDescriptor : Descriptor, IEquatable { /// /// Gets or Sets Administration /// - [DataMember(Name = "administration")] + [ DataMember(Name = "administration") ] public AdministrativeInformation Administration { get; set; } /// /// Gets or Sets Endpoints /// - [Required] - - [DataMember(Name = "endpoints")] + [ Required ] + [ DataMember(Name = "endpoints") ] public List Endpoints { get; set; } /// /// Gets or Sets IdShort /// - [MaxLength(128)] - [DataMember(Name = "idShort")] + [ MaxLength(128) ] + [ DataMember(Name = "idShort") ] public string IdShort { get; set; } /// /// Gets or Sets Id /// - [Required] + [ Required ] //[RegularExpression("/^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$/")] - [StringLength(2000, MinimumLength = 1)] - [DataMember(Name = "id")] + [ StringLength(2000, MinimumLength = 1) ] + [ DataMember(Name = "id") ] public string Id { get; set; } /// /// Gets or Sets SemanticId /// - [DataMember(Name = "semanticId")] + [ DataMember(Name = "semanticId") ] public Reference SemanticId { get; set; } /// /// Gets or Sets SupplementalSemanticId /// - [DataMember(Name = "supplementalSemanticId")] + [ DataMember(Name = "supplementalSemanticId") ] public List SupplementalSemanticId { get; set; } // TODO (jtikekar, 2023-09-04): @Andreas Not conformant with specifications @@ -74,10 +74,11 @@ public partial class SubmodelDescriptor : Descriptor, IEquatable - [DataMember(Name = "federatedElements")] + [ DataMember(Name = "federatedElements") ] public List FederatedElements { get; set; } - public SubmodelDescriptor(AdministrativeInformation administration = null, List endpoints = null, string idShort = null, string id = null, Reference semanticId = null, List supplementalSemanticId = null, List federatedElements = null) + public SubmodelDescriptor(AdministrativeInformation administration = null, List endpoints = null, string idShort = null, string id = null, + Reference semanticId = null, List supplementalSemanticId = null, List federatedElements = null) { Administration = administration; Endpoints = endpoints; @@ -124,7 +125,7 @@ public override bool Equals(object obj = null) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((SubmodelDescriptor)obj); + return obj.GetType() == GetType() && Equals((SubmodelDescriptor) obj); } /// @@ -197,6 +198,7 @@ public override int GetHashCode() } #region Operators + #pragma warning disable 1591 public static bool operator ==(SubmodelDescriptor left, SubmodelDescriptor right) @@ -210,6 +212,7 @@ public override int GetHashCode() } #pragma warning restore 1591 + #endregion Operators } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Serializers/DescriptorDeserializeImplementation.cs b/src/IO.Swagger.Registry.Lib.V3/Serializers/DescriptorDeserializeImplementation.cs index a028e6e1f..4855b47c9 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Serializers/DescriptorDeserializeImplementation.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Serializers/DescriptorDeserializeImplementation.cs @@ -35,228 +35,248 @@ internal static AssetAdministrationShellDescriptor AssetAdministrationShellDescr { continue; } + switch (keyValue.Key) { case "administration": + { + if (keyValue.Value == null) { - if (keyValue.Value == null) - { - continue; - } - administrativeInformation = Jsonization.Deserialize.AdministrativeInformationFrom(keyValue.Value); - break; + continue; } + + administrativeInformation = Jsonization.Deserialize.AdministrativeInformationFrom(keyValue.Value); + break; + } case "assetKind": + { + if (keyValue.Value == null) { - if (keyValue.Value == null) - { - continue; - } - assetKind = Jsonization.Deserialize.AssetKindFrom(keyValue.Value); - break; + continue; } + + assetKind = Jsonization.Deserialize.AssetKindFrom(keyValue.Value); + break; + } case "assetType": + { + if (keyValue.Value == null) { - if (keyValue.Value == null) - { - continue; - } - assetType = StringFrom( - keyValue.Value, - out error); - if (error != null) - { - error.PrependSegment( - new Reporting.NameSegment( - "id")); - return null; - } - break; + continue; + } + + assetType = StringFrom( + keyValue.Value, + out error); + if (error != null) + { + error.PrependSegment( + new Reporting.NameSegment( + "id")); + return null; } + + break; + } case "endpoints": + { + if (keyValue.Value == null) { - if (keyValue.Value == null) - { - continue; - } + continue; + } + + JsonArray? arrayEndpoints = keyValue.Value as JsonArray; + if (arrayEndpoints == null) + { + error = new Reporting.Error( + $"Expected a JsonArray, but got {keyValue.Value.GetType()}"); + error.PrependSegment( + new Reporting.NameSegment( + "endpoints")); + return null; + } - JsonArray? arrayEndpoints = keyValue.Value as JsonArray; - if (arrayEndpoints == null) + endpoints = new List( + arrayEndpoints.Count); + int indexEndpoint = 0; + foreach (JsonNode? item in arrayEndpoints) + { + if (item == null) { error = new Reporting.Error( - $"Expected a JsonArray, but got {keyValue.Value.GetType()}"); + "Expected a non-null item, but got a null"); + error.PrependSegment( + new Reporting.IndexSegment( + indexEndpoint)); error.PrependSegment( new Reporting.NameSegment( "endpoints")); return null; } - endpoints = new List( - arrayEndpoints.Count); - int indexEndpoint = 0; - foreach (JsonNode? item in arrayEndpoints) - { - if (item == null) - { - error = new Reporting.Error( - "Expected a non-null item, but got a null"); - error.PrependSegment( - new Reporting.IndexSegment( - indexEndpoint)); - error.PrependSegment( - new Reporting.NameSegment( - "endpoints")); - return null; - } - Endpoint? parsedItem = EndpointFrom( - item ?? throw new System.InvalidOperationException(), - out error); - if (error != null) - { - error.PrependSegment( - new Reporting.IndexSegment( - indexEndpoint)); - error.PrependSegment( - new Reporting.NameSegment( - "endpoint")); - return null; - } - endpoints.Add( - parsedItem - ?? throw new System.InvalidOperationException( - "Unexpected result null when error is null")); - indexEndpoint++; - } - break; - } - case "globalAssetId": - { - globalAssetId = StringFrom( - keyValue.Value, - out error); + + Endpoint? parsedItem = EndpointFrom( + item ?? throw new System.InvalidOperationException(), + out error); if (error != null) { + error.PrependSegment( + new Reporting.IndexSegment( + indexEndpoint)); error.PrependSegment( new Reporting.NameSegment( - "globalAssetId")); + "endpoint")); return null; } - break; + + endpoints.Add( + parsedItem + ?? throw new System.InvalidOperationException( + "Unexpected result null when error is null")); + indexEndpoint++; } + + break; + } + case "globalAssetId": + { + globalAssetId = StringFrom( + keyValue.Value, + out error); + if (error != null) + { + error.PrependSegment( + new Reporting.NameSegment( + "globalAssetId")); + return null; + } + + break; + } case "idShort": + { + idShort = StringFrom( + keyValue.Value, + out error); + if (error != null) { - idShort = StringFrom( - keyValue.Value, - out error); - if (error != null) - { - error.PrependSegment( - new Reporting.NameSegment( - "idShort")); - return null; - } - break; + error.PrependSegment( + new Reporting.NameSegment( + "idShort")); + return null; } + + break; + } case "id": + { + id = StringFrom( + keyValue.Value, + out error); + if (error != null) { - id = StringFrom( - keyValue.Value, - out error); - if (error != null) - { - error.PrependSegment( - new Reporting.NameSegment( - "id")); - return null; - } - break; + error.PrependSegment( + new Reporting.NameSegment( + "id")); + return null; } + + break; + } case "specificAssetIds": + { + JsonArray? arraySpecificAssetIds = keyValue.Value as JsonArray; + if (arraySpecificAssetIds == null) + { + error = new Reporting.Error( + $"Expected a JsonArray, but got {keyValue.Value.GetType()}"); + error.PrependSegment( + new Reporting.NameSegment( + "specificAssetIds")); + return null; + } + + specificAssetIds = new List(arraySpecificAssetIds.Count); + int indexSpecificAssetId = 0; + foreach (JsonNode item in arraySpecificAssetIds) { - JsonArray? arraySpecificAssetIds = keyValue.Value as JsonArray; - if (arraySpecificAssetIds == null) + if (item == null) { error = new Reporting.Error( - $"Expected a JsonArray, but got {keyValue.Value.GetType()}"); + "Expected a non-null item, but got a null"); + error.PrependSegment( + new Reporting.IndexSegment( + indexSpecificAssetId)); error.PrependSegment( new Reporting.NameSegment( - "specificAssetIds")); + "endpoints")); return null; } - specificAssetIds = new List(arraySpecificAssetIds.Count); - int indexSpecificAssetId = 0; - foreach (JsonNode item in arraySpecificAssetIds) - { - if (item == null) - { - error = new Reporting.Error( - "Expected a non-null item, but got a null"); - error.PrependSegment( - new Reporting.IndexSegment( - indexSpecificAssetId)); - error.PrependSegment( - new Reporting.NameSegment( - "endpoints")); - return null; - } - SpecificAssetId specificAssetId = Jsonization.Deserialize.SpecificAssetIdFrom(item); - specificAssetIds.Add(specificAssetId); - } - break; + + SpecificAssetId specificAssetId = Jsonization.Deserialize.SpecificAssetIdFrom(item); + specificAssetIds.Add(specificAssetId); } + + break; + } case "submodelDescriptors": + { + JsonArray? arraySubmodelDescriptors = keyValue.Value as JsonArray; + if (arraySubmodelDescriptors == null) + { + error = new Reporting.Error( + $"Expected a JsonArray, but got {keyValue.Value.GetType()}"); + error.PrependSegment( + new Reporting.NameSegment( + "submodelDescriptors")); + return null; + } + + submodelDescriptors = new List( + arraySubmodelDescriptors.Count); + int indexSubmodelDescriptors = 0; + foreach (JsonNode? item in arraySubmodelDescriptors) { - JsonArray? arraySubmodelDescriptors = keyValue.Value as JsonArray; - if (arraySubmodelDescriptors == null) + if (item == null) { error = new Reporting.Error( - $"Expected a JsonArray, but got {keyValue.Value.GetType()}"); + "Expected a non-null item, but got a null"); + error.PrependSegment( + new Reporting.IndexSegment( + indexSubmodelDescriptors)); error.PrependSegment( new Reporting.NameSegment( "submodelDescriptors")); return null; } - submodelDescriptors = new List( - arraySubmodelDescriptors.Count); - int indexSubmodelDescriptors = 0; - foreach (JsonNode? item in arraySubmodelDescriptors) + + SubmodelDescriptor? parsedItem = SubmodelDescriptorFrom( + item ?? throw new System.InvalidOperationException(), + out error); + if (error != null) { - if (item == null) - { - error = new Reporting.Error( - "Expected a non-null item, but got a null"); - error.PrependSegment( - new Reporting.IndexSegment( - indexSubmodelDescriptors)); - error.PrependSegment( - new Reporting.NameSegment( - "submodelDescriptors")); - return null; - } - SubmodelDescriptor? parsedItem = SubmodelDescriptorFrom( - item ?? throw new System.InvalidOperationException(), - out error); - if (error != null) - { - error.PrependSegment( - new Reporting.IndexSegment( - indexSubmodelDescriptors)); - error.PrependSegment( - new Reporting.NameSegment( - "submodelDescriptors")); - return null; - } - submodelDescriptors.Add( - parsedItem - ?? throw new System.InvalidOperationException( - "Unexpected result null when error is null")); - indexSubmodelDescriptors++; + error.PrependSegment( + new Reporting.IndexSegment( + indexSubmodelDescriptors)); + error.PrependSegment( + new Reporting.NameSegment( + "submodelDescriptors")); + return null; } - break; + + submodelDescriptors.Add( + parsedItem + ?? throw new System.InvalidOperationException( + "Unexpected result null when error is null")); + indexSubmodelDescriptors++; } + + break; + } } } - return new AssetAdministrationShellDescriptor(administrativeInformation, assetKind, assetType, endpoints, globalAssetId, idShort, id, specificAssetIds, submodelDescriptors); + return new AssetAdministrationShellDescriptor(administrativeInformation, assetKind, assetType, endpoints, globalAssetId, idShort, id, specificAssetIds, + submodelDescriptors); } internal static SubmodelDescriptor SubmodelDescriptorFrom(JsonNode node, out Reporting.Error error) @@ -285,184 +305,198 @@ internal static SubmodelDescriptor SubmodelDescriptorFrom(JsonNode node, out Rep { continue; } + switch (keyValue.Key) { case "administration": + { + administration = Jsonization.Deserialize.AdministrativeInformationFrom(keyValue.Value); + break; + } + case "endpoints": + { + if (keyValue.Value == null) { - administration = Jsonization.Deserialize.AdministrativeInformationFrom(keyValue.Value); - break; + continue; } - case "endpoints": + + JsonArray? arrayEndpoints = keyValue.Value as JsonArray; + if (arrayEndpoints == null) { - if (keyValue.Value == null) - { - continue; - } + error = new Reporting.Error( + $"Expected a JsonArray, but got {keyValue.Value.GetType()}"); + error.PrependSegment( + new Reporting.NameSegment( + "endpoints")); + return null; + } - JsonArray? arrayEndpoints = keyValue.Value as JsonArray; - if (arrayEndpoints == null) + endpoints = new List( + arrayEndpoints.Count); + int indexEndpoint = 0; + foreach (JsonNode? item in arrayEndpoints) + { + if (item == null) { error = new Reporting.Error( - $"Expected a JsonArray, but got {keyValue.Value.GetType()}"); + "Expected a non-null item, but got a null"); + error.PrependSegment( + new Reporting.IndexSegment( + indexEndpoint)); error.PrependSegment( new Reporting.NameSegment( "endpoints")); return null; } - endpoints = new List( - arrayEndpoints.Count); - int indexEndpoint = 0; - foreach (JsonNode? item in arrayEndpoints) - { - if (item == null) - { - error = new Reporting.Error( - "Expected a non-null item, but got a null"); - error.PrependSegment( - new Reporting.IndexSegment( - indexEndpoint)); - error.PrependSegment( - new Reporting.NameSegment( - "endpoints")); - return null; - } - Endpoint? parsedItem = EndpointFrom( - item ?? throw new System.InvalidOperationException(), - out error); - if (error != null) - { - error.PrependSegment( - new Reporting.IndexSegment( - indexEndpoint)); - error.PrependSegment( - new Reporting.NameSegment( - "endpoint")); - return null; - } - endpoints.Add( - parsedItem - ?? throw new System.InvalidOperationException( - "Unexpected result null when error is null")); - indexEndpoint++; - } - break; - } - case "idShort": - { - idShort = StringFrom( - keyValue.Value, - out error); + + Endpoint? parsedItem = EndpointFrom( + item ?? throw new System.InvalidOperationException(), + out error); if (error != null) { + error.PrependSegment( + new Reporting.IndexSegment( + indexEndpoint)); error.PrependSegment( new Reporting.NameSegment( - "idShort")); + "endpoint")); return null; } - break; + + endpoints.Add( + parsedItem + ?? throw new System.InvalidOperationException( + "Unexpected result null when error is null")); + indexEndpoint++; + } + + break; + } + case "idShort": + { + idShort = StringFrom( + keyValue.Value, + out error); + if (error != null) + { + error.PrependSegment( + new Reporting.NameSegment( + "idShort")); + return null; } + + break; + } case "id": + { + id = StringFrom( + keyValue.Value, + out error); + if (error != null) { - id = StringFrom( - keyValue.Value, - out error); - if (error != null) - { - error.PrependSegment( - new Reporting.NameSegment( - "id")); - return null; - } - break; + error.PrependSegment( + new Reporting.NameSegment( + "id")); + return null; } + + break; + } case "semanticId": + { + semanticId = Jsonization.Deserialize.ReferenceFrom(keyValue.Value); + break; + } + case "supplementalSemanticId": + { + JsonArray? arraySupplementalSemanticId = keyValue.Value as JsonArray; + if (arraySupplementalSemanticId == null) { - semanticId = Jsonization.Deserialize.ReferenceFrom(keyValue.Value); - break; + error = new Reporting.Error( + $"Expected a JsonArray, but got {keyValue.Value.GetType()}"); + error.PrependSegment( + new Reporting.NameSegment( + "supplementalSemanticId")); + return null; } - case "supplementalSemanticId": + + supplementalSemanticId = new List(arraySupplementalSemanticId.Count); + int indexSpecificAssetId = 0; + foreach (JsonNode item in arraySupplementalSemanticId) { - JsonArray? arraySupplementalSemanticId = keyValue.Value as JsonArray; - if (arraySupplementalSemanticId == null) + if (item == null) { error = new Reporting.Error( - $"Expected a JsonArray, but got {keyValue.Value.GetType()}"); + "Expected a non-null item, but got a null"); + error.PrependSegment( + new Reporting.IndexSegment( + indexSpecificAssetId)); error.PrependSegment( new Reporting.NameSegment( "supplementalSemanticId")); return null; } - supplementalSemanticId = new List(arraySupplementalSemanticId.Count); - int indexSpecificAssetId = 0; - foreach (JsonNode item in arraySupplementalSemanticId) - { - if (item == null) - { - error = new Reporting.Error( - "Expected a non-null item, but got a null"); - error.PrependSegment( - new Reporting.IndexSegment( - indexSpecificAssetId)); - error.PrependSegment( - new Reporting.NameSegment( - "supplementalSemanticId")); - return null; - } - Reference suppSemanticId = Jsonization.Deserialize.ReferenceFrom(item); - supplementalSemanticId.Add(suppSemanticId); - } - break; + + Reference suppSemanticId = Jsonization.Deserialize.ReferenceFrom(item); + supplementalSemanticId.Add(suppSemanticId); } + + break; + } case "federatedElements": + { + JsonArray? arrayFederatedElements = keyValue.Value as JsonArray; + if (arrayFederatedElements == null) { - JsonArray? arrayFederatedElements = keyValue.Value as JsonArray; - if (arrayFederatedElements == null) + error = new Reporting.Error( + $"Expected a JsonArray, but got {keyValue.Value.GetType()}"); + error.PrependSegment( + new Reporting.NameSegment( + "federatedElements")); + return null; + } + + federatedElements = new List( + arrayFederatedElements.Count); + int indexFederatedElements = 0; + foreach (JsonNode? item in arrayFederatedElements) + { + if (item == null) { error = new Reporting.Error( - $"Expected a JsonArray, but got {keyValue.Value.GetType()}"); + "Expected a non-null item, but got a null"); + error.PrependSegment( + new Reporting.IndexSegment( + indexFederatedElements)); error.PrependSegment( new Reporting.NameSegment( "federatedElements")); return null; } - federatedElements = new List( - arrayFederatedElements.Count); - int indexFederatedElements = 0; - foreach (JsonNode? item in arrayFederatedElements) + + string? parsedItem = StringFrom( + item ?? throw new System.InvalidOperationException(), + out error); + if (error != null) { - if (item == null) - { - error = new Reporting.Error( - "Expected a non-null item, but got a null"); - error.PrependSegment( - new Reporting.IndexSegment( - indexFederatedElements)); - error.PrependSegment( - new Reporting.NameSegment( - "federatedElements")); - return null; - } - string? parsedItem = StringFrom( - item ?? throw new System.InvalidOperationException(), - out error); - if (error != null) - { - error.PrependSegment( - new Reporting.IndexSegment( - indexFederatedElements)); - error.PrependSegment( - new Reporting.NameSegment( - "endpoint")); - return null; - } - federatedElements.Add( - parsedItem - ?? throw new System.InvalidOperationException( - "Unexpected result null when error is null")); - indexFederatedElements++; + error.PrependSegment( + new Reporting.IndexSegment( + indexFederatedElements)); + error.PrependSegment( + new Reporting.NameSegment( + "endpoint")); + return null; } - break; + + federatedElements.Add( + parsedItem + ?? throw new System.InvalidOperationException( + "Unexpected result null when error is null")); + indexFederatedElements++; } + + break; + } } } @@ -490,38 +524,40 @@ private static Endpoint EndpointFrom(JsonNode node, out Reporting.Error error) { continue; } + switch (keyValue.Key) { case "interface": + { + _interface = StringFrom( + keyValue.Value, + out error); + if (error != null) { - _interface = StringFrom( - keyValue.Value, - out error); - if (error != null) - { - error.PrependSegment( - new Reporting.NameSegment( - "interface")); - return null; - } - break; + error.PrependSegment( + new Reporting.NameSegment( + "interface")); + return null; } + + break; + } case "protocolInformation": + { + protocolInformation = ProtocolInformationFrom( + keyValue.Value, + out error); + if (error != null) { - protocolInformation = ProtocolInformationFrom( - keyValue.Value, - out error); - if (error != null) - { - error.PrependSegment( - new Reporting.NameSegment( - "protocolInformation")); - return null; - } - break; + error.PrependSegment( + new Reporting.NameSegment( + "protocolInformation")); + return null; } - } + break; + } + } } return new Endpoint(_interface, protocolInformation); @@ -553,178 +589,192 @@ private static ProtocolInformation ProtocolInformationFrom(JsonNode node, out Re { continue; } + switch (keyValue.Key) { case "href": + { + href = StringFrom( + keyValue.Value, + out error); + if (error != null) { - href = StringFrom( - keyValue.Value, - out error); - if (error != null) - { - error.PrependSegment( - new Reporting.NameSegment( - "href")); - return null; - } - break; + error.PrependSegment( + new Reporting.NameSegment( + "href")); + return null; } + + break; + } case "endpointProtocol": + { + endpointProtocol = StringFrom( + keyValue.Value, + out error); + if (error != null) { - endpointProtocol = StringFrom( - keyValue.Value, - out error); - if (error != null) - { - error.PrependSegment( - new Reporting.NameSegment( - "endpointProtocol")); - return null; - } - break; + error.PrependSegment( + new Reporting.NameSegment( + "endpointProtocol")); + return null; } + + break; + } case "endpointProtocolVersion": + { + JsonArray? arrayEndpointsProtocolVersion = keyValue.Value as JsonArray; + if (arrayEndpointsProtocolVersion == null) + { + error = new Reporting.Error( + $"Expected a JsonArray, but got {keyValue.Value.GetType()}"); + error.PrependSegment( + new Reporting.NameSegment( + "EndpointsProtocolVersion")); + return null; + } + + endpointProtocolVersion = new List( + arrayEndpointsProtocolVersion.Count); + int indexEndpointsProtocolVersion = 0; + foreach (JsonNode? item in arrayEndpointsProtocolVersion) { - JsonArray? arrayEndpointsProtocolVersion = keyValue.Value as JsonArray; - if (arrayEndpointsProtocolVersion == null) + if (item == null) { error = new Reporting.Error( - $"Expected a JsonArray, but got {keyValue.Value.GetType()}"); + "Expected a non-null item, but got a null"); + error.PrependSegment( + new Reporting.IndexSegment( + indexEndpointsProtocolVersion)); error.PrependSegment( new Reporting.NameSegment( "EndpointsProtocolVersion")); return null; } - endpointProtocolVersion = new List( - arrayEndpointsProtocolVersion.Count); - int indexEndpointsProtocolVersion = 0; - foreach (JsonNode? item in arrayEndpointsProtocolVersion) - { - if (item == null) - { - error = new Reporting.Error( - "Expected a non-null item, but got a null"); - error.PrependSegment( - new Reporting.IndexSegment( - indexEndpointsProtocolVersion)); - error.PrependSegment( - new Reporting.NameSegment( - "EndpointsProtocolVersion")); - return null; - } - string? parsedItem = StringFrom( - item ?? throw new System.InvalidOperationException(), - out error); - if (error != null) - { - error.PrependSegment( - new Reporting.IndexSegment( - indexEndpointsProtocolVersion)); - error.PrependSegment( - new Reporting.NameSegment( - "endpoint")); - return null; - } - endpointProtocolVersion.Add( - parsedItem - ?? throw new System.InvalidOperationException( - "Unexpected result null when error is null")); - indexEndpointsProtocolVersion++; - } - break; - } - case "subprotocol": - { - subprotocol = StringFrom( - keyValue.Value, - out error); + + string? parsedItem = StringFrom( + item ?? throw new System.InvalidOperationException(), + out error); if (error != null) { + error.PrependSegment( + new Reporting.IndexSegment( + indexEndpointsProtocolVersion)); error.PrependSegment( new Reporting.NameSegment( - "subprotocol")); + "endpoint")); return null; } - break; + + endpointProtocolVersion.Add( + parsedItem + ?? throw new System.InvalidOperationException( + "Unexpected result null when error is null")); + indexEndpointsProtocolVersion++; + } + + break; + } + case "subprotocol": + { + subprotocol = StringFrom( + keyValue.Value, + out error); + if (error != null) + { + error.PrependSegment( + new Reporting.NameSegment( + "subprotocol")); + return null; } + + break; + } case "subprotocolBody": + { + subprotocolBody = StringFrom( + keyValue.Value, + out error); + if (error != null) { - subprotocolBody = StringFrom( - keyValue.Value, - out error); - if (error != null) - { - error.PrependSegment( - new Reporting.NameSegment( - "subprotocolBody")); - return null; - } - break; + error.PrependSegment( + new Reporting.NameSegment( + "subprotocolBody")); + return null; } + + break; + } case "subprotocolBodyEncoding": + { + subprotocolBodyEncoding = StringFrom( + keyValue.Value, + out error); + if (error != null) { - subprotocolBodyEncoding = StringFrom( - keyValue.Value, - out error); - if (error != null) - { - error.PrependSegment( - new Reporting.NameSegment( - "subprotocolBodyEncoding")); - return null; - } - break; + error.PrependSegment( + new Reporting.NameSegment( + "subprotocolBodyEncoding")); + return null; } + + break; + } case "securityAttributes": + { + JsonArray? arraySecurityAttributes = keyValue.Value as JsonArray; + if (arraySecurityAttributes == null) + { + error = new Reporting.Error( + $"Expected a JsonArray, but got {keyValue.Value.GetType()}"); + error.PrependSegment( + new Reporting.NameSegment( + "securityAttributes")); + return null; + } + + securityAttributes = new List( + arraySecurityAttributes.Count); + int indexSecurityAttributes = 0; + foreach (JsonNode? item in arraySecurityAttributes) { - JsonArray? arraySecurityAttributes = keyValue.Value as JsonArray; - if (arraySecurityAttributes == null) + if (item == null) { error = new Reporting.Error( - $"Expected a JsonArray, but got {keyValue.Value.GetType()}"); + "Expected a non-null item, but got a null"); + error.PrependSegment( + new Reporting.IndexSegment( + indexSecurityAttributes)); error.PrependSegment( new Reporting.NameSegment( - "securityAttributes")); + "SecurityAttributes")); return null; } - securityAttributes = new List( - arraySecurityAttributes.Count); - int indexSecurityAttributes = 0; - foreach (JsonNode? item in arraySecurityAttributes) + + ProtocolInformationSecurityAttributes? parsedItem = ProtocolInformationSecurityAttributesFrom( + item ?? throw new System.InvalidOperationException(), + out error); + if (error != null) { - if (item == null) - { - error = new Reporting.Error( - "Expected a non-null item, but got a null"); - error.PrependSegment( - new Reporting.IndexSegment( - indexSecurityAttributes)); - error.PrependSegment( - new Reporting.NameSegment( - "SecurityAttributes")); - return null; - } - ProtocolInformationSecurityAttributes? parsedItem = ProtocolInformationSecurityAttributesFrom( - item ?? throw new System.InvalidOperationException(), - out error); - if (error != null) - { - error.PrependSegment( - new Reporting.IndexSegment( - indexSecurityAttributes)); - error.PrependSegment( - new Reporting.NameSegment( - "SecurityAttributes")); - return null; - } - securityAttributes.Add( - parsedItem - ?? throw new System.InvalidOperationException( - "Unexpected result null when error is null")); - indexSecurityAttributes++; + error.PrependSegment( + new Reporting.IndexSegment( + indexSecurityAttributes)); + error.PrependSegment( + new Reporting.NameSegment( + "SecurityAttributes")); + return null; } - break; + + securityAttributes.Add( + parsedItem + ?? throw new System.InvalidOperationException( + "Unexpected result null when error is null")); + indexSecurityAttributes++; } + + break; + } } } @@ -753,41 +803,44 @@ private static ProtocolInformationSecurityAttributes ProtocolInformationSecurity { continue; } + switch (keyValue.Key) { case "type": - { - //Enum.TryParse(typeof(ProtocolInformationSecurityAttributes.TypeEnum), out type); - break; - } + { + //Enum.TryParse(typeof(ProtocolInformationSecurityAttributes.TypeEnum), out type); + break; + } case "key": + { + key = StringFrom( + keyValue.Value, + out error); + if (error != null) { - key = StringFrom( - keyValue.Value, - out error); - if (error != null) - { - error.PrependSegment( - new Reporting.NameSegment( - "key")); - return null; - } - break; + error.PrependSegment( + new Reporting.NameSegment( + "key")); + return null; } + + break; + } case "value": + { + key = StringFrom( + keyValue.Value, + out error); + if (error != null) { - key = StringFrom( - keyValue.Value, - out error); - if (error != null) - { - error.PrependSegment( - new Reporting.NameSegment( - "value")); - return null; - } - break; + error.PrependSegment( + new Reporting.NameSegment( + "value")); + return null; } + + break; + } } } @@ -795,8 +848,8 @@ private static ProtocolInformationSecurityAttributes ProtocolInformationSecurity } internal static string? StringFrom( - JsonNode node, - out Reporting.Error? error) + JsonNode node, + out Reporting.Error? error) { error = null; JsonValue? value = node as JsonValue; @@ -806,6 +859,7 @@ private static ProtocolInformationSecurityAttributes ProtocolInformationSecurity $"Expected a JsonValue, but got {node.GetType()}"); return null; } + bool ok = value.TryGetValue(out string? result); if (!ok) { @@ -814,13 +868,15 @@ private static ProtocolInformationSecurityAttributes ProtocolInformationSecurity $"from {value.ToJsonString()}"); return null; } + if (result == null) { error = new Reporting.Error( "Expected a string, but got a null"); return null; } + return result; } } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Serializers/DescriptorDeserializer.cs b/src/IO.Swagger.Registry.Lib.V3/Serializers/DescriptorDeserializer.cs index 2a917b824..d02165862 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Serializers/DescriptorDeserializer.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Serializers/DescriptorDeserializer.cs @@ -8,33 +8,35 @@ public static class DescriptorDeserializer public static AssetAdministrationShellDescriptor AssetAdministrationShellDescriptorFrom(JsonNode node) { AssetAdministrationShellDescriptor? result = DescriptorDeserializeImplementation.AssetAdministrationShellDescriptorFrom( - node, - out Reporting.Error? error); + node, + out Reporting.Error? error); if (error != null) { throw new Jsonization.Exception( Reporting.GenerateJsonPath(error.PathSegments), error.Cause); } + return result - ?? throw new System.InvalidOperationException( - "Unexpected output null when error is null"); + ?? throw new System.InvalidOperationException( + "Unexpected output null when error is null"); } public static SubmodelDescriptor SubmodelDescriptorFrom(JsonNode node) { SubmodelDescriptor? result = DescriptorDeserializeImplementation.SubmodelDescriptorFrom( - node, - out Reporting.Error? error); + node, + out Reporting.Error? error); if (error != null) { throw new Jsonization.Exception( Reporting.GenerateJsonPath(error.PathSegments), error.Cause); } + return result - ?? throw new System.InvalidOperationException( - "Unexpected output null when error is null"); + ?? throw new System.InvalidOperationException( + "Unexpected output null when error is null"); } } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Serializers/DescriptorSerializer.cs b/src/IO.Swagger.Registry.Lib.V3/Serializers/DescriptorSerializer.cs index 45cb14507..aee6bfcc0 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Serializers/DescriptorSerializer.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Serializers/DescriptorSerializer.cs @@ -22,7 +22,6 @@ public static JsonObject ToJsonObject(object that) { throw new NotSupportedException(); } - } private static JsonObject Transform(AssetAdministrationShellDescriptor that) @@ -33,17 +32,20 @@ private static JsonObject Transform(AssetAdministrationShellDescriptor that) var result = new JsonObject(); if (that.Administration != null) { - result["administration"] = Jsonization.Serialize.ToJsonObject(that.Administration); + result[ "administration" ] = Jsonization.Serialize.ToJsonObject(that.Administration); } + if (that.AssetKind != null) { - result["assetKind"] = Jsonization.Serialize.AssetKindToJsonValue( + result[ "assetKind" ] = Jsonization.Serialize.AssetKindToJsonValue( that.AssetKind); } + if (that.AssetType != null) { - result["assetType"] = that.AssetType; + result[ "assetType" ] = that.AssetType; } + if (that.Endpoints != null) { var arrayEndpoints = new JsonArray(); @@ -51,20 +53,25 @@ private static JsonObject Transform(AssetAdministrationShellDescriptor that) { arrayEndpoints.Add(Transform(endpoint)); } - result["endpoints"] = arrayEndpoints; + + result[ "endpoints" ] = arrayEndpoints; } + if (that.GlobalAssetId != null) { - result["globalAssetId"] = that.GlobalAssetId; + result[ "globalAssetId" ] = that.GlobalAssetId; } + if (that.IdShort != null) { - result["idShort"] = that.IdShort; + result[ "idShort" ] = that.IdShort; } + if (that.Id != null) { - result["id"] = that.Id; + result[ "id" ] = that.Id; } + if (that.SpecificAssetIds != null) { var arraySpecificAssetIds = new JsonArray(); @@ -72,8 +79,10 @@ private static JsonObject Transform(AssetAdministrationShellDescriptor that) { arraySpecificAssetIds.Add(Jsonization.Serialize.ToJsonObject(specificAssetId)); } - result["specificAssetIds"] = arraySpecificAssetIds; + + result[ "specificAssetIds" ] = arraySpecificAssetIds; } + if (that.SubmodelDescriptors != null) { var arraySubmodelDescriptors = new JsonArray(); @@ -81,7 +90,8 @@ private static JsonObject Transform(AssetAdministrationShellDescriptor that) { arraySubmodelDescriptors.Add(Transform(submodelDescriptor)); } - result["submodelDescriptors"] = arraySubmodelDescriptors; + + result[ "submodelDescriptors" ] = arraySubmodelDescriptors; } return result; @@ -95,7 +105,7 @@ private static JsonObject Transform(SubmodelDescriptor that) var result = new JsonObject(); if (that.Administration != null) { - result["administration"] = Jsonization.Serialize.ToJsonObject(that.Administration); + result[ "administration" ] = Jsonization.Serialize.ToJsonObject(that.Administration); } if (that.Endpoints != null) @@ -105,21 +115,25 @@ private static JsonObject Transform(SubmodelDescriptor that) { arrayEndpoints.Add(Transform(endpoint)); } - result["endpoints"] = arrayEndpoints; + + result[ "endpoints" ] = arrayEndpoints; } if (that.IdShort != null) { - result["idShort"] = that.IdShort; + result[ "idShort" ] = that.IdShort; } + if (that.Id != null) { - result["id"] = that.Id; + result[ "id" ] = that.Id; } + if (that.SemanticId != null) { - result["semanticId"] = Jsonization.Serialize.ToJsonObject(that.SemanticId); + result[ "semanticId" ] = Jsonization.Serialize.ToJsonObject(that.SemanticId); } + if (that.SupplementalSemanticId != null) { var arraySupplementalSemanticId = new JsonArray(); @@ -127,8 +141,10 @@ private static JsonObject Transform(SubmodelDescriptor that) { arraySupplementalSemanticId.Add(Jsonization.Serialize.ToJsonObject(suppSemId)); } - result["supplementalSemanticId"] = arraySupplementalSemanticId; + + result[ "supplementalSemanticId" ] = arraySupplementalSemanticId; } + if (that.FederatedElements != null) { var arrayFederatedElements = new JsonArray(); @@ -136,7 +152,8 @@ private static JsonObject Transform(SubmodelDescriptor that) { arrayFederatedElements.Add(fedElement); } - result["federatedElements"] = arrayFederatedElements; + + result[ "federatedElements" ] = arrayFederatedElements; } return result; @@ -151,12 +168,12 @@ private static JsonObject Transform(Endpoint that) if (that.Interface != null) { - result["interface"] = that.Interface; + result[ "interface" ] = that.Interface; } if (that.ProtocolInformation != null) { - result["protocolInformation"] = Transform(that.ProtocolInformation); + result[ "protocolInformation" ] = Transform(that.ProtocolInformation); } return result; @@ -171,12 +188,12 @@ private static JsonObject Transform(ProtocolInformation that) if (that.Href != null) { - result["href"] = that.Href; + result[ "href" ] = that.Href; } if (that.EndpointProtocol != null) { - result["endpointProtocol"] = that.EndpointProtocol; + result[ "endpointProtocol" ] = that.EndpointProtocol; } if (that.EndpointProtocolVersion != null) @@ -186,22 +203,23 @@ private static JsonObject Transform(ProtocolInformation that) { arrayProtocolVersion.Add(protocol); } - result["endpointProtocolVersion"] = arrayProtocolVersion; + + result[ "endpointProtocolVersion" ] = arrayProtocolVersion; } if (that.Subprotocol != null) { - result["subprotocol"] = that.Subprotocol; + result[ "subprotocol" ] = that.Subprotocol; } if (that.SubprotocolBody != null) { - result["subprotocolBody"] = that.SubprotocolBody; + result[ "subprotocolBody" ] = that.SubprotocolBody; } if (that.SubprotocolBodyEncoding != null) { - result["subprotocolBodyEncoding"] = that.SubprotocolBodyEncoding; + result[ "subprotocolBodyEncoding" ] = that.SubprotocolBodyEncoding; } if (that.SecurityAttributes != null) @@ -211,7 +229,8 @@ private static JsonObject Transform(ProtocolInformation that) { arraySecurityAttributes.Add(Transform(securityAttribute)); } - result["securityAttributes"] = arraySecurityAttributes; + + result[ "securityAttributes" ] = arraySecurityAttributes; } return result; @@ -225,18 +244,20 @@ private static JsonObject Transform(ProtocolInformationSecurityAttributes that) var result = new JsonObject(); if (that.Type != null) { - result["type"] = that.Type.ToString(); + result[ "type" ] = that.Type.ToString(); } + if (that.Key != null) { - result["key"] = that.Key; + result[ "key" ] = that.Key; } + if (that.Value != null) { - result["value"] = that.Value; + result[ "value" ] = that.Value; } return result; } } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Services/AasDescriptorPaginationService.cs b/src/IO.Swagger.Registry.Lib.V3/Services/AasDescriptorPaginationService.cs index c310995bc..6c5f6e2ab 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Services/AasDescriptorPaginationService.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Services/AasDescriptorPaginationService.cs @@ -57,10 +57,10 @@ private List GetPaginationList(List sourceList, int startIndex, int end for (int i = startIndex; i <= endIndex; i++) { - outputList.Add(sourceList[i]); + outputList.Add(sourceList[ i ]); } return outputList; } } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Services/AasRegistryService.cs b/src/IO.Swagger.Registry.Lib.V3/Services/AasRegistryService.cs index 4cf03d2ad..0af2190ce 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Services/AasRegistryService.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Services/AasRegistryService.cs @@ -49,7 +49,8 @@ public AssetAdministrationShellDescriptor CreateAasDescriptorFromDB(AasSet aasDB ad.GlobalAssetId = globalAssetId; // ad.SpecificAssetIds = new List(); - var specificAssetId = new SpecificAssetId("AssetKind", aasDB.AssetKind, externalSubjectId: new Reference(ReferenceTypes.ExternalReference, new List() { new Key(KeyTypes.GlobalReference, "assetKind") })); + var specificAssetId = new SpecificAssetId("AssetKind", aasDB.AssetKind, + externalSubjectId: new Reference(ReferenceTypes.ExternalReference, new List() {new Key(KeyTypes.GlobalReference, "assetKind")})); ad.SpecificAssetIds.Add(specificAssetId); // Submodels @@ -75,7 +76,7 @@ public AssetAdministrationShellDescriptor CreateAasDescriptorFromDB(AasSet aasDB { esm }; - sd.SemanticId = new Reference(ReferenceTypes.ExternalReference, new List() { new Key(KeyTypes.GlobalReference, submodelDB.SemanticId) }); + sd.SemanticId = new Reference(ReferenceTypes.ExternalReference, new List() {new Key(KeyTypes.GlobalReference, submodelDB.SemanticId)}); ad.SubmodelDescriptors.Add(sd); } } @@ -85,7 +86,8 @@ public AssetAdministrationShellDescriptor CreateAasDescriptorFromDB(AasSet aasDB } //getFromAasRegistry from old implementation - public List GetAllAssetAdministrationShellDescriptors(string assetKind = null, List assetList = null, string aasIdentifier = null) + public List GetAllAssetAdministrationShellDescriptors(string assetKind = null, List assetList = null, + string aasIdentifier = null) { List result = new List(); @@ -109,6 +111,7 @@ public List GetAllAssetAdministrationShellDe found = true; } } + if (found) result.Add(ad); } @@ -143,9 +146,9 @@ public List GetAllAssetAdministrationShellDe descriptorJSON = p.Value; break; } - } } + bool found = false; if (aasIdentifier == null && assetList.IsNullOrEmpty()) found = true; @@ -159,6 +162,7 @@ public List GetAllAssetAdministrationShellDe } } } + if (!assetList.IsNullOrEmpty()) { if (assetID != "" && descriptorJSON != "") @@ -169,6 +173,7 @@ public List GetAllAssetAdministrationShellDe } } } + if (found) { //ad = JsonConvert.DeserializeObject(descriptorJSON); @@ -181,12 +186,14 @@ public List GetAllAssetAdministrationShellDe { ad = null; } + result.Add(ad); } } } } + return result; } } -} +} \ No newline at end of file diff --git a/src/IO.Swagger.Registry.Lib.V3/Services/RegistryInitializerService.cs b/src/IO.Swagger.Registry.Lib.V3/Services/RegistryInitializerService.cs index 4eb7fbf51..9f6775150 100644 --- a/src/IO.Swagger.Registry.Lib.V3/Services/RegistryInitializerService.cs +++ b/src/IO.Swagger.Registry.Lib.V3/Services/RegistryInitializerService.cs @@ -71,7 +71,7 @@ public void InitRegistry(List cList, DateTime timestamp, b int i = initiallyEmpty; while (i < AasxServer.Program.env.Length) { - AasxServer.Program.env[i] = null; + AasxServer.Program.env[ i ] = null; i++; } } @@ -82,7 +82,7 @@ public void InitRegistry(List cList, DateTime timestamp, b { if (env != null) { - var aas = env.AasEnv.AssetAdministrationShells[0]; + var aas = env.AasEnv.AssetAdministrationShells[ 0 ]; if (aas.IdShort == "REGISTRY") { envRegistry = env.AasEnv; @@ -157,7 +157,7 @@ public void InitRegistry(List cList, DateTime timestamp, b { if (env != null) { - var aas = env.AasEnv.AssetAdministrationShells[0]; + var aas = env.AasEnv.AssetAdministrationShells[ 0 ]; if (aas.IdShort != "REGISTRY" && aas.IdShort != "myAASwithGlobalSecurityMetaModel") { AddAasToRegistry(env, timestamp); @@ -255,7 +255,7 @@ public void InitRegistry(List cList, DateTime timestamp, b { if (jo.ContainsKey("result")) { - node = (JsonNode) jo["result"]; + node = (JsonNode) jo[ "result" ]; if (node is JsonArray a) { foreach (JsonNode n in a) @@ -340,7 +340,7 @@ public void InitRegistry(List cList, DateTime timestamp, b { if (jo.ContainsKey("result")) { - node = (JsonNode) jo["result"]; + node = (JsonNode) jo[ "result" ]; if (node is JsonArray a) { foreach (JsonNode n in a) @@ -353,7 +353,7 @@ public void InitRegistry(List cList, DateTime timestamp, b ad.SubmodelDescriptors = new List(); if (ad.SubmodelDescriptors.Count == 0) { - requestPath = ad.Endpoints[0].ProtocolInformation.Href; + requestPath = ad.Endpoints[ 0 ].ProtocolInformation.Href; Console.WriteLine("GET " + requestPath); task = Task.Run(async () => { response = await client.GetAsync(requestPath); }); task.Wait(); @@ -365,7 +365,7 @@ public void InitRegistry(List cList, DateTime timestamp, b var ids = new List(); foreach (var s in aas.Submodels) { - var id = s.Keys[0].Value; + var id = s.Keys[ 0 ].Value; ids.Add(id); } @@ -404,7 +404,7 @@ public void InitRegistry(List cList, DateTime timestamp, b int i = 0; while (i < AasxServer.Program.env.Length) { - var env = AasxServer.Program.env[i]; + var env = AasxServer.Program.env[ i ]; if (env == null) { break; @@ -422,7 +422,7 @@ public void InitRegistry(List cList, DateTime timestamp, b var watch = System.Diagnostics.Stopwatch.StartNew(); // check, if AAS is exisiting and must be replaced - var extensions = new List {new Extension("endpoint", value: ad.Endpoints[0].ProtocolInformation.Href)}; + var extensions = new List {new Extension("endpoint", value: ad.Endpoints[ 0 ].ProtocolInformation.Href)}; var aas = new AssetAdministrationShell(ad.Id, new AssetInformation(AssetKind.Instance, ad.GlobalAssetId), extensions, idShort: ad.IdShort + " - EXTERNAL"); aas.TimeStamp = timestamp; @@ -438,16 +438,16 @@ public void InitRegistry(List cList, DateTime timestamp, b bool success = false; bool external = false; string idEncoded = ""; - string endpoint = sd.Endpoints[0].ProtocolInformation.Href; + string endpoint = sd.Endpoints[ 0 ].ProtocolInformation.Href; var s1 = endpoint.Split("/shells/"); if (s1.Length == 2) { - var s2 = s1[1].Split("/submodels/"); + var s2 = s1[ 1 ].Split("/submodels/"); if (s2.Length == 2) { - idEncoded = s2[1].Replace("/submodel/", ""); + idEncoded = s2[ 1 ].Replace("/submodel/", ""); ; - endpoint = s1[0] + "/submodels/" + idEncoded; + endpoint = s1[ 0 ] + "/submodels/" + idEncoded; } } @@ -552,7 +552,7 @@ public void InitRegistry(List cList, DateTime timestamp, b sm.IdShort += " - COPY"; sm.Extensions = new List { - new Extension("endpoint", value: sd.Endpoints[0].ProtocolInformation.Href), + new Extension("endpoint", value: sd.Endpoints[ 0 ].ProtocolInformation.Href), new Extension("clientToken", value: clientToken) }; sm.SetAllParentsAndTimestamps(null, timestamp, timestamp); @@ -623,7 +623,7 @@ public void InitRegistry(List cList, DateTime timestamp, b sm.Extensions = new List { - new Extension("endpoint", value: sd.Endpoints[0].ProtocolInformation.Href), + new Extension("endpoint", value: sd.Endpoints[ 0 ].ProtocolInformation.Href), new Extension("clientToken", value: clientToken) }; sm.SetAllParentsAndTimestamps(null, timestamp, timestamp); @@ -635,7 +635,7 @@ public void InitRegistry(List cList, DateTime timestamp, b watch.Stop(); Console.WriteLine(watch.ElapsedMilliseconds + " ms"); - AasxServer.Program.env[i] = newEnv; + AasxServer.Program.env[ i ] = newEnv; i++; } } @@ -676,7 +676,7 @@ static string TranslateURL(string url) static void AddAasToRegistry(AdminShellNS.AdminShellPackageEnv env, DateTime timestamp) #pragma warning restore IDE1006 // Benennungsstile { - var aas = env.AasEnv.AssetAdministrationShells[0]; + var aas = env.AasEnv.AssetAdministrationShells[ 0 ]; AssetAdministrationShellDescriptor ad = new AssetAdministrationShellDescriptor(); string globalAssetId = aas.AssetInformation.GlobalAssetId!; @@ -741,15 +741,15 @@ static void AddAasToRegistry(AdminShellNS.AdminShellPackageEnv env, DateTime tim { var sme = se; bool federate = false; - if (sme.SemanticId != null && sme.SemanticId.Keys != null && sme.SemanticId.Keys.Count != 0 && sme.SemanticId.Keys[0] != null) + if (sme.SemanticId != null && sme.SemanticId.Keys != null && sme.SemanticId.Keys.Count != 0 && sme.SemanticId.Keys[ 0 ] != null) { - if (federatedElemensSemanticId.Contains(sme.SemanticId.Keys[0].Value)) + if (federatedElemensSemanticId.Contains(sme.SemanticId.Keys[ 0 ].Value)) federate = true; } if (sme.Qualifiers != null && sme.Qualifiers.Count != 0) { - if (sme.Qualifiers[0].Type == "federatedElement") + if (sme.Qualifiers[ 0 ].Type == "federatedElement") federate = true; } @@ -924,7 +924,7 @@ static void AddAasDescriptorToRegistry(AssetAdministrationShellDescriptor ad, Da string endpoint = ""; if (ad.Endpoints != null && ad.Endpoints.Count != 0) { - endpoint = ad.Endpoints[0].ProtocolInformation.Href; + endpoint = ad.Endpoints[ 0 ].ProtocolInformation.Href; } // overwrite existing entry, if assetID AND aasID are identical @@ -1046,7 +1046,7 @@ static void AddAasDescriptorToRegistry(AssetAdministrationShellDescriptor ad, Da cs.Value.Add(ps); if (sd.Endpoints != null && sd.Endpoints.Count != 0) { - endpoint = sd.Endpoints[0].ProtocolInformation.Href; + endpoint = sd.Endpoints[ 0 ].ProtocolInformation.Href; } ps = new Property(DataTypeDefXsd.String, idShort: "endpoint"); @@ -1082,9 +1082,9 @@ static void AddAasDescriptorToRegistry(AssetAdministrationShellDescriptor ad, Da int last = r.Value.Keys.Count - 1; while (first < last) { - var temp = r.Value.Keys[first]; - r.Value.Keys[first] = r.Value.Keys[last]; - r.Value.Keys[last] = temp; + var temp = r.Value.Keys[ first ]; + r.Value.Keys[ first ] = r.Value.Keys[ last ]; + r.Value.Keys[ last ] = temp; first++; last--; } @@ -1095,7 +1095,7 @@ static void AddAasDescriptorToRegistry(AssetAdministrationShellDescriptor ad, Da { if (sd.Endpoints != null && sd.Endpoints.Count > 0) { - var ep = sd.Endpoints[0].ProtocolInformation.Href; + var ep = sd.Endpoints[ 0 ].ProtocolInformation.Href; p = new Property(DataTypeDefXsd.String, idShort: "NameplateVC"); p.TimeStampCreate = timestamp; p.TimeStamp = timestamp; diff --git a/src/IO.Swagger.Registry.Lib.V3/wwwroot/web.config b/src/IO.Swagger.Registry.Lib.V3/wwwroot/web.config index e70a7778d..495a86853 100644 --- a/src/IO.Swagger.Registry.Lib.V3/wwwroot/web.config +++ b/src/IO.Swagger.Registry.Lib.V3/wwwroot/web.config @@ -1,9 +1,10 @@ + - - - - - - - + + + + + + + \ No newline at end of file diff --git a/src/es6numberserializer/NumberCachedPowers.cs b/src/es6numberserializer/NumberCachedPowers.cs index e34a6439b..f21985ee1 100644 --- a/src/es6numberserializer/NumberCachedPowers.cs +++ b/src/es6numberserializer/NumberCachedPowers.cs @@ -41,7 +41,7 @@ namespace Org.Webpki.Es6NumberSerialization { class NumberCachedPowers { - const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10) + const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10) class CachedPower { @@ -51,7 +51,7 @@ class CachedPower internal CachedPower(ulong significand, short binaryExponent, short decimalExponent) { - this.significand = (long)significand; + this.significand = (long) significand; this.binaryExponent = binaryExponent; this.decimalExponent = decimalExponent; } @@ -61,8 +61,8 @@ public static int GetCachedPower(int e, int alpha, int gamma, NumberDiyFp c_mk) { int kQ = NumberDiyFp.kSignificandSize; double k = Math.Ceiling((alpha - e + kQ - 1) * kD_1_LOG2_10); - int index = (GRISU_CACHE_OFFSET + (int)k - 1) / CACHED_POWERS_SPACING + 1; - CachedPower cachedPower = CACHED_POWERS[index]; + int index = (GRISU_CACHE_OFFSET + (int) k - 1) / CACHED_POWERS_SPACING + 1; + CachedPower cachedPower = CACHED_POWERS[ index ]; c_mk.SetF(cachedPower.significand); c_mk.SetE(cachedPower.binaryExponent); @@ -79,88 +79,88 @@ public static int GetCachedPower(int e, int alpha, int gamma, NumberDiyFp c_mk) static readonly CachedPower[] CACHED_POWERS = { - new CachedPower(0xe61acf033d1a45dfL, -1087, -308), - new CachedPower(0xab70fe17c79ac6caL, -1060, -300), - new CachedPower(0xff77b1fcbebcdc4fL, -1034, -292), - new CachedPower(0xbe5691ef416bd60cL, -1007, -284), - new CachedPower(0x8dd01fad907ffc3cL, -980, -276), - new CachedPower(0xd3515c2831559a83L, -954, -268), - new CachedPower(0x9d71ac8fada6c9b5L, -927, -260), - new CachedPower(0xea9c227723ee8bcbL, -901, -252), - new CachedPower(0xaecc49914078536dL, -874, -244), - new CachedPower(0x823c12795db6ce57L, -847, -236), - new CachedPower(0xc21094364dfb5637L, -821, -228), - new CachedPower(0x9096ea6f3848984fL, -794, -220), - new CachedPower(0xd77485cb25823ac7L, -768, -212), - new CachedPower(0xa086cfcd97bf97f4L, -741, -204), - new CachedPower(0xef340a98172aace5L, -715, -196), - new CachedPower(0xb23867fb2a35b28eL, -688, -188), - new CachedPower(0x84c8d4dfd2c63f3bL, -661, -180), - new CachedPower(0xc5dd44271ad3cdbaL, -635, -172), - new CachedPower(0x936b9fcebb25c996L, -608, -164), - new CachedPower(0xdbac6c247d62a584L, -582, -156), - new CachedPower(0xa3ab66580d5fdaf6L, -555, -148), - new CachedPower(0xf3e2f893dec3f126L, -529, -140), - new CachedPower(0xb5b5ada8aaff80b8L, -502, -132), - new CachedPower(0x87625f056c7c4a8bL, -475, -124), - new CachedPower(0xc9bcff6034c13053L, -449, -116), - new CachedPower(0x964e858c91ba2655L, -422, -108), - new CachedPower(0xdff9772470297ebdL, -396, -100), - new CachedPower(0xa6dfbd9fb8e5b88fL, -369, -92), - new CachedPower(0xf8a95fcf88747d94L, -343, -84), - new CachedPower(0xb94470938fa89bcfL, -316, -76), - new CachedPower(0x8a08f0f8bf0f156bL, -289, -68), - new CachedPower(0xcdb02555653131b6L, -263, -60), - new CachedPower(0x993fe2c6d07b7facL, -236, -52), - new CachedPower(0xe45c10c42a2b3b06L, -210, -44), - new CachedPower(0xaa242499697392d3L, -183, -36), - new CachedPower(0xfd87b5f28300ca0eL, -157, -28), - new CachedPower(0xbce5086492111aebL, -130, -20), - new CachedPower(0x8cbccc096f5088ccL, -103, -12), - new CachedPower(0xd1b71758e219652cL, -77, -4), - new CachedPower(0x9c40000000000000L, -50, 4), - new CachedPower(0xe8d4a51000000000L, -24, 12), - new CachedPower(0xad78ebc5ac620000L, 3, 20), - new CachedPower(0x813f3978f8940984L, 30, 28), - new CachedPower(0xc097ce7bc90715b3L, 56, 36), - new CachedPower(0x8f7e32ce7bea5c70L, 83, 44), - new CachedPower(0xd5d238a4abe98068L, 109, 52), - new CachedPower(0x9f4f2726179a2245L, 136, 60), - new CachedPower(0xed63a231d4c4fb27L, 162, 68), - new CachedPower(0xb0de65388cc8ada8L, 189, 76), - new CachedPower(0x83c7088e1aab65dbL, 216, 84), - new CachedPower(0xc45d1df942711d9aL, 242, 92), - new CachedPower(0x924d692ca61be758L, 269, 100), - new CachedPower(0xda01ee641a708deaL, 295, 108), - new CachedPower(0xa26da3999aef774aL, 322, 116), - new CachedPower(0xf209787bb47d6b85L, 348, 124), - new CachedPower(0xb454e4a179dd1877L, 375, 132), - new CachedPower(0x865b86925b9bc5c2L, 402, 140), - new CachedPower(0xc83553c5c8965d3dL, 428, 148), - new CachedPower(0x952ab45cfa97a0b3L, 455, 156), - new CachedPower(0xde469fbd99a05fe3L, 481, 164), - new CachedPower(0xa59bc234db398c25L, 508, 172), - new CachedPower(0xf6c69a72a3989f5cL, 534, 180), - new CachedPower(0xb7dcbf5354e9beceL, 561, 188), - new CachedPower(0x88fcf317f22241e2L, 588, 196), - new CachedPower(0xcc20ce9bd35c78a5L, 614, 204), - new CachedPower(0x98165af37b2153dfL, 641, 212), - new CachedPower(0xe2a0b5dc971f303aL, 667, 220), - new CachedPower(0xa8d9d1535ce3b396L, 694, 228), - new CachedPower(0xfb9b7cd9a4a7443cL, 720, 236), - new CachedPower(0xbb764c4ca7a44410L, 747, 244), - new CachedPower(0x8bab8eefb6409c1aL, 774, 252), - new CachedPower(0xd01fef10a657842cL, 800, 260), - new CachedPower(0x9b10a4e5e9913129L, 827, 268), - new CachedPower(0xe7109bfba19c0c9dL, 853, 276), - new CachedPower(0xac2820d9623bf429L, 880, 284), - new CachedPower(0x80444b5e7aa7cf85L, 907, 292), - new CachedPower(0xbf21e44003acdd2dL, 933, 300), - new CachedPower(0x8e679c2f5e44ff8fL, 960, 308), - new CachedPower(0xd433179d9c8cb841L, 986, 316), - new CachedPower(0x9e19db92b4e31ba9L, 1013, 324), - new CachedPower(0xeb96bf6ebadf77d9L, 1039, 332), - new CachedPower(0xaf87023b9bf0ee6bL, 1066, 340) + new CachedPower(0xe61acf033d1a45dfL, -1087, -308), + new CachedPower(0xab70fe17c79ac6caL, -1060, -300), + new CachedPower(0xff77b1fcbebcdc4fL, -1034, -292), + new CachedPower(0xbe5691ef416bd60cL, -1007, -284), + new CachedPower(0x8dd01fad907ffc3cL, -980, -276), + new CachedPower(0xd3515c2831559a83L, -954, -268), + new CachedPower(0x9d71ac8fada6c9b5L, -927, -260), + new CachedPower(0xea9c227723ee8bcbL, -901, -252), + new CachedPower(0xaecc49914078536dL, -874, -244), + new CachedPower(0x823c12795db6ce57L, -847, -236), + new CachedPower(0xc21094364dfb5637L, -821, -228), + new CachedPower(0x9096ea6f3848984fL, -794, -220), + new CachedPower(0xd77485cb25823ac7L, -768, -212), + new CachedPower(0xa086cfcd97bf97f4L, -741, -204), + new CachedPower(0xef340a98172aace5L, -715, -196), + new CachedPower(0xb23867fb2a35b28eL, -688, -188), + new CachedPower(0x84c8d4dfd2c63f3bL, -661, -180), + new CachedPower(0xc5dd44271ad3cdbaL, -635, -172), + new CachedPower(0x936b9fcebb25c996L, -608, -164), + new CachedPower(0xdbac6c247d62a584L, -582, -156), + new CachedPower(0xa3ab66580d5fdaf6L, -555, -148), + new CachedPower(0xf3e2f893dec3f126L, -529, -140), + new CachedPower(0xb5b5ada8aaff80b8L, -502, -132), + new CachedPower(0x87625f056c7c4a8bL, -475, -124), + new CachedPower(0xc9bcff6034c13053L, -449, -116), + new CachedPower(0x964e858c91ba2655L, -422, -108), + new CachedPower(0xdff9772470297ebdL, -396, -100), + new CachedPower(0xa6dfbd9fb8e5b88fL, -369, -92), + new CachedPower(0xf8a95fcf88747d94L, -343, -84), + new CachedPower(0xb94470938fa89bcfL, -316, -76), + new CachedPower(0x8a08f0f8bf0f156bL, -289, -68), + new CachedPower(0xcdb02555653131b6L, -263, -60), + new CachedPower(0x993fe2c6d07b7facL, -236, -52), + new CachedPower(0xe45c10c42a2b3b06L, -210, -44), + new CachedPower(0xaa242499697392d3L, -183, -36), + new CachedPower(0xfd87b5f28300ca0eL, -157, -28), + new CachedPower(0xbce5086492111aebL, -130, -20), + new CachedPower(0x8cbccc096f5088ccL, -103, -12), + new CachedPower(0xd1b71758e219652cL, -77, -4), + new CachedPower(0x9c40000000000000L, -50, 4), + new CachedPower(0xe8d4a51000000000L, -24, 12), + new CachedPower(0xad78ebc5ac620000L, 3, 20), + new CachedPower(0x813f3978f8940984L, 30, 28), + new CachedPower(0xc097ce7bc90715b3L, 56, 36), + new CachedPower(0x8f7e32ce7bea5c70L, 83, 44), + new CachedPower(0xd5d238a4abe98068L, 109, 52), + new CachedPower(0x9f4f2726179a2245L, 136, 60), + new CachedPower(0xed63a231d4c4fb27L, 162, 68), + new CachedPower(0xb0de65388cc8ada8L, 189, 76), + new CachedPower(0x83c7088e1aab65dbL, 216, 84), + new CachedPower(0xc45d1df942711d9aL, 242, 92), + new CachedPower(0x924d692ca61be758L, 269, 100), + new CachedPower(0xda01ee641a708deaL, 295, 108), + new CachedPower(0xa26da3999aef774aL, 322, 116), + new CachedPower(0xf209787bb47d6b85L, 348, 124), + new CachedPower(0xb454e4a179dd1877L, 375, 132), + new CachedPower(0x865b86925b9bc5c2L, 402, 140), + new CachedPower(0xc83553c5c8965d3dL, 428, 148), + new CachedPower(0x952ab45cfa97a0b3L, 455, 156), + new CachedPower(0xde469fbd99a05fe3L, 481, 164), + new CachedPower(0xa59bc234db398c25L, 508, 172), + new CachedPower(0xf6c69a72a3989f5cL, 534, 180), + new CachedPower(0xb7dcbf5354e9beceL, 561, 188), + new CachedPower(0x88fcf317f22241e2L, 588, 196), + new CachedPower(0xcc20ce9bd35c78a5L, 614, 204), + new CachedPower(0x98165af37b2153dfL, 641, 212), + new CachedPower(0xe2a0b5dc971f303aL, 667, 220), + new CachedPower(0xa8d9d1535ce3b396L, 694, 228), + new CachedPower(0xfb9b7cd9a4a7443cL, 720, 236), + new CachedPower(0xbb764c4ca7a44410L, 747, 244), + new CachedPower(0x8bab8eefb6409c1aL, 774, 252), + new CachedPower(0xd01fef10a657842cL, 800, 260), + new CachedPower(0x9b10a4e5e9913129L, 827, 268), + new CachedPower(0xe7109bfba19c0c9dL, 853, 276), + new CachedPower(0xac2820d9623bf429L, 880, 284), + new CachedPower(0x80444b5e7aa7cf85L, 907, 292), + new CachedPower(0xbf21e44003acdd2dL, 933, 300), + new CachedPower(0x8e679c2f5e44ff8fL, 960, 308), + new CachedPower(0xd433179d9c8cb841L, 986, 316), + new CachedPower(0x9e19db92b4e31ba9L, 1013, 324), + new CachedPower(0xeb96bf6ebadf77d9L, 1039, 332), + new CachedPower(0xaf87023b9bf0ee6bL, 1066, 340) }; const int GRISU_CACHE_MAX_DISTANCE = 27; @@ -168,4 +168,4 @@ public static int GetCachedPower(int e, int alpha, int gamma, NumberDiyFp c_mk) const int GRISU_CACHE_OFFSET = 308; } -} +} \ No newline at end of file diff --git a/src/es6numberserializer/NumberDToA.cs b/src/es6numberserializer/NumberDToA.cs index 1dd95d6cd..92faf7773 100644 --- a/src/es6numberserializer/NumberDToA.cs +++ b/src/es6numberserializer/NumberDToA.cs @@ -34,13 +34,12 @@ namespace Org.Webpki.Es6NumberSerialization { class NumberDToA { - public const int - DTOSTR_STANDARD = 0, /* Either fixed or exponential format; round-trip */ - DTOSTR_STANDARD_EXPONENTIAL = 1, /* Always exponential format; round-trip */ - DTOSTR_FIXED = 2, /* Round to digits after the decimal point; exponential if number is large */ - DTOSTR_EXPONENTIAL = 3, /* Always exponential format; significant digits */ - DTOSTR_PRECISION = 4; /* Either fixed or exponential format; significant digits */ + DTOSTR_STANDARD = 0, /* Either fixed or exponential format; round-trip */ + DTOSTR_STANDARD_EXPONENTIAL = 1, /* Always exponential format; round-trip */ + DTOSTR_FIXED = 2, /* Round to digits after the decimal point; exponential if number is large */ + DTOSTR_EXPONENTIAL = 3, /* Always exponential format; significant digits */ + DTOSTR_PRECISION = 4; /* Either fixed or exponential format; significant digits */ private const int Frac_mask = 0xfffff; @@ -77,11 +76,11 @@ public const int 1e20, 1e21, 1e22 }; - private static double[] bigtens = { 1e16, 1e32, 1e64, 1e128, 1e256 }; + private static double[] bigtens = {1e16, 1e32, 1e64, 1e128, 1e256}; private static int Lo0bits(int inty) { - uint y = (uint)inty; + uint y = (uint) inty; uint k; uint x = y; @@ -93,29 +92,35 @@ private static int Lo0bits(int inty) { return 1; } + return 2; } + k = 0; if ((x & 0xffff) == 0) { k = 16; x >>= 16; } + if ((x & 0xff) == 0) { k += 8; x >>= 8; } + if ((x & 0xf) == 0) { k += 4; x >>= 4; } + if ((x & 0x3) == 0) { k += 2; x >>= 2; } + if ((x & 1) == 0) { k++; @@ -123,7 +128,8 @@ private static int Lo0bits(int inty) if ((x & 1) == 0) return 32; } - return (int)k; + + return (int) k; } /* Return the number (0 through 32) of most significant zero bits in x. */ @@ -136,36 +142,41 @@ private static int Hi0bits(int x) k = 16; x <<= 16; } + if ((x & 0xff000000) == 0) { k += 8; x <<= 8; } + if ((x & 0xf0000000) == 0) { k += 4; x <<= 4; } + if ((x & 0xc0000000) == 0) { k += 2; x <<= 2; } + if ((x & 0x80000000) == 0) { k++; if ((x & 0x40000000) == 0) return 32; } + return k; } private static void StuffBits(byte[] bits, int offset, int val) { - bits[offset] = (byte)(val >> 24); - bits[offset + 1] = (byte)(val >> 16); - bits[offset + 2] = (byte)(val >> 8); - bits[offset + 3] = (byte)(val); + bits[ offset ] = (byte) (val >> 24); + bits[ offset + 1 ] = (byte) (val >> 16); + bits[ offset + 2 ] = (byte) (val >> 8); + bits[ offset + 3 ] = (byte) (val); } /* Convert d into the form b*2^e, where b is an odd integer. b is the returned @@ -175,12 +186,12 @@ private static BigInteger D2B(double d, int[] e, int[] bits) { byte[] dbl_bits; int i, k, y, z, de; - ulong dBits = (ulong)BitConverter.DoubleToInt64Bits(d); - int d0 = (int)(dBits >> 32); - int d1 = (int)(dBits); + ulong dBits = (ulong) BitConverter.DoubleToInt64Bits(d); + int d0 = (int) (dBits >> 32); + int d1 = (int) (dBits); z = d0 & Frac_mask; - d0 &= 0x7fffffff; /* clear sign bit, which we ignore */ + d0 &= 0x7fffffff; /* clear sign bit, which we ignore */ if ((de = (d0 >> Exp_shift)) != 0) z |= Exp_msk1; @@ -189,7 +200,7 @@ private static BigInteger D2B(double d, int[] e, int[] bits) { dbl_bits = new byte[8]; k = Lo0bits(y); - y = (int)((uint)y >> k); + y = (int) ((uint) y >> k); if (k != 0) { StuffBits(dbl_bits, 4, y | z << (32 - k)); @@ -197,6 +208,7 @@ private static BigInteger D2B(double d, int[] e, int[] bits) } else StuffBits(dbl_bits, 4, y); + StuffBits(dbl_bits, 0, z); i = (z != 0) ? 2 : 1; } @@ -211,22 +223,25 @@ private static BigInteger D2B(double d, int[] e, int[] bits) k += 32; i = 1; } + if (de != 0) { - e[0] = de - Bias - (P - 1) + k; - bits[0] = P - k; + e[ 0 ] = de - Bias - (P - 1) + k; + bits[ 0 ] = P - k; } else { - e[0] = de - Bias - (P - 1) + 1 + k; - bits[0] = 32 * i - Hi0bits(z); + e[ 0 ] = de - Bias - (P - 1) + 1 + k; + bits[ 0 ] = 32 * i - Hi0bits(z); } + byte[] reverse = new byte[dbl_bits.Length]; int q = dbl_bits.Length; foreach (byte b in dbl_bits) { - reverse[--q] = b; + reverse[ --q ] = b; } + return new BigInteger(reverse); } @@ -267,20 +282,20 @@ private static BigInteger D2B(double d, int[] e, int[] bits) static int Word0(double d) { long dBits = BitConverter.DoubleToInt64Bits(d); - return (int)(dBits >> 32); + return (int) (dBits >> 32); } private static double SetWord0(double d, int i) { long dBits = BitConverter.DoubleToInt64Bits(d); - dBits = ((long)i << 32) | (dBits & 0x0FFFFFFFFL); + dBits = ((long) i << 32) | (dBits & 0x0FFFFFFFFL); return BitConverter.Int64BitsToDouble(dBits); } private static int Word1(double d) { long dBits = BitConverter.DoubleToInt64Bits(d); - return (int)(dBits); + return (int) (dBits); } /* Return b * 5^k. k must be nonnegative. */ @@ -296,14 +311,15 @@ private static bool RoundOff(StringBuilder buf) while (i != 0) { --i; - char c = buf[i]; + char c = buf[ i ]; if (c != '9') { - buf[i] = (char)(c + 1); + buf[ i ] = (char) (c + 1); buf.Length = i + 1; return false; } } + buf.Length = 0; return true; } @@ -316,7 +332,7 @@ private static bool RoundOff(StringBuilder buf) /* bufsize should be at least 20 for modes 0 and 1. For the other modes, * bufsize should be two greater than the maximum number of output characters expected. */ public static int JS_dtoa(double d, int mode, bool biasUp, int ndigits, - bool[] sign, StringBuilder buf) + bool[] sign, StringBuilder buf) { /* Arguments ndigits, decpt, sign are similar to those of ecvt and fcvt; trailing zeros are suppressed from @@ -352,8 +368,21 @@ Values of mode other than 0-9 are treated as mode 0. to hold the suppressed trailing zeros. */ - int b2, b5, i, ieps, ilim, ilim0, ilim1, - j, j1, k, k0, m2, m5, s2, s5; + int b2, + b5, + i, + ieps, + ilim, + ilim0, + ilim1, + j, + j1, + k, + k0, + m2, + m5, + s2, + s5; char dig; long L; long x; @@ -366,12 +395,12 @@ to hold the suppressed trailing zeros. if ((Word0(d) & Sign_bit) != 0) { /* set sign for everything, including 0's and NaNs */ - sign[0] = true; + sign[ 0 ] = true; // Word0(d) &= ~Sign_bit; /* clear sign bit */ d = SetWord0(d, Word0(d) & ~Sign_bit); } else - sign[0] = false; + sign[ 0 ] = false; if ((Word0(d) & Exp_mask) == Exp_mask) { @@ -379,16 +408,17 @@ to hold the suppressed trailing zeros. buf.Append(((Word1(d) == 0) && ((Word0(d) & Frac_mask) == 0)) ? "Infinity" : "NaN"); return 9999; } + if (d == 0) { // no_digits: buf.Length = 0; - buf.Append('0'); /* copy "0" to buffer */ + buf.Append('0'); /* copy "0" to buffer */ return 1; } b = D2B(d, be, bbits); - if ((i = ((int)(((uint)Word0(d)) >> Exp_shift1) & (Exp_mask >> Exp_shift1))) != 0) + if ((i = ((int) (((uint) Word0(d)) >> Exp_shift1) & (Exp_mask >> Exp_shift1))) != 0) { d2 = SetWord0(d, (Word0(d) & Frac_mask1) | Exp_11); /* log(x) ~=~ log(1.5) + (x-1.5)/1.5 @@ -418,31 +448,33 @@ to hold the suppressed trailing zeros. else { /* d is denormalized */ - i = bbits[0] + be[0] + (Bias + (P - 1) - 1); + i = bbits[ 0 ] + be[ 0 ] + (Bias + (P - 1) - 1); x = (i > 32) - ? ((long)Word0(d)) << (64 - i) | (((uint)Word1(d)) >> (i - 32)) - : ((long)Word1(d)) << (32 - i); + ? ((long) Word0(d)) << (64 - i) | (((uint) Word1(d)) >> (i - 32)) + : ((long) Word1(d)) << (32 - i); // d2 = x; // Word0(d2) -= 31*Exp_msk1; /* adjust exponent */ d2 = SetWord0(x, Word0(x) - 31 * Exp_msk1); i -= (Bias + (P - 1) - 1) + 1; denorm = true; } + /* At this point d = f*2^i, where 1 <= f < 2. d2 is an approximation of f. */ ds = (d2 - 1.5) * 0.289529654602168 + 0.1760912590558 + i * 0.301029995663981; - k = (int)ds; + k = (int) ds; if (ds < 0.0 && ds != k) - k--; /* want k = floor(ds) */ + k--; /* want k = floor(ds) */ k_check = true; if (k >= 0 && k <= Ten_pmax) { - if (d < tens[k]) + if (d < tens[ k ]) k--; k_check = false; } + /* At this point floor(log10(d)) <= k <= floor(log10(d))+1. If k_check is zero, we're guaranteed that k = floor(log10(d)). */ - j = bbits[0] - i - 1; + j = bbits[ 0 ] - i - 1; /* At this point d = b/2^j, where b is an odd integer. */ if (j >= 0) { @@ -454,6 +486,7 @@ to hold the suppressed trailing zeros. b2 = -j; s2 = 0; } + if (k >= 0) { b5 = 0; @@ -466,6 +499,7 @@ to hold the suppressed trailing zeros. b5 = -k; s5 = 0; } + /* At this point d/10^k = (b * 2^b2 * 5^b5) / (2^s2 * 5^s5), where b is an odd integer, b2 >= 0, b5 >= 0, s2 >= 0, and s5 >= 0. */ if (mode < 0 || mode > 9) @@ -476,6 +510,7 @@ to hold the suppressed trailing zeros. mode -= 4; try_quick = false; } + leftright = true; ilim = ilim1 = 0; switch (mode) @@ -514,7 +549,6 @@ when it turns out that k was computed too high by one. */ bool fast_failed = false; if (ilim >= 0 && ilim <= Quick_max && try_quick) { - /* Try to get by with floating-point arithmetic. */ i = 0; @@ -525,33 +559,36 @@ when it turns out that k was computed too high by one. */ /* Divide d by 10^k, keeping track of the roundoff error and avoiding overflows. */ if (k > 0) { - ds = tens[k & 0xf]; + ds = tens[ k & 0xf ]; j = k >> 4; if ((j & Bletch) != 0) { /* prevent overflows */ j &= Bletch - 1; - d /= bigtens[n_bigtens - 1]; + d /= bigtens[ n_bigtens - 1 ]; ieps++; } + for (; (j != 0); j >>= 1, i++) if ((j & 1) != 0) { ieps++; - ds *= bigtens[i]; + ds *= bigtens[ i ]; } + d /= ds; } else if ((j1 = -k) != 0) { - d *= tens[j1 & 0xf]; + d *= tens[ j1 & 0xf ]; for (j = j1 >> 4; (j != 0); j >>= 1, i++) if ((j & 1) != 0) { ieps++; - d *= bigtens[i]; + d *= bigtens[ i ]; } } + /* Check that k was computed correctly. */ if (k_check && d < 1.0 && ilim > 0) { @@ -565,6 +602,7 @@ when it turns out that k was computed too high by one. */ ieps++; } } + /* eps bounds the cumulative error. */ // eps = ieps*d + 7.0; // Word0(eps) -= (P-1)*Exp_msk1; @@ -580,14 +618,17 @@ when it turns out that k was computed too high by one. */ k++; return k + 1; } + if (d < -eps) { buf.Length = 0; - buf.Append('0'); /* copy "0" to buffer */ + buf.Append('0'); /* copy "0" to buffer */ return 1; } + fast_failed = true; } + if (!fast_failed) { fast_failed = true; @@ -596,23 +637,24 @@ when it turns out that k was computed too high by one. */ /* Use Steele & White method of only * generating digits needed. */ - eps = 0.5 / tens[ilim - 1] - eps; - for (i = 0; ;) + eps = 0.5 / tens[ ilim - 1 ] - eps; + for (i = 0;;) { - L = (long)d; + L = (long) d; d -= L; - buf.Append((char)('0' + L)); + buf.Append((char) ('0' + L)); if (d < eps) { return k + 1; } + if (1.0 - d < eps) { // goto bump_up; char lastCh; while (true) { - lastCh = buf[buf.Length - 1]; + lastCh = buf[ buf.Length - 1 ]; buf.Length = buf.Length - 1; if (lastCh != '9') break; if (buf.Length == 0) @@ -622,9 +664,11 @@ when it turns out that k was computed too high by one. */ break; } } - buf.Append((char)(lastCh + 1)); + + buf.Append((char) (lastCh + 1)); return k + 1; } + if (++i >= ilim) break; eps *= 10.0; @@ -634,12 +678,12 @@ when it turns out that k was computed too high by one. */ else { /* Generate ilim digits, then fix them up. */ - eps *= tens[ilim - 1]; - for (i = 1; ; i++, d *= 10.0) + eps *= tens[ ilim - 1 ]; + for (i = 1;; i++, d *= 10.0) { - L = (long)d; + L = (long) d; d -= L; - buf.Append((char)('0' + L)); + buf.Append((char) ('0' + L)); if (i == ilim) { if (d > 0.5 + eps) @@ -648,7 +692,7 @@ when it turns out that k was computed too high by one. */ char lastCh; while (true) { - lastCh = buf[buf.Length - 1]; + lastCh = buf[ buf.Length - 1 ]; buf.Length = buf.Length - 1; if (lastCh != '9') break; if (buf.Length == 0) @@ -658,7 +702,8 @@ when it turns out that k was computed too high by one. */ break; } } - buf.Append((char)(lastCh + 1)); + + buf.Append((char) (lastCh + 1)); return k + 1; } else if (d < 0.5 - eps) @@ -668,11 +713,13 @@ when it turns out that k was computed too high by one. */ // s++; return k + 1; } + break; } } } } + if (fast_failed) { buf.Length = 0; @@ -684,27 +731,29 @@ when it turns out that k was computed too high by one. */ /* Do we have a "small" integer? */ - if (be[0] >= 0 && k <= Int_max) + if (be[ 0 ] >= 0 && k <= Int_max) { /* Yes. */ - ds = tens[k]; + ds = tens[ k ]; if (ndigits < 0 && ilim <= 0) { if (ilim < 0 || d < 5 * ds || (!biasUp && d == 5 * ds)) { buf.Length = 0; - buf.Append('0'); /* copy "0" to buffer */ + buf.Append('0'); /* copy "0" to buffer */ return 1; } + buf.Append('1'); k++; return k + 1; } - for (i = 1; ; i++) + + for (i = 1;; i++) { - L = (long)(d / ds); + L = (long) (d / ds); d -= L * ds; - buf.Append((char)('0' + L)); + buf.Append((char) ('0' + L)); if (i == ilim) { d += d; @@ -721,7 +770,7 @@ when it turns out that k was computed too high by one. */ char lastCh; while (true) { - lastCh = buf[buf.Length - 1]; + lastCh = buf[ buf.Length - 1 ]; buf.Length = buf.Length - 1; if (lastCh != '9') break; if (buf.Length == 0) @@ -731,14 +780,18 @@ when it turns out that k was computed too high by one. */ break; } } - buf.Append((char)(lastCh + 1)); + + buf.Append((char) (lastCh + 1)); } + break; } + d *= 10.0; if (d == 0) break; } + return k + 1; } @@ -749,7 +802,7 @@ when it turns out that k was computed too high by one. */ { if (mode < 2) { - i = (denorm) ? be[0] + (Bias + (P - 1) - 1 + 1) : 1 + P - bbits[0]; + i = (denorm) ? be[ 0 ] + (Bias + (P - 1) - 1 + 1) : 1 + P - bbits[ 0 ]; /* i is 1 plus the number of trailing zero bits in d's significand. Thus, (2^m2 * 5^m5) / (2^(s2+i) * 5^s5) = (1/2 lsb of d)/10^k. */ } @@ -764,6 +817,7 @@ when it turns out that k was computed too high by one. */ b5 += j; m5 = 0; } + if ((i = ilim) < 0) { m2 -= i; @@ -771,12 +825,14 @@ when it turns out that k was computed too high by one. */ } /* (2^m2 * 5^m5) / (2^(s2+i) * 5^s5) = (1/2 * 10^(1-ilim))/10^k. */ } + b2 += i; s2 += i; mhi = 1; /* (mhi * 2^m2 * 5^m5) / (2^s2 * 5^s5) = one-half of last printed (when mode >= 2) or input (when mode < 2) significant digit, divided by 10^k. */ } + /* We still have d/10^k = (b * 2^b2 * 5^b5) / (2^s2 * 5^s5). Reduce common factors in b2, m2, and s2 without changing the equalities. */ if (m2 > 0 && s2 > 0) @@ -798,6 +854,7 @@ when it turns out that k was computed too high by one. */ b1 = mhi * b; b = b1; } + if ((j = b5 - m5) != 0) b = Pow5mult(b, j); } @@ -818,8 +875,8 @@ when it turns out that k was computed too high by one. */ if (mode < 2) { if ((Word1(d) == 0) && ((Word0(d) & Bndry_mask) == 0) - && ((Word0(d) & (Exp_mask & Exp_mask << 1)) != 0) - ) + && ((Word0(d) & (Exp_mask & Exp_mask << 1)) != 0) + ) { /* The special case. Here we want to be within a quarter of the last input significant digit instead of one half of it when the decimal output string's value is less than d. */ @@ -837,14 +894,15 @@ significant digit instead of one half of it when the decimal output string's val * can do shifts and ors to compute the numerator for q. */ byte[] S_bytes = S.ToByteArray(); - Array.Reverse(S_bytes); // Note: Opposite to java + Array.Reverse(S_bytes); // Note: Opposite to java int S_hiWord = 0; for (int idx = 0; idx < 4; idx++) { S_hiWord = (S_hiWord << 8); if (idx < S_bytes.Length) - S_hiWord |= (S_bytes[idx] & 0xFF); + S_hiWord |= (S_bytes[ idx ] & 0xFF); } + if ((i = (((s5 != 0) ? 32 - Hi0bits(S_hiWord) : 1) + s2) & 0x1f) != 0) i = 32 - i; /* i is the number of leading zero bits in the most significant word of S*2^s2. */ @@ -862,6 +920,7 @@ significant digit instead of one half of it when the decimal output string's val m2 += i; s2 += i; } + /* Now S*2^s2 has exactly four leading zero bits in its most significant word. */ if (b2 > 0) b <<= b2; @@ -874,7 +933,7 @@ significant digit instead of one half of it when the decimal output string's val if (b.CompareTo(S) < 0) { k--; - b *= 10; /* we botched the k estimate */ + b *= 10; /* we botched the k estimate */ if (leftright) mhi *= 10; ilim = ilim1; @@ -887,8 +946,8 @@ significant digit instead of one half of it when the decimal output string's val /* We're doing fixed-mode output and d is less than the minimum nonzero output in this mode. Output either zero or the minimum nonzero output depending on which is closer to d. */ if ((ilim < 0) - || ((i = b.CompareTo(S *= 5)) < 0) - || ((i == 0 && !biasUp))) + || ((i = b.CompareTo(S *= 5)) < 0) + || ((i == 0 && !biasUp))) { /* Always emit at least one digit. If the number appears to be zero using the current mode, then emit one '0' digit and set decpt to 1. */ @@ -896,15 +955,17 @@ Output either zero or the minimum nonzero output depending on which is closer to k = -1 - ndigits; goto ret; */ buf.Length = 0; - buf.Append('0'); /* copy "0" to buffer */ + buf.Append('0'); /* copy "0" to buffer */ return 1; // goto no_digits; } + // one_digit: buf.Append('1'); k++; return k + 1; } + if (leftright) { if (m2 > 0) @@ -923,11 +984,11 @@ Output either zero or the minimum nonzero output depending on which is closer to /* mlo/S = maximum acceptable error, divided by 10^k, if the output is less than d. */ /* mhi/S = maximum acceptable error, divided by 10^k, if the output is greater than d. */ - for (i = 1; ; i++) + for (i = 1;; i++) { BigInteger quotient = BigInteger.DivRem(b, S, out BigInteger remainder); b = remainder; - dig = (char)((int)quotient + '0'); + dig = (char) ((int) quotient + '0'); /* Do we yet have the shortest decimal string * that will round to d? */ @@ -946,19 +1007,22 @@ Output either zero or the minimum nonzero output depending on which is closer to k++; buf.Append('1'); } + return k + 1; // goto round_9_up; } + if (j > 0) dig++; buf.Append(dig); return k + 1; } + if ((j < 0) - || ((j == 0) + || ((j == 0) && (mode == 0) && ((Word1(d) & 1) == 0) - )) + )) { if (j1 > 0) { @@ -967,7 +1031,7 @@ Use whichever would produce a decimal value closer to d. */ b <<= 1; j1 = b.CompareTo(S); if (((j1 > 0) || (j1 == 0 && (((dig & 1) == 1) || biasUp))) - && (dig++ == '9')) + && (dig++ == '9')) { buf.Append('9'); if (RoundOff(buf)) @@ -975,17 +1039,21 @@ Use whichever would produce a decimal value closer to d. */ k++; buf.Append('1'); } + return k + 1; // goto round_9_up; } } + buf.Append(dig); return k + 1; } + if (j1 > 0) { if (dig == '9') - { /* possible if i == 1 */ + { + /* possible if i == 1 */ // round_9_up: // *s++ = '9'; // goto roundoff; @@ -995,11 +1063,14 @@ Use whichever would produce a decimal value closer to d. */ k++; buf.Append('1'); } + return k + 1; } - buf.Append((char)(dig + 1)); + + buf.Append((char) (dig + 1)); return k + 1; } + buf.Append(dig); if (i == ilim) break; @@ -1014,12 +1085,12 @@ Use whichever would produce a decimal value closer to d. */ } } else - for (i = 1; ; i++) + for (i = 1;; i++) { // (char)(dig = quorem(b,S) + '0'); BigInteger quotient = BigInteger.DivRem(b, S, out BigInteger remainder); b = remainder; - dig = (char)((int)quotient + '0'); + dig = (char) ((int) quotient + '0'); buf.Append(dig); if (i >= ilim) @@ -1054,6 +1125,7 @@ Use whichever would produce a decimal value closer to d. */ // while(*--s == '0') ; // s++; } + // ret: // Bfree(S); // if (mhi) { @@ -1072,26 +1144,29 @@ private static void StripTrailingZeroes(StringBuilder buf) // while(*--s == '0') ; // s++; int bl = buf.Length; - while (bl-- > 0 && buf[bl] == '0') + while (bl-- > 0 && buf[ bl ] == '0') { // empty } + buf.Length = bl + 1; } /* Mapping of JSDToStrMode -> JS_dtoa mode */ - private static int[] dtoaModes = { - 0, /* DTOSTR_STANDARD */ - 0, /* DTOSTR_STANDARD_EXPONENTIAL, */ - 3, /* DTOSTR_FIXED, */ - 2, /* DTOSTR_EXPONENTIAL, */ - 2}; /* DTOSTR_PRECISION */ + private static int[] dtoaModes = + { + 0, /* DTOSTR_STANDARD */ + 0, /* DTOSTR_STANDARD_EXPONENTIAL, */ + 3, /* DTOSTR_FIXED, */ + 2, /* DTOSTR_EXPONENTIAL, */ + 2 + }; /* DTOSTR_PRECISION */ public static void JS_dtostr(StringBuilder buffer, int mode, int precision, double d) { - int decPt; /* Position of decimal point relative to first digit returned by JS_dtoa */ - bool[] sign = new bool[1]; /* true if the sign bit was set in d */ - int nDigits; /* Number of significand digits returned by JS_dtoa */ + int decPt; /* Position of decimal point relative to first digit returned by JS_dtoa */ + bool[] sign = new bool[1]; /* true if the sign bit was set in d */ + int nDigits; /* Number of significand digits returned by JS_dtoa */ // JS_ASSERT(bufferSize >= (size_t)(mode <= DTOSTR_STANDARD_EXPONENTIAL ? DTOSTR_STANDARD_BUFFER_SIZE : // DTOSTR_VARIABLE_BUFFER_SIZE(precision))); @@ -1099,14 +1174,14 @@ public static void JS_dtostr(StringBuilder buffer, int mode, int precision, doub if (mode == DTOSTR_FIXED && (d >= 1e21 || d <= -1e21)) mode = DTOSTR_STANDARD; /* Change mode here rather than below because the buffer may not be large enough to hold a large integer. */ - decPt = JS_dtoa(d, dtoaModes[mode], mode >= DTOSTR_FIXED, precision, sign, buffer); + decPt = JS_dtoa(d, dtoaModes[ mode ], mode >= DTOSTR_FIXED, precision, sign, buffer); nDigits = buffer.Length; /* If Infinity, -Infinity, or NaN, return the string regardless of the mode. */ if (decPt != 9999) { bool exponentialNotation = false; - int minNDigits = 0; /* Minimum number of significand digits required by mode and precision */ + int minNDigits = 0; /* Minimum number of significand digits required by mode and precision */ int p; switch (mode) @@ -1160,6 +1235,7 @@ public static void JS_dtostr(StringBuilder buffer, int mode, int precision, doub { buffer.Insert(1, '.'); } + buffer.Append('e'); if ((decPt - 1) >= 0) buffer.Append('+'); @@ -1186,13 +1262,13 @@ public static void JS_dtostr(StringBuilder buffer, int mode, int precision, doub } /* If negative and neither -0.0 nor NaN, output a leading '-'. */ - if (sign[0] && - !(Word0(d) == Sign_bit && Word1(d) == 0) && - !((Word0(d) & Exp_mask) == Exp_mask && - ((Word1(d) != 0) || ((Word0(d) & Frac_mask) != 0)))) + if (sign[ 0 ] && + !(Word0(d) == Sign_bit && Word1(d) == 0) && + !((Word0(d) & Exp_mask) == Exp_mask && + ((Word1(d) != 0) || ((Word0(d) & Frac_mask) != 0)))) { buffer.Insert(0, '-'); } } } -} +} \ No newline at end of file diff --git a/src/es6numberserializer/NumberDiyFp.cs b/src/es6numberserializer/NumberDiyFp.cs index d74d64a4a..3095d8257 100644 --- a/src/es6numberserializer/NumberDiyFp.cs +++ b/src/es6numberserializer/NumberDiyFp.cs @@ -45,7 +45,6 @@ namespace Org.Webpki.Es6NumberSerialization // DiyFp are not designed to contain special doubles (NaN and Infinity). class NumberDiyFp { - private long fv; private int ev; @@ -101,19 +100,19 @@ private void Multiply(NumberDiyFp other) // significant 64 bits are only used for rounding the most significant 64 // bits. const long kM32 = 0xFFFFFFFFL; - long a = (long)((ulong)fv >> 32); + long a = (long) ((ulong) fv >> 32); long b = fv & kM32; - long c = (long)((ulong)other.fv >> 32); + long c = (long) ((ulong) other.fv >> 32); long d = other.fv & kM32; long ac = a * c; long bc = b * c; long ad = a * d; long bd = b * d; - long tmp = ((long)((ulong)bd >> 32)) + (ad & kM32) + (bc & kM32); + long tmp = ((long) ((ulong) bd >> 32)) + (ad & kM32) + (bc & kM32); // By adding 1U << 31 to tmp we round the final result. // Halfway cases will be round up. tmp += 1L << 31; - long result_f = ac + ((long)((ulong)ad >> 32)) + ((long)((ulong)bc >> 32)) + ((long)((ulong)tmp >> 32)); + long result_f = ac + ((long) ((ulong) ad >> 32)) + ((long) ((ulong) bc >> 32)) + ((long) ((ulong) tmp >> 32)); ev += other.ev + 64; fv = result_f; } @@ -140,11 +139,13 @@ public void Normalize() f <<= 10; e -= 10; } + while ((f & kUint64MSB) == 0) { f <<= 1; e--; } + this.fv = f; this.ev = e; } @@ -175,6 +176,5 @@ internal void SetE(int new_value) { ev = new_value; } - } -} +} \ No newline at end of file diff --git a/src/es6numberserializer/NumberDoubleHelper.cs b/src/es6numberserializer/NumberDoubleHelper.cs index 9f31db743..e07c01992 100644 --- a/src/es6numberserializer/NumberDoubleHelper.cs +++ b/src/es6numberserializer/NumberDoubleHelper.cs @@ -38,7 +38,6 @@ namespace Org.Webpki.Es6NumberSerialization { - // Helper functions for doubles. class NumberDoubleHelper { @@ -67,6 +66,7 @@ public static NumberDiyFp AsNormalizedDiyFp(long d64) f <<= 1; e--; } + // Do the final shifts in one go. Don't forget the hidden bit (the '-1'). f <<= NumberDiyFp.kSignificandSize - kSignificandSize - 1; e -= NumberDiyFp.kSignificandSize - kSignificandSize - 1; @@ -77,7 +77,7 @@ public static int Exponent(long d64) { if (IsDenormal(d64)) return kDenormalExponent; - int biased_e = (int)(((d64 & kExponentMask) >> kSignificandSize) & 0xffffffffL); + int biased_e = (int) (((d64 & kExponentMask) >> kSignificandSize) & 0xffffffffL); return biased_e - kExponentBias; } @@ -110,14 +110,14 @@ public static bool IsSpecial(long d64) public static bool IsNan(long d64) { return ((d64 & kExponentMask) == kExponentMask) && - ((d64 & kSignificandMask) != 0L); + ((d64 & kSignificandMask) != 0L); } public static bool IsInfinite(long d64) { return ((d64 & kExponentMask) == kExponentMask) && - ((d64 & kSignificandMask) == 0L); + ((d64 & kSignificandMask) == 0L); } @@ -153,12 +153,13 @@ public static void NormalizedBoundaries(long d64, NumberDiyFp m_minus, NumberDiy m_minus.SetF((v.F() << 1) - 1); m_minus.SetE(v.E() - 1); } + m_minus.SetF(m_minus.F() << (m_minus.E() - m_plus.E())); m_minus.SetE(m_plus.E()); } - private const int kSignificandSize = 52; // Excludes the hidden bit. + private const int kSignificandSize = 52; // Excludes the hidden bit. private const int kExponentBias = 0x3FF + kSignificandSize; private const int kDenormalExponent = -kExponentBias + 1; } -} +} \ No newline at end of file diff --git a/src/es6numberserializer/NumberFastDToA.cs b/src/es6numberserializer/NumberFastDToA.cs index dff42a4e5..34c1368e4 100644 --- a/src/es6numberserializer/NumberFastDToA.cs +++ b/src/es6numberserializer/NumberFastDToA.cs @@ -69,11 +69,11 @@ class NumberFastDToA // representable number to the input. // Modifies the generated digits in the buffer to approach (round towards) w. private static bool RoundWeed(NumberFastDToABuilder buffer, - long distance_too_high_w, - long unsafe_interval, - long rest, - long ten_kappa, - long unit) + long distance_too_high_w, + long unsafe_interval, + long rest, + long ten_kappa, + long unit) { long small_distance = distance_too_high_w - unit; long big_distance = distance_too_high_w + unit; @@ -146,10 +146,10 @@ private static bool RoundWeed(NumberFastDToABuilder buffer, // (buffer{-1} < w_high) && w_high - buffer{-1} > buffer - w_high // Instead of using the buffer directly we use its distance to too_high. // Conceptually rest ~= too_high - buffer - while (rest < small_distance && // Negated condition 1 - unsafe_interval - rest >= ten_kappa && // Negated condition 2 - (rest + ten_kappa < small_distance || // buffer{-1} > w_high - small_distance - rest >= rest + ten_kappa - small_distance)) + while (rest < small_distance && // Negated condition 1 + unsafe_interval - rest >= ten_kappa && // Negated condition 2 + (rest + ten_kappa < small_distance || // buffer{-1} > w_high + small_distance - rest >= rest + ten_kappa - small_distance)) { buffer.DecreaseLast(); rest += ten_kappa; @@ -159,9 +159,9 @@ private static bool RoundWeed(NumberFastDToABuilder buffer, // would require changing the buffer. If yes, then we have two possible // representations close to w, but we cannot decide which one is closer. if (rest < big_distance && - unsafe_interval - rest >= ten_kappa && - (rest + ten_kappa < big_distance || - big_distance - rest > rest + ten_kappa - big_distance)) + unsafe_interval - rest >= ten_kappa && + (rest + ten_kappa < big_distance || + big_distance - rest > rest + ten_kappa - big_distance)) { return false; } @@ -201,6 +201,7 @@ private static long BiggestPowerTen(int number, int number_bits) exponent = 9; break; } + // else fallthrough goto case 29; case 29: @@ -212,6 +213,7 @@ private static long BiggestPowerTen(int number, int number_bits) exponent = 8; break; } + // else fallthrough goto case 26; case 26: @@ -223,6 +225,7 @@ private static long BiggestPowerTen(int number, int number_bits) exponent = 7; break; } + // else fallthrough goto case 23; case 23: @@ -235,6 +238,7 @@ private static long BiggestPowerTen(int number, int number_bits) exponent = 6; break; } + // else fallthrough goto case 19; case 19: @@ -246,6 +250,7 @@ private static long BiggestPowerTen(int number, int number_bits) exponent = 5; break; } + // else fallthrough goto case 16; case 16: @@ -256,7 +261,8 @@ private static long BiggestPowerTen(int number, int number_bits) power = kTen4; exponent = 4; break; - } // else fallthrough + } // else fallthrough + goto case 13; case 13: case 12: @@ -268,6 +274,7 @@ private static long BiggestPowerTen(int number, int number_bits) exponent = 3; break; } + // else fallthrough goto case 9; case 9: @@ -279,6 +286,7 @@ private static long BiggestPowerTen(int number, int number_bits) exponent = 2; break; } + // else fallthrough goto case 6; case 6: @@ -290,6 +298,7 @@ private static long BiggestPowerTen(int number, int number_bits) exponent = 1; break; } + // else fallthrough goto case 3; case 3: @@ -301,6 +310,7 @@ private static long BiggestPowerTen(int number, int number_bits) exponent = 0; break; } + // else fallthrough goto case 0; case 0: @@ -312,9 +322,10 @@ private static long BiggestPowerTen(int number, int number_bits) power = 0; exponent = 0; break; - // UNREACHABLE(); + // UNREACHABLE(); } - return ((long)power << 32) | (0xffffffffL & exponent); + + return ((long) power << 32) | (0xffffffffL & exponent); } private static bool Uint64_lte(long a, long b) @@ -366,10 +377,10 @@ private static bool Uint64_lte(long a, long b) // represents w. However we have to pay attention to low, high and w's // imprecision. private static bool DigitGen(NumberDiyFp low, - NumberDiyFp w, - NumberDiyFp high, - NumberFastDToABuilder buffer, - int mk) + NumberDiyFp w, + NumberDiyFp high, + NumberFastDToABuilder buffer, + int mk) { Debug.Assert(low.E() == w.E() && w.E() == high.E()); Debug.Assert(Uint64_lte(low.F() + 1, high.F() - 1)); @@ -400,12 +411,12 @@ private static bool DigitGen(NumberDiyFp low, // If we stop early we effectively round down. NumberDiyFp one = new NumberDiyFp(1L << -w.E(), w.E()); // Division by one is a shift. - int integrals = (int)(((ulong)too_high.F() >> -one.E()) & 0xffffffffL); + int integrals = (int) (((ulong) too_high.F() >> -one.E()) & 0xffffffffL); // Modulo by one is an and. long fractionals = too_high.F() & (one.F() - 1); long result = BiggestPowerTen(integrals, NumberDiyFp.kSignificandSize - (-one.E())); - int divider = (int)(((ulong)result >> 32) & 0xffffffffL); - int divider_exponent = (int)(result & 0xffffffffL); + int divider = (int) (((ulong) result >> 32) & 0xffffffffL); + int divider_exponent = (int) (result & 0xffffffffL); int kappa = divider_exponent + 1; // Loop invariant: buffer = too_high / 10^kappa (integer division) // The invariant holds for the first iteration: kappa has been initialized @@ -414,13 +425,13 @@ private static bool DigitGen(NumberDiyFp low, while (kappa > 0) { int digit = integrals / divider; - buffer.Append((char)('0' + digit)); + buffer.Append((char) ('0' + digit)); integrals %= divider; kappa--; // Note that kappa now equals the exponent of the divider and that the // invariant thus holds again. long rest = - ((long)integrals << -one.E()) + fractionals; + ((long) integrals << -one.E()) + fractionals; // Invariant: too_high = buffer * 10^kappa + DiyFp(rest, one.E()) // Reminder: unsafe_interval.E() == one.E() if (rest < unsafe_interval.F()) @@ -429,9 +440,10 @@ private static bool DigitGen(NumberDiyFp low, // that lies within the unsafe interval. buffer.point = buffer.end - mk + kappa; return RoundWeed(buffer, NumberDiyFp.Minus(too_high, w).F(), - unsafe_interval.F(), rest, - (long)divider << -one.E(), unit); + unsafe_interval.F(), rest, + (long) divider << -one.E(), unit); } + divider /= 10; } @@ -454,19 +466,19 @@ private static bool DigitGen(NumberDiyFp low, fractionals *= 5; unit *= 5; unsafe_interval.SetF(unsafe_interval.F() * 5); - unsafe_interval.SetE(unsafe_interval.E() + 1); // Will be optimized out. - one.SetF((long)((ulong)one.F() >> 1)); + unsafe_interval.SetE(unsafe_interval.E() + 1); // Will be optimized out. + one.SetF((long) ((ulong) one.F() >> 1)); one.SetE(one.E() + 1); // Integer division by one. - int digit = (int)(((ulong)fractionals >> -one.E()) & 0xffffffffL); - buffer.Append((char)('0' + digit)); - fractionals &= one.F() - 1; // Modulo by one. + int digit = (int) (((ulong) fractionals >> -one.E()) & 0xffffffffL); + buffer.Append((char) ('0' + digit)); + fractionals &= one.F() - 1; // Modulo by one. kappa--; if (fractionals < unsafe_interval.F()) { buffer.point = buffer.end - mk + kappa; return RoundWeed(buffer, NumberDiyFp.Minus(too_high, w).F() * unit, - unsafe_interval.F(), fractionals, one.F(), unit); + unsafe_interval.F(), fractionals, one.F(), unit); } } } @@ -494,13 +506,13 @@ private static bool Grisu3(double v, NumberFastDToABuilder buffer) NumberDiyFp boundary_minus = new NumberDiyFp(), boundary_plus = new NumberDiyFp(); NumberDoubleHelper.NormalizedBoundaries(bits, boundary_minus, boundary_plus); Debug.Assert(boundary_plus.E() == w.E()); - NumberDiyFp ten_mk = new NumberDiyFp(); // Cached power of ten: 10^-k + NumberDiyFp ten_mk = new NumberDiyFp(); // Cached power of ten: 10^-k int mk = NumberCachedPowers.GetCachedPower(w.E() + NumberDiyFp.kSignificandSize, - minimal_target_exponent, maximal_target_exponent, ten_mk); + minimal_target_exponent, maximal_target_exponent, ten_mk); Debug.Assert(minimal_target_exponent <= w.E() + ten_mk.E() + - NumberDiyFp.kSignificandSize && - maximal_target_exponent >= w.E() + ten_mk.E() + - NumberDiyFp.kSignificandSize); + NumberDiyFp.kSignificandSize && + maximal_target_exponent >= w.E() + ten_mk.E() + + NumberDiyFp.kSignificandSize); // Note that ten_mk is only an approximation of 10^-k. A DiyFp only contains a // 64 bit significand and ten_mk is thus only precise up to 64 bits. @@ -512,7 +524,7 @@ private static bool Grisu3(double v, NumberFastDToABuilder buffer) // (f-1) * 2^e < w*10^k < (f+1) * 2^e NumberDiyFp scaled_w = NumberDiyFp.Times(w, ten_mk); Debug.Assert(scaled_w.E() == - boundary_plus.E() + ten_mk.E() + NumberDiyFp.kSignificandSize); + boundary_plus.E() + ten_mk.E() + NumberDiyFp.kSignificandSize); // In theory it would be possible to avoid some recomputations by computing // the difference between w and boundary_minus/plus (a power of 2) and to // compute scaled_boundary_minus/plus by subtracting/adding from @@ -554,7 +566,8 @@ public static bool NumberToString(double v, NumberFastDToABuilder buffer) buffer.Append('-'); v = -v; } + return Dtoa(v, buffer); } } -} +} \ No newline at end of file diff --git a/src/es6numberserializer/NumberFastDToABuilder.cs b/src/es6numberserializer/NumberFastDToABuilder.cs index 305009739..b7cd2952b 100644 --- a/src/es6numberserializer/NumberFastDToABuilder.cs +++ b/src/es6numberserializer/NumberFastDToABuilder.cs @@ -24,12 +24,12 @@ class NumberFastDToABuilder public void Append(char c) { - chars[end++] = c; + chars[ end++ ] = c; } public void DecreaseLast() { - chars[end - 1]--; + chars[ end - 1 ]--; } public void Reset() @@ -43,7 +43,7 @@ public String Format() if (!formatted) { // check for minus sign - int firstDigit = chars[0] == '-' ? 1 : 0; + int firstDigit = chars[ 0 ] == '-' ? 1 : 0; int decPoint = point - firstDigit; if (decPoint < -5 || decPoint > 21) { @@ -53,17 +53,18 @@ public String Format() { ToFixedFormat(firstDigit, decPoint); } + formatted = true; } - return new String(chars, 0, end); + return new String(chars, 0, end); } private void ArrayFill0(int from, int to) { while (from < to) { - chars[from++] = '0'; + chars[ from++ ] = '0'; } } @@ -76,7 +77,7 @@ private void ToFixedFormat(int firstDigit, int decPoint) { // >= 1, split decimals and insert point Array.Copy(chars, point, chars, point + 1, end - point); - chars[point] = '.'; + chars[ point ] = '.'; end++; } else @@ -84,12 +85,13 @@ private void ToFixedFormat(int firstDigit, int decPoint) // < 1, int target = firstDigit + 2 - decPoint; Array.Copy(chars, firstDigit, chars, target, end - firstDigit); - chars[firstDigit] = '0'; - chars[firstDigit + 1] = '.'; + chars[ firstDigit ] = '0'; + chars[ firstDigit + 1 ] = '.'; if (decPoint < 0) { ArrayFill0(firstDigit + 2, target); } + end += 2 - decPoint; } } @@ -108,10 +110,11 @@ private void ToExponentialFormat(int firstDigit, int decPoint) // insert decimal point if more than one digit was produced int dot = firstDigit + 1; Array.Copy(chars, dot, chars, dot + 1, end - dot); - chars[dot] = '.'; + chars[ dot ] = '.'; end++; } - chars[end++] = 'e'; + + chars[ end++ ] = 'e'; char sign = '+'; int exp = decPoint - 1; if (exp < 0) @@ -119,16 +122,17 @@ private void ToExponentialFormat(int firstDigit, int decPoint) sign = '-'; exp = -exp; } - chars[end++] = sign; + + chars[ end++ ] = sign; int charPos = exp > 99 ? end + 2 : exp > 9 ? end + 1 : end; end = charPos + 1; // code below is needed because Integer.getChars() is not internal - for (; ; ) + for (;;) { int r = exp % 10; - chars[charPos--] = digits[r]; + chars[ charPos-- ] = digits[ r ]; exp = exp / 10; if (exp == 0) break; } @@ -139,4 +143,4 @@ private void ToExponentialFormat(int firstDigit, int decPoint) '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; } -} +} \ No newline at end of file diff --git a/src/es6numberserializer/NumberToJson.cs b/src/es6numberserializer/NumberToJson.cs index 94b40de92..069d60c6a 100644 --- a/src/es6numberserializer/NumberToJson.cs +++ b/src/es6numberserializer/NumberToJson.cs @@ -54,10 +54,10 @@ public static string SerializeNumber(double value) { return result; } + StringBuilder buffer = new StringBuilder(); NumberDToA.JS_dtostr(buffer, NumberDToA.DTOSTR_STANDARD, 0, value); return buffer.ToString(); } } -} - +} \ No newline at end of file diff --git a/src/es6numberserializer/es6numberserializer.csproj b/src/es6numberserializer/es6numberserializer.csproj index 5ebf10b90..92ebea7d9 100644 --- a/src/es6numberserializer/es6numberserializer.csproj +++ b/src/es6numberserializer/es6numberserializer.csproj @@ -1,8 +1,8 @@ - - netstandard2.0 - true - + + netstandard2.0 + true + - + \ No newline at end of file