diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..4935e41 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,11 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "csharpier": { + "version": "0.29.2", + "commands": ["dotnet-csharpier"], + "rollForward": false + } + } +} diff --git a/.github/workflows/formatter.yml b/.github/workflows/formatter.yml index 631ef96..f11f194 100644 --- a/.github/workflows/formatter.yml +++ b/.github/workflows/formatter.yml @@ -1,18 +1,17 @@ -name: dotnet-format +name: csharpier -on: [push, pull_request] +on: [pull_request] jobs: format: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Setup .NET 5 + - name: Setup .NET 8 uses: actions/setup-dotnet@v4 with: dotnet-version: 8.0.100 - - name: Install dotnet-format - run: | - dotnet tool install -g dotnet-format - - name: Run dotnet-format - run: dotnet-format EDILibrary.sln --check + - name: Restore .NET tools + run: dotnet tool restore + - name: Run CSharpier + run: dotnet csharpier EDILibrary.sln --check diff --git a/EDIFileLoader/AzureStorageLoader.cs b/EDIFileLoader/AzureStorageLoader.cs index a84ff87..383f208 100644 --- a/EDIFileLoader/AzureStorageLoader.cs +++ b/EDIFileLoader/AzureStorageLoader.cs @@ -9,9 +9,7 @@ using System.Text.Json; using System.Text.Json.Serialization; using System.Threading.Tasks; - using Azure.Storage.Blobs; - using EDILibrary; namespace EDIFileLoader @@ -23,16 +21,23 @@ public class AzureStorageLoader : EDILibrary.Interfaces.ITemplateLoader protected string _containerName; protected string _connectionString; - protected BlobServiceClient _blobClient; protected BlobContainerClient _container; - protected ConcurrentDictionary> Cache { get; set; } = new ConcurrentDictionary>(); + protected ConcurrentDictionary> Cache { get; set; } = + new ConcurrentDictionary>(); + /// /// JsonSerializer options /// protected JsonSerializerOptions JsonOptions { get; set; } - public AzureStorageLoader(string accountName, string accountKey, string containerName, string connectionString) + + public AzureStorageLoader( + string accountName, + string accountKey, + string containerName, + string connectionString + ) { _accountKey = accountKey; _accountName = accountName; @@ -50,55 +55,100 @@ public AzureStorageLoader(string accountName, string accountKey, string containe PropertyNamingPolicy = JsonNamingPolicy.CamelCase, }; } + public async Task PreloadCache() { var tasks = new ConcurrentBag(); - await foreach (var prefixPage in _container.GetBlobsByHierarchyAsync(Azure.Storage.Blobs.Models.BlobTraits.Metadata, Azure.Storage.Blobs.Models.BlobStates.None, "/").AsPages()) + await foreach ( + var prefixPage in _container + .GetBlobsByHierarchyAsync( + Azure.Storage.Blobs.Models.BlobTraits.Metadata, + Azure.Storage.Blobs.Models.BlobStates.None, + "/" + ) + .AsPages() + ) { foreach (var prefix in prefixPage.Values) { - tasks.Add(Task.Run(async () => - { - if (prefix.IsPrefix) + tasks.Add( + Task.Run(async () => { - Cache.TryAdd(prefix.Prefix.TrimEnd('/'), new Dictionary()); - await foreach (var blobPage in _container.GetBlobsByHierarchyAsync(Azure.Storage.Blobs.Models.BlobTraits.Metadata, Azure.Storage.Blobs.Models.BlobStates.None, null, prefix.Prefix).AsPages()) + if (prefix.IsPrefix) { - foreach (var blob in blobPage.Values) + Cache.TryAdd( + prefix.Prefix.TrimEnd('/'), + new Dictionary() + ); + await foreach ( + var blobPage in _container + .GetBlobsByHierarchyAsync( + Azure.Storage.Blobs.Models.BlobTraits.Metadata, + Azure.Storage.Blobs.Models.BlobStates.None, + null, + prefix.Prefix + ) + .AsPages() + ) { - if (blob.IsBlob) + foreach (var blob in blobPage.Values) { - var blockBlob = _container.GetBlobClient(blob.Blob.Name); - // if this stream reader failes, because the blockBlob comes without a ByteOrderMark, then use new UTF8Encoding(false) as encoding - var text = await new StreamReader((await blockBlob.DownloadAsync()).Value.Content, Encoding.UTF8).ReadToEndAsync(); - text = EDIHelper.RemoveByteOrderMark(text); - Cache[prefix.Prefix.TrimEnd('/')].TryAdd(blob.Blob.Name, text); + if (blob.IsBlob) + { + var blockBlob = _container.GetBlobClient( + blob.Blob.Name + ); + // if this stream reader failes, because the blockBlob comes without a ByteOrderMark, then use new UTF8Encoding(false) as encoding + var text = await new StreamReader( + (await blockBlob.DownloadAsync()).Value.Content, + Encoding.UTF8 + ).ReadToEndAsync(); + text = EDIHelper.RemoveByteOrderMark(text); + Cache[prefix.Prefix.TrimEnd('/')] + .TryAdd(blob.Blob.Name, text); + } } } } - } - })); + }) + ); } } await Task.WhenAll(tasks); } + public async Task LoadEDITemplate(EDIFileInfo info, string type) { if (Cache != null) { try { - return Cache["edi"][Path.Combine("edi", info.Format.ToString(), info.Format.ToString() + info.Version + "." + type).Replace("\\", "/")]; - } - catch (KeyNotFoundException) - { + return Cache["edi"][ + Path.Combine( + "edi", + info.Format.ToString(), + info.Format.ToString() + info.Version + "." + type + ) + .Replace("\\", "/") + ]; } + catch (KeyNotFoundException) { } } - var blockBlob = _container.GetBlobClient(Path.Combine("edi", info.Format.ToString(), info.Format.ToString() + info.Version + "." + type)); - var text = await new StreamReader((await blockBlob.DownloadAsync()).Value.Content, Encoding.UTF8).ReadToEndAsync(); + var blockBlob = _container.GetBlobClient( + Path.Combine( + "edi", + info.Format.ToString(), + info.Format.ToString() + info.Version + "." + type + ) + ); + var text = await new StreamReader( + (await blockBlob.DownloadAsync()).Value.Content, + Encoding.UTF8 + ).ReadToEndAsync(); text = EDIHelper.RemoveByteOrderMark(text); return text; } + public Task LoadJSONTemplate(string fileName) { throw new NotSupportedException(); @@ -112,44 +162,69 @@ public async Task LoadJSONTemplate(string formatPackage, string fileName return await LoadJSONTemplate(format, version, fileName); } - public async Task LoadJSONTemplate(EdifactFormat? format, string version, string fileName) + public async Task LoadJSONTemplate( + EdifactFormat? format, + string version, + string fileName + ) { if (Cache != null) { try { - return Cache["edi"][Path.Combine(version.Replace("/", ""), fileName.Replace("\\", "/"))]; - } - catch (KeyNotFoundException) - { + return Cache["edi"][ + Path.Combine(version.Replace("/", ""), fileName.Replace("\\", "/")) + ]; } + catch (KeyNotFoundException) { } } - var blockBlob = _container.GetBlobClient(Path.Combine(version.Replace("/", ""), fileName).Replace("\\", "/")); + var blockBlob = _container.GetBlobClient( + Path.Combine(version.Replace("/", ""), fileName).Replace("\\", "/") + ); - var text = await new StreamReader((await blockBlob.DownloadAsync()).Value.Content, Encoding.UTF8).ReadToEndAsync(); + var text = await new StreamReader( + (await blockBlob.DownloadAsync()).Value.Content, + Encoding.UTF8 + ).ReadToEndAsync(); text = EDIHelper.RemoveByteOrderMark(text); return text; } + /// /// /// - public async Task LoadMausTemplate(EdifactFormat? format, EdifactFormatVersion version, string pid) + public async Task LoadMausTemplate( + EdifactFormat? format, + EdifactFormatVersion version, + string pid + ) { if (Cache != null) { try { - return JsonSerializer.Deserialize(Cache["maus"][Path.Combine(version.ToString(), format.ToString(), pid + "_maus.json")], JsonOptions); - } - catch (KeyNotFoundException) - { + return JsonSerializer.Deserialize( + Cache["maus"][ + Path.Combine(version.ToString(), format.ToString(), pid + "_maus.json") + ], + JsonOptions + ); } + catch (KeyNotFoundException) { } } - var blockBlob = _container.GetBlobClient(Path.Combine("maus", version.ToString(), format.ToString(), pid + "_maus.json")); + var blockBlob = _container.GetBlobClient( + Path.Combine("maus", version.ToString(), format.ToString(), pid + "_maus.json") + ); - var text = await new StreamReader((await blockBlob.DownloadAsync()).Value.Content, Encoding.UTF8).ReadToEndAsync(); + var text = await new StreamReader( + (await blockBlob.DownloadAsync()).Value.Content, + Encoding.UTF8 + ).ReadToEndAsync(); text = EDIHelper.RemoveByteOrderMark(text); - return JsonSerializer.Deserialize(text, JsonOptions); + return JsonSerializer.Deserialize( + text, + JsonOptions + ); } } } diff --git a/EDIFileLoader/StorageNetLoader.cs b/EDIFileLoader/StorageNetLoader.cs index bb17bd8..083ce92 100644 --- a/EDIFileLoader/StorageNetLoader.cs +++ b/EDIFileLoader/StorageNetLoader.cs @@ -9,10 +9,9 @@ using System.Text.Json; using System.Text.Json.Serialization; using System.Threading.Tasks; - using EDILibrary; - using Microsoft.Extensions.Logging; + namespace EDIFileLoader { public class StorageNetLoader : EDILibrary.Interfaces.ITemplateLoader @@ -31,15 +30,23 @@ public class StorageNetLoader : EDILibrary.Interfaces.ITemplateLoader /// Logger /// protected ILogger Logger { get; set; } + /// /// Cache dictionary to not download every file again /// - protected ConcurrentDictionary> Cache { get; set; } = new ConcurrentDictionary>(); + protected ConcurrentDictionary> Cache { get; set; } = + new ConcurrentDictionary>(); + /// /// JsonSerializer options /// protected JsonSerializerOptions JsonOptions { get; set; } - public StorageNetLoader(ILogger logger, Storage.Net.Blobs.IBlobStorage storage, string root = "/") + + public StorageNetLoader( + ILogger logger, + Storage.Net.Blobs.IBlobStorage storage, + string root = "/" + ) { Storage = storage ?? throw new ArgumentNullException(nameof(storage)); Logger = logger; @@ -53,6 +60,7 @@ public StorageNetLoader(ILogger logger, Storage.Net.Blobs.IBlo PropertyNamingPolicy = JsonNamingPolicy.CamelCase, }; } + /// /// Loads all templates from the root of the blob in a cache (parallelizes per folder) /// @@ -61,29 +69,43 @@ public async Task PreloadCache() { var tasks = new ConcurrentBag(); // go through all folders - foreach (var folder in await Storage.ListAsync(new Storage.Net.Blobs.ListOptions() { FolderPath = Root })) + foreach ( + var folder in await Storage.ListAsync( + new Storage.Net.Blobs.ListOptions() { FolderPath = Root } + ) + ) { - - tasks.Add(Task.Run(async () => - { - if (folder.IsFolder) - { - Cache.TryAdd(folder.Name.TrimEnd('/'), new Dictionary()); - foreach (var blob in await Storage.ListAsync(new Storage.Net.Blobs.ListOptions() { FolderPath = folder.FolderPath })) - { - if (blob.IsFile) - { - var text = await GetUTF8TextFromPath(blob.FullPath); - Cache[folder.Name.TrimEnd('/')].TryAdd(blob.Name, text); - } - - } - } - })); - + tasks.Add( + Task.Run(async () => + { + if (folder.IsFolder) + { + Cache.TryAdd( + folder.Name.TrimEnd('/'), + new Dictionary() + ); + foreach ( + var blob in await Storage.ListAsync( + new Storage.Net.Blobs.ListOptions() + { + FolderPath = folder.FolderPath, + } + ) + ) + { + if (blob.IsFile) + { + var text = await GetUTF8TextFromPath(blob.FullPath); + Cache[folder.Name.TrimEnd('/')].TryAdd(blob.Name, text); + } + } + } + }) + ); } await Task.WhenAll(tasks); } + /// /// Helper method to download a UTF-8 string from the blob storage /// @@ -98,6 +120,7 @@ protected async Task GetUTF8TextFromPath(string path) await ss.CopyToAsync(s); return Encoding.UTF8.GetString(s.ToArray()); } + /// /// Load an edifact template specified by file info and type /// @@ -110,15 +133,28 @@ public async Task LoadEDITemplate(EDIFileInfo info, string type) { try { - return Cache["edi"][Path.Combine("edi", info.Format.ToString(), info.Format.ToString() + info.Version + "." + type).Replace("\\", "/")]; - } - catch (KeyNotFoundException) - { + return Cache["edi"][ + Path.Combine( + "edi", + info.Format.ToString(), + info.Format.ToString() + info.Version + "." + type + ) + .Replace("\\", "/") + ]; } + catch (KeyNotFoundException) { } } try { - var text = await GetUTF8TextFromPath(Path.Combine(Root != "/" ? Root : "", "edi", info.Format.ToString(), info.Format.ToString() + info.Version + "." + type).Replace("\\", "/")); + var text = await GetUTF8TextFromPath( + Path.Combine( + Root != "/" ? Root : "", + "edi", + info.Format.ToString(), + info.Format.ToString() + info.Version + "." + type + ) + .Replace("\\", "/") + ); text = EDIHelper.RemoveByteOrderMark(text); if (Cache != null) { @@ -132,7 +168,14 @@ public async Task LoadEDITemplate(EDIFileInfo info, string type) ediCache = new Dictionary(); } - ediCache[Path.Combine("edi", info.Format.ToString(), info.Format.ToString() + info.Version + "." + type).Replace("\\", "/")] = text; + ediCache[ + Path.Combine( + "edi", + info.Format.ToString(), + info.Format.ToString() + info.Version + "." + type + ) + .Replace("\\", "/") + ] = text; } return text; } @@ -142,6 +185,7 @@ public async Task LoadEDITemplate(EDIFileInfo info, string type) return ""; } } + [Obsolete("Use strongly typed version instead.", true)] public Task LoadJSONTemplate(string fileName) { @@ -155,6 +199,7 @@ public async Task LoadJSONTemplate(string formatPackage, string fileName var version = formatPackage.Split("|").Last(); return await LoadJSONTemplate(format, version, fileName); } + /// /// Load a template or create.template for a specifig format and version /// @@ -162,7 +207,11 @@ public async Task LoadJSONTemplate(string formatPackage, string fileName /// /// template/create.template /// In case of any error (pokemon catcher!) returns an empty string - public async Task LoadJSONTemplate(EdifactFormat? format, string version, string fileName) + public async Task LoadJSONTemplate( + EdifactFormat? format, + string version, + string fileName + ) { if (Cache != null && Cache.Any()) { @@ -170,13 +219,14 @@ public async Task LoadJSONTemplate(EdifactFormat? format, string version { return Cache[version.Replace("/", "")][fileName.Replace("\\", "/")]; } - catch (KeyNotFoundException) - { - } + catch (KeyNotFoundException) { } } try { - var text = await GetUTF8TextFromPath(Path.Combine(Root != "/" ? Root : "", version.Replace("/", ""), fileName).Replace("\\", "/")); + var text = await GetUTF8TextFromPath( + Path.Combine(Root != "/" ? Root : "", version.Replace("/", ""), fileName) + .Replace("\\", "/") + ); text = EDIHelper.RemoveByteOrderMark(text); if (Cache != null) { @@ -201,25 +251,41 @@ public async Task LoadJSONTemplate(EdifactFormat? format, string version return ""; } } + /// /// /// - public async Task LoadMausTemplate(EdifactFormat? format, EdifactFormatVersion version, string pid) + public async Task LoadMausTemplate( + EdifactFormat? format, + EdifactFormatVersion version, + string pid + ) { if (Cache != null && Cache.Any()) { try { - return JsonSerializer.Deserialize(Cache["maus"][Path.Combine(version.ToString(), format.ToString(), pid + "_maus.json")], JsonOptions); - } - catch (KeyNotFoundException) - { + return JsonSerializer.Deserialize( + Cache["maus"][ + Path.Combine(version.ToString(), format.ToString(), pid + "_maus.json") + ], + JsonOptions + ); } + catch (KeyNotFoundException) { } catch (JsonException) { } } try { - var text = await GetUTF8TextFromPath(Path.Combine(Root != "/" ? Root : "", "maus", version.ToString(), format.ToString(), pid + "_maus.json")); + var text = await GetUTF8TextFromPath( + Path.Combine( + Root != "/" ? Root : "", + "maus", + version.ToString(), + format.ToString(), + pid + "_maus.json" + ) + ); text = EDIHelper.RemoveByteOrderMark(text); if (Cache != null) { @@ -233,9 +299,14 @@ public async Task LoadJSONTemplate(EdifactFormat? format, string version ediCache = new Dictionary(); } - ediCache[Path.Combine(version.ToString(), format.ToString(), pid + "_maus.json")] = text; + ediCache[ + Path.Combine(version.ToString(), format.ToString(), pid + "_maus.json") + ] = text; } - return JsonSerializer.Deserialize(text, JsonOptions); + return JsonSerializer.Deserialize( + text, + JsonOptions + ); } catch (Exception exc) { diff --git a/EDILibrary/CSVMapper.cs b/EDILibrary/CSVMapper.cs index 8054c60..3907f71 100644 --- a/EDILibrary/CSVMapper.cs +++ b/EDILibrary/CSVMapper.cs @@ -4,6 +4,7 @@ using System.Text; using Newtonsoft.Json; using Newtonsoft.Json.Linq; + namespace EDILibrary { public class CSVMapper @@ -20,7 +21,11 @@ protected static void ParseStep(JObject step, StringBuilder builder) { if (field.Property("steps") != null) { - foreach (var subStep in (field.Property("steps").Value as JObject).Properties()) + foreach ( + var subStep in ( + field.Property("steps").Value as JObject + ).Properties() + ) { ParseStep(subStep.Value.Value(), builder); } @@ -39,7 +44,9 @@ protected static void ParseStep(JObject step, StringBuilder builder) { if (field.Property("steps") != null) { - foreach (var subStep in (field.Property("steps").Value as JObject).Properties()) + foreach ( + var subStep in (field.Property("steps").Value as JObject).Properties() + ) { ParseStep(subStep.Value.Value(), builder); } @@ -52,7 +59,13 @@ protected static void ParseStep(JObject step, StringBuilder builder) } } } - protected static void ParseProperty(JProperty prop, string prefix, StringBuilder builder, StringBuilder valueBuilder) + + protected static void ParseProperty( + JProperty prop, + string prefix, + StringBuilder builder, + StringBuilder valueBuilder + ) { if (prop.Value.GetType() == typeof(JArray)) { @@ -83,6 +96,7 @@ protected static void ParseProperty(JProperty prop, string prefix, StringBuilder } } } + public static string CreateCSVTemplateFromJSON(string json) { var rootObject = JsonConvert.DeserializeObject(json); @@ -112,10 +126,16 @@ public static string CreateCSVTemplateFromJSON(string json) ParseProperty(prop, "", builder, valueBuilder); } } - return builder.ToString().TrimEnd(';') + Environment.NewLine + valueBuilder.ToString().TrimEnd(';'); + return builder.ToString().TrimEnd(';') + + Environment.NewLine + + valueBuilder.ToString().TrimEnd(';'); } - protected static void BuildObjectFromSegment(string segment, string value, JObject localRoot) + protected static void BuildObjectFromSegment( + string segment, + string value, + JObject localRoot + ) { while (true) { @@ -144,6 +164,7 @@ protected static string RemoveStepFromSegment(string segment) { return !segment.Contains("|") ? segment : string.Join("|", segment.Split('|').Skip(1)); } + public static List CreateJSONFromCSV(string csv) { //first split header line from content lines @@ -155,14 +176,8 @@ public static List CreateJSONFromCSV(string csv) var lineSegments = line.Split(new[] { ";" }, StringSplitOptions.None); var index = 0; var lineObject = new JObject(); - var nachrichtObject = new JObject - { - { "Nachricht", new JArray(lineObject) } - }; - var dokumentObject = new JObject - { - { "Dokument", new JArray(nachrichtObject) } - }; + var nachrichtObject = new JObject { { "Nachricht", new JArray(lineObject) } }; + var dokumentObject = new JObject { { "Dokument", new JArray(nachrichtObject) } }; foreach (var segment in segments) { BuildObjectFromSegment(segment, lineSegments[index], lineObject); diff --git a/EDILibrary/Constants/German/Pruefidentifikatoren.cs b/EDILibrary/Constants/German/Pruefidentifikatoren.cs index 398eda5..95234a1 100644 --- a/EDILibrary/Constants/German/Pruefidentifikatoren.cs +++ b/EDILibrary/Constants/German/Pruefidentifikatoren.cs @@ -1,9 +1,10 @@ namespace EDILibrary.Constants.German -{/// - /// Prüfidentifikatoren - /// Basierend auf https://www.edi-energy.de/ ➡ Dokumente ➡ Anwendungsübersicht der Prüfidentifikatoren 2.2 und 2.1 - /// Excel code generator snipet : =TEXTKETTE("public const string UTILMD_";E2;"_";WECHSELN(WECHSELN(GROSS2(WECHSELN(WECHSELN(WECHSELN(WECHSELN(KLEIN(F2);"ä";"ae");"ö";"oe");"ü";"ue");".";""));" ";"");"/";"_");" = """;E2;""";") - /// +{ + /// + /// Prüfidentifikatoren + /// Basierend auf https://www.edi-energy.de/ ➡ Dokumente ➡ Anwendungsübersicht der Prüfidentifikatoren 2.2 und 2.1 + /// Excel code generator snipet : =TEXTKETTE("public const string UTILMD_";E2;"_";WECHSELN(WECHSELN(GROSS2(WECHSELN(WECHSELN(WECHSELN(WECHSELN(KLEIN(F2);"ä";"ae");"ö";"oe");"ü";"ue");".";""));" ";"");"/";"_");" = """;E2;""";") + /// public static class Pruefidentifikatoren { #pragma warning disable CS1591 @@ -58,7 +59,8 @@ public static class Pruefidentifikatoren public const string IFTSTA_21037_Rd_NbBewertung = "21037"; public const string IFTSTA_21038_Rd_BtrBewertung = "21038"; public const string IFTSTA_21039_Gpke_AwhSperrpGas_AuftragsstatusSperren = "21039"; - public const string IFTSTA_21040_Gpke_AwhSperrpGas_InformationUeberEntsperrauftrag = "21040"; + public const string IFTSTA_21040_Gpke_AwhSperrpGas_InformationUeberEntsperrauftrag = + "21040"; public const string IFTSTA_21042_Wim_UmsetzungsstatusDerBestellung = "21042"; public const string IFTSTA_21043_Gpke_BestellungsantwortMitteilung = "21043"; public const string IFTSTA_21044_Gpke_Bestellungsbeendigung = "21044"; @@ -70,11 +72,15 @@ public static class Pruefidentifikatoren public const string INSRPT_23001_Wim_StoerungsmeldungVomLf_Nb_MsbAnMsb = "23001"; public const string INSRPT_23003_Wim_AblehnungVomMsbAnLf_Nb_Msb = "23003"; public const string INSRPT_23004_Wim_BestaetigungVomMsbAnLf_Nb_Msb = "23004"; - public const string INSRPT_23005_Wim_InformationsmeldungStoerungsmeldungVomMsbAnNbGas_MsbStrom = "23005"; + public const string INSRPT_23005_Wim_InformationsmeldungStoerungsmeldungVomMsbAnNbGas_MsbStrom = + "23005"; public const string INSRPT_23008_Wim_ErgebnisberichtVomMsbAnLf_Nb_Msb = "23008"; - public const string INSRPT_23009_Wim_InformationsmeldungStoerungsbehebungVomMsbAnNbGas_MsbStrom = "23009"; - public const string INSRPT_23011_Wim_InformationsmeldungStoerungsmeldungVomMsbDerMalo = "23011"; - public const string INSRPT_23012_Wim_InformationsmeldungStoerungsbehebungVomMsbDerMalo = "23012"; + public const string INSRPT_23009_Wim_InformationsmeldungStoerungsbehebungVomMsbAnNbGas_MsbStrom = + "23009"; + public const string INSRPT_23011_Wim_InformationsmeldungStoerungsmeldungVomMsbDerMalo = + "23011"; + public const string INSRPT_23012_Wim_InformationsmeldungStoerungsbehebungVomMsbDerMalo = + "23012"; #endregion @@ -119,7 +125,8 @@ public static class Pruefidentifikatoren public const string MSCONS_13022_RedispatchEinzelzeitreiheAusfallarbeit = "13022"; public const string MSCONS_13023_RedispatchAusfallarbeitssummenzeitreihe = "13023"; public const string MSCONS_13025_LastgangMarktlokationTranche = "13025"; - public const string MSCONS_13026_RedispatchEegUeberfuehrungszeitreiheAufgrundAusfallarbeit = "13026"; + public const string MSCONS_13026_RedispatchEegUeberfuehrungszeitreiheAufgrundAusfallarbeit = + "13026"; public const string MSCONS_13027_WerteNachTyp2 = "13027"; #endregion @@ -189,7 +196,8 @@ public static class Pruefidentifikatoren public const string ORDRSP_19005_AuftragsbestaetigungDerAenderungDerMesslokation = "19005"; public const string ORDRSP_19006_AblehnungDerAenderungDerMesslokation = "19006"; public const string ORDRSP_19007_AblehnungAnforderungMesswerte = "19007"; - public const string ORDRSP_19009_BestaetigungBeendigungRechnungsabwicklungMsbUeberLf = "19009"; + public const string ORDRSP_19009_BestaetigungBeendigungRechnungsabwicklungMsbUeberLf = + "19009"; public const string ORDRSP_19010_AblehnungBeendigungRechnungsabwicklungMsbUeberLf = "19010"; public const string ORDRSP_19011_BestaetigungDerAbBestellungVonWertenFuerEsa = "19011"; public const string ORDRSP_19012_AblehnungDerAbBestellungVonWertenFuerEsa = "19012"; @@ -218,7 +226,8 @@ public static class Pruefidentifikatoren public const string ORDRSP_19129_AblehnungStornierungSperrEntsperrauftrag = "19129"; public const string ORDRSP_19130_BearbeitungsstandZurReklamationEiner = "19130"; public const string ORDRSP_19131_AntwortAufBestellungBeendigungEinerKonfiguration = "19131"; - public const string ORDRSP_19132_MitteilungZurBestellungAenderungEinerKonfiguration = "19132"; + public const string ORDRSP_19132_MitteilungZurBestellungAenderungEinerKonfiguration = + "19132"; public const string ORDRSP_19204_AblehnungAbBestellungDerAggregationsebene = "19204"; public const string ORDRSP_19301_AblehnungAbo = "19301"; public const string ORDRSP_19302_BestaetigungEndeAbo = "19302"; @@ -308,16 +317,21 @@ public static class Pruefidentifikatoren public const string UTILMD_11016_Gpke_GeliGas_KuendigungBeimAltenLieferanten = "11016"; public const string UTILMD_11017_Gpke_GeliGas_BestaetigungKuendigung = "11017"; public const string UTILMD_11018_Gpke_GeliGas_AblehnungKuendigung = "11018"; - public const string UTILMD_11019_GeliGas_ZuordnungslisteZugeordneteMarktlokationen = "11019"; + public const string UTILMD_11019_GeliGas_ZuordnungslisteZugeordneteMarktlokationen = + "11019"; public const string UTILMD_11020_GeliGas_AenderungsmeldungZurZuordnungsliste = "11020"; - public const string UTILMD_11021_GeliGas_AntwortAufAenderungsmeldungZurZuordnungsliste = "11021"; + public const string UTILMD_11021_GeliGas_AntwortAufAenderungsmeldungZurZuordnungsliste = + "11021"; public const string UTILMD_11022_Gpke_GeliGas_AnfrageNachStornierung = "11022"; public const string UTILMD_11023_Gpke_GeliGas_BestaetigungAnfrageStornierung = "11023"; public const string UTILMD_11024_Gpke_GeliGas_AblehnungAnfrageStornierung = "11024"; public const string UTILMD_11035_Gpke_GeliGas_AntwortAufDieGeschaeftsdatenanfrage = "11035"; - public const string UTILMD_11036_Gpke_GeliGas_InformationsmeldungUeberExistierendeZuordnung = "11036"; - public const string UTILMD_11037_Gpke_GeliGas_InformationsmeldungZurBeendigungDerZuordnung = "11037"; - public const string UTILMD_11038_Gpke_GeliGas_InformationsmeldungZurAufhebungEinerZukZuordnung = "11038"; + public const string UTILMD_11036_Gpke_GeliGas_InformationsmeldungUeberExistierendeZuordnung = + "11036"; + public const string UTILMD_11037_Gpke_GeliGas_InformationsmeldungZurBeendigungDerZuordnung = + "11037"; + public const string UTILMD_11038_Gpke_GeliGas_InformationsmeldungZurAufhebungEinerZukZuordnung = + "11038"; public const string UTILMD_11039_Wim_KuendigungMsb = "11039"; public const string UTILMD_11040_Wim_BestaetigungKuendigungMsb = "11040"; public const string UTILMD_11041_Wim_AblehnungKuendigungMsb = "11041"; @@ -344,7 +358,8 @@ public static class Pruefidentifikatoren public const string UTILMD_11076_Hknr_AntwortAufStammdatenaenderung = "11076"; public const string UTILMD_11077_Mpes_Anmeldung = "11077"; public const string UTILMD_11078_Mpes_BestaetigungAnmeldung = "11078"; - public const string UTILMD_11079_Mpes_BestaetigungAnmeldungNeuanlageUndBestaetigungLf = "11079"; + public const string UTILMD_11079_Mpes_BestaetigungAnmeldungNeuanlageUndBestaetigungLf = + "11079"; public const string UTILMD_11080_Mpes_AblehnungAnmeldung = "11080"; public const string UTILMD_11081_Mpes_Abmeldung = "11081"; public const string UTILMD_11082_Mpes_BestaetigungAbmeldung = "11082"; @@ -357,20 +372,27 @@ public static class Pruefidentifikatoren public const string UTILMD_11089_Mpes_KuendigungBeimAltenLieferanten = "11089"; public const string UTILMD_11090_Mpes_BestaetigungKuendigung = "11090"; public const string UTILMD_11091_Mpes_AblehnungKuendigung = "11091"; - public const string UTILMD_11092_Mpes_InformationsmeldungUeberExistierendeZuordnung = "11092"; - public const string UTILMD_11093_Mpes_InformationsmeldungZurBeendigungDerZuordnung = "11093"; - public const string UTILMD_11094_Mpes_InformationsmeldungZurAufhebungEinerZukZuordnung = "11094"; + public const string UTILMD_11092_Mpes_InformationsmeldungUeberExistierendeZuordnung = + "11092"; + public const string UTILMD_11093_Mpes_InformationsmeldungZurBeendigungDerZuordnung = + "11093"; + public const string UTILMD_11094_Mpes_InformationsmeldungZurAufhebungEinerZukZuordnung = + "11094"; public const string UTILMD_11095_Mpes_AntwortAufDieGeschaeftsdatenanfrage = "11095"; public const string UTILMD_11096_Tsimsg_DeklarationslisteAnMgv = "11096"; public const string UTILMD_11097_Tsimsg_DeklarationslisteAnBkv = "11097"; public const string UTILMD_11101_Nbw_StammdatenZurMesslokation = "11101"; public const string UTILMD_11102_Nbw_AktualisierteStammdatenZurMesslokation = "11102"; public const string UTILMD_11103_Nbw_StammdatenZurVerbrauchendenMarktlokation = "11103"; - public const string UTILMD_11104_Nbw_AktualisierteStammdatenZurVerbrauchendenMarktlokation = "11104"; - public const string UTILMD_11105_Nbw_AblehnungAufStammdatenZurVerbrauchendenMarktlokation = "11105"; + public const string UTILMD_11104_Nbw_AktualisierteStammdatenZurVerbrauchendenMarktlokation = + "11104"; + public const string UTILMD_11105_Nbw_AblehnungAufStammdatenZurVerbrauchendenMarktlokation = + "11105"; public const string UTILMD_11106_Nbw_StammdatenZurErzeugendenMarktlokation = "11106"; - public const string UTILMD_11107_Nbw_AktualisierteStammdatenZurErzeugendenMarktlokation = "11107"; - public const string UTILMD_11108_Nbw_AblehnungAufStammdatenZurErzeugendenMarktlokation = "11108"; + public const string UTILMD_11107_Nbw_AktualisierteStammdatenZurErzeugendenMarktlokation = + "11107"; + public const string UTILMD_11108_Nbw_AblehnungAufStammdatenZurErzeugendenMarktlokation = + "11108"; public const string UTILMD_11109_Sdae_NichtBilarelAenderungVomLfAnNb = "11109"; public const string UTILMD_11110_Sdae_NichtBilarelAenderungVomLfNbAnMsb = "11110"; public const string UTILMD_11111_Sdae_AntwortAufAenderungVomLfAgAnAf = "11111"; @@ -382,10 +404,13 @@ public static class Pruefidentifikatoren public const string UTILMD_11119_Sdae_AntwortAufAenderungVomMsbAgAnAf = "11119"; public const string UTILMD_11120_Sdae_BilarelAenderungVomLfAnNb = "11120"; public const string UTILMD_11121_Sdae_AntwortAufBilarelAenderungVomLfNbAnLf = "11121"; - public const string UTILMD_11123_Sdae_BilarelAenderungVomNbMitAbhaengigkeitenNbAnLf_Msb = "11123"; - public const string UTILMD_11124_Sdae_AntwortAufBilarelAenderungVomNbMitAbhaengigkeitenAgAnNb = "11124"; + public const string UTILMD_11123_Sdae_BilarelAenderungVomNbMitAbhaengigkeitenNbAnLf_Msb = + "11123"; + public const string UTILMD_11124_Sdae_AntwortAufBilarelAenderungVomNbMitAbhaengigkeitenAgAnNb = + "11124"; public const string UTILMD_11126_Sdae_AenderungDerPrognosegrundlageNbAnLf_Msb = "11126"; - public const string UTILMD_11127_Sdae_AntwortAufAenderungDerPrognosegrundlageAgAnNb = "11127"; + public const string UTILMD_11127_Sdae_AntwortAufAenderungDerPrognosegrundlageAgAnNb = + "11127"; public const string UTILMD_11133_Sdae_NichtBilarelAnfrageAnLfMsbAnNb = "11133"; public const string UTILMD_11134_Sdae_AntwortAufNichtBilarelAnfrageAnLfNbAnMsb = "11134"; public const string UTILMD_11135_Sdae_AntwortAufNichtBilarelAnfrageAnLfNbAnMsb = "11135"; @@ -396,42 +421,63 @@ public static class Pruefidentifikatoren public const string UTILMD_11140_Sdae_NichtBilarelAnfrageAnNbMsbAnNb = "11140"; public const string UTILMD_11142_Sdae_AntwortAufNichtBilarelAnfrageAnNbNbAnAf = "11142"; public const string UTILMD_11143_Sdae_AnfrageAnMsbMitAbhaengigkeitenLfAnNb = "11143"; - public const string UTILMD_11145_Sdae_AntwortAufAnfrageAnMsbMitAbhaengigkeitenNbAnAf = "11145"; - public const string UTILMD_11146_Sdae_AblehnungDerAnfrageAnMsbMitAbhaengigkeitenNbAnAf = "11146"; - public const string UTILMD_11147_Sdae_AnfrageAnMsbMitAbhaengigkeitenNbVerteilerAnMsb = "11147"; - public const string UTILMD_11148_Sdae_AnfrageAnMsbMitAbhaengigkeitenNbBerechtigtAnMsb = "11148"; - public const string UTILMD_11149_Sdae_AntwortAufAnfrageAnMsbMitAbhaengigkeitenMsbAnNb = "11149"; + public const string UTILMD_11145_Sdae_AntwortAufAnfrageAnMsbMitAbhaengigkeitenNbAnAf = + "11145"; + public const string UTILMD_11146_Sdae_AblehnungDerAnfrageAnMsbMitAbhaengigkeitenNbAnAf = + "11146"; + public const string UTILMD_11147_Sdae_AnfrageAnMsbMitAbhaengigkeitenNbVerteilerAnMsb = + "11147"; + public const string UTILMD_11148_Sdae_AnfrageAnMsbMitAbhaengigkeitenNbBerechtigtAnMsb = + "11148"; + public const string UTILMD_11149_Sdae_AntwortAufAnfrageAnMsbMitAbhaengigkeitenMsbAnNb = + "11149"; public const string UTILMD_11150_Sdae_BilarelAnfrageAnLfNbAnLf = "11150"; public const string UTILMD_11151_Sdae_AntwortAufBilarelAnfrageAnLfLfAnNb = "11151"; public const string UTILMD_11152_Sdae_AblehnungDerBilarelAnfrageAnLfLfAnNb = "11152"; public const string UTILMD_11153_Sdae_BilarelAnfrageAnNbOhneAbhaengigkeiten = "11153"; - public const string UTILMD_11154_Sdae_AntwortAufBilarelAnfrageAnNbOhneAbhaengigkeiten = "11154"; - public const string UTILMD_11155_Sdae_AblehnungDerBilarelAnfrageAnNbOhneAbhaengigkeiten = "11155"; + public const string UTILMD_11154_Sdae_AntwortAufBilarelAnfrageAnNbOhneAbhaengigkeiten = + "11154"; + public const string UTILMD_11155_Sdae_AblehnungDerBilarelAnfrageAnNbOhneAbhaengigkeiten = + "11155"; public const string UTILMD_11156_Sdae_BilarelAnfrageAnNbMitAbhaengigkeiten = "11156"; - public const string UTILMD_11157_Sdae_AntwortAufBilarelAnfrageAnNbMitAbhaengigkeiten = "11157"; + public const string UTILMD_11157_Sdae_AntwortAufBilarelAnfrageAnNbMitAbhaengigkeiten = + "11157"; public const string UTILMD_11159_Sdae_AenderungVomMsbOhneAbhaengigkeitenMsbAnNb = "11159"; - public const string UTILMD_11160_Sdae_AenderungVomMsbOhneAbhaengigkeitenNbAnLf_Msb = "11160"; + public const string UTILMD_11160_Sdae_AenderungVomMsbOhneAbhaengigkeitenNbAnLf_Msb = + "11160"; public const string UTILMD_11161_Sdae_AenderungVomMsbOhneAbhaengigkeitenAgAnAf = "11161"; - public const string UTILMD_11162_Sdae_AnfrageAnMsbOhneAbhaengigkeitenVonLf_MsbAnNb = "11162"; - public const string UTILMD_11163_Sdae_AntwortAufAnfrageAnMsbOhneAbhaengigkeitenLf_MsbAnNb = "11163"; - public const string UTILMD_11164_Sdae_AblehnungAufAnfrageAnMsbOhneAbhaengigkeitenLf_MsbAnNb = "11164"; - public const string UTILMD_11165_Sdae_AnfrageAnMsbOhneAbhaengigkeitenNbVerteilerAnMsb = "11165"; - public const string UTILMD_11166_Sdae_AnfrageAnMsbOhneAbhaengigkeitenNbBerechtigterAnMsb = "11166"; - public const string UTILMD_11167_Sdae_AntwortAufAnfrageAnMsbOhneAbhaengigkeitenMsbAnNb = "11167"; + public const string UTILMD_11162_Sdae_AnfrageAnMsbOhneAbhaengigkeitenVonLf_MsbAnNb = + "11162"; + public const string UTILMD_11163_Sdae_AntwortAufAnfrageAnMsbOhneAbhaengigkeitenLf_MsbAnNb = + "11163"; + public const string UTILMD_11164_Sdae_AblehnungAufAnfrageAnMsbOhneAbhaengigkeitenLf_MsbAnNb = + "11164"; + public const string UTILMD_11165_Sdae_AnfrageAnMsbOhneAbhaengigkeitenNbVerteilerAnMsb = + "11165"; + public const string UTILMD_11166_Sdae_AnfrageAnMsbOhneAbhaengigkeitenNbBerechtigterAnMsb = + "11166"; + public const string UTILMD_11167_Sdae_AntwortAufAnfrageAnMsbOhneAbhaengigkeitenMsbAnNb = + "11167"; public const string UTILMD_11168_Verpflichtungsanfrage_Aufforderung = "11168"; public const string UTILMD_11169_BestaetigungVerpflichtungsanfrage = "11169"; public const string UTILMD_11170_AblehnungVerpflichtungsanfrage = "11170"; public const string UTILMD_11171_Sdae_AenderungVomMsbNbAnMsb = "11171"; public const string UTILMD_11172_Sdae_AnfrageAnMsbMitAbhaengigkeitMsbAnNb = "11172"; public const string UTILMD_11173_Sdae_AenderungDerLokationsbuendelstrukturNbAnMsb = "11173"; - public const string UTILMD_11174_Sdae_AntwortAufAenderungDerLokationsbuendelstrukturMsbAnNb = "11174"; + public const string UTILMD_11174_Sdae_AntwortAufAenderungDerLokationsbuendelstrukturMsbAnNb = + "11174"; public const string UTILMD_11175_Sdae_AenderungDerMarktlokationsstrukturNbAnLf = "11175"; - public const string UTILMD_11176_Sdae_AntwortAufAenderungDerMarktlokationsstrukturLfAnNb = "11176"; + public const string UTILMD_11176_Sdae_AntwortAufAenderungDerMarktlokationsstrukturLfAnNb = + "11176"; public const string UTILMD_11177_Sdae_AnfrageDerLokationsbuendelstrukturMsbAnNb = "11177"; - public const string UTILMD_11178_Sdae_AntwortAufAnfrageDerLokationsbuendelstrukturNbAnMsb = "11178"; - public const string UTILMD_11180_Sdae_AnfrageDerKomplexenMarktlokationsstrukturLfAnNb = "11180"; - public const string UTILMD_11181_Sdae_AntwortAufAnfrageDerKomplexenMarktlokationsstrukturNbAnLf = "11181"; - public const string UTILMD_11182_Sdae_AblehnungDerAnfrageDerKomplexenMarktlokationsstrukturNbAnLf = "11182"; + public const string UTILMD_11178_Sdae_AntwortAufAnfrageDerLokationsbuendelstrukturNbAnMsb = + "11178"; + public const string UTILMD_11180_Sdae_AnfrageDerKomplexenMarktlokationsstrukturLfAnNb = + "11180"; + public const string UTILMD_11181_Sdae_AntwortAufAnfrageDerKomplexenMarktlokationsstrukturNbAnLf = + "11181"; + public const string UTILMD_11182_Sdae_AblehnungDerAnfrageDerKomplexenMarktlokationsstrukturNbAnLf = + "11182"; public const string UTILMD_11185_StammdatensynchronisationVomNb = "11185"; public const string UTILMD_11186_StammdatensynchronisationVomLf = "11186"; public const string UTILMD_11187_StammdatensynchronisationVomUenb = "11187"; @@ -443,7 +489,8 @@ public static class Pruefidentifikatoren public const string UTILMD_11193_AblehnungAnfrageAnUenb = "11193"; public const string UTILMD_11194_AntwortAufDieGeschaeftsdatenanfrageAnDenMsbGas = "11194"; public const string UTILMD_11195_Mabis_Bilanzierungsgebietsclearingliste = "11195"; - public const string UTILMD_11196_Mabis_AntwortAufDieBilanzierungsgebietsclearingliste = "11196"; + public const string UTILMD_11196_Mabis_AntwortAufDieBilanzierungsgebietsclearingliste = + "11196"; public const string UTILMD_11197_Redispatch_AktivierungZpTaeglicheAauez = "11197"; public const string UTILMD_11198_Redispatch_DeaktivierungTaeglicheAauez = "11198"; public const string UTILMD_11199_Redispatch_AktivierungZpLfAaszr = "11199"; @@ -465,21 +512,28 @@ public static class Pruefidentifikatoren public const string UTILMD_11215_Gpke_AntwortAufDieGeschaeftsdatenanfrageDesUenb = "11215"; public const string UTILMD_11216_AntwortBestellungZaehlzeitdefinitionDesLf = "11216"; public const string UTILMD_11217_AntwortBestellungZaehlzeitdefinitionDesLf = "11217"; - public const string UTILMD_11218_Sdae_NichtBilarelAenderungNnaVomNbAnMarktlokation = "11218"; + public const string UTILMD_11218_Sdae_NichtBilarelAenderungNnaVomNbAnMarktlokation = + "11218"; public const string UTILMD_11219_Sdae_AntwortAufAenderungNnaVomNbAnMarktlokation = "11219"; public const string UTILMD_11220_Sdae_NichtBilarelAnfrageNnaAnNbAnMarktlokation = "11220"; public const string UTILMD_11221_Sdae_AntwortAufAnfrageNnaAnNbAnMarktlokation = "11221"; public const string UTILMD_11222_Sdae_AblehnungAnfrageNnaAnNbAnMarktlokation = "11222"; public const string UTILMD_11223_Mabis_DzueListe = "11223"; public const string UTILMD_11224_Mabis_AntwortAufDzueListe = "11224"; - public const string UTILMD_11225_Sdae_NichtBilarelAenderungAbrechnungBlindarbeitVomNb = "11225"; - public const string UTILMD_11226_Sdae_AntwortAufAenderungAbrechnungBlindarbeitVomNb = "11226"; - public const string UTILMD_11227_Sdae_NichtBilarelAnfrageAbrechnungBlindarbeitAnNb = "11227"; + public const string UTILMD_11225_Sdae_NichtBilarelAenderungAbrechnungBlindarbeitVomNb = + "11225"; + public const string UTILMD_11226_Sdae_AntwortAufAenderungAbrechnungBlindarbeitVomNb = + "11226"; + public const string UTILMD_11227_Sdae_NichtBilarelAnfrageAbrechnungBlindarbeitAnNb = + "11227"; public const string UTILMD_11228_Sdae_AntwortAufAnfrageAbrechnungBlindarbeitAnNb = "11228"; public const string UTILMD_11229_Sdae_AblehnungAnfrageAbrechnungBlindarbeitAnNb = "11229"; - public const string UTILMD_11230_Sdae_NichtBilarelAenderungAbrechnungBlindarbeitVomLf = "11230"; - public const string UTILMD_11231_Sdae_AntwortAufAenderungAbrechnungBlindarbeitVomLf = "11231"; - public const string UTILMD_11232_Sdae_NichtBilarelAnfrageAbrechnungBlindarbeitAnLf = "11232"; + public const string UTILMD_11230_Sdae_NichtBilarelAenderungAbrechnungBlindarbeitVomLf = + "11230"; + public const string UTILMD_11231_Sdae_AntwortAufAenderungAbrechnungBlindarbeitVomLf = + "11231"; + public const string UTILMD_11232_Sdae_NichtBilarelAnfrageAbrechnungBlindarbeitAnLf = + "11232"; public const string UTILMD_11233_Sdae_AntwortAufAnfrageAbrechnungBlindarbeitAnLf = "11233"; public const string UTILMD_11234_Sdae_AblehnungAnfrageAbrechnungBlindarbeitAnLf = "11234"; @@ -494,7 +548,8 @@ public static class Pruefidentifikatoren public const string UTILMD_55070_Mabis_ClearinglisteBas = "55070"; public const string UTILMD_55073_Mabis_UebermittlungDerProfildefinitionen = "55073"; public const string UTILMD_55195_Mabis_Bilanzierungsgebietsclearingliste = "55195"; - public const string UTILMD_55196_Mabis_AntwortAufDieBilanzierungsgebietsclearingliste = "55196"; + public const string UTILMD_55196_Mabis_AntwortAufDieBilanzierungsgebietsclearingliste = + "55196"; public const string UTILMD_55201_Redispatch_LfAacl = "55201"; public const string UTILMD_55202_Redispatch_KorrekturlisteLfAacl = "55202"; public const string UTILMD_55223_Mabis_DzueListe = "55223"; @@ -521,9 +576,12 @@ public static class Pruefidentifikatoren public const string UTILMD_55023_Gpke_BestaetigungAnfrageStornierung = "55023"; public const string UTILMD_55024_Gpke_AblehnungAnfrageStornierung = "55024"; public const string UTILMD_55035_Gpke_AntwortAufDieGeschaeftsdatenanfrage = "55035"; - public const string UTILMD_55036_Gpke_InformationsmeldungUeberExistierendeZuordnung = "55036"; - public const string UTILMD_55037_Gpke_InformationsmeldungZurBeendigungDerZuordnung = "55037"; - public const string UTILMD_55038_Gpke_InformationsmeldungZurAufhebungEinerZukZuordnung = "55038"; + public const string UTILMD_55036_Gpke_InformationsmeldungUeberExistierendeZuordnung = + "55036"; + public const string UTILMD_55037_Gpke_InformationsmeldungZurBeendigungDerZuordnung = + "55037"; + public const string UTILMD_55038_Gpke_InformationsmeldungZurAufhebungEinerZukZuordnung = + "55038"; public const string UTILMD_55039_WimStrom_KuendigungMsb = "55039"; public const string UTILMD_55040_WimStrom_BestaetigungKuendigungMsb = "55040"; public const string UTILMD_55041_WimStrom_AblehnungKuendigungMsb = "55041"; @@ -536,7 +594,8 @@ public static class Pruefidentifikatoren public const string UTILMD_55060_WimStrom_AntwortAufDieMsbGeschaeftsdatenanfrage = "55060"; public const string UTILMD_55062_Mabis_AktivierungVonMabisZp = "55062"; public const string UTILMD_55063_Mabis_DeaktivierungVonMabisZp = "55063"; - public const string UTILMD_55064_Mabis_AntwortAufAktivierung_DeaktivierungVonMabisZp = "55064"; + public const string UTILMD_55064_Mabis_AntwortAufAktivierung_DeaktivierungVonMabisZp = + "55064"; public const string UTILMD_55071_Mabis_AktivierungDerZuordnungsermaechtigung = "55071"; public const string UTILMD_55072_Mabis_DeaktivierungDerZuordnungsermaechtigung = "55072"; public const string UTILMD_55074_Hknr_StammdatenAufEineOrders = "55074"; @@ -544,7 +603,8 @@ public static class Pruefidentifikatoren public const string UTILMD_55076_Hknr_AntwortAufStammdatenaenderung = "55076"; public const string UTILMD_55077_Mpes_Anmeldung = "55077"; public const string UTILMD_55078_Mpes_BestaetigungAnmeldung = "55078"; - public const string UTILMD_55079_Mpes_BestaetigungAnmeldungNeuanlageUndBestaetigungLf = "55079"; + public const string UTILMD_55079_Mpes_BestaetigungAnmeldungNeuanlageUndBestaetigungLf = + "55079"; public const string UTILMD_55080_Mpes_AblehnungAnmeldung = "55080"; public const string UTILMD_55081_Mpes_Abmeldung = "55081"; public const string UTILMD_55082_Mpes_BestaetigungAbmeldung = "55082"; @@ -557,18 +617,26 @@ public static class Pruefidentifikatoren public const string UTILMD_55089_Mpes_KuendigungBeimAltenLieferanten = "55089"; public const string UTILMD_55090_Mpes_BestaetigungKuendigung = "55090"; public const string UTILMD_55091_Mpes_AblehnungKuendigung = "55091"; - public const string UTILMD_55092_Mpes_InformationsmeldungUeberExistierendeZuordnung = "55092"; - public const string UTILMD_55093_Mpes_InformationsmeldungZurBeendigungDerZuordnung = "55093"; - public const string UTILMD_55094_Mpes_InformationsmeldungZurAufhebungEinerZukZuordnung = "55094"; + public const string UTILMD_55092_Mpes_InformationsmeldungUeberExistierendeZuordnung = + "55092"; + public const string UTILMD_55093_Mpes_InformationsmeldungZurBeendigungDerZuordnung = + "55093"; + public const string UTILMD_55094_Mpes_InformationsmeldungZurAufhebungEinerZukZuordnung = + "55094"; public const string UTILMD_55095_Mpes_AntwortAufDieGeschaeftsdatenanfrage = "55095"; public const string UTILMD_55101_NbwStrom_StammdatenZurMesslokation = "55101"; public const string UTILMD_55102_NbwStrom_AktualisierteStammdatenZurMesslokation = "55102"; - public const string UTILMD_55103_NbwStrom_StammdatenZurVerbrauchendenMarktlokation = "55103"; - public const string UTILMD_55104_NbwStrom_AktualisierteStammdatenZurVerbrauchendenMarktlokation = "55104"; - public const string UTILMD_55105_NbwStrom_AblehnungAufStammdatenZurVerbrauchendenMarktlokation = "55105"; + public const string UTILMD_55103_NbwStrom_StammdatenZurVerbrauchendenMarktlokation = + "55103"; + public const string UTILMD_55104_NbwStrom_AktualisierteStammdatenZurVerbrauchendenMarktlokation = + "55104"; + public const string UTILMD_55105_NbwStrom_AblehnungAufStammdatenZurVerbrauchendenMarktlokation = + "55105"; public const string UTILMD_55106_NbwStrom_StammdatenZurErzeugendenMarktlokation = "55106"; - public const string UTILMD_55107_NbwStrom_AktualisierteStammdatenZurErzeugendenMarktlokation = "55107"; - public const string UTILMD_55108_NbwStrom_AblehnungAufStammdatenZurErzeugendenMarktlokation = "55108"; + public const string UTILMD_55107_NbwStrom_AktualisierteStammdatenZurErzeugendenMarktlokation = + "55107"; + public const string UTILMD_55108_NbwStrom_AblehnungAufStammdatenZurErzeugendenMarktlokation = + "55108"; public const string UTILMD_55109_SdaeStrom_NichtBilarelAenderungVomLfAnNb = "55109"; public const string UTILMD_55110_SdaeStrom_NichtBilarelAenderungVomLfNbAnMsb = "55110"; public const string UTILMD_55111_SdaeStrom_AntwortAufAenderungVomLfAg = "55111"; @@ -580,66 +648,104 @@ public static class Pruefidentifikatoren public const string UTILMD_55119_SdaeStrom_AntwortAufAenderungVomMsbAgAnAf = "55119"; public const string UTILMD_55120_SdaeStrom_BilarelAenderungVomLfAnNb = "55120"; public const string UTILMD_55121_SdaeStrom_AntwortAufBilarelAenderungVomLfNbAnLf = "55121"; - public const string UTILMD_55123_SdaeStrom_BilarelAenderungVomNbMitAbhaengigkeitenNbAnLf_Msb = "55123"; - public const string UTILMD_55124_SdaeStrom_AntwortAufBilarelAenderungVomNbMitAbhaengigkeitenAgAnNb = "55124"; - public const string UTILMD_55126_SdaeStrom_AenderungDerPrognosegrundlageNbAnLf_Msb = "55126"; - public const string UTILMD_55127_SdaeStrom_AntwortAufAenderungDerPrognosegrundlageAgAnNb = "55127"; + public const string UTILMD_55123_SdaeStrom_BilarelAenderungVomNbMitAbhaengigkeitenNbAnLf_Msb = + "55123"; + public const string UTILMD_55124_SdaeStrom_AntwortAufBilarelAenderungVomNbMitAbhaengigkeitenAgAnNb = + "55124"; + public const string UTILMD_55126_SdaeStrom_AenderungDerPrognosegrundlageNbAnLf_Msb = + "55126"; + public const string UTILMD_55127_SdaeStrom_AntwortAufAenderungDerPrognosegrundlageAgAnNb = + "55127"; public const string UTILMD_55133_SdaeStrom_NichtBilarelAnfrageAnLfMsbAnNb = "55133"; - public const string UTILMD_55134_SdaeStrom_AntwortAufNichtBilarelAnfrageAnLfNbAnMsb = "55134"; - public const string UTILMD_55135_SdaeStrom_AntwortAufNichtBilarelAnfrageAnLfNbAnMsb = "55135"; + public const string UTILMD_55134_SdaeStrom_AntwortAufNichtBilarelAnfrageAnLfNbAnMsb = + "55134"; + public const string UTILMD_55135_SdaeStrom_AntwortAufNichtBilarelAnfrageAnLfNbAnMsb = + "55135"; public const string UTILMD_55136_SdaeStrom_NichtBilarelAnfrageAnLfNbVerteilerAnLf = "55136"; - public const string UTILMD_55137_SdaeStrom_NichtBilarelAnfrageAnLfNbBerechtigtAnLf = "55137"; - public const string UTILMD_55138_SdaeStrom_AntwortAufNichtBilarelAnfrageAnLfLfAnNb = "55138"; + public const string UTILMD_55137_SdaeStrom_NichtBilarelAnfrageAnLfNbBerechtigtAnLf = + "55137"; + public const string UTILMD_55138_SdaeStrom_AntwortAufNichtBilarelAnfrageAnLfLfAnNb = + "55138"; public const string UTILMD_55139_SdaeStrom_NichtBilarelAnfrageAnNbLfAnNb = "55139"; public const string UTILMD_55140_SdaeStrom_NichtBilarelAnfrageAnNbMsbAnNb = "55140"; - public const string UTILMD_55142_SdaeStrom_AntwortAufNichtBilarelAnfrageAnNbNbAnAf = "55142"; + public const string UTILMD_55142_SdaeStrom_AntwortAufNichtBilarelAnfrageAnNbNbAnAf = + "55142"; public const string UTILMD_55143_SdaeStrom_AnfrageAnMsbMitAbhaengigkeitenLfAnNb = "55143"; - public const string UTILMD_55145_SdaeStrom_AntwortAufAnfrageAnMsbMitAbhaengigkeitenNbAnAf = "55145"; - public const string UTILMD_55146_SdaeStrom_AblehnungDerAnfrageAnMsbMitAbhaengigkeitenNbAnAf = "55146"; - public const string UTILMD_55147_SdaeStrom_AnfrageAnMsbMitAbhaengigkeitenNbVerteilerAnMsb = "55147"; - public const string UTILMD_55148_SdaeStrom_AnfrageAnMsbMitAbhaengigkeitenNbBerechtigtAnMsb = "55148"; - public const string UTILMD_55149_SdaeStrom_AntwortAufAnfrageAnMsbMitAbhaengigkeitenMsbAnNb = "55149"; + public const string UTILMD_55145_SdaeStrom_AntwortAufAnfrageAnMsbMitAbhaengigkeitenNbAnAf = + "55145"; + public const string UTILMD_55146_SdaeStrom_AblehnungDerAnfrageAnMsbMitAbhaengigkeitenNbAnAf = + "55146"; + public const string UTILMD_55147_SdaeStrom_AnfrageAnMsbMitAbhaengigkeitenNbVerteilerAnMsb = + "55147"; + public const string UTILMD_55148_SdaeStrom_AnfrageAnMsbMitAbhaengigkeitenNbBerechtigtAnMsb = + "55148"; + public const string UTILMD_55149_SdaeStrom_AntwortAufAnfrageAnMsbMitAbhaengigkeitenMsbAnNb = + "55149"; public const string UTILMD_55150_SdaeStrom_BilarelAnfrageAnLfNbAnLf = "55150"; public const string UTILMD_55151_SdaeStrom_AntwortAufBilarelAnfrageAnLfLfAnNb = "55151"; public const string UTILMD_55152_SdaeStrom_AblehnungDerBilarelAnfrage = "55152"; public const string UTILMD_55153_SdaeStrom_BilarelAnfrageAnNbOhneAbhaengigkeiten = "55153"; - public const string UTILMD_55154_SdaeStrom_AntwortAufBilarelAnfrageAnNbOhneAbhaengigkeiten = "55154"; - public const string UTILMD_55155_SdaeStrom_AblehnungDerBilarelAnfrageAnNbOhneAbhaengigkeiten = "55155"; + public const string UTILMD_55154_SdaeStrom_AntwortAufBilarelAnfrageAnNbOhneAbhaengigkeiten = + "55154"; + public const string UTILMD_55155_SdaeStrom_AblehnungDerBilarelAnfrageAnNbOhneAbhaengigkeiten = + "55155"; public const string UTILMD_55156_SdaeStrom_BilarelAnfrageAnNbMitAbhaengigkeiten = "55156"; - public const string UTILMD_55157_SdaeStrom_AntwortAufBilarelAnfrageAnNbMitAbhaengigkeiten = "55157"; - public const string UTILMD_55159_SdaeStrom_AenderungVomMsbOhneAbhaengigkeitenMsbAnNb = "55159"; - public const string UTILMD_55160_SdaeStrom_AenderungVomMsbOhneAbhaengigkeitenNbAnLf_Msb = "55160"; - public const string UTILMD_55161_SdaeStrom_AenderungVomMsbOhneAbhaengigkeitenAgAnAf = "55161"; - public const string UTILMD_55162_SdaeStrom_AnfrageAnMsbOhneAbhaengigkeitenVonLf_MsbAnNb = "55162"; - public const string UTILMD_55163_SdaeStrom_AntwortAufAnfrageAnMsbOhneAbhaengigkeitenLf_MsbAnNb = "55163"; - public const string UTILMD_55164_SdaeStrom_AblehnungAufAnfrageAnMsbOhneAbhaengigkeitenLf_MsbAnNb = "55164"; - public const string UTILMD_55165_SdaeStrom_AnfrageAnMsbOhneAbhaengigkeitenNbVerteilerAnMsb = "55165"; - public const string UTILMD_55166_SdaeStrom_AnfrageAnMsbOhneAbhaengigkeitenNbBerechtigterAnMsb = "55166"; - public const string UTILMD_55167_SdaeStrom_AntwortAufAnfrageAnMsbOhneAbhaengigkeitenMsbAnNb = "55167"; + public const string UTILMD_55157_SdaeStrom_AntwortAufBilarelAnfrageAnNbMitAbhaengigkeiten = + "55157"; + public const string UTILMD_55159_SdaeStrom_AenderungVomMsbOhneAbhaengigkeitenMsbAnNb = + "55159"; + public const string UTILMD_55160_SdaeStrom_AenderungVomMsbOhneAbhaengigkeitenNbAnLf_Msb = + "55160"; + public const string UTILMD_55161_SdaeStrom_AenderungVomMsbOhneAbhaengigkeitenAgAnAf = + "55161"; + public const string UTILMD_55162_SdaeStrom_AnfrageAnMsbOhneAbhaengigkeitenVonLf_MsbAnNb = + "55162"; + public const string UTILMD_55163_SdaeStrom_AntwortAufAnfrageAnMsbOhneAbhaengigkeitenLf_MsbAnNb = + "55163"; + public const string UTILMD_55164_SdaeStrom_AblehnungAufAnfrageAnMsbOhneAbhaengigkeitenLf_MsbAnNb = + "55164"; + public const string UTILMD_55165_SdaeStrom_AnfrageAnMsbOhneAbhaengigkeitenNbVerteilerAnMsb = + "55165"; + public const string UTILMD_55166_SdaeStrom_AnfrageAnMsbOhneAbhaengigkeitenNbBerechtigterAnMsb = + "55166"; + public const string UTILMD_55167_SdaeStrom_AntwortAufAnfrageAnMsbOhneAbhaengigkeitenMsbAnNb = + "55167"; public const string UTILMD_55168_WimStrom_Verpflichtungsanfrage_Aufforderung = "55168"; public const string UTILMD_55169_WimStrom_BestaetigungVerpflichtungsanfrage = "55169"; public const string UTILMD_55170_WimStrom_AblehnungVerpflichtungsanfrage = "55170"; public const string UTILMD_55171_SdaeStrom_AenderungVomMsbNbAnMsbBerechtigter = "55171"; public const string UTILMD_55172_SdaeStrom_AnfrageAnMsbMitAbhaengigkeitMsbAnNb = "55172"; - public const string UTILMD_55173_SdaeStrom_AenderungDerLokationsbuendelstrukturNbAnMsb = "55173"; - public const string UTILMD_55174_SdaeStrom_AntwortAufAenderungDerLokationsbuendelstrukturMsbAnNb = "55174"; - public const string UTILMD_55175_SdaeStrom_AenderungDerMarktlokationsstrukturNbAnLf = "55175"; - public const string UTILMD_55176_SdaeStrom_AntwortAufAenderungDerMarktlokationsstrukturLfAnNb = "55176"; - public const string UTILMD_55177_SdaeStrom_AnfrageDerLokationsbuendelstrukturMsbAnNb = "55177"; - public const string UTILMD_55178_SdaeStrom_AntwortAufAnfrageDerLokationsbuendelstrukturNbAnMsb = "55178"; - public const string UTILMD_55180_SdaeStrom_AnfrageDerKomplexenMarktlokationsstrukturLfAnNb = "55180"; - public const string UTILMD_55181_SdaeStrom_AntwortAufAnfrageDerKomplexenMarktlokationsstrukturNbAnLf = "55181"; + public const string UTILMD_55173_SdaeStrom_AenderungDerLokationsbuendelstrukturNbAnMsb = + "55173"; + public const string UTILMD_55174_SdaeStrom_AntwortAufAenderungDerLokationsbuendelstrukturMsbAnNb = + "55174"; + public const string UTILMD_55175_SdaeStrom_AenderungDerMarktlokationsstrukturNbAnLf = + "55175"; + public const string UTILMD_55176_SdaeStrom_AntwortAufAenderungDerMarktlokationsstrukturLfAnNb = + "55176"; + public const string UTILMD_55177_SdaeStrom_AnfrageDerLokationsbuendelstrukturMsbAnNb = + "55177"; + public const string UTILMD_55178_SdaeStrom_AntwortAufAnfrageDerLokationsbuendelstrukturNbAnMsb = + "55178"; + public const string UTILMD_55180_SdaeStrom_AnfrageDerKomplexenMarktlokationsstrukturLfAnNb = + "55180"; + public const string UTILMD_55181_SdaeStrom_AntwortAufAnfrageDerKomplexenMarktlokationsstrukturNbAnLf = + "55181"; public const string UTILMD_55182_SdaeStrom_AblehnungDerAnfrageDer = "55182"; public const string UTILMD_55185_SdaeStrom_StammdatensynchronisationVomNb = "55185"; public const string UTILMD_55186_SdaeStrom_StammdatensynchronisationVomLf = "55186"; public const string UTILMD_55187_SdaeStrom_StammdatensynchronisationVomUenb = "55187"; - public const string UTILMD_55188_SdaeStrom_BeendigungDerAggregationsverantwortungVomNb = "55188"; - public const string UTILMD_55189_SdaeStrom_BeendigungDerAggregationsverantwortungVomLf = "55189"; - public const string UTILMD_55190_SdaeStrom_BeendigungDerAggregationsverantwortungVomUenb = "55190"; + public const string UTILMD_55188_SdaeStrom_BeendigungDerAggregationsverantwortungVomNb = + "55188"; + public const string UTILMD_55189_SdaeStrom_BeendigungDerAggregationsverantwortungVomLf = + "55189"; + public const string UTILMD_55190_SdaeStrom_BeendigungDerAggregationsverantwortungVomUenb = + "55190"; public const string UTILMD_55191_SdaeStrom_AnfrageAnNbVomUenb = "55191"; public const string UTILMD_55192_SdaeStrom_AntwortAufAnfrageAnUenb = "55192"; public const string UTILMD_55193_SdaeStrom_AblehnungAnfrageAnUenb = "55193"; - public const string UTILMD_55194_Gpke_AntwortAufDieGeschaeftsdatenanfrageAnDenMsbGas = "55194"; + public const string UTILMD_55194_Gpke_AntwortAufDieGeschaeftsdatenanfrageAnDenMsbGas = + "55194"; public const string UTILMD_55197_Redispatch_AktivierungZpTaeglicheAauez = "55197"; public const string UTILMD_55198_Redispatch_DeaktivierungTaeglicheAauez = "55198"; public const string UTILMD_55199_Redispatch_AktivierungZpLfAaszr = "55199"; @@ -657,37 +763,57 @@ public static class Pruefidentifikatoren public const string UTILMD_55213_Redispatch_AntwortAufDeaktivierungZp = "55213"; public const string UTILMD_55214_Redispatch_WeiterleitungDeaktivierungZp = "55214"; public const string UTILMD_55215_Gpke_AntwortAufDieGeschaeftsdatenanfrageDesUenb = "55215"; - public const string UTILMD_55218_SdaeStrom_NichtBilarelAenderungNnaVomNbAnMarktlokation = "55218"; - public const string UTILMD_55219_SdaeStrom_AntwortAufAenderungNnaVomNbAnMarktlokation = "55219"; - public const string UTILMD_55220_SdaeStrom_NichtBilarelAnfrageNnaAnNbAnMarktlokation = "55220"; - public const string UTILMD_55221_SdaeStrom_AntwortAufAnfrageNnaAnNbAnMarktlokation = "55221"; + public const string UTILMD_55218_SdaeStrom_NichtBilarelAenderungNnaVomNbAnMarktlokation = + "55218"; + public const string UTILMD_55219_SdaeStrom_AntwortAufAenderungNnaVomNbAnMarktlokation = + "55219"; + public const string UTILMD_55220_SdaeStrom_NichtBilarelAnfrageNnaAnNbAnMarktlokation = + "55220"; + public const string UTILMD_55221_SdaeStrom_AntwortAufAnfrageNnaAnNbAnMarktlokation = + "55221"; public const string UTILMD_55222_SdaeStrom_AblehnungAnfrageNnaAnNbAnMarktlokation = "55222"; - public const string UTILMD_55225_SdaeStrom_NichtBilarelAenderungAbrechnungBlindarbeitVomNb = "55225"; - public const string UTILMD_55226_SdaeStrom_AntwortAufAenderungAbrechnungBlindarbeitVomNb = "55226"; - public const string UTILMD_55227_SdaeStrom_NichtBilarelAnfrageAbrechnungBlindarbeitAnNb = "55227"; - public const string UTILMD_55228_SdaeStrom_AntwortAufAnfrageAbrechnungBlindarbeitAnNb = "55228"; - public const string UTILMD_55229_SdaeStrom_AblehnungAnfrageAbrechnungBlindarbeitAnNb = "55229"; - public const string UTILMD_55230_SdaeStrom_NichtBilarelAenderungAbrechnungBlindarbeitVomLf = "55230"; - public const string UTILMD_55231_SdaeStrom_AntwortAufAenderungAbrechnungBlindarbeitVomLf = "55231"; - public const string UTILMD_55232_SdaeStrom_NichtBilarelAnfrageAbrechnungBlindarbeitAnLf = "55232"; - public const string UTILMD_55233_SdaeStrom_AntwortAufAnfrageAbrechnungBlindarbeitAnLf = "55233"; - public const string UTILMD_55234_SdaeStrom_AblehnungAnfrageAbrechnungBlindarbeitAnLf = "55234"; + public const string UTILMD_55225_SdaeStrom_NichtBilarelAenderungAbrechnungBlindarbeitVomNb = + "55225"; + public const string UTILMD_55226_SdaeStrom_AntwortAufAenderungAbrechnungBlindarbeitVomNb = + "55226"; + public const string UTILMD_55227_SdaeStrom_NichtBilarelAnfrageAbrechnungBlindarbeitAnNb = + "55227"; + public const string UTILMD_55228_SdaeStrom_AntwortAufAnfrageAbrechnungBlindarbeitAnNb = + "55228"; + public const string UTILMD_55229_SdaeStrom_AblehnungAnfrageAbrechnungBlindarbeitAnNb = + "55229"; + public const string UTILMD_55230_SdaeStrom_NichtBilarelAenderungAbrechnungBlindarbeitVomLf = + "55230"; + public const string UTILMD_55231_SdaeStrom_AntwortAufAenderungAbrechnungBlindarbeitVomLf = + "55231"; + public const string UTILMD_55232_SdaeStrom_NichtBilarelAnfrageAbrechnungBlindarbeitAnLf = + "55232"; + public const string UTILMD_55233_SdaeStrom_AntwortAufAnfrageAbrechnungBlindarbeitAnLf = + "55233"; + public const string UTILMD_55234_SdaeStrom_AblehnungAnfrageAbrechnungBlindarbeitAnLf = + "55234"; public const string UTILMD_55557_SdaeStrom_AenderungVonMSBAbrechnungsdaten = "55557"; - public const string UTILMD_55558_SdaeStrom_AntwortAufAenderungVonMSBAbrechnungsdaten = "55558"; + public const string UTILMD_55558_SdaeStrom_AntwortAufAenderungVonMSBAbrechnungsdaten = + "55558"; public const string UTILMD_55559_SdaeStrom_AnfrageVonMSBAbrechnungsdaten = "55559"; - public const string UTILMD_55560_SdaeStrom_AntwortAufAnfrageVonMSBAbrechnungsdaten = "55560"; - public const string UTILMD_55561_SdaeStrom_AblehnungDerAnfrageVonMSBAbrechnungsdaten = "55561"; + public const string UTILMD_55560_SdaeStrom_AntwortAufAnfrageVonMSBAbrechnungsdaten = + "55560"; + public const string UTILMD_55561_SdaeStrom_AblehnungDerAnfrageVonMSBAbrechnungsdaten = + "55561"; public const string UTILMD_55235_Mabis_ZuordnungZpDerNgzZurNzr = "55235"; public const string UTILMD_55236_Mabis_BeendigungZuordnungZpDerNgzZurNzr = "55236"; - public const string UTILMD_55237_Mabis_AntwortAufZuordnung_BeendigungZuordnungZpDerNgzZurNzr = "55237"; + public const string UTILMD_55237_Mabis_AntwortAufZuordnung_BeendigungZuordnungZpDerNgzZurNzr = + "55237"; public const string UTILMD_55238_E_Mob_AnmeldungInModell2 = "55238"; public const string UTILMD_55239_E_Mob_AntwortAufAnmeldungInModell2 = "55239"; public const string UTILMD_55240_E_Mob_BeendigungDerZuordnungZurMarktlokation = "55240"; - public const string UTILMD_55241_E_Mob_AntwortAufBeendigungDerZuordnungZurMarktlokation = "55241"; + public const string UTILMD_55241_E_Mob_AntwortAufBeendigungDerZuordnungZurMarktlokation = + "55241"; public const string UTILMD_55242_E_Mob_AbmeldungAusDemModell2 = "55242"; public const string UTILMD_55243_E_Mob_AntwortAufAbmeldungAusDemModell2 = "55243"; public const string UTILMD_55553_Gpke_StammdatenAufIndividuelleBestellung = "55553"; - public const string UTILMD_55554_Gpke_AntwortAufAenderungDerIndividuellenBestellung = "55554"; + public const string UTILMD_55554_Gpke_AntwortAufAenderungDerIndividuellenBestellung = + "55554"; public const string UTILMD_55555_Gpke_AnfrageStammdatenAufIndividuelleBestellung = "55555"; public const string UTILMD_55556_Gpke_AntwortAufAnfrageDerIndividuellenBestellung = "55556"; @@ -716,14 +842,18 @@ public static class Pruefidentifikatoren public const string UTILMD_44018_GeliGas_AblehnungKuendigung = "44018"; public const string UTILMD_44019_GeliGas_BestandslisteZugeordneteMarktlokationen = "44019"; public const string UTILMD_44020_GeliGas_AenderungsmeldungZurBestandsliste = "44020"; - public const string UTILMD_44021_GeliGas_AntwortAufAenderungsmeldungZurBestandsliste = "44021"; + public const string UTILMD_44021_GeliGas_AntwortAufAenderungsmeldungZurBestandsliste = + "44021"; public const string UTILMD_44022_GeliGas_AnfrageNachStornierung = "44022"; public const string UTILMD_44023_GeliGas_BestaetigungAnfrageStornierung = "44023"; public const string UTILMD_44024_GeliGas_AblehnungAnfrageStornierung = "44024"; public const string UTILMD_44035_GeliGas_AntwortAufDieGeschaeftsdatenanfrage = "44035"; - public const string UTILMD_44036_GeliGas_InformationsmeldungUeberExistierendeZuordnung = "44036"; - public const string UTILMD_44037_GeliGas_InformationsmeldungZurBeendigungDerZuordnung = "44037"; - public const string UTILMD_44038_GeliGas_InformationsmeldungZurAufhebungEinerZukZuordnung = "44038"; + public const string UTILMD_44036_GeliGas_InformationsmeldungUeberExistierendeZuordnung = + "44036"; + public const string UTILMD_44037_GeliGas_InformationsmeldungZurBeendigungDerZuordnung = + "44037"; + public const string UTILMD_44038_GeliGas_InformationsmeldungZurAufhebungEinerZukZuordnung = + "44038"; public const string UTILMD_44039_WimGas_KuendigungMsb = "44039"; public const string UTILMD_44040_WimGas_BestaetigungKuendigungMsb = "44040"; public const string UTILMD_44041_WimGas_AblehnungKuendigungMsb = "44041"; @@ -739,8 +869,10 @@ public static class Pruefidentifikatoren public const string UTILMD_44101_NbwGas_StammdatenZurMesslokation = "44101"; public const string UTILMD_44102_NbwGas_AktualisierteStammdatenZurMesslokation = "44102"; public const string UTILMD_44103_NbwGas_StammdatenZurVerbrauchendenMarktlokation = "44103"; - public const string UTILMD_44104_NbwGas_AktualisierteStammdatenZurVerbrauchendenMarktlokation = "44104"; - public const string UTILMD_44105_NbwGas_AblehnungAufStammdatenZurVerbrauchendenMarktlokation = "44105"; + public const string UTILMD_44104_NbwGas_AktualisierteStammdatenZurVerbrauchendenMarktlokation = + "44104"; + public const string UTILMD_44105_NbwGas_AblehnungAufStammdatenZurVerbrauchendenMarktlokation = + "44105"; public const string UTILMD_44109_SdaeGas_NichtBilarelAenderungVomLfAnNb = "44109"; public const string UTILMD_44111_SdaeGas_AntwortAufAenderungVomLfAgAnAf = "44111"; public const string UTILMD_44112_SdaeGas_NichtBilarelAenderungVomNbAnLf = "44112"; @@ -751,42 +883,61 @@ public static class Pruefidentifikatoren public const string UTILMD_44119_SdaeGas_AntwortAufAenderungVomMsbAgAnAf = "44119"; public const string UTILMD_44120_SdaeGas_BilarelAenderungVomLfAnNb = "44120"; public const string UTILMD_44121_SdaeGas_AntwortAufBilarelAenderungVomLfNbAnLf = "44121"; - public const string UTILMD_44123_SdaeGas_BilarelAenderungVomNbMitAbhaengigkeitenNbAnLf_Msb = "44123"; - public const string UTILMD_44124_SdaeGas_AntwortAufBilarelAenderungVomNbMitAbhaengigkeitenAgAnNb = "44124"; + public const string UTILMD_44123_SdaeGas_BilarelAenderungVomNbMitAbhaengigkeitenNbAnLf_Msb = + "44123"; + public const string UTILMD_44124_SdaeGas_AntwortAufBilarelAenderungVomNbMitAbhaengigkeitenAgAnNb = + "44124"; public const string UTILMD_44137_SdaeGas_NichtBilarelAnfrageAnLfNbBerechtigtAnLf = "44137"; public const string UTILMD_44138_SdaeGas_AntwortAufNichtBilarelAnfrageAnLfLfAnNb = "44138"; public const string UTILMD_44139_SdaeGas_NichtBilarelAnfrageAnNbLfAnNb = "44139"; public const string UTILMD_44140_SdaeGas_NichtBilarelAnfrageAnNbMsbAnNb = "44140"; public const string UTILMD_44142_SdaeGas_AntwortAufNichtBilarelAnfrageAnNbNbAnAf = "44142"; public const string UTILMD_44143_SdaeGas_AnfrageAnMsbMitAbhaengigkeitenLfAnNb = "44143"; - public const string UTILMD_44145_SdaeGas_AntwortAufAnfrageAnMsbMitAbhaengigkeitenNbAnAf = "44145"; - public const string UTILMD_44146_SdaeGas_AblehnungDerAnfrageAnMsbMitAbhaengigkeitenNbAnAf = "44146"; - public const string UTILMD_44147_SdaeGas_AnfrageAnMsbMitAbhaengigkeitenNbVerteilerAnMsb = "44147"; + public const string UTILMD_44145_SdaeGas_AntwortAufAnfrageAnMsbMitAbhaengigkeitenNbAnAf = + "44145"; + public const string UTILMD_44146_SdaeGas_AblehnungDerAnfrageAnMsbMitAbhaengigkeitenNbAnAf = + "44146"; + public const string UTILMD_44147_SdaeGas_AnfrageAnMsbMitAbhaengigkeitenNbVerteilerAnMsb = + "44147"; public const string UTILMD_44148_SdaeGas_AnfrageAnMsbMitAbhaengigkeiten = "44148"; - public const string UTILMD_44149_SdaeGas_AntwortAufAnfrageAnMsbMitAbhaengigkeitenMsbAnNb = "44149"; + public const string UTILMD_44149_SdaeGas_AntwortAufAnfrageAnMsbMitAbhaengigkeitenMsbAnNb = + "44149"; public const string UTILMD_44150_SdaeGas_BilarelAnfrageAnLfNbAnLf = "44150"; public const string UTILMD_44151_SdaeGas_AntwortAufBilarelAnfrageAnLfLfAnNb = "44151"; public const string UTILMD_44152_SdaeGas_AblehnungDerBilarelAnfrageAnLfLfAnNb = "44152"; public const string UTILMD_44156_SdaeGas_BilarelAnfrageAnNbMitAbhaengigkeiten = "44156"; - public const string UTILMD_44157_SdaeGas_AntwortAufBilarelAnfrageAnNbMitAbhaengigkeiten = "44157"; - public const string UTILMD_44159_SdaeGas_AenderungVomMsbOhneAbhaengigkeitenMsbAnNb = "44159"; - public const string UTILMD_44160_SdaeGas_AenderungVomMsbOhneAbhaengigkeitenNbAnLf_Msb = "44160"; + public const string UTILMD_44157_SdaeGas_AntwortAufBilarelAnfrageAnNbMitAbhaengigkeiten = + "44157"; + public const string UTILMD_44159_SdaeGas_AenderungVomMsbOhneAbhaengigkeitenMsbAnNb = + "44159"; + public const string UTILMD_44160_SdaeGas_AenderungVomMsbOhneAbhaengigkeitenNbAnLf_Msb = + "44160"; public const string UTILMD_44161_SdaeGas_AenderungVomMsbOhneAbhaengigkeitenAgAnAf = "44161"; - public const string UTILMD_44162_Sdae_AnfrageAnMsbOhneAbhaengigkeitenVonLf_MsbAnNb = "44162"; - public const string UTILMD_44163_SdaeGas_AntwortAufAnfrageAnMsbOhneAbhaengigkeitenLf_MsbAnNb = "44163"; - public const string UTILMD_44164_SdaeGas_AblehnungAufAnfrageAnMsbOhneAbhaengigkeitenLf_MsbAnNb = "44164"; - public const string UTILMD_44165_SdaeGas_AnfrageAnMsbOhneAbhaengigkeitenNbVerteilerAnMsb = "44165"; - public const string UTILMD_44166_SdaeGas_AnfrageAnMsbOhneAbhaengigkeitenNbBerechtigterAnMsb = "44166"; - public const string UTILMD_44167_SdaeGas_AntwortAufAnfrageAnMsbOhneAbhaengigkeitenMsbAnNb = "44167"; + public const string UTILMD_44162_Sdae_AnfrageAnMsbOhneAbhaengigkeitenVonLf_MsbAnNb = + "44162"; + public const string UTILMD_44163_SdaeGas_AntwortAufAnfrageAnMsbOhneAbhaengigkeitenLf_MsbAnNb = + "44163"; + public const string UTILMD_44164_SdaeGas_AblehnungAufAnfrageAnMsbOhneAbhaengigkeitenLf_MsbAnNb = + "44164"; + public const string UTILMD_44165_SdaeGas_AnfrageAnMsbOhneAbhaengigkeitenNbVerteilerAnMsb = + "44165"; + public const string UTILMD_44166_SdaeGas_AnfrageAnMsbOhneAbhaengigkeitenNbBerechtigterAnMsb = + "44166"; + public const string UTILMD_44167_SdaeGas_AntwortAufAnfrageAnMsbOhneAbhaengigkeitenMsbAnNb = + "44167"; public const string UTILMD_44168_WimGas_Verpflichtungsanfrage_Aufforderung = "44168"; public const string UTILMD_44169_WimGas_BestaetigungVerpflichtungsanfrage = "44169"; public const string UTILMD_44170_WimGas_AblehnungVerpflichtungsanfrage = "44170"; public const string UTILMD_44172_SdaeGas_AnfrageAnMsbMitAbhaengigkeitMsbAnNb = "44172"; public const string UTILMD_44175_SdaeGas_AenderungDerMarktlokationsstrukturNbAnLf = "44175"; - public const string UTILMD_44176_SdaeGas_AntwortAufAenderungDerMarktlokationsstrukturLfAnNb = "44176"; - public const string UTILMD_44180_SdaeGas_AnfrageDerKomplexenMarktlokationsstrukturLfAnNb = "44180"; - public const string UTILMD_44181_SdaeGas_AntwortAufAnfrageDerKomplexenMarktlokationsstrukturNbAnLf = "44181"; - public const string UTILMD_44182_SdaeGas_AblehnungDerAnfrageDerKomplexenMarktlokationsstrukturNbAnLf = "44182"; + public const string UTILMD_44176_SdaeGas_AntwortAufAenderungDerMarktlokationsstrukturLfAnNb = + "44176"; + public const string UTILMD_44180_SdaeGas_AnfrageDerKomplexenMarktlokationsstrukturLfAnNb = + "44180"; + public const string UTILMD_44181_SdaeGas_AntwortAufAnfrageDerKomplexenMarktlokationsstrukturNbAnLf = + "44181"; + public const string UTILMD_44182_SdaeGas_AblehnungDerAnfrageDerKomplexenMarktlokationsstrukturNbAnLf = + "44182"; #endregion diff --git a/EDILibrary/EDIFACTEnums.cs b/EDILibrary/EDIFACTEnums.cs index 1b1516a..46d3807 100644 --- a/EDILibrary/EDIFACTEnums.cs +++ b/EDILibrary/EDIFACTEnums.cs @@ -13,19 +13,24 @@ public APERAKDescriptionAttribute(string desc) { Description = desc; } + public string Description { get; set; } } + public class EDIDescriptionAttribute : Attribute { public EDIDescriptionAttribute(string desc) { Description = desc; } + public string Description { get; set; } } + public class EDIEnumHelper { public static Dictionary DescriptionMap; + public static string GetDescription(string name) { if (DescriptionMap == null) @@ -34,27 +39,36 @@ public static string GetDescription(string name) var fields = typeof(EDIEnums).GetRuntimeFields().ToArray(); foreach (var field in fields) { - var att = field.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault(); + var att = field + .GetCustomAttributes(typeof(DescriptionAttribute), false) + .FirstOrDefault(); if (att != null) { DescriptionMap[(att as DescriptionAttribute).Description] = field.Name; } } } - var attrs = (IEnumerable) - typeof(EDIEnums).GetRuntimeField(DescriptionMap[name]).GetCustomAttributes(typeof(EDIDescriptionAttribute), false); + var attrs = + (IEnumerable) + typeof(EDIEnums) + .GetRuntimeField(DescriptionMap[name]) + .GetCustomAttributes(typeof(EDIDescriptionAttribute), false); //if (attrs != null) // Always true { return attrs.Any() ? ((EDIDescriptionAttribute)attrs.First()).Description : name; } //return name; - } + public static string GetAPERAKDescription(EDIEnums enumValue) { var name = enumValue.ToString(); - var attrs = (IEnumerable) - enumValue.GetType().GetRuntimeField(name).GetCustomAttributes(typeof(APERAKDescriptionAttribute), false); + var attrs = + (IEnumerable) + enumValue + .GetType() + .GetRuntimeField(name) + .GetCustomAttributes(typeof(APERAKDescriptionAttribute), false); //if (attrs != null) // expression is always true { return attrs.Any() ? ((APERAKDescriptionAttribute)attrs.First()).Description : name; @@ -65,11 +79,16 @@ public static string GetAPERAKDescription(EDIEnums enumValue) return attrs.Count() > 0 ? "FEHLER:" + ((DescriptionAttribute)attrs.First()).Description : "FEHLER:" + name; */ } + public static string GetEDIDescription(EDIEnums enumValue) { var name = enumValue.ToString(); - var attrs = (IEnumerable) - enumValue.GetType().GetRuntimeField(name).GetCustomAttributes(typeof(EDIDescriptionAttribute), false); + var attrs = + (IEnumerable) + enumValue + .GetType() + .GetRuntimeField(name) + .GetCustomAttributes(typeof(EDIDescriptionAttribute), false); //if (attrs != null) // always true { return attrs.Any() ? ((EDIDescriptionAttribute)attrs.First()).Description : name; @@ -80,92 +99,135 @@ public static string GetEDIDescription(EDIEnums enumValue) return attrs.Any() ? ((DescriptionAttribute)attrs.First()).Description : name; */ } + public static string GetDescription(EDIEnums enumValue) { var name = enumValue.ToString(); - var attrs = (IEnumerable) - enumValue.GetType().GetRuntimeField(name).GetCustomAttributes(typeof(DescriptionAttribute), false); + var attrs = + (IEnumerable) + enumValue + .GetType() + .GetRuntimeField(name) + .GetCustomAttributes(typeof(DescriptionAttribute), false); return attrs.Any() ? ((DescriptionAttribute)attrs.First()).Description : name; } } + public enum EDIEnums { [Description("Dokument")] Dokument, + [Description("Nachricht")] Nachricht, + [Description("Kategorie")] Kategorie, + [Description("Nachrichtenfunktion")] Nachrichtenfunktion, + [Description("Nachrichtendatum")] Nachrichtendatum, + [Description("Zeitzone")] Zeitzone, + [Description("Gueltigkeit")] Gueltigkeit, + [Description("Referenz Anfrage")] Referenz_Anfrage, + [Description("Absender_NAD")] Absender_NAD, + [Description("Empfaenger_NAD")] [APERAKDescription("MP-ID Empfänger")] Empfänger_NAD, + [Description("Absender_Code_UNB")] Absender_Code_UNB, + [Description("Absender")] Absender, + [Description("Empfaenger_Code_UNB")] Empfänger_Code_UNB, + [Description("Empfaenger")] Empfänger, + [Description("Vorgang")] Vorgang, + [Description("Syntaxfehler")] Syntaxfehler, + [Description("Servicesegment")] Servicesegment, + [Description("Segmentposition")] Segmentposition, + [Description("Gruppenposition")] Gruppenposition, + [Description("Nachrichtentyp")] Nachrichtentyp, + [Description("Nachrichtenversion")] Nachrichtenversion, + [Description("Freigabenummer")] Freigabenummer, + [Description("Anwendungscode")] Anwendungscode, + [Description("Aktion")] Aktion, + [Description("Herausgeber")] Herausgeber, + [Description("Antwortsegment")] Antwortsegment, + [Description("Fehlersegment")] Fehlersegment, + [Description("Fehlerelement")] Fehlerelement, + [Description("Segment")] Segment, + [Description("Segmentname")] Segmentname, + [Description("Dokumentendatum")] Dokumentendatum, + [Description("Dokumentenuhrzeit")] Dokumentenuhrzeit, + [Description("Referenzdatum")] Referenzdatum, + [Description("Status Identifikation")] Status_Identifikation, + [Description("Absenderreferenz")] Absenderreferenz, + [Description("Status")] Status, + [Description("Referenz")] Referenz, + [Description("Version")] - Version + Version, } } diff --git a/EDILibrary/EDIHelper.cs b/EDILibrary/EDIHelper.cs index 792513a..6433494 100644 --- a/EDILibrary/EDIHelper.cs +++ b/EDILibrary/EDIHelper.cs @@ -74,6 +74,7 @@ public class EDIFileInfo : IEquatable /// e.g. 5.2h /// public string Version; + /// /// EDIFACT format if set. Null in case of error (formerly: "ERROR") /// @@ -87,11 +88,18 @@ public class EDIFileInfo : IEquatable public override string ToString() { - return string.Join("_", + return string.Join( + "_", new List { - Format.ToString(), Referenz, Sender != null ? Sender.ToString() : "", Empfänger != null ? Empfänger.ToString() : "", DateTime.UtcNow.ToString("yyyyMMdd"), ID - }); + Format.ToString(), + Referenz, + Sender != null ? Sender.ToString() : "", + Empfänger != null ? Empfänger.ToString() : "", + DateTime.UtcNow.ToString("yyyyMMdd"), + ID, + } + ); } public bool Equals(EDIFileInfo other) @@ -106,8 +114,14 @@ public bool Equals(EDIFileInfo other) return true; } - return Version == other.Version && Format == other.Format && Equals(Sender, other.Sender) && Equals(Empfänger, other.Empfänger) && ID == other.ID && - Referenz == other.Referenz && Freigabenummer == other.Freigabenummer && Nachrichtenversion == other.Nachrichtenversion; + return Version == other.Version + && Format == other.Format + && Equals(Sender, other.Sender) + && Equals(Empfänger, other.Empfänger) + && ID == other.ID + && Referenz == other.Referenz + && Freigabenummer == other.Freigabenummer + && Nachrichtenversion == other.Nachrichtenversion; } public override bool Equals(object obj) @@ -132,7 +146,16 @@ public override bool Equals(object obj) public override int GetHashCode() { - return HashCode.Combine(Version, Format, Sender, Empfänger, ID, Referenz, Freigabenummer, Nachrichtenversion); + return HashCode.Combine( + Version, + Format, + Sender, + Empfänger, + ID, + Referenz, + Freigabenummer, + Nachrichtenversion + ); } } @@ -157,7 +180,9 @@ public static string RemoveBOM(string edi) return edi; } - private static readonly string ByteOrderMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble()); + private static readonly string ByteOrderMarkUtf8 = Encoding.UTF8.GetString( + Encoding.UTF8.GetPreamble() + ); /// /// Removes a byte order mark from @@ -208,7 +233,10 @@ private static EdifactSpecialChars GetSpecialChars(string edi) if (segmentDelimiter == "U" || segmentDelimiter == "\n" || segmentDelimiter == "\r") { // if your edifact starts with `UNA:+.?'` instead of `UNA:+.? '` - throw new ArgumentException($"The edifact is probably missing a space after \"{una.Substring(0, 8)}\"", nameof(edi)); + throw new ArgumentException( + $"The edifact is probably missing a space after \"{una.Substring(0, 8)}\"", + nameof(edi) + ); } return new EdifactSpecialChars { @@ -217,7 +245,8 @@ private static EdifactSpecialChars GetSpecialChars(string edi) GroupDelimiter = una.Substring(4, 1), DecimalChar = una.Substring(5, 1), EscapeChar = una.Substring(6, 1), - SegmentDelimiter = segmentDelimiter == "\r" ? Environment.NewLine : segmentDelimiter + SegmentDelimiter = + segmentDelimiter == "\r" ? Environment.NewLine : segmentDelimiter, }; } @@ -228,13 +257,16 @@ private static EdifactSpecialChars GetSpecialChars(string edi) GroupDelimiter = DefaultGroupDelimiter, SegmentDelimiter = DefaultSegmentDelimiter, DecimalChar = DefaultDecimalChar, - EscapeChar = DefaultEscapeChar + EscapeChar = DefaultEscapeChar, }; } private static string GetActualMessage(string edi, EdifactSpecialChars specialChars) { - return edi.Substring(specialChars.UnaOffset + specialChars.SegmentDelimiter.Length, edi.Length - (specialChars.UnaOffset + specialChars.SegmentDelimiter.Length)); + return edi.Substring( + specialChars.UnaOffset + specialChars.SegmentDelimiter.Length, + edi.Length - (specialChars.UnaOffset + specialChars.SegmentDelimiter.Length) + ); } /// @@ -299,8 +331,10 @@ public static EDIFileInfo GetEdiFileInfo(string edi, bool maskUTILMDX = true) } catch (IndexOutOfRangeException indexOutOfRangeException) { - throw new InvalidDataException("The EDIFACT seems invalid. Couldn't determine the necessary first two segments (UNB and UNH)", - innerException: indexOutOfRangeException); + throw new InvalidDataException( + "The EDIFACT seems invalid. Couldn't determine the necessary first two segments (UNB and UNH)", + innerException: indexOutOfRangeException + ); } var unbParts = unb.Split(specialChars.GroupDelimiter.ToCharArray()); @@ -309,17 +343,23 @@ public static EDIFileInfo GetEdiFileInfo(string edi, bool maskUTILMDX = true) var sender = new EDIPartner { CodeList = - unbParts[2].Split(specialChars.ElementDelimiter.ToCharArray()).Length > 1 ? unbParts[2].Split(specialChars.ElementDelimiter.ToCharArray())[1] : "500", - ID = unbParts[2].Split(specialChars.ElementDelimiter.ToCharArray())[0] + unbParts[2].Split(specialChars.ElementDelimiter.ToCharArray()).Length > 1 + ? unbParts[2].Split(specialChars.ElementDelimiter.ToCharArray())[1] + : "500", + ID = unbParts[2].Split(specialChars.ElementDelimiter.ToCharArray())[0], }; var receiver = new EDIPartner { CodeList = - unbParts[3].Split(specialChars.ElementDelimiter.ToCharArray()).Length > 1 ? unbParts[3].Split(specialChars.ElementDelimiter.ToCharArray())[1] : "500", - ID = unbParts[3].Split(specialChars.ElementDelimiter.ToCharArray())[0] + unbParts[3].Split(specialChars.ElementDelimiter.ToCharArray()).Length > 1 + ? unbParts[3].Split(specialChars.ElementDelimiter.ToCharArray())[1] + : "500", + ID = unbParts[3].Split(specialChars.ElementDelimiter.ToCharArray())[0], }; var version = unhParts[2].Split(specialChars.ElementDelimiter.ToCharArray())[4]; - var format = Enum.Parse(unhParts[2].Split(specialChars.ElementDelimiter.ToCharArray())[0]); + var format = Enum.Parse( + unhParts[2].Split(specialChars.ElementDelimiter.ToCharArray())[0] + ); if (!maskUTILMDX && format == EdifactFormat.UTILMD) { if (version.StartsWith("G")) @@ -348,23 +388,24 @@ public static EDIFileInfo GetEdiFileInfo(string edi, bool maskUTILMDX = true) ID = unbParts[5].Split(specialChars.ElementDelimiter.ToCharArray())[0], Format = format, Version = version, - Freigabenummer = unhParts[2].Split(specialChars.ElementDelimiter.ToCharArray())[2], - Nachrichtenversion = unhParts[2].Split(specialChars.ElementDelimiter.ToCharArray())[1] + Freigabenummer = unhParts[2].Split(specialChars.ElementDelimiter.ToCharArray())[ + 2 + ], + Nachrichtenversion = unhParts[2] + .Split(specialChars.ElementDelimiter.ToCharArray())[1], }; if (unbParts.Length >= 7) { - file.Referenz = unbParts[7].Split(specialChars.ElementDelimiter.ToCharArray())[0]; + file.Referenz = unbParts[7].Split(specialChars.ElementDelimiter.ToCharArray())[ + 0 + ]; } return file; } catch (Exception) // todo: get rid of this pokemon catcher. If this returns format=null any following code will fail anyways. { - return new EDIFileInfo - { - Format = null, - Referenz = Guid.NewGuid().ToString(), - }; + return new EDIFileInfo { Format = null, Referenz = Guid.NewGuid().ToString() }; } } } diff --git a/EDILibrary/EdiJsonMapper.cs b/EDILibrary/EdiJsonMapper.cs index e5c9cab..a73b35a 100644 --- a/EDILibrary/EdiJsonMapper.cs +++ b/EDILibrary/EdiJsonMapper.cs @@ -5,12 +5,9 @@ using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; - using EDILibrary.Exceptions; using EDILibrary.Helper; - using Humanizer; - using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -24,10 +21,12 @@ public EdiJsonMapper(Interfaces.ITemplateLoader loader) { _loader = loader; } + public struct JsonResult { public string EDI; public EdifactFormat? Format; + /// /// e.g. 5.2h /// @@ -37,13 +36,34 @@ public struct JsonResult } [Obsolete("Use strongly typed version instead")] - public async Task ParseToJson(string edi, string packageVersion, string includeEmptyValues = null) + public async Task ParseToJson( + string edi, + string packageVersion, + string includeEmptyValues = null + ) { - return (await ParseToJsonWithVersion(edi, packageVersion.ToEdifactFormatVersion(), includeEmptyValues)).EDI; + return ( + await ParseToJsonWithVersion( + edi, + packageVersion.ToEdifactFormatVersion(), + includeEmptyValues + ) + ).EDI; } - public async Task ParseToJsonWithTemplates(string edi, EdifactFormatVersion? packageVersion, string ediTemplate, string ediTreeTemplate, string ediJsonTemplate, string includeEmptyValues = null) + + public async Task ParseToJsonWithTemplates( + string edi, + EdifactFormatVersion? packageVersion, + string ediTemplate, + string ediTreeTemplate, + string ediJsonTemplate, + string includeEmptyValues = null + ) { - var ediInfo = EDIHelper.GetEdiFileInfo(edi.Substring(0, Math.Min(1000, edi.Length)), false); + var ediInfo = EDIHelper.GetEdiFileInfo( + edi.Substring(0, Math.Min(1000, edi.Length)), + false + ); var ediString = EDIHelper.NormalizeEDIHeader(edi); var templateString = ediTemplate; var loader = new GenericEDILoader(); @@ -57,7 +77,10 @@ public async Task ParseToJsonWithTemplates(string edi, EdifactFormat Tuple package; if (packageVersion.HasValue) { - package = new Tuple(null, packageVersion.Value.ToLegacyVersionString()); + package = new Tuple( + null, + packageVersion.Value.ToLegacyVersionString() + ); } else { @@ -77,20 +100,33 @@ public async Task ParseToJsonWithTemplates(string edi, EdifactFormat dynamic resultObject = new ExpandoObject(); // var resultDict = resultObject as IDictionary; - ParseObject(jsonResult, resultObject as IDictionary, mappings, includeEmptyValues != null); + ParseObject( + jsonResult, + resultObject as IDictionary, + mappings, + includeEmptyValues != null + ); var result = new JsonResult { EDI = JsonConvert.SerializeObject(resultObject), Format = ediInfo.Format, Version = ediInfo.Version, Sender = ediInfo.Sender.ID, - Receiver = ediInfo.Empfänger.ID + Receiver = ediInfo.Empfänger.ID, }; return result; } - public async Task ParseToJsonWithVersion(string edi, EdifactFormatVersion? packageVersion, string includeEmptyValues = null) + + public async Task ParseToJsonWithVersion( + string edi, + EdifactFormatVersion? packageVersion, + string includeEmptyValues = null + ) { - var ediInfo = EDIHelper.GetEdiFileInfo(edi.Substring(0, Math.Min(1000, edi.Length)), false); + var ediInfo = EDIHelper.GetEdiFileInfo( + edi.Substring(0, Math.Min(1000, edi.Length)), + false + ); var treeStringTask = _loader.LoadEDITemplate(ediInfo, "tree"); var templateStringTask = _loader.LoadEDITemplate(ediInfo, "template"); await Task.WhenAll(new List { treeStringTask, templateStringTask }); @@ -104,7 +140,10 @@ public async Task ParseToJsonWithVersion(string edi, EdifactFormatVe Tuple package; if (packageVersion.HasValue) { - package = new Tuple(null, packageVersion.Value.ToLegacyVersionString()); + package = new Tuple( + null, + packageVersion.Value.ToLegacyVersionString() + ); } else { @@ -115,21 +154,56 @@ public async Task ParseToJsonWithVersion(string edi, EdifactFormatVe string mappingJson = null; try { - mappingJson = await _loader.LoadJSONTemplate(package.Item1, package.Item2, ediInfo.Format + ".json"); + mappingJson = await _loader.LoadJSONTemplate( + package.Item1, + package.Item2, + ediInfo.Format + ".json" + ); } catch (Exception e) { throw new BadFormatException(ediInfo.Format, ediInfo.Version, e); } - return await ParseToJsonWithTemplates(edi, packageVersion, templateString, treeString, mappingJson, includeEmptyValues); + return await ParseToJsonWithTemplates( + edi, + packageVersion, + templateString, + treeString, + mappingJson, + includeEmptyValues + ); } [Obsolete("Use strongly typed overload instead.")] - public async Task CreateFromJson(string jsonInput, string pid, string formatPackage, TimeZoneInfo localTime, MAUS.Anwendungshandbuch? ahb, bool convertFromUTC = false) + public async Task CreateFromJson( + string jsonInput, + string pid, + string formatPackage, + TimeZoneInfo localTime, + MAUS.Anwendungshandbuch? ahb, + bool convertFromUTC = false + ) { - return await CreateFromJson(jsonInput, pid, formatPackage.ToEdifactFormatVersion(), localTime, ahb, convertFromUTC); + return await CreateFromJson( + jsonInput, + pid, + formatPackage.ToEdifactFormatVersion(), + localTime, + ahb, + convertFromUTC + ); } - public string CreateFromJsonWithTemplates(string jsonInput, string pid, EdifactFormatVersion formatPackage, string ediJsonTemplate, string createTemplate, TimeZoneInfo localTime, MAUS.Anwendungshandbuch? ahb, bool convertFromUTC = false) + + public string CreateFromJsonWithTemplates( + string jsonInput, + string pid, + EdifactFormatVersion formatPackage, + string ediJsonTemplate, + string createTemplate, + TimeZoneInfo localTime, + MAUS.Anwendungshandbuch? ahb, + bool convertFromUTC = false + ) { var format = EdifactFormatHelper.FromPruefidentifikator(pid, false, formatPackage); @@ -138,29 +212,58 @@ public string CreateFromJsonWithTemplates(string jsonInput, string pid, EdifactF var inputJson = JsonConvert.DeserializeObject(jsonInput); var mappings = JsonConvert.DeserializeObject(mappingsBody); var version = mappings[0]["_meta"]["version"].Value(); - var outputJson = CreateMsgJSON(inputJson, mappings, null, ahb?.Lines?.FirstOrDefault(), null, false, new Stack(), out var subParent, convertFromUTC); + var outputJson = CreateMsgJSON( + inputJson, + mappings, + null, + ahb?.Lines?.FirstOrDefault(), + null, + false, + new Stack(), + out var subParent, + convertFromUTC + ); EdiObject result = EdiObject.CreateFromJSON(JsonConvert.SerializeObject(outputJson)); //apply scripts - return MappingHelper.ExecuteMappings(result, new EDIFileInfo - { - Format = format, - Version = version, - }, new List(), createTemplate, localTime, convertFromUTC); + return MappingHelper.ExecuteMappings( + result, + new EDIFileInfo { Format = format, Version = version }, + new List(), + createTemplate, + localTime, + convertFromUTC + ); } - public async Task CreateFromJson(string jsonInput, string pid, EdifactFormatVersion formatPackage, TimeZoneInfo localTime, MAUS.Anwendungshandbuch? ahb, bool convertFromUTC = false) + + public async Task CreateFromJson( + string jsonInput, + string pid, + EdifactFormatVersion formatPackage, + TimeZoneInfo localTime, + MAUS.Anwendungshandbuch? ahb, + bool convertFromUTC = false + ) { var format = EdifactFormatHelper.FromPruefidentifikator(pid, false, formatPackage); string jsonBody = null; try { - jsonBody = await _loader.LoadJSONTemplate(format, formatPackage.ToLegacyVersionString(), $"{pid}.json"); + jsonBody = await _loader.LoadJSONTemplate( + format, + formatPackage.ToLegacyVersionString(), + $"{pid}.json" + ); } catch (Exception) { //we don't have a mask for this pid, which is fine, go ahead } - var mappingsBody = await _loader.LoadJSONTemplate(format, formatPackage.ToLegacyVersionString(), format + ".json"); + var mappingsBody = await _loader.LoadJSONTemplate( + format, + formatPackage.ToLegacyVersionString(), + format + ".json" + ); var json = jsonBody != null ? JsonConvert.DeserializeObject(jsonBody) : null; var inputJson = JsonConvert.DeserializeObject(jsonInput); @@ -186,38 +289,64 @@ public async Task CreateFromJson(string jsonInput, string pid, EdifactFo maskArray = new JArray(); foreach (var step in json.Property("steps").Value) { - foreach (var prop in ((step as JObject)?.Property("fields").Value as JObject).Properties()) + foreach ( + var prop in ( + (step as JObject)?.Property("fields").Value as JObject + ).Properties() + ) { var newObj = new JObject - { - { "key", prop.Name }, - { "type", (prop.Value as JObject).Property("obligType").Value } - }; + { + { "key", prop.Name }, + { "type", (prop.Value as JObject).Property("obligType").Value }, + }; maskArray.Add(newObj); } //maskArray.Merge(((step as JObject)?.Property("fields").Value as JObject).Properties(), new JsonMergeSettings() { MergeArrayHandling = MergeArrayHandling.Union }); } } - var outputJson = CreateMsgJSON(inputJson, mappings, maskArray, ahb?.Lines?.FirstOrDefault(), null, false, new Stack(), out var subParent, convertFromUTC); + var outputJson = CreateMsgJSON( + inputJson, + mappings, + maskArray, + ahb?.Lines?.FirstOrDefault(), + null, + false, + new Stack(), + out var subParent, + convertFromUTC + ); EdiObject result = EdiObject.CreateFromJSON(JsonConvert.SerializeObject(outputJson)); //apply scripts - var createTemplate = await _loader.LoadEDITemplate(new EDIFileInfo - { - Format = format, - Version = version, - }, "create.template"); - return MappingHelper.ExecuteMappings(result, new EDIFileInfo - { - Format = format, - Version = version - }, new List(), createTemplate, localTime, convertFromUTC); + var createTemplate = await _loader.LoadEDITemplate( + new EDIFileInfo { Format = format, Version = version }, + "create.template" + ); + return MappingHelper.ExecuteMappings( + result, + new EDIFileInfo { Format = format, Version = version }, + new List(), + createTemplate, + localTime, + convertFromUTC + ); } - public async Task CreateFromEdiJson(string jsonInput, string pid, EdifactFormatVersion formatPackage, TimeZoneInfo localTime, bool convertFromUTC = false) + + public async Task CreateFromEdiJson( + string jsonInput, + string pid, + EdifactFormatVersion formatPackage, + TimeZoneInfo localTime, + bool convertFromUTC = false + ) { var format = EdifactFormatHelper.FromPruefidentifikator(pid, false, formatPackage); - var mappingsBody = await _loader.LoadJSONTemplate(format, formatPackage.ToLegacyVersionString(), format + ".json"); - + var mappingsBody = await _loader.LoadJSONTemplate( + format, + formatPackage.ToLegacyVersionString(), + format + ".json" + ); var inputJson = JsonConvert.DeserializeObject(jsonInput); var mappings = JsonConvert.DeserializeObject(mappingsBody); @@ -226,27 +355,40 @@ public async Task CreateFromEdiJson(string jsonInput, string pid, Edifac EdiObject result = EdiObject.CreateFromJSON(jsonInput); //apply scripts - var createTemplate = await _loader.LoadEDITemplate(new EDIFileInfo - { - Format = format, - Version = version, - }, "create.template"); - return MappingHelper.ExecuteMappings(result, new EDIFileInfo - { - Format = format, - Version = version, - }, new List(), createTemplate, localTime, convertFromUTC); + var createTemplate = await _loader.LoadEDITemplate( + new EDIFileInfo { Format = format, Version = version }, + "create.template" + ); + return MappingHelper.ExecuteMappings( + result, + new EDIFileInfo { Format = format, Version = version }, + new List(), + createTemplate, + localTime, + convertFromUTC + ); } - protected static void ParseObject(JObject value, IDictionary target, JArray mappings, bool _) + + protected static void ParseObject( + JObject value, + IDictionary target, + JArray mappings, + bool _ + ) { if (value is null) { // instead of running into the NullReferenceException only one line later we can also just throw an Exception here - throw new ArgumentNullException(nameof(value), "This might be due to a missing tree object. Are you sure that template and tree have been loaded correctly?"); + throw new ArgumentNullException( + nameof(value), + "This might be due to a missing tree object. Are you sure that template and tree have been loaded correctly?" + ); } foreach (var prop in value.Properties()) { - var deps = mappings.Where(map => FindDependentObject(map, prop.Name, out var propVal) != null).ToList(); + var deps = mappings + .Where(map => FindDependentObject(map, prop.Name, out var propVal) != null) + .ToList(); if (deps.Any()) { foreach (var dep in deps) @@ -265,13 +407,23 @@ protected static void ParseObject(JObject value, IDictionary tar foreach (var entry in prop.Value as JArray) { dynamic subObj = new ExpandoObject(); - ParseObject(entry as JObject, subObj as IDictionary, (JArray)propVal, _); + ParseObject( + entry as JObject, + subObj as IDictionary, + (JArray)propVal, + _ + ); obj.Add(subObj); } } else { - ParseObject(prop.Value as JObject, obj as IDictionary, (JArray)propVal, _); + ParseObject( + prop.Value as JObject, + obj as IDictionary, + (JArray)propVal, + _ + ); } target.Add(((JObject)dep).Property("key").Value.Value(), obj); @@ -319,7 +471,11 @@ protected static void ParseObject(JObject value, IDictionary tar } } - protected static void AddProperty(IDictionary target, string name, JToken value) + protected static void AddProperty( + IDictionary target, + string name, + JToken value + ) { while (true) { @@ -349,6 +505,7 @@ protected static void AddProperty(IDictionary target, string nam } static readonly Regex noLetterRegex = new Regex("[^A-Za-z]", RegexOptions.Compiled); + protected static bool CompareKey(string left, string right) { var leftReplaced = noLetterRegex.Replace(left, ""); @@ -356,7 +513,12 @@ protected static bool CompareKey(string left, string right) return leftReplaced == rightReplaced; } - protected static bool FindMask(JArray mask, string maskKey, MAUS.SegmentGroup? ahb, Stack parentPath) + protected static bool FindMask( + JArray mask, + string maskKey, + MAUS.SegmentGroup? ahb, + Stack parentPath + ) { if (mask == null) { @@ -366,7 +528,12 @@ protected static bool FindMask(JArray mask, string maskKey, MAUS.SegmentGroup? a foreach (var maskEntry in mask) { - if (CompareKey((maskEntry as JObject).Property("key")?.Value.Value(), maskKey)) + if ( + CompareKey( + (maskEntry as JObject).Property("key")?.Value.Value(), + maskKey + ) + ) { if ((maskEntry as JObject).Property("type")?.Value.Value() == "N") { @@ -378,7 +545,18 @@ protected static bool FindMask(JArray mask, string maskKey, MAUS.SegmentGroup? a } return false; } - protected static dynamic CreateMsgJSON(JObject input, JArray mapping, JArray mask, MAUS.SegmentGroup? ahb, List? segments, bool virtualChild, Stack parentPath, out bool createInParent, bool convertFromUTC = false) + + protected static dynamic CreateMsgJSON( + JObject input, + JArray mapping, + JArray mask, + MAUS.SegmentGroup? ahb, + List? segments, + bool virtualChild, + Stack parentPath, + out bool createInParent, + bool convertFromUTC = false + ) { createInParent = false; if (input == null) @@ -390,7 +568,9 @@ protected static dynamic CreateMsgJSON(JObject input, JArray mapping, JArray mas foreach (var prop in input.Properties()) { MAUS.SegmentGroup? localAhb = ahb; - var deps = mapping.Where(map => FindObjectByKey(map, prop.Name, out var propVal, false) != null).ToList(); + var deps = mapping + .Where(map => FindObjectByKey(map, prop.Name, out var propVal, false) != null) + .ToList(); if (deps.Any()) { var foundObj = FindObjectByKey(deps.First(), prop.Name, out var propVal, false); @@ -398,7 +578,9 @@ protected static dynamic CreateMsgJSON(JObject input, JArray mapping, JArray mas { string sg = foundObj.SelectToken("_meta.sg")?.Value(); string key = prop.Name; - string virtualKey = foundObj.SelectToken("_meta.virtualKey")?.Value(); + string virtualKey = foundObj + .SelectToken("_meta.virtualKey") + ?.Value(); var rootLikeSgKeys = new HashSet() { "UNH", "/", "root" }; if (virtualKey is not null) { @@ -406,41 +588,64 @@ protected static dynamic CreateMsgJSON(JObject input, JArray mapping, JArray mas } if (ahb is not null || localAhb is not null) { - if (sg is not null && sg != "/" && sg != "UNH" && sg.StartsWith("SG") && sg != ahb?.Discriminator && virtualKey is null && !virtualChild) + if ( + sg is not null + && sg != "/" + && sg != "UNH" + && sg.StartsWith("SG") + && sg != ahb?.Discriminator + && virtualKey is null + && !virtualChild + ) { if (localAhb?.SegmentGroups.Any(s => s.Discriminator == sg) == true) { - localAhb = localAhb.SegmentGroups.First(s => s.Discriminator == sg); + localAhb = localAhb.SegmentGroups.First(s => + s.Discriminator == sg + ); } else { continue; } } - else if (localAhb?.Segments.Any(s => s.SectionName.Replace(" ", "").Dehumanize() == key.Replace(" ", "").Dehumanize()) == true) // check segments + else if ( + localAhb?.Segments.Any(s => + s.SectionName.Replace(" ", "").Dehumanize() + == key.Replace(" ", "").Dehumanize() + ) == true + ) // check segments { bool notFoundAnySegment = true; - foreach (var segment in localAhb.Segments.Where(s => s.SectionName.Replace(" ", "").Dehumanize() == key.Replace(" ", "").Dehumanize())) + foreach ( + var segment in localAhb.Segments.Where(s => + s.SectionName.Replace(" ", "").Dehumanize() + == key.Replace(" ", "").Dehumanize() + ) + ) { - var id = foundObj.SelectToken("_meta.id")?.Value(); if (id is null) { - var group = foundObj.SelectToken("_meta.type")?.Value(); + var group = foundObj + .SelectToken("_meta.type") + ?.Value(); if (group == "group") { notFoundAnySegment = false; - } } else { - if (segment.DataElements.Any(s => s.DataElementId.Dehumanize() == id.Dehumanize())) + if ( + segment.DataElements.Any(s => + s.DataElementId.Dehumanize() == id.Dehumanize() + ) + ) { notFoundAnySegment = false; } } - } if (notFoundAnySegment) { @@ -463,7 +668,11 @@ protected static dynamic CreateMsgJSON(JObject input, JArray mapping, JArray mas bool notFoundAnySegment = true; foreach (var segment in segments) { - if (segment.DataElements.Any(s => s.DataElementId.Dehumanize() == id.Dehumanize())) + if ( + segment.DataElements.Any(s => + s.DataElementId.Dehumanize() == id.Dehumanize() + ) + ) { notFoundAnySegment = false; } @@ -474,11 +683,14 @@ protected static dynamic CreateMsgJSON(JObject input, JArray mapping, JArray mas } } } - else if (sg is not null && !rootLikeSgKeys.Contains(sg) && sg == ahb?.Discriminator) + else if ( + sg is not null + && !rootLikeSgKeys.Contains(sg) + && sg == ahb?.Discriminator + ) { continue; } - } else if (segments is not null && segments.Any()) // check segments { @@ -496,7 +708,11 @@ protected static dynamic CreateMsgJSON(JObject input, JArray mapping, JArray mas bool notFoundAnySegment = true; foreach (var segment in segments) { - if (segment.DataElements.Any(s => s.DataElementId.Dehumanize() == id.Dehumanize())) + if ( + segment.DataElements.Any(s => + s.DataElementId.Dehumanize() == id.Dehumanize() + ) + ) { notFoundAnySegment = false; } @@ -507,25 +723,38 @@ protected static dynamic CreateMsgJSON(JObject input, JArray mapping, JArray mas } } } - else if (sg is not null && rootLikeSgKeys.Contains(sg) && sg == ahb?.Discriminator) + else if ( + sg is not null + && rootLikeSgKeys.Contains(sg) + && sg == ahb?.Discriminator + ) { continue; } } if (propVal == null) // then create new target element and recurse { - - var newMappings = ((deps.First() as JObject).Property("requires").Value as JArray).Select(req => - { - if ((req as JObject).Properties().FirstOrDefault()?.Value as JArray != null) + var newMappings = ( + (deps.First() as JObject).Property("requires").Value as JArray + ) + .Select(req => { - return (req as JObject).Properties().FirstOrDefault()?.Value as JArray; - } + if ( + (req as JObject).Properties().FirstOrDefault()?.Value as JArray + != null + ) + { + return (req as JObject).Properties().FirstOrDefault()?.Value + as JArray; + } - return null; - }).ToArray(); + return null; + }) + .ToArray(); var newArray = new JArray(); - newArray = newMappings.Where(map => map != null).Aggregate(newArray, (current, map) => new JArray(current.Union(map))); + newArray = newMappings + .Where(map => map != null) + .Aggregate(newArray, (current, map) => new JArray(current.Union(map))); if (newMappings.Any() && !newArray.Any()) { //Spezialfall für "groupBy"-Array-Objekte (z.B. Beginn der Nachricht) @@ -537,7 +766,17 @@ protected static dynamic CreateMsgJSON(JObject input, JArray mapping, JArray mas continue; } parentPath.Push(prop.Name); - var newSub = CreateMsgJSON((prop.Value as JArray)[0] as JObject, newArray, mask, ahb, null, false, parentPath, out var subParent, convertFromUTC); + var newSub = CreateMsgJSON( + (prop.Value as JArray)[0] as JObject, + newArray, + mask, + ahb, + null, + false, + parentPath, + out var subParent, + convertFromUTC + ); foreach (var (key, value) in newSub as IDictionary) { (returnObject as IDictionary).Add(key, value); @@ -547,72 +786,137 @@ protected static dynamic CreateMsgJSON(JObject input, JArray mapping, JArray mas } if (!newArray.Any()) { - var subObj = FindObjectByKey(deps.First(), prop.Name, out propVal, false); + var subObj = FindObjectByKey( + deps.First(), + prop.Name, + out propVal, + false + ); if (subObj.SelectToken("_meta") != null) { var format = subObj.SelectToken("_meta.format").Value(); //format date - (returnObject as IDictionary).Add(propVal.Value(), new ScriptHelper { useLocalTime = convertFromUTC }.FormatDate(prop.Value.Value(), format)); + (returnObject as IDictionary).Add( + propVal.Value(), + new ScriptHelper { useLocalTime = convertFromUTC }.FormatDate( + prop.Value.Value(), + format + ) + ); } else { - (returnObject as IDictionary).Add(propVal.Value(), prop.Value); + (returnObject as IDictionary).Add( + propVal.Value(), + prop.Value + ); } } else { //check for virtual groups var virtualGroup = false; - var subObj = FindObjectByKey(deps.First(), prop.Name, out propVal, false); + var subObj = FindObjectByKey( + deps.First(), + prop.Name, + out propVal, + false + ); if (subObj.SelectToken("_meta.virtual") != null) { virtualGroup = subObj.SelectToken("_meta.virtual").Value(); } - if (FindMask(mask, prop.Name, ahb, parentPath) || prop.Name == "Dokument" || prop.Name == "Nachricht" || virtualGroup) + if ( + FindMask(mask, prop.Name, ahb, parentPath) + || prop.Name == "Dokument" + || prop.Name == "Nachricht" + || virtualGroup + ) { - var newPropName = ((deps.First() as JObject).Property("requires").Value.Value().FirstOrDefault() as JObject)?.Properties().FirstOrDefault()?.Name; + var newPropName = ( + (deps.First() as JObject) + .Property("requires") + .Value.Value() + .FirstOrDefault() as JObject + ) + ?.Properties() + .FirstOrDefault() + ?.Name; if (prop.Value.Type == JTokenType.Array) { - (returnObject as IDictionary).Add(newPropName, new List()); + (returnObject as IDictionary).Add( + newPropName, + new List() + ); int index = 0; foreach (var sub in prop.Value as JArray) { if (sub is JObject) { parentPath.Push($"{prop.Name}[{index}]"); - List localSegment = new List(); + List localSegment = + new List(); bool isVirtualKey = false; if (localAhb is not null) { var key = prop.Name; - var virtualKey = foundObj.SelectToken("_meta.virtualKey")?.Value(); + var virtualKey = foundObj + .SelectToken("_meta.virtualKey") + ?.Value(); if (virtualKey is not null) { key = virtualKey; isVirtualKey = true; } - if (localAhb?.Segments?.Any(s => s.SectionName.Replace(" ", "").Dehumanize() == key.Replace(" ", "").Dehumanize()) == true) + if ( + localAhb?.Segments?.Any(s => + s.SectionName.Replace(" ", "").Dehumanize() + == key.Replace(" ", "").Dehumanize() + ) == true + ) { - foreach (var segment in localAhb?.Segments?.Where(s => s.SectionName.Replace(" ", "").Dehumanize() == key.Replace(" ", "").Dehumanize())) + foreach ( + var segment in localAhb?.Segments?.Where( + s => + s.SectionName.Replace(" ", "") + .Dehumanize() + == key.Replace(" ", "").Dehumanize() + ) + ) { if (segment.Discriminator == "CCI") //special handling for CCI/CAV { - var seg_index = localAhb.Segments.IndexOf(segment); + var seg_index = + localAhb.Segments.IndexOf(segment); do { seg_index++; try { - if (localAhb.Segments[seg_index].Discriminator != "CAV") + if ( + localAhb + .Segments[seg_index] + .Discriminator != "CAV" + ) { break; } else { - if (!localSegment.Contains(localAhb.Segments[seg_index])) + if ( + !localSegment.Contains( + localAhb.Segments[ + seg_index + ] + ) + ) { - localSegment.Add(localAhb.Segments[seg_index]); + localSegment.Add( + localAhb.Segments[ + seg_index + ] + ); } } } @@ -620,9 +924,7 @@ protected static dynamic CreateMsgJSON(JObject input, JArray mapping, JArray mas { break; } - } - while (true); - + } while (true); } if (!localSegment.Contains(segment)) { @@ -631,28 +933,54 @@ protected static dynamic CreateMsgJSON(JObject input, JArray mapping, JArray mas } } } - else if (localAhb?.Discriminator != "root") - { - - } - if (localAhb is not null && localAhb?.Discriminator != "root" && !localSegment.Any()) + else if (localAhb?.Discriminator != "root") { } + if ( + localAhb is not null + && localAhb?.Discriminator != "root" + && !localSegment.Any() + ) { continue; } - var newSub = CreateMsgJSON(sub as JObject, newArray, mask, localAhb, localSegment, virtualChild || isVirtualKey, parentPath, out var subParent, convertFromUTC); + var newSub = CreateMsgJSON( + sub as JObject, + newArray, + mask, + localAhb, + localSegment, + virtualChild || isVirtualKey, + parentPath, + out var subParent, + convertFromUTC + ); if (!subParent) { - ((returnObject as IDictionary)[newPropName] as List).Add(newSub); + ( + (returnObject as IDictionary)[ + newPropName + ] as List + ).Add(newSub); } else { dynamic newObj = new ExpandoObject(); - foreach (var (key, value) in (newSub as IDictionary).ToList()) + foreach ( + var (key, value) in ( + newSub as IDictionary + ).ToList() + ) { - (newObj as IDictionary).Add(key, value); + (newObj as IDictionary).Add( + key, + value + ); } - ((returnObject as IDictionary)[newPropName] as List).Add(newObj); + ( + (returnObject as IDictionary)[ + newPropName + ] as List + ).Add(newObj); } } index++; @@ -661,19 +989,40 @@ protected static dynamic CreateMsgJSON(JObject input, JArray mapping, JArray mas else { parentPath.Push(prop.Name); - var newSub = CreateMsgJSON(prop.Value as JObject, newArray, mask, localAhb, null, false, parentPath, out var subParent, convertFromUTC); + var newSub = CreateMsgJSON( + prop.Value as JObject, + newArray, + mask, + localAhb, + null, + false, + parentPath, + out var subParent, + convertFromUTC + ); if (!subParent) { - (returnObject as IDictionary).Add(newPropName, newSub); + (returnObject as IDictionary).Add( + newPropName, + newSub + ); } else { dynamic newObj = new ExpandoObject(); - foreach (var (key, value) in (newSub as IDictionary).ToList()) + foreach ( + var (key, value) in ( + newSub as IDictionary + ).ToList() + ) { (newObj as IDictionary).Add(key, value); } - ((returnObject as IDictionary)[newPropName] as List).Add(newObj); + ( + (returnObject as IDictionary)[ + newPropName + ] as List + ).Add(newObj); } } } @@ -684,7 +1033,14 @@ protected static dynamic CreateMsgJSON(JObject input, JArray mapping, JArray mas if (foundObj.Property("key") != null) { //check for validity mask - if (!FindMask(mask, foundObj.Property("key").Value.Value(), ahb, parentPath)) + if ( + !FindMask( + mask, + foundObj.Property("key").Value.Value(), + ahb, + parentPath + ) + ) { continue; } @@ -694,52 +1050,62 @@ protected static dynamic CreateMsgJSON(JObject input, JArray mapping, JArray mas { //if we have a complex type (e.g. Absender.Code) make sure to apply all values case JTokenType.Array: + { + foreach (var dep in deps) + { + FindObjectByKey(dep, prop.Name, out var newVal, false); + var valPath = dep[newVal.Value()].Value(); + var pathParts = valPath.Split('.'); + //TODO: generalize this to enable more deep object nesting (e.g. A.B.C) + createInParent = true; + (returnObject as IDictionary).Add( + newVal.Value(), + prop.Value[0][pathParts[1]] + ); + } + + break; + } + case JTokenType.Object: + { + foreach (var dep in deps) { - foreach (var dep in deps) + FindObjectByKey(dep, prop.Name, out var newVal, false); + var valPath = dep[newVal.Value()].Value(); + var pathParts = valPath.Split('.'); + if (pathParts.Length > 1) { - FindObjectByKey(dep, prop.Name, out var newVal, false); - var valPath = dep[newVal.Value()].Value(); - var pathParts = valPath.Split('.'); //TODO: generalize this to enable more deep object nesting (e.g. A.B.C) createInParent = true; - (returnObject as IDictionary).Add(newVal.Value(), prop.Value[0][pathParts[1]]); - + (returnObject as IDictionary).Add( + newVal.Value(), + prop.Value[pathParts[1]] + ); } - - break; - } - case JTokenType.Object: - { - foreach (var dep in deps) + else { - FindObjectByKey(dep, prop.Name, out var newVal, false); - var valPath = dep[newVal.Value()].Value(); - var pathParts = valPath.Split('.'); - if (pathParts.Length > 1) - { - //TODO: generalize this to enable more deep object nesting (e.g. A.B.C) - createInParent = true; - (returnObject as IDictionary).Add(newVal.Value(), prop.Value[pathParts[1]]); - } - else - { - (returnObject as IDictionary).Add(propVal.Value(), prop.Value); - } - + (returnObject as IDictionary).Add( + propVal.Value(), + prop.Value + ); } - - break; } + + break; + } default: - (returnObject as IDictionary).Add(propVal.Value(), prop.Value); + (returnObject as IDictionary).Add( + propVal.Value(), + prop.Value + ); break; } } - } } return returnObject; } + protected static void SetValue(JObject input, string path, string value) { var splits = path.Split(new[] { "[]." }, StringSplitOptions.None); @@ -759,10 +1125,7 @@ protected static void SetValue(JObject input, string path, string value) if (splits.Length > 1) { //add array - var newArray = new JArray - { - new JObject() - }; + var newArray = new JArray { new JObject() }; SetValue(newArray.First as JObject, string.Join("[].", splits.Skip(1)), value); //unescape name var unescapedName = splits.First().Replace("['", "").Replace("']", ""); @@ -777,6 +1140,7 @@ protected static void SetValue(JObject input, string path, string value) } } } + protected static JObject ApplyFix(JObject input, JObject fix) { if (fix.SelectToken("fix") == null) @@ -794,7 +1158,9 @@ protected static JObject ApplyFix(JObject input, JObject fix) } else if (subFix.SelectToken("_path") != null) { - value = input.SelectToken(subFix.SelectToken("_path")?.Value())?.Value(); + value = input + .SelectToken(subFix.SelectToken("_path")?.Value()) + ?.Value(); } if (name.Contains("[].")) { @@ -807,6 +1173,7 @@ protected static JObject ApplyFix(JObject input, JObject fix) } return input; } + protected static JObject FindDependentObject(JToken val, string key, out JToken propVal) { propVal = null; @@ -849,6 +1216,7 @@ protected static JObject FindDependentObject(JToken val, string key, out JToken } return null; } + protected static bool CheckFieldName(string name, string key) { if (name == key) @@ -865,7 +1233,13 @@ protected static bool CheckFieldName(string name, string key) } return false; } - protected static JObject FindObjectByKey(JToken val, string key, out JToken propVal, bool ignoreParentKey) + + protected static JObject FindObjectByKey( + JToken val, + string key, + out JToken propVal, + bool ignoreParentKey + ) { //searches in a mapping json object for a corresponding key and returns the found token propVal = null; @@ -904,7 +1278,6 @@ protected static JObject FindObjectByKey(JToken val, string key, out JToken prop } } return null; - } //if it is an array check all entries in the array foreach (JObject req in (JArray)requires) diff --git a/EDILibrary/EdifactFormatVersion.cs b/EDILibrary/EdifactFormatVersion.cs index 5e5c81e..376fd67 100644 --- a/EDILibrary/EdifactFormatVersion.cs +++ b/EDILibrary/EdifactFormatVersion.cs @@ -114,7 +114,7 @@ public enum EdifactFormat /// /// Custom pruefis /// - CUSTOM = 99 + CUSTOM = 99, } /// @@ -129,13 +129,21 @@ public static class EdifactFormatHelper /// is true, UTILMD is returned instead of UTILMDG bzw. UTILMDS /// optional EdifactFormatVersion, in case of >= than FV2310 will return UTILMDW for '11xxxx' PIDs. /// the EdifactFormat, e.g. or throws a NotImplementedException iff EdiFormat was found - public static EdifactFormat FromPruefidentifikator(string pruefidentifikator, bool maskUTILMDX = true, EdifactFormatVersion? formatPackage = null) + public static EdifactFormat FromPruefidentifikator( + string pruefidentifikator, + bool maskUTILMDX = true, + EdifactFormatVersion? formatPackage = null + ) { if (string.IsNullOrWhiteSpace(pruefidentifikator)) { throw new ArgumentNullException(nameof(pruefidentifikator)); } - if (formatPackage is not null && formatPackage >= EdifactFormatVersion.FV2310 && pruefidentifikator.StartsWith("11")) + if ( + formatPackage is not null + && formatPackage >= EdifactFormatVersion.FV2310 + && pruefidentifikator.StartsWith("11") + ) { return EdifactFormat.UTILMDW; } @@ -143,11 +151,15 @@ public static EdifactFormat FromPruefidentifikator(string pruefidentifikator, bo { if (pruefidentifikator.StartsWith(((int)ef).ToString())) { - return maskUTILMDX && ef is EdifactFormat.UTILMDG or EdifactFormat.UTILMDS ? EdifactFormat.UTILMD : ef; + return maskUTILMDX && ef is EdifactFormat.UTILMDG or EdifactFormat.UTILMDS + ? EdifactFormat.UTILMD + : ef; } } - throw new NotImplementedException($"No matching EdiFormat found for Prüfidentifikator {pruefidentifikator}"); + throw new NotImplementedException( + $"No matching EdiFormat found for Prüfidentifikator {pruefidentifikator}" + ); } } @@ -190,10 +202,12 @@ public enum EdifactFormatVersion /// Format Version October 2022 (aka MaKo2022) /// FV2210, + /// /// Format Version April 2023 /// FV2304, + /// /// Format Version October 2023 (aka MaKo2023) /// @@ -212,7 +226,7 @@ public enum EdifactFormatVersion /// /// Format Version valid since April 2025 /// - FV2504 + FV2504, } public class EdifactFormatVersionComparer : IComparer @@ -251,7 +265,9 @@ public static string ToLegacyVersionString(this EdifactFormatVersion edifactForm EdifactFormatVersion.FV2404 => "04/24", EdifactFormatVersion.FV2410 => "10/24", EdifactFormatVersion.FV2504 => "04/25", - _ => throw new NotImplementedException($"The legacy format for {edifactFormatVersion} is not yet implemented.") + _ => throw new NotImplementedException( + $"The legacy format for {edifactFormatVersion} is not yet implemented." + ), }; } @@ -262,7 +278,10 @@ public static string ToLegacyVersionString(this EdifactFormatVersion edifactForm /// /// -1 = smaller, 0 equal, 1 greater [Obsolete("Use the IComparer class " + nameof(EdifactFormatVersionComparer) + " instead")] - public static int CompareToVersion(this EdifactFormatVersion edifactFormatVersion, EdifactFormatVersion compare) + public static int CompareToVersion( + this EdifactFormatVersion edifactFormatVersion, + EdifactFormatVersion compare + ) { return new EdifactFormatVersionComparer().Compare(edifactFormatVersion, compare); } @@ -281,7 +300,10 @@ public static EdifactFormatVersion ToEdifactFormatVersion(this string legacyForm new EdifactFormatVersionHelper().GetCurrent(); } #if NETSTANDARD2_1 - foreach (EdifactFormatVersion efv in Enum.GetValues(typeof(EdifactFormatVersion)).Cast()) + foreach ( + EdifactFormatVersion efv in Enum.GetValues(typeof(EdifactFormatVersion)) + .Cast() + ) { if (legacyFormatString == efv.ToLegacyVersionString()) { @@ -303,7 +325,9 @@ public static EdifactFormatVersion ToEdifactFormatVersion(this string legacyForm return result; } - throw new NotImplementedException($"The legacy format string '{legacyFormatString}' could not be mapped."); + throw new NotImplementedException( + $"The legacy format string '{legacyFormatString}' could not be mapped." + ); } } @@ -341,57 +365,64 @@ public class EdifactFormatVersionHelper : IEdifactFormatVersionProvider /// /// validity date of /// - private static readonly DateTime Keydate1912 = new(2019, 11, 30, 23, 0, 0, 0, DateTimeKind.Utc); + private static readonly DateTime Keydate1912 = + new(2019, 11, 30, 23, 0, 0, 0, DateTimeKind.Utc); /// /// validity date of /// - private static readonly DateTime Keydate2004 = new(2020, 03, 31, 22, 0, 0, 0, DateTimeKind.Utc); + private static readonly DateTime Keydate2004 = + new(2020, 03, 31, 22, 0, 0, 0, DateTimeKind.Utc); /// /// validity date of /// - private static readonly DateTime Keydate2104 = new(2021, 03, 31, 22, 0, 0, 0, DateTimeKind.Utc); + private static readonly DateTime Keydate2104 = + new(2021, 03, 31, 22, 0, 0, 0, DateTimeKind.Utc); /// /// validity date of /// - private static readonly DateTime KeyDate2110 = new(2021, 09, 30, 22, 0, 0, DateTimeKind.Utc); - + private static readonly DateTime KeyDate2110 = + new(2021, 09, 30, 22, 0, 0, DateTimeKind.Utc); /// /// validity date of /// - private static readonly DateTime KeyDate2210 = new(2022, 09, 30, 22, 0, 0, DateTimeKind.Utc); - + private static readonly DateTime KeyDate2210 = + new(2022, 09, 30, 22, 0, 0, DateTimeKind.Utc); /// /// validity date of /// - private static readonly DateTime KeyDate2304 = new(2023, 03, 31, 22, 0, 0, DateTimeKind.Utc); + private static readonly DateTime KeyDate2304 = + new(2023, 03, 31, 22, 0, 0, DateTimeKind.Utc); /// /// validity date of /// - private static readonly DateTime KeyDate2310 = new(2023, 09, 30, 22, 0, 0, DateTimeKind.Utc); + private static readonly DateTime KeyDate2310 = + new(2023, 09, 30, 22, 0, 0, DateTimeKind.Utc); /// /// validity date of /// /// Note that this is _not_ April 1st - private static readonly DateTime KeyDate2404 = new(2024, 04, 02, 22, 0, 0, DateTimeKind.Utc); + private static readonly DateTime KeyDate2404 = + new(2024, 04, 02, 22, 0, 0, DateTimeKind.Utc); /// /// validity date of /// - private static readonly DateTime KeyDate2410 = new(2024, 09, 30, 22, 0, 0, DateTimeKind.Utc); + private static readonly DateTime KeyDate2410 = + new(2024, 09, 30, 22, 0, 0, DateTimeKind.Utc); /// /// validity date of /// /// Note that this is _not_ April 1st - private static readonly DateTime KeyDate2504 = new(2025, 04, 03, 22, 0, 0, DateTimeKind.Utc); - + private static readonly DateTime KeyDate2504 = + new(2025, 04, 03, 22, 0, 0, DateTimeKind.Utc); public EdifactFormatVersion GetFormatVersion(DateTimeOffset keydate) { @@ -447,6 +478,7 @@ public EdifactFormatVersion GetFormatVersion(DateTimeOffset keydate) return EdifactFormatVersion.FV1710; } + /// /// returns the format version valid as of now. /// @@ -456,6 +488,7 @@ public EdifactFormatVersion GetCurrent() var keydate = DateTime.UtcNow; return GetFormatVersion(keydate); } + /// /// /// does not support anything older than 2110 at the moment @@ -471,25 +504,25 @@ public EdifactFormatVersion GetFormatVersion(EdifactFormat format, string versio { "5.2e" => EdifactFormatVersion.FV2210, "5.2c" => EdifactFormatVersion.FV2110, - _ => GetCurrent() + _ => GetCurrent(), }, EdifactFormat.UTILMDG => version switch { "G1.0a" => EdifactFormatVersion.FV2310, - _ => GetCurrent() + _ => GetCurrent(), }, EdifactFormat.UTILMDW => version switch { "5.2e" => EdifactFormatVersion.FV2210, "5.2c" => EdifactFormatVersion.FV2110, "G1.0a" => EdifactFormatVersion.FV2310, - _ => GetCurrent() + _ => GetCurrent(), }, EdifactFormat.UTILMDS => version switch { "S1.1a" => EdifactFormatVersion.FV2404, "S1.1" => EdifactFormatVersion.FV2310, - _ => GetCurrent() + _ => GetCurrent(), }, EdifactFormat.MSCONS => version switch { @@ -497,27 +530,27 @@ public EdifactFormatVersion GetFormatVersion(EdifactFormat format, string versio "2.4b" => EdifactFormatVersion.FV2310, "2.4a" => EdifactFormatVersion.FV2210, "2.3c" => EdifactFormatVersion.FV2110, - _ => GetCurrent() + _ => GetCurrent(), }, EdifactFormat.PARTIN => version switch { "1.0d" => EdifactFormatVersion.FV2404, "1.0c" => EdifactFormatVersion.FV2310, "1.0a" => EdifactFormatVersion.FV2210, - _ => GetCurrent() + _ => GetCurrent(), }, EdifactFormat.IFTSTA => version switch { "2.0e" => EdifactFormatVersion.FV2310, "2.0d" => EdifactFormatVersion.FV2210, "2.0c" => EdifactFormatVersion.FV2110, - _ => GetCurrent() + _ => GetCurrent(), }, EdifactFormat.APERAK => version switch { "2.1h" => EdifactFormatVersion.FV2210, "2.1f" => EdifactFormatVersion.FV2110, - _ => GetCurrent() + _ => GetCurrent(), }, EdifactFormat.COMDIS => version switch { @@ -525,19 +558,19 @@ public EdifactFormatVersion GetFormatVersion(EdifactFormat format, string versio "1.0c" => EdifactFormatVersion.FV2310, "1.0b" => EdifactFormatVersion.FV2210, "1.0a" => EdifactFormatVersion.FV2110, - _ => GetCurrent() + _ => GetCurrent(), }, EdifactFormat.CONTRL => version switch { "2.0b" => EdifactFormatVersion.FV2210, "2.0a" => EdifactFormatVersion.FV2110, - _ => GetCurrent() + _ => GetCurrent(), }, EdifactFormat.INSRPT => version switch { "1.1a" => EdifactFormatVersion.FV2210, "1.1" => EdifactFormatVersion.FV2110, - _ => GetCurrent() + _ => GetCurrent(), }, EdifactFormat.INVOIC => version switch { @@ -546,13 +579,13 @@ public EdifactFormatVersion GetFormatVersion(EdifactFormat format, string versio "2.8a" => EdifactFormatVersion.FV2304, "2.8" => EdifactFormatVersion.FV2210, "2.7a" => EdifactFormatVersion.FV2110, - _ => GetCurrent() + _ => GetCurrent(), }, EdifactFormat.ORDCHG => version switch { "1.1" => EdifactFormatVersion.FV2310, "1.0" => EdifactFormatVersion.FV2210, - _ => GetCurrent() + _ => GetCurrent(), }, EdifactFormat.ORDERS => version switch { @@ -560,7 +593,7 @@ public EdifactFormatVersion GetFormatVersion(EdifactFormat format, string versio "1.2b" => EdifactFormatVersion.FV2304, "1.2a" => EdifactFormatVersion.FV2210, "1.1m" => EdifactFormatVersion.FV2110, - _ => GetCurrent() + _ => GetCurrent(), }, EdifactFormat.ORDRSP => version switch { @@ -568,7 +601,7 @@ public EdifactFormatVersion GetFormatVersion(EdifactFormat format, string versio "1.2b" => EdifactFormatVersion.FV2304, "1.2a" => EdifactFormatVersion.FV2210, "1.1k" => EdifactFormatVersion.FV2110, - _ => GetCurrent() + _ => GetCurrent(), }, EdifactFormat.PRICAT => version switch { @@ -576,14 +609,14 @@ public EdifactFormatVersion GetFormatVersion(EdifactFormat format, string versio "2.0b" => EdifactFormatVersion.FV2304, "2.0a" => EdifactFormatVersion.FV2210, "1.1b" => EdifactFormatVersion.FV2110, - _ => GetCurrent() + _ => GetCurrent(), }, EdifactFormat.QUOTES => version switch { "1.3" => EdifactFormatVersion.FV2310, "1.2" => EdifactFormatVersion.FV2210, "1.1b" => EdifactFormatVersion.FV2110, - _ => GetCurrent() + _ => GetCurrent(), }, EdifactFormat.REMADV => version switch { @@ -592,14 +625,14 @@ public EdifactFormatVersion GetFormatVersion(EdifactFormat format, string versio "2.9a" => EdifactFormatVersion.FV2304, "2.9" => EdifactFormatVersion.FV2210, "2.8" => EdifactFormatVersion.FV2110, - _ => GetCurrent() + _ => GetCurrent(), }, EdifactFormat.REQOTE => version switch { "1.3" => EdifactFormatVersion.FV2310, "1.2" => EdifactFormatVersion.FV2210, "1.1d" => EdifactFormatVersion.FV2110, - _ => GetCurrent() + _ => GetCurrent(), }, EdifactFormat.UTILTS => version switch { @@ -607,9 +640,9 @@ public EdifactFormatVersion GetFormatVersion(EdifactFormat format, string versio "1.1b" => EdifactFormatVersion.FV2310, "1.1a" => EdifactFormatVersion.FV2210, "1.0a" => EdifactFormatVersion.FV2110, - _ => GetCurrent() + _ => GetCurrent(), }, - _ => GetCurrent() + _ => GetCurrent(), }; return determinedVersion; } diff --git a/EDILibrary/Exceptions/BadFormatException.cs b/EDILibrary/Exceptions/BadFormatException.cs index 31f54e6..5caf6f5 100644 --- a/EDILibrary/Exceptions/BadFormatException.cs +++ b/EDILibrary/Exceptions/BadFormatException.cs @@ -9,20 +9,21 @@ namespace EDILibrary.Exceptions public class BadFormatException : Exception { private EdifactFormat? _format; + /// /// e.g. 5.2h /// private string _version; - public BadFormatException(EdifactFormat? format, string version, Exception innerException) : base($"Format {format} in version {version} could not be found", innerException) + public BadFormatException(EdifactFormat? format, string version, Exception innerException) + : base($"Format {format} in version {version} could not be found", innerException) { _format = format; _version = version; } [Obsolete("Use strongly typed overload instead")] - public BadFormatException(string format, string version, Exception innerException) : this(Enum.Parse(format), version, innerException) - { - } + public BadFormatException(string format, string version, Exception innerException) + : this(Enum.Parse(format), version, innerException) { } } } diff --git a/EDILibrary/ExtendedMappings.cs b/EDILibrary/ExtendedMappings.cs index 5b2ff13..4c36e8a 100644 --- a/EDILibrary/ExtendedMappings.cs +++ b/EDILibrary/ExtendedMappings.cs @@ -12,33 +12,44 @@ public class MappingEntry public string Type { get; set; } public string Format { get; set; } } + public class ExtendedMappings { - public readonly string _zuLang; protected List _mappingRoot = new List(); public ExtendedMappings() { - _zuLang = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."; + _zuLang = + "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."; } + public List GetListOfMappings() { return _mappingRoot.Select(mr => mr.Attribute("Name").Value).ToList(); } + public List GetListOfMappingTypes() { - return _mappingRoot.Select(mr => new MappingEntry - { - Name = mr.Attribute("Name").Value, - Type = mr.Attribute("type") != null ? mr.Attribute("type").Value : "python", - Format = mr.Attribute("format")?.Value - }).ToList(); + return _mappingRoot + .Select(mr => new MappingEntry + { + Name = mr.Attribute("Name").Value, + Type = mr.Attribute("type") != null ? mr.Attribute("type").Value : "python", + Format = mr.Attribute("format")?.Value, + }) + .ToList(); } + public void LoadMappings(string mappingXML, int iClient) { - _mappingRoot = XElement.Parse(mappingXML).Descendants("Mapping").Where(dsc => dsc.Attribute("Client").Value == iClient.ToString()).ToList(); + _mappingRoot = XElement + .Parse(mappingXML) + .Descendants("Mapping") + .Where(dsc => dsc.Attribute("Client").Value == iClient.ToString()) + .ToList(); } + public void LoadMappings(string mappingXML) { if (string.IsNullOrEmpty(mappingXML)) @@ -47,34 +58,57 @@ public void LoadMappings(string mappingXML) } _mappingRoot = XElement.Parse(mappingXML).Descendants("Mapping").ToList(); - } + public string GetMapping(string mappingName) { - var mapping = _mappingRoot.FirstOrDefault(mr => mr.Attribute("Name").Value == mappingName); + var mapping = _mappingRoot.FirstOrDefault(mr => + mr.Attribute("Name").Value == mappingName + ); return mapping != null ? mapping.Value : null; } + public void OverrideMapping(string mappingName, string newMapping) { - var mapping = _mappingRoot.FirstOrDefault(mr => mr.Attribute("Name").Value == mappingName); + var mapping = _mappingRoot.FirstOrDefault(mr => + mr.Attribute("Name").Value == mappingName + ); if (mapping != null) { mapping.Value = newMapping; } } - public void ExecuteMapping(string mappingName, EdiObject obj, string sparte, EdifactFormat? format) + public void ExecuteMapping( + string mappingName, + EdiObject obj, + string sparte, + EdifactFormat? format + ) { - var mapping = _mappingRoot.FirstOrDefault(mr => mr.Attribute("Name").Value == mappingName && (mr.Attribute("format") == null || Enum.Parse(mr.Attribute("format").Value) == format)); + var mapping = _mappingRoot.FirstOrDefault(mr => + mr.Attribute("Name").Value == mappingName + && ( + mr.Attribute("format") == null + || Enum.Parse(mr.Attribute("format").Value) == format + ) + ); if (mapping != null) { - if (mapping.Attribute("type") == null || mapping.Attribute("type")?.Value == "python") + if ( + mapping.Attribute("type") == null + || mapping.Attribute("type")?.Value == "python" + ) { - throw new NotImplementedException("Der .net Core-Port unterstützt kein IronPython"); + throw new NotImplementedException( + "Der .net Core-Port unterstützt kein IronPython" + ); } } } + protected List _ediLines; + protected static string GetValue(string pos, string edi) { //if (_valueCache.ContainsKey(edi)) @@ -117,7 +151,13 @@ protected static string GetValue(string pos, string edi) break; } - parts.Add(subGroups[i].Replace("?<", "+").Replace("?>", ":").Replace("?$", "'").Replace("<<", "?")); + parts.Add( + subGroups[i] + .Replace("?<", "+") + .Replace("?>", ":") + .Replace("?$", "'") + .Replace("<<", "?") + ); } //Abweichend zur Behandlung im EDIReader bleiben hier die :-Trennzeichen erhalten um eine korrekte Ersetzung sicherzustellen var endValue = string.Join(":", parts).Trim(); @@ -135,7 +175,11 @@ protected static string GetValue(string pos, string edi) return null; } - var result = subGroups[detailPos].Replace("?<", "+").Replace("?>", ":").Replace("?$", "'").Replace("<<", "?"); + var result = subGroups[detailPos] + .Replace("?<", "+") + .Replace("?>", ":") + .Replace("?$", "'") + .Replace("<<", "?"); //if (!_valueCache.ContainsKey(edi)) //{ // _valueCache.Add(edi, new Dictionary()); @@ -143,15 +187,18 @@ protected static string GetValue(string pos, string edi) //_valueCache[edi][pos] = result.Trim(); return Escape(result.Trim()); } + public void PrepareEDIMapping(string edi) { _ediLines = new List(); _ediLines = edi.Split(new[] { "'" }, StringSplitOptions.None).ToList(); } + public static string Escape(string input) { return input.Replace("+", "?+").Replace(":", "?:").Replace("'", "?'"); } + public void ExecuteEDIMapping(string mappingName) { if (_ediLines == null) @@ -159,10 +206,14 @@ public void ExecuteEDIMapping(string mappingName) throw new Exception("Call PrepareEDIMapping before executing a mapping"); } - var mapping = _mappingRoot.FirstOrDefault(mr => mr.Attribute("Name").Value == mappingName); + var mapping = _mappingRoot.FirstOrDefault(mr => + mr.Attribute("Name").Value == mappingName + ); if (mapping?.Attribute("type") != null && mapping.Attribute("type").Value == "edi") { - var parts = mapping.Value.Replace("\n", "").Split(new[] { "==" }, StringSplitOptions.RemoveEmptyEntries); + var parts = mapping + .Value.Replace("\n", "") + .Split(new[] { "==" }, StringSplitOptions.RemoveEmptyEntries); var selector = parts[0].Trim(); var newValue = ""; if (parts.Length > 1) @@ -191,7 +242,10 @@ public void ExecuteEDIMapping(string mappingName) var segment = selection.Substring(0, sepIndex); if (klammerIndex != selector.Length) { - path = selector.Substring(klammerIndex + 1, selector.Length - 1 - klammerIndex - 1); + path = selector.Substring( + klammerIndex + 1, + selector.Length - 1 - klammerIndex - 1 + ); } // string[] paths = path.Split(new char[] { '^', '|' }, StringSplitOptions.RemoveEmptyEntries); @@ -214,7 +268,10 @@ public void ExecuteEDIMapping(string mappingName) if (path.Length != sepIndex) { - pathValue = path.Substring(opIndex + sepOp.Length, path.Length - opIndex - sepOp.Length); + pathValue = path.Substring( + opIndex + sepOp.Length, + path.Length - opIndex - sepOp.Length + ); } else { @@ -264,6 +321,7 @@ public void ExecuteEDIMapping(string mappingName) } } } + public string GetFinalEDIMapping() { return string.Join("'", _ediLines); diff --git a/EDILibrary/GenericEDILoader.cs b/EDILibrary/GenericEDILoader.cs index 9102fca..773d480 100644 --- a/EDILibrary/GenericEDILoader.cs +++ b/EDILibrary/GenericEDILoader.cs @@ -10,18 +10,26 @@ namespace EDILibrary public class GenericEDILoader { protected TreeHelper TreeHelper { get; set; } = new TreeHelper(); - protected virtual EdiObject ProcessSpecificTemplate(XElement template, Dictionary> objectMapping) + + protected virtual EdiObject ProcessSpecificTemplate( + XElement template, + Dictionary> objectMapping + ) { var treeRoot = objectMapping[TreeHelper.GetHash(template.ToString())][0]; return ProcessSpecificTemplate(template, treeRoot, objectMapping); } - protected virtual EdiObject ProcessSpecificTemplate(XElement template, TreeElement treeRoot, Dictionary> objectMapping) + + protected virtual EdiObject ProcessSpecificTemplate( + XElement template, + TreeElement treeRoot, + Dictionary> objectMapping + ) { string key = null; string ediSeg = null; if (template.Attribute("key") != null) { - key = EvaluateTemplate(template.Attribute("key").Value, treeRoot, out ediSeg); if (key == null) // criteria not met @@ -32,7 +40,7 @@ protected virtual EdiObject ProcessSpecificTemplate(XElement template, TreeEleme var rootObject = new EdiObject(template.Attribute("name").Value, template, key) { - Edi = ediSeg + Edi = ediSeg, }; if (template.Attribute("migName") != null) { @@ -45,7 +53,9 @@ protected virtual EdiObject ProcessSpecificTemplate(XElement template, TreeEleme var selector = field.Attribute("ref").Value; if (field.Attribute("migName") != null) { - rootObject.MigFields[field.Attribute("name").Value] = field.Attribute("migName").Value; + rootObject.MigFields[field.Attribute("name").Value] = field + .Attribute("migName") + .Value; } var value = EvaluateTemplate(selector, treeRoot, out var ediSegment); rootObject.EdiFields[field.Attribute("name").Value] = ediSegment; @@ -85,15 +95,24 @@ protected virtual EdiObject ProcessSpecificTemplate(XElement template, TreeEleme var refName = child.Attribute("ref").Value.Split(new[] { '[' })[0]; var childTree = new List(); treeRoot.FindElements(refName, true, ref childTree, 1); - childTree = (from childElem in childTree where childElem.Name == "/" || childElem.Dirty || childElem.Edi.Count > 0 select childElem).ToList(); - - foreach (var childObject in childTree.Select(childRoot => ProcessSpecificTemplate(child, childRoot, objectMapping))) + childTree = ( + from childElem in childTree + where childElem.Name == "/" || childElem.Dirty || childElem.Edi.Count > 0 + select childElem + ).ToList(); + + foreach ( + var childObject in childTree.Select(childRoot => + ProcessSpecificTemplate(child, childRoot, objectMapping) + ) + ) { rootObject.AddChild(childObject); } } return rootObject; } + protected string getValue(string pos, string edi) { if (_useCache && _valueCache.ContainsKey(edi)) @@ -136,7 +155,13 @@ protected string getValue(string pos, string edi) break; } - parts.Add(subGroups[i].Replace("?<", "+").Replace("?>", ":").Replace("?$", "'").Replace("<<", "?")); + parts.Add( + subGroups[i] + .Replace("?<", "+") + .Replace("?>", ":") + .Replace("?$", "'") + .Replace("<<", "?") + ); } var endValue = string.Join("", parts).Trim(); if (_useCache && !_valueCache.ContainsKey(edi)) @@ -157,7 +182,11 @@ protected string getValue(string pos, string edi) return null; } - var result = subGroups[DetailPos].Replace("?<", "+").Replace("?>", ":").Replace("?$", "'").Replace("<<", "?"); + var result = subGroups[DetailPos] + .Replace("?<", "+") + .Replace("?>", ":") + .Replace("?$", "'") + .Replace("<<", "?"); if (!_valueCache.ContainsKey(edi)) { _valueCache.Add(edi, new Dictionary()); @@ -165,7 +194,12 @@ protected string getValue(string pos, string edi) _valueCache[edi][pos] = result.Trim(); return result.Trim(); } - protected string EvaluateTemplate(string selector, TreeElement templateRoot, out string ediSegment) + + protected string EvaluateTemplate( + string selector, + TreeElement templateRoot, + out string ediSegment + ) { //string[] sel_path= selector.Split(new char[]{'['}); var klammerIndex = selector.IndexOf('['); @@ -174,7 +208,7 @@ protected string EvaluateTemplate(string selector, TreeElement templateRoot, out klammerIndex = selector.Length; } - var selection = selector.Substring(0, klammerIndex);// sel_path[0]; + var selection = selector.Substring(0, klammerIndex); // sel_path[0]; string path = null; //string[] sel_segments = selection.Split(new char[] { ':' }); var sepIndex = selection.IndexOf(':'); @@ -200,29 +234,47 @@ protected string EvaluateTemplate(string selector, TreeElement templateRoot, out else { templateRoot.FindElements(segment, true, ref resultList, 2); - if ((from TreeElement res in resultList where res.Edi != null && res.Edi.Any() select res).Any()) + if ( + ( + from TreeElement res in resultList + where res.Edi != null && res.Edi.Any() + select res + ).Any() + ) { - resultEDI.AddRange(resultList.Where(result => result.Edi.Any()).SelectMany(result => result.Edi)); + resultEDI.AddRange( + resultList + .Where(result => result.Edi.Any()) + .SelectMany(result => result.Edi) + ); if (_useCache) { _elementCache[templateRoot].Add(segment, resultEDI); } } - - } } else { templateRoot.FindElements(segment, true, ref resultList, 2); - if ((from TreeElement res in resultList where res.Edi != null && res.Edi.Any() select res).Any()) + if ( + ( + from TreeElement res in resultList + where res.Edi != null && res.Edi.Any() + select res + ).Any() + ) { if (_useCache) { _elementCache.Add(templateRoot, new Dictionary>()); } - resultEDI.AddRange(resultList.Where(result => result.Edi.Any()).SelectMany(result => result.Edi)); + resultEDI.AddRange( + resultList + .Where(result => result.Edi.Any()) + .SelectMany(result => result.Edi) + ); if (_useCache) { _elementCache[templateRoot].Add(segment, resultEDI); @@ -242,7 +294,10 @@ protected string EvaluateTemplate(string selector, TreeElement templateRoot, out { if (path != null) { - var paths = path.Split(new[] { '^', '|' }, StringSplitOptions.RemoveEmptyEntries); + var paths = path.Split( + new[] { '^', '|' }, + StringSplitOptions.RemoveEmptyEntries + ); var searchEdi = new List(); var part = ""; var conditionMet = true; @@ -259,7 +314,10 @@ protected string EvaluateTemplate(string selector, TreeElement templateRoot, out if (tempPath.Split(new[] { ':' }).Length > 2) { segPath = tempPath; - var searchElement = templateRoot.FindElement(segPath.Split(new[] { ':' })[0], false); + var searchElement = templateRoot.FindElement( + segPath.Split(new[] { ':' })[0], + false + ); if (searchElement != null) { searchEdi.AddRange(searchElement.Edi); @@ -287,7 +345,10 @@ protected string EvaluateTemplate(string selector, TreeElement templateRoot, out string pathValue = null; if (segPath.Length != sepIndex) { - pathValue = segPath.Substring(opIndex + sepOp.Length, segPath.Length - opIndex - sepOp.Length); + pathValue = segPath.Substring( + opIndex + sepOp.Length, + segPath.Length - opIndex - sepOp.Length + ); } else { @@ -295,7 +356,12 @@ protected string EvaluateTemplate(string selector, TreeElement templateRoot, out } //.Where(s=>s==edi) - foreach (var ediSearch in searchEdi.Where(ediSearch => ediSearch.Substring(0, 3) != edi.Substring(0, 3) || ediSearch == edi)) + foreach ( + var ediSearch in searchEdi.Where(ediSearch => + ediSearch.Substring(0, 3) != edi.Substring(0, 3) + || ediSearch == edi + ) + ) { if (sepOp == "=") { @@ -358,6 +424,7 @@ protected string EvaluateTemplate(string selector, TreeElement templateRoot, out return null; } + public XElement LoadTemplate(string template) { var reader = new StringReader(template); @@ -366,25 +433,34 @@ public XElement LoadTemplate(string template) { root = XElement.Load(reader); } - catch (System.Xml.XmlException xmlException) when (xmlException.Message == "Root element is missing.") + catch (System.Xml.XmlException xmlException) + when (xmlException.Message == "Root element is missing.") { throw new System.Xml.XmlException( - $"The edifact template '{template}' could not be parsed. Are you sure the EDIFACT Format has been detected correctly?", innerException: xmlException); + $"The edifact template '{template}' could not be parsed. Are you sure the EDIFACT Format has been detected correctly?", + innerException: xmlException + ); } return root; } protected bool _useCache = true; - protected Dictionary>> _elementCache = new Dictionary>>(); - protected Dictionary> _valueCache = new Dictionary>(); + protected Dictionary>> _elementCache = + new Dictionary>>(); + protected Dictionary> _valueCache = + new Dictionary>(); + public EdiObject LoadTemplateWithLoadedTree(XElement template, TreeElement tree) { var objectMapping = new Dictionary>(); - var classes = from cls in template.DescendantsAndSelf("class") - select cls; + var classes = from cls in template.DescendantsAndSelf("class") select cls; _elementCache.Clear(); _valueCache.Clear(); - var dokument = (from temp in template.DescendantsAndSelf("class") where temp.Attribute("name").Value == "Dokument" select temp).Single(); + var dokument = ( + from temp in template.DescendantsAndSelf("class") + where temp.Attribute("name").Value == "Dokument" + select temp + ).Single(); TreeElement docElement = null; foreach (var cls in classes) { @@ -393,7 +469,11 @@ public EdiObject LoadTemplateWithLoadedTree(XElement template, TreeElement tree) var treeElements = new List(); var refName = cls.Attribute("ref").Value.Split(new[] { '[' })[0]; tree.FindElements(refName, true, ref treeElements); - treeElements = (from childElem in treeElements where childElem.Name == "/" || childElem.Dirty || childElem.Edi.Count > 0 select childElem).ToList(); + treeElements = ( + from childElem in treeElements + where childElem.Name == "/" || childElem.Dirty || childElem.Edi.Count > 0 + select childElem + ).ToList(); docElement = treeElements[0]; } //List treeElements = new List(); @@ -403,8 +483,8 @@ public EdiObject LoadTemplateWithLoadedTree(XElement template, TreeElement tree) //objectMapping[TreeHelper.GetHash(cls.ToString())] = treeElements; } return ProcessSpecificTemplate(dokument, docElement, null); - } + public TreeElement LoadTree(string tree) { TreeElement treeRoot; @@ -443,6 +523,7 @@ public TreeElement LoadTree(string tree) } return treeRoot; } + public TreeElement LoadEDI(string edi, TreeElement tree) { var elementDelimiter = ":"; @@ -464,7 +545,10 @@ public TreeElement LoadEDI(string edi, TreeElement tree) } } - var message = edi.Substring(unAoffset + segDelimiterLength, edi.Length - (unAoffset + segDelimiterLength)); + var message = edi.Substring( + unAoffset + segDelimiterLength, + edi.Length - (unAoffset + segDelimiterLength) + ); message = message.Replace("?'", "?$"); message = message.Replace("\"", "\\\""); if (tree != null) @@ -473,7 +557,10 @@ public TreeElement LoadEDI(string edi, TreeElement tree) var currentTreeRoot = tree; foreach (var segment in message.SplitLines(segmentDelimiter.First())) { - var strSegment = segment.Line.ToString().TrimStart('\r', '\n', '\t').TrimEnd('\r', '\n', '\t'); + var strSegment = segment + .Line.ToString() + .TrimStart('\r', '\n', '\t') + .TrimEnd('\r', '\n', '\t'); var child = TreeHelper.FindEdiElement(ref currentTreeRoot, strSegment); if (child != null) { @@ -487,7 +574,6 @@ public TreeElement LoadEDI(string edi, TreeElement tree) return tree; } return null; - } } } diff --git a/EDILibrary/GenericEDIWriter.cs b/EDILibrary/GenericEDIWriter.cs index d0f57b0..6c52ada 100644 --- a/EDILibrary/GenericEDIWriter.cs +++ b/EDILibrary/GenericEDIWriter.cs @@ -12,16 +12,27 @@ public class ScriptHelper { public bool useLocalTime = true; public TimeZoneInfo LocalTimeZone { get; set; } = TimeZoneInfo.Local; + public static string Escape(string input) { return input.Replace("+", "?+").Replace(":", "?:").Replace("'", "?'"); } + public string FormatDate(string dateString, string format) { DateTime date; var deDE = new CultureInfo("de-DE"); - bool foundDate = DateTime.TryParseExact(dateString, new[] { "yyyyMMdd", "MMdd", "yyyyMMddHHmm", "yyyyMMddHHmmss" }, deDE, DateTimeStyles.AdjustToUniversal, out date); - if (!foundDate && !DateTime.TryParse(dateString, deDE, DateTimeStyles.AdjustToUniversal, out date)) + bool foundDate = DateTime.TryParseExact( + dateString, + new[] { "yyyyMMdd", "MMdd", "yyyyMMddHHmm", "yyyyMMddHHmmss" }, + deDE, + DateTimeStyles.AdjustToUniversal, + out date + ); + if ( + !foundDate + && !DateTime.TryParse(dateString, deDE, DateTimeStyles.AdjustToUniversal, out date) + ) { return dateString.Replace("+0000", "+00"); } @@ -29,95 +40,109 @@ public string FormatDate(string dateString, string format) switch (format) { case "102": - { - return TimeZoneInfo.ConvertTimeFromUtc(date, LocalTimeZone).ToString("yyyyMMdd"); - } + { + return TimeZoneInfo + .ConvertTimeFromUtc(date, LocalTimeZone) + .ToString("yyyyMMdd"); + } case "106": + { + if (useLocalTime) { - if (useLocalTime) - { - return TimeZoneInfo.ConvertTimeFromUtc(date, LocalTimeZone).ToString("MMdd"); - } - - return date.ToString("MMdd"); + return TimeZoneInfo + .ConvertTimeFromUtc(date, LocalTimeZone) + .ToString("MMdd"); } + + return date.ToString("MMdd"); + } case "203": + { + if (useLocalTime) { - if (useLocalTime) - { - return TimeZoneInfo.ConvertTimeFromUtc(date, LocalTimeZone).ToString("yyyyMMddHHmm"); - } - - return date.ToString("yyyyMMddHHmm"); + return TimeZoneInfo + .ConvertTimeFromUtc(date, LocalTimeZone) + .ToString("yyyyMMddHHmm"); } + + return date.ToString("yyyyMMddHHmm"); + } case "204": + { + if (useLocalTime) { - if (useLocalTime) - { - return TimeZoneInfo.ConvertTimeFromUtc(date, LocalTimeZone).ToString("yyyyMMddHHmmss"); - } - - return date.ToString("yyyyMMddHHmmss"); + return TimeZoneInfo + .ConvertTimeFromUtc(date, LocalTimeZone) + .ToString("yyyyMMddHHmmss"); } + + return date.ToString("yyyyMMddHHmmss"); + } case "303": + { + if (useLocalTime) { - if (useLocalTime) - { - var dateMidnightInUtc = new DateTimeOffset(date, TimeSpan.Zero); - var offsetHours = dateMidnightInUtc.ToOffset(LocalTimeZone.GetUtcOffset(dateMidnightInUtc)).Offset.Hours; - return date.ToLocalTime().ToString("yyyyMMddHHmm") + "+0" + offsetHours; // assuming 0<=offsetHours<10 which is true for germany - } - // Zeitzone ist stets UTC - return date.ToString("yyyyMMddHHmm") + "+00"; + var dateMidnightInUtc = new DateTimeOffset(date, TimeSpan.Zero); + var offsetHours = dateMidnightInUtc + .ToOffset(LocalTimeZone.GetUtcOffset(dateMidnightInUtc)) + .Offset.Hours; + return date.ToLocalTime().ToString("yyyyMMddHHmm") + "+0" + offsetHours; // assuming 0<=offsetHours<10 which is true for germany } + // Zeitzone ist stets UTC + return date.ToString("yyyyMMddHHmm") + "+00"; + } case "304": + { + if (useLocalTime) { - if (useLocalTime) - { - var dateMidnightInUtc = new DateTimeOffset(date, TimeSpan.Zero); - var offsetHours = dateMidnightInUtc.ToOffset(LocalTimeZone.GetUtcOffset(dateMidnightInUtc)).Offset.Hours; - return date.ToLocalTime().ToString("yyyyMMddHHmmss") + "+0" + offsetHours; // assuming 0<=offsetHours<10 which is true for germany - } - // Zeitzone ist stets UTC - return date.ToString("yyyyMMddHHmmss") + "+00"; + var dateMidnightInUtc = new DateTimeOffset(date, TimeSpan.Zero); + var offsetHours = dateMidnightInUtc + .ToOffset(LocalTimeZone.GetUtcOffset(dateMidnightInUtc)) + .Offset.Hours; + return date.ToLocalTime().ToString("yyyyMMddHHmmss") + "+0" + offsetHours; // assuming 0<=offsetHours<10 which is true for germany } + // Zeitzone ist stets UTC + return date.ToString("yyyyMMddHHmmss") + "+00"; + } case "406": + { + if (useLocalTime) { - if (useLocalTime) - { - var utcOffset = new DateTimeOffset(date, TimeSpan.Zero); - var offset = utcOffset.ToOffset(LocalTimeZone.GetUtcOffset(utcOffset)).Offset.Hours; - return "+0" + offset + "00"; - } - - // wir speichern immer UTC, daher die Zeitzone auf 0 setzen - return "+0000"; + var utcOffset = new DateTimeOffset(date, TimeSpan.Zero); + var offset = utcOffset + .ToOffset(LocalTimeZone.GetUtcOffset(utcOffset)) + .Offset.Hours; + return "+0" + offset + "00"; } + + // wir speichern immer UTC, daher die Zeitzone auf 0 setzen + return "+0000"; + } case "Z01": - { - return dateString; - } + { + return dateString; + } case "602": - { - return date.ToString("yyyy"); - } + { + return date.ToString("yyyy"); + } case "610": - { - return date.ToString("yyyyMM"); - } + { + return date.ToString("yyyyMM"); + } default: - { - return dateString.Replace("+0000", "+00"); - } - - + { + return dateString.Replace("+0000", "+00"); + } } } } + public class GenericEDIWriter { public ScriptHelper helper = new ScriptHelper(); static readonly Regex numericRegex = new Regex("^[0-9]+$", RegexOptions.Compiled); + public GenericEDIWriter() { escapeMap.Add(":", "?:"); @@ -127,13 +152,18 @@ public GenericEDIWriter() escapeMap.Add("‘", "?'"); escapeMap.Add("‛", "?'"); escapeMap.Add("′", "?'"); - } + protected Dictionary escapeMap = new Dictionary(); + protected string EscapeValue(string value) { - return escapeMap.Aggregate(value, (current, pair) => current.Replace(pair.Key, pair.Value)); + return escapeMap.Aggregate( + value, + (current, pair) => current.Replace(pair.Key, pair.Value) + ); } + static readonly Regex questionMarkRegex = new Regex("\\?'", RegexOptions.Compiled); string RecurseTemplate(string template, EdiObject parent) @@ -144,7 +174,7 @@ string RecurseTemplate(string template, EdiObject parent) var resultBuilder = new StringBuilder(); do { - beginIndex = template.IndexOf("<", currentIndex);// :warn: is culture specific + beginIndex = template.IndexOf("<", currentIndex); // :warn: is culture specific if (beginIndex == -1) { continue; @@ -158,16 +188,15 @@ string RecurseTemplate(string template, EdiObject parent) { var nodeparts = code.Split(new[] { ' ' }); var node = string.Join(" ", nodeparts.Skip(1)); - beginIndex = template.IndexOf("", endIndex);// :warn: is culture specific + beginIndex = template.IndexOf("", endIndex); // :warn: is culture specific var innercode = template.Substring(endIndex + 1, beginIndex - endIndex - 1); - var nodes = from ele in parent.SelfOrChildren - where ele.Name == node - select ele; + var nodes = from ele in parent.SelfOrChildren where ele.Name == node select ele; if (!nodes.Any()) // wenn keine Treffer könnte es sich noch um eine field-Liste handeln { - var stringNodes = from ele in parent.Fields - where ele.Key == node - select ele.Value; + var stringNodes = + from ele in parent.Fields + where ele.Key == node + select ele.Value; foreach (var valueNode in stringNodes) { foreach (var val in valueNode) @@ -182,13 +211,24 @@ string RecurseTemplate(string template, EdiObject parent) var max = nodes.Count(); foreach (var subnode in nodes) { - resultBuilder.Append(RecurseTemplate(innercode, subnode) + (i != max ? Environment.NewLine : "")); + resultBuilder.Append( + RecurseTemplate(innercode, subnode) + + (i != max ? Environment.NewLine : "") + ); } beginIndex = template.IndexOf(""; endIndex = template.IndexOf(end, beginIndex); - template = template.Substring(0, beginIndex) + template.Substring(beginIndex, endIndex - beginIndex + end.Length).Replace(template.Substring(beginIndex, endIndex - beginIndex + end.Length), resultBuilder.ToString()) + template.Substring(endIndex + end.Length); + template = + template.Substring(0, beginIndex) + + template + .Substring(beginIndex, endIndex - beginIndex + end.Length) + .Replace( + template.Substring(beginIndex, endIndex - beginIndex + end.Length), + resultBuilder.ToString() + ) + + template.Substring(endIndex + end.Length); template = template.TrimEnd('\r', '\n', '\t'); beginIndex = 0; } @@ -201,9 +241,10 @@ string RecurseTemplate(string template, EdiObject parent) string value = null; - var selection = from ele in parent.Fields - where ele.Key == node - select ele.Value[0]; + var selection = + from ele in parent.Fields + where ele.Key == node + select ele.Value[0]; if (selection.Any()) { value = selection.Single(); @@ -224,7 +265,15 @@ string RecurseTemplate(string template, EdiObject parent) } beginIndex = template.IndexOf("", beginIndex); - template = template.Substring(0, beginIndex) + template.Substring(beginIndex, endIndex - beginIndex + 5).Replace(template.Substring(beginIndex, endIndex - beginIndex + 5), resultBuilder.ToString()) + template.Substring(endIndex + 5); + template = + template.Substring(0, beginIndex) + + template + .Substring(beginIndex, endIndex - beginIndex + 5) + .Replace( + template.Substring(beginIndex, endIndex - beginIndex + 5), + resultBuilder.ToString() + ) + + template.Substring(endIndex + 5); beginIndex = 0; } else if (codeTemplate.StartsWith("", beginIndex); - template = template.Substring(0, beginIndex) + template.Substring(beginIndex, endIndex - beginIndex + 1).Replace(template.Substring(beginIndex, endIndex - beginIndex + 1), resultBuilder.ToString()) + template.Substring(endIndex + 1); + template = + template.Substring(0, beginIndex) + + template + .Substring(beginIndex, endIndex - beginIndex + 1) + .Replace( + template.Substring(beginIndex, endIndex - beginIndex + 1), + resultBuilder.ToString() + ) + + template.Substring(endIndex + 1); beginIndex = 0; } else if (codeTemplate.StartsWith("", beginIndex); - template = template.Substring(0, beginIndex) + template.Substring(beginIndex, endIndex - beginIndex + 1).Replace(template.Substring(beginIndex, endIndex - beginIndex + 1), resultBuilder.ToString()) + template.Substring(endIndex + 1); + template = + template.Substring(0, beginIndex) + + template + .Substring(beginIndex, endIndex - beginIndex + 1) + .Replace( + template.Substring(beginIndex, endIndex - beginIndex + 1), + resultBuilder.ToString() + ) + + template.Substring(endIndex + 1); beginIndex = 0; } - else if (codeTemplate.StartsWith(" c == "'".ToCharArray()[0]); // warn: culture specific - //escapte ' muss ich abziehen - - var deduct = questionMarkRegex.Matches(template.Substring(template.Substring(0, beginIndex).LastIndexOf("UNH+"))).Count; + var segCount = template + .Substring(template.Substring(0, beginIndex).LastIndexOf("UNH+")) + .Count(c => c == "'".ToCharArray()[0]); // warn: culture specific + //escapte ' muss ich abziehen + + var deduct = questionMarkRegex + .Matches( + template.Substring( + template.Substring(0, beginIndex).LastIndexOf("UNH+") + ) + ) + .Count; segCount -= deduct; resultBuilder.Append(segCount); } else if (codeTemplate.Contains("MessageNumber")) { - var messageCount = template.Split(new[] { "UNH+" }, StringSplitOptions.RemoveEmptyEntries).Length - 1; + var messageCount = + template + .Split(new[] { "UNH+" }, StringSplitOptions.RemoveEmptyEntries) + .Length - 1; resultBuilder.Append(messageCount); } code = code.TrimStart('!', '$'); @@ -400,7 +477,7 @@ string RecurseTemplate(string template, EdiObject parent) } else { - string value;// = null; + string value; // = null; string length = null; string maxCount = null; string[] fieldLengths = null; @@ -434,9 +511,10 @@ string RecurseTemplate(string template, EdiObject parent) } else { - var selection = from ele in parent.Fields - where ele.Key == code - select ele.Value[0]; + var selection = + from ele in parent.Fields + where ele.Key == code + select ele.Value[0]; var enumerable = selection as string[] ?? selection.ToArray(); if (enumerable.Any()) { @@ -466,7 +544,6 @@ string RecurseTemplate(string template, EdiObject parent) { while (temp_value.Length > laenge) { - var temp = temp_value.Substring(0, laenge); parts.Add(temp); temp_value = temp_value.Substring(laenge); @@ -495,7 +572,6 @@ string RecurseTemplate(string template, EdiObject parent) { parts.Add(temp_value); } - } while (parts.Count < count) { @@ -505,29 +581,35 @@ string RecurseTemplate(string template, EdiObject parent) // Bei leerem Vornamen muss trotzdem ein Doppelpunkt drin sein. //if((from string s in parts where s!="" select s).Count()>0) value = string.Join(":", parts.Take(int.Parse(maxCount))); - } resultBuilder.Append(value); //template = template.Replace(codeTemplate, evalResult); - template = template.Substring(0, beginIndex) + template.Substring(beginIndex, endIndex - beginIndex + 1).Replace(template.Substring(beginIndex, endIndex - beginIndex + 1), resultBuilder.ToString()) + template.Substring(endIndex + 1); + template = + template.Substring(0, beginIndex) + + template + .Substring(beginIndex, endIndex - beginIndex + 1) + .Replace( + template.Substring(beginIndex, endIndex - beginIndex + 1), + resultBuilder.ToString() + ) + + template.Substring(endIndex + 1); } currentIndex = 0; } while (beginIndex != -1); return template.Trim(); - } - public static void Preinitialize() - { - } + public static void Preinitialize() { } - private static readonly List> CompileReplacements = new List> + private static readonly List> CompileReplacements = new List< + Tuple + > { new Tuple(":+", "+"), - new Tuple(":'","'"), + new Tuple(":'", "'"), new Tuple("+'", "'"), new Tuple(":'", "'"), // why are there duplicates? and why is the order important? new Tuple("+'", "'"), @@ -551,7 +633,15 @@ public string CompileTemplate(string template, EdiObject sourceRoot) } } // todo: write a unittest for the edge cases this code is supposed to solve and then find a better way - while (content.Contains("\n\n") || content.Contains("\r\r") || content.Contains("\n\r") || content.Contains("\r\n\r\n") || content.Contains(Environment.NewLine) || content.Contains("\r\n\r\n") || content.Contains(Environment.NewLine)) + while ( + content.Contains("\n\n") + || content.Contains("\r\r") + || content.Contains("\n\r") + || content.Contains("\r\n\r\n") + || content.Contains(Environment.NewLine) + || content.Contains("\r\n\r\n") + || content.Contains(Environment.NewLine) + ) { while (content.Contains("\r\n\r\n")) { diff --git a/EDILibrary/Helper/MappingHelper.cs b/EDILibrary/Helper/MappingHelper.cs index a209b44..d1f0cd1 100644 --- a/EDILibrary/Helper/MappingHelper.cs +++ b/EDILibrary/Helper/MappingHelper.cs @@ -6,7 +6,14 @@ namespace EDILibrary.Helper { public class MappingHelper { - public static string ExecuteMappingsWithTemplates(EdiObject edi, EDIFileInfo fileInfo, List mappings, string createTemplate, TimeZoneInfo localZone, bool bUseLocalTime = true) + public static string ExecuteMappingsWithTemplates( + EdiObject edi, + EDIFileInfo fileInfo, + List mappings, + string createTemplate, + TimeZoneInfo localZone, + bool bUseLocalTime = true + ) { var extMapping = new ExtendedMappings(); extMapping.LoadMappings(""); @@ -17,8 +24,7 @@ public static string ExecuteMappingsWithTemplates(EdiObject edi, EDIFileInfo fil extMapping.ExecuteMapping(map, edi, "S", fileInfo.Format); } catch (Exception) // todo: fix pokemon catching - { - } + { } } var writer = new GenericEDIWriter(); writer.helper.useLocalTime = bUseLocalTime; @@ -32,12 +38,19 @@ public static string ExecuteMappingsWithTemplates(EdiObject edi, EDIFileInfo fil extMapping.ExecuteEDIMapping(map); } catch (Exception) // todo: fix pokemon catching - { - } + { } } return extMapping.GetFinalEDIMapping(); } - public static string ExecuteMappings(EdiObject edi, EDIFileInfo fileInfo, List mappings, string createTemplate, TimeZoneInfo localZone, bool bUseLocalTime = true) + + public static string ExecuteMappings( + EdiObject edi, + EDIFileInfo fileInfo, + List mappings, + string createTemplate, + TimeZoneInfo localZone, + bool bUseLocalTime = true + ) { var extMapping = new ExtendedMappings(); extMapping.LoadMappings(""); @@ -48,8 +61,7 @@ public static string ExecuteMappings(EdiObject edi, EDIFileInfo fileInfo, List /// All known GS1 providers of Strom /// - public ISet STROM { get; } = new HashSet - { - // Strom provider IDs - "4033872000041", - "4038777000004", - "4041408000007", - "4041409000006", - "4042322000005", - "4042322000005", - "4042805002007", - "4043581000027", - "4045399000060", - "4048454000005", - "4260016040025", - "4260016040032", - "4260154980047", - "4260154980115", - "4260400590006", - "4399901903883", - "4399902034364", - "4399902114356", - "4399902196468", - "4399902232050" - }; + public ISet STROM { get; } = + new HashSet + { + // Strom provider IDs + "4033872000041", + "4038777000004", + "4041408000007", + "4041409000006", + "4042322000005", + "4042322000005", + "4042805002007", + "4043581000027", + "4045399000060", + "4048454000005", + "4260016040025", + "4260016040032", + "4260154980047", + "4260154980115", + "4260400590006", + "4399901903883", + "4399902034364", + "4399902114356", + "4399902196468", + "4399902232050", + }; + /// /// All known GS1 providers of Gas /// - public ISet GAS { get; } = new HashSet - { - // Gas provider IDs - "4041408700013", - "4042322100002", - "4042322100002", - "4042805000607", - "4043581000041", - "4048454000012", - "4260016042005", - "4043581000034" - }; + public ISet GAS { get; } = + new HashSet + { + // Gas provider IDs + "4041408700013", + "4042322100002", + "4042322100002", + "4042805000607", + "4043581000041", + "4048454000012", + "4260016042005", + "4043581000034", + }; /// /// All known marktpartnerIds of Water /// public ISet WASSER { get; set; } = new HashSet(); } + public enum Sparte { STROM, GAS, WASSER, - ABWASSER + ABWASSER, } /// @@ -71,7 +74,6 @@ public enum Sparte /// public class SpartenHelper : IDivisionResolver { - private static readonly Sparten sparten = new(); /// diff --git a/EDILibrary/IEdiObject.cs b/EDILibrary/IEdiObject.cs index bf45630..cfde062 100644 --- a/EDILibrary/IEdiObject.cs +++ b/EDILibrary/IEdiObject.cs @@ -4,25 +4,24 @@ using System.Runtime.Serialization; using System.Text; using System.Xml.Linq; - using Newtonsoft.Json; using Newtonsoft.Json.Linq; + namespace EDILibrary { - [Obsolete("Use " + nameof(EdiObject) + " instead.", true)] // ReSharper disable once InconsistentNaming - public class IEdiObject - { - } + public class IEdiObject { } [DataContract] public class EdiObject { [DataMember] public string Name { get; set; } + [DataMember] public string MigName { get; set; } + [DataMember] public string Key { get; set; } @@ -30,22 +29,31 @@ public class EdiObject public string Edi { get; set; } public EdiObject Parent { get; private set; } XElement template; + [DataMember] public List Children { get; set; } public List SelfOrChildren { - get { var list = Children.Take(Children.Count).ToList(); list.Add(this); return list; } + get + { + var list = Children.Take(Children.Count).ToList(); + list.Add(this); + return list; + } } + [DataMember] public Dictionary> Fields { get; set; } + [DataMember] public Dictionary MigFields { get; set; } + [DataMember] public Dictionary EdiFields { get; set; } - public EdiObject(EDIEnums enumValue, XElement temp, string keyValue) : this(EDIEnumHelper.GetDescription(enumValue), temp, keyValue) - { - } + public EdiObject(EDIEnums enumValue, XElement temp, string keyValue) + : this(EDIEnumHelper.GetDescription(enumValue), temp, keyValue) { } + public EdiObject(string name, XElement temp, string keyValue) { Name = name; @@ -55,8 +63,8 @@ public EdiObject(string name, XElement temp, string keyValue) EdiFields = new Dictionary(); template = temp; Key = keyValue; - } + protected static string GenerateKey(string objectName) { switch (objectName) @@ -64,19 +72,18 @@ protected static string GenerateKey(string objectName) case "Dokument": case "Nachricht": case "Vorgang": - { - return Guid.NewGuid().ToString("N").Substring(0, 13).ToUpper(); - } + { + return Guid.NewGuid().ToString("N").Substring(0, 13).ToUpper(); + } default: - { - return null; - } + { + return null; + } } } protected void ParseJSON(dynamic json) { - foreach (var child in json.Children()) { if (child.Value.GetType() == typeof(JArray)) @@ -99,13 +106,28 @@ protected void ParseJSON(dynamic json) foreach (var childprop in (child.Value as JObject).Properties()) { //only allow one nest level, so only strings allowed here - if (childprop.Value != null && (childprop.Value.Type == JTokenType.Float)) + if ( + childprop.Value != null + && (childprop.Value.Type == JTokenType.Float) + ) { - Fields.Add(child.Name + "." + childprop.Name, new List { childprop.Value.Value().ToString() }); + Fields.Add( + child.Name + "." + childprop.Name, + new List { childprop.Value.Value().ToString() } + ); } - else if (childprop.Value != null && (childprop.Value.Type == JTokenType.String || childprop.Value.Type == JTokenType.Integer)) + else if ( + childprop.Value != null + && ( + childprop.Value.Type == JTokenType.String + || childprop.Value.Type == JTokenType.Integer + ) + ) { - Fields.Add(child.Name + "." + childprop.Name, new List { childprop.Value.Value() }); + Fields.Add( + child.Name + "." + childprop.Name, + new List { childprop.Value.Value() } + ); } } } @@ -113,7 +135,10 @@ protected void ParseJSON(dynamic json) { if (child.Value.Type == JTokenType.Float) { - Fields.Add(child.Name, new List { child.Value.ToString("0.00######") }); + Fields.Add( + child.Name, + new List { child.Value.ToString("0.00######") } + ); } else { @@ -122,8 +147,8 @@ protected void ParseJSON(dynamic json) } } } - } + public static EdiObject CreateFromJSON(string JSON) { dynamic json = JsonConvert.DeserializeObject(JSON); @@ -137,6 +162,7 @@ public override string ToString() { return Name + " " + Key; } + protected static void Recurse(XElement elem, EdiObject child) { foreach (var (key, value) in child.Fields) @@ -155,11 +181,14 @@ protected static void Recurse(XElement elem, EdiObject child) elem.Add(ch); } } + protected static string escapeSpecialChars(string value) { return value.Replace("\"", "\\\""); } + protected StringBuilder _builder; + protected void RecurseJSON(EdiObject cur) { var hasKey = false; @@ -169,9 +198,14 @@ protected void RecurseJSON(EdiObject cur) if (cur.Key != null) { hasKey = true; - _builder.AppendLine("\"" + "Key" + "\" : \"" + cur.Key + "\"" + (i != 0 || hasClass ? "," : "")); + _builder.AppendLine( + "\"" + "Key" + "\" : \"" + cur.Key + "\"" + (i != 0 || hasClass ? "," : "") + ); } - if (cur.Fields.Count(f => f.Value.Count > 1) == cur.Fields.Count && cur.Fields.Any(f => f.Value.Count > 1)) // check for multiple values + if ( + cur.Fields.Count(f => f.Value.Count > 1) == cur.Fields.Count + && cur.Fields.Any(f => f.Value.Count > 1) + ) // check for multiple values { var index = 0; var oldI = i; @@ -180,7 +214,14 @@ protected void RecurseJSON(EdiObject cur) foreach (var (key, value) in cur.Fields) { i--; - _builder.AppendLine("\"" + key + "\" : \"" + escapeSpecialChars(value.ElementAt(index)) + "\"" + (i != 0 || hasClass ? "," : "")); + _builder.AppendLine( + "\"" + + key + + "\" : \"" + + escapeSpecialChars(value.ElementAt(index)) + + "\"" + + (i != 0 || hasClass ? "," : "") + ); } i = oldI; if (index + 1 < cur.Fields.First(f => f.Value.Count > 1).Value.Count) @@ -196,8 +237,17 @@ protected void RecurseJSON(EdiObject cur) foreach (var (key, value) in cur.Fields) { i--; - _builder.AppendLine("\"" + key + "\" : \"" + escapeSpecialChars(value.Where(v => !string.IsNullOrWhiteSpace(v)).FirstOrDefault() ?? "") + "\"" + (i != 0 || hasClass ? "," : "")); - + _builder.AppendLine( + "\"" + + key + + "\" : \"" + + escapeSpecialChars( + value.Where(v => !string.IsNullOrWhiteSpace(v)).FirstOrDefault() + ?? "" + ) + + "\"" + + (i != 0 || hasClass ? "," : "") + ); } } var j = cur.Children.Count; @@ -205,18 +255,24 @@ protected void RecurseJSON(EdiObject cur) { if (!hasKey) { - string key;// = ""; + string key; // = ""; if (cur.Key != null) { - key = "\"" + "Key" + "\" : \"" + cur.Key + "\"" + (i != 0 || hasClass ? "," : ""); + key = + "\"" + + "Key" + + "\" : \"" + + cur.Key + + "\"" + + (i != 0 || hasClass ? "," : ""); } else { - key = "\"" + "Key" + "\" : \"" + "" + "\"" + (i != 0 || hasClass ? "," : ""); + key = + "\"" + "Key" + "\" : \"" + "" + "\"" + (i != 0 || hasClass ? "," : ""); } _builder.AppendLine(key); } - } var lastName = ""; var openElement = false; @@ -247,6 +303,7 @@ protected void RecurseJSON(EdiObject cur) _builder.AppendLine("]" + (j != 0 ? "," : "")); } } + protected void RecurseJSON(XElement cur) { var hasKey = false; @@ -256,31 +313,50 @@ protected void RecurseJSON(XElement cur) if (cur.Attribute("key") != null) { hasKey = true; - _builder.AppendLine("\"" + "Key" + "\" : \"" + cur.Attribute("key").Value + "\"" + (i != 0 || hasClass ? "," : "")); + _builder.AppendLine( + "\"" + + "Key" + + "\" : \"" + + cur.Attribute("key").Value + + "\"" + + (i != 0 || hasClass ? "," : "") + ); } foreach (var elem in cur.Descendants("Field").Where(d => d.Parent == cur)) { i--; - _builder.AppendLine("\"" + elem.Attribute("name").Value + "\" : \"" + elem.Value + "\"" + (i != 0 || hasClass ? "," : "")); - + _builder.AppendLine( + "\"" + + elem.Attribute("name").Value + + "\" : \"" + + elem.Value + + "\"" + + (i != 0 || hasClass ? "," : "") + ); } var j = cur.Descendants("Class").Count(d => d.Parent == cur); if (j == 0 && cur.Descendants("Field").All(d => d.Parent != cur)) // bei keinen fields und classes einen Key einfügen (momentan nur für Kontakt notwendig) { if (!hasKey) { - string key;// = ""; + string key; // = ""; if (cur.Attribute("key") != null) { - key = "\"" + "Key" + "\" : \"" + cur.Attribute("key").Value + "\"" + (i != 0 || hasClass ? "," : ""); + key = + "\"" + + "Key" + + "\" : \"" + + cur.Attribute("key").Value + + "\"" + + (i != 0 || hasClass ? "," : ""); } else { - key = "\"" + "Key" + "\" : \"" + "" + "\"" + (i != 0 || hasClass ? "," : ""); + key = + "\"" + "Key" + "\" : \"" + "" + "\"" + (i != 0 || hasClass ? "," : ""); } _builder.AppendLine(key); } - } foreach (var elem in cur.Descendants("Class").Where(d => d.Parent == cur)) { @@ -290,6 +366,7 @@ protected void RecurseJSON(XElement cur) _builder.AppendLine("}]" + (j != 0 ? "," : "")); } } + public string Serialize() { var root = new XElement("EDIFACT"); @@ -307,14 +384,17 @@ public string SerializeToJSON() _builder.Replace("\\\\\"", "\\\""); return _builder.ToString(); } + public bool ContainsField(string name) { return Fields.ContainsKey(name); } + public bool ContainsField(EDIEnums enumValue) { return Fields.ContainsKey(EDIEnumHelper.GetDescription(enumValue)); } + public string[] FieldList(EDIEnums enumValue) { if (Fields.ContainsKey(EDIEnumHelper.GetDescription(enumValue))) @@ -324,6 +404,7 @@ public string[] FieldList(EDIEnums enumValue) return null; } + public string[] FieldList(string name) { if (Fields.ContainsKey(name)) @@ -333,6 +414,7 @@ public string[] FieldList(string name) return null; } + public string Field(EDIEnums enumValue) { if (Fields.ContainsKey(EDIEnumHelper.GetDescription(enumValue))) @@ -342,6 +424,7 @@ public string Field(EDIEnums enumValue) return null; } + public string Field(string name) { if (Fields.ContainsKey(name)) @@ -361,6 +444,7 @@ public string Field(EDIEnums enumValue, int index) return null; } + public void AddField(EDIEnums enumValue, string value) { if (Fields.ContainsKey(EDIEnumHelper.GetDescription(enumValue))) @@ -372,22 +456,31 @@ public void AddField(EDIEnums enumValue, string value) Fields.Add(EDIEnumHelper.GetDescription(enumValue), new List { value }); } } + public EdiObject Child(EDIEnums name, string key) { return Child(EDIEnumHelper.GetDescription(name), key); } + public EdiObject Child(EDIEnums name) { return Child(EDIEnumHelper.GetDescription(name)); } + public EdiObject Child(string name, string key) { - return (from child in Children where child.Name == name && child.Key == key select child).FirstOrDefault(); + return ( + from child in Children + where child.Name == name && child.Key == key + select child + ).FirstOrDefault(); } + public EdiObject Child(string name) { return (from child in Children where child.Name == name select child).FirstOrDefault(); } + public void AddChild(EdiObject child) { if (child == null) @@ -398,30 +491,41 @@ public void AddChild(EdiObject child) child.Parent = this; Children.Add(child); } + public bool ContainsChild(EDIEnums name, string key) { return ContainsChild(EDIEnumHelper.GetDescription(name), key); } + public bool ContainsChild(EDIEnums name) { return ContainsChild(EDIEnumHelper.GetDescription(name)); } + public bool ContainsChild(string name, string key) { - return (from child in Children where child.Name == name && child.Key == key select child).Any(); + return ( + from child in Children + where child.Name == name && child.Key == key + select child + ).Any(); } + public bool ContainsChild(string name) { return (from child in Children where child.Name == name select child).Any(); } + public void RemoveField(string name) { Fields.Remove(name); } + public void RemoveChilds(EDIEnums name) { RemoveChilds(EDIEnumHelper.GetDescription(name)); } + public void RemoveChilds(string name) { var children = (from child in Children where child.Name == name select child).ToList(); @@ -430,14 +534,17 @@ public void RemoveChilds(string name) Children.Remove(child); } } + public List Childs(EDIEnums name) { return Childs(EDIEnumHelper.GetDescription(name)); } + public List Childs(string name) { return (from child in Children where child.Name == name select child).ToList(); } + public EdiObject Clone() { var clone = new EdiObject(Name, null, Key); diff --git a/EDILibrary/Interfaces/Anwendungshandbuch.cs b/EDILibrary/Interfaces/Anwendungshandbuch.cs index ff6029c..0c7e1a8 100644 --- a/EDILibrary/Interfaces/Anwendungshandbuch.cs +++ b/EDILibrary/Interfaces/Anwendungshandbuch.cs @@ -2,7 +2,6 @@ namespace EDILibrary.MAUS { - public class Anwendungshandbuch { public List Lines { get; set; } @@ -11,7 +10,7 @@ public class Anwendungshandbuch //public class Line //{ - // [System.Text.Json.Serialization.JsonPropertyName("ahb_expression")] + // [System.Text.Json.Serialization.JsonPropertyName("ahb_expression")] // public string AhbExpression { get; set; } // public string Discriminator { get; set; } // [System.Text.Json.Serialization.JsonPropertyName("segment_groups")] @@ -24,6 +23,7 @@ public class SegmentGroup [System.Text.Json.Serialization.JsonPropertyName("ahb_expression")] public string AhbExpression { get; set; } public string Discriminator { get; set; } + [System.Text.Json.Serialization.JsonPropertyName("segment_groups")] public List SegmentGroups { get; set; } public List Segments { get; set; } @@ -32,9 +32,11 @@ public class SegmentGroup public class Segment { public string AhbExpression { get; set; } + [System.Text.Json.Serialization.JsonPropertyName("data_elements")] public List DataElements { get; set; } public string Discriminator { get; set; } + [System.Text.Json.Serialization.JsonPropertyName("section_name")] public string SectionName { get; set; } } @@ -44,15 +46,16 @@ public class DataElement [System.Text.Json.Serialization.JsonPropertyName("data_element_id")] public string DataElementId { get; set; } public string Discriminator { get; set; } - } public class FreeText : DataElement { [System.Text.Json.Serialization.JsonPropertyName("ahb_expression")] public string AhbExpression { get; set; } + [System.Text.Json.Serialization.JsonPropertyName("entered_input")] public string EnteredInput { get; set; } + [System.Text.Json.Serialization.JsonPropertyName("value_type")] public ValueType? ValueType { get; set; } } @@ -61,6 +64,7 @@ public class DataElementValuePool : DataElement { [System.Text.Json.Serialization.JsonPropertyName("value_pool")] public List ValuePool { get; set; } + [System.Text.Json.Serialization.JsonPropertyName("value_type")] public ValueType? ValueType { get; set; } } @@ -69,6 +73,7 @@ public class ValuePoolElement { [System.Text.Json.Serialization.JsonPropertyName("ahb_expression")] public string AhbExpression { get; set; } + [System.Text.Json.Serialization.JsonPropertyName("edifact_key")] public string EdifactKey { get; set; } public string Meaning { get; set; } @@ -79,5 +84,10 @@ public class Meta public string Pruefidentifikator { get; set; } } - public enum ValueType { Datetime, Text, ValuePool }; + public enum ValueType + { + Datetime, + Text, + ValuePool, + }; } diff --git a/EDILibrary/Interfaces/IDivisionResolver.cs b/EDILibrary/Interfaces/IDivisionResolver.cs index 55d9aa4..8934206 100644 --- a/EDILibrary/Interfaces/IDivisionResolver.cs +++ b/EDILibrary/Interfaces/IDivisionResolver.cs @@ -17,9 +17,6 @@ public interface IDivisionResolver /// the 13 digit market partner ID of the sending marktpartner /// the 13 digit market partner ID of the sending marktpartner /// the sparte - public Sparte GetSparte( - string? senderMarketPartnerId, - string? receiverMarketPartnerId - ); + public Sparte GetSparte(string? senderMarketPartnerId, string? receiverMarketPartnerId); } } diff --git a/EDILibrary/Interfaces/ITemplateLoader.cs b/EDILibrary/Interfaces/ITemplateLoader.cs index 5c968f4..5da0d5e 100644 --- a/EDILibrary/Interfaces/ITemplateLoader.cs +++ b/EDILibrary/Interfaces/ITemplateLoader.cs @@ -9,6 +9,7 @@ public interface ITemplateLoader { Task LoadEDITemplate(EDIFileInfo info, string type); Task LoadJSONTemplate(string fileName); + /// /// todo @JoschaMetze add docstring /// @@ -17,6 +18,7 @@ public interface ITemplateLoader /// /// Task LoadJSONTemplate(EdifactFormat? format, string version, string fileName); + /// /// Loads a MAUS template file from the storage provider /// @@ -24,7 +26,11 @@ public interface ITemplateLoader /// e.g. 5.2h /// The pruefidentifikator (e.g. 11001) /// the deserialized anwendungshandbuch - Task LoadMausTemplate(EdifactFormat? format, EdifactFormatVersion version, string pid); + Task LoadMausTemplate( + EdifactFormat? format, + EdifactFormatVersion version, + string pid + ); [Obsolete("Use strongly typed overload")] Task LoadJSONTemplate(string formatPackage, string fileName); diff --git a/EDILibrary/Interfaces/TemplateLoaderExtensions.cs b/EDILibrary/Interfaces/TemplateLoaderExtensions.cs index e10648b..b9cdcd1 100644 --- a/EDILibrary/Interfaces/TemplateLoaderExtensions.cs +++ b/EDILibrary/Interfaces/TemplateLoaderExtensions.cs @@ -21,20 +21,41 @@ public static class TemplateLoaderExtensions /// The MAUS matching the params or any maus younger than plus the actual format version of the loaded maus. /// The latter can be used to e.g. log a warning in the application if the requested maus was not found and a fallback is used. /// - public static async Task> LoadMausTemplateOrFallback(this ITemplateLoader loader, EdifactFormat format, EdifactFormatVersion formatVersion, string pid) + public static async Task< + Tuple + > LoadMausTemplateOrFallback( + this ITemplateLoader loader, + EdifactFormat format, + EdifactFormatVersion formatVersion, + string pid + ) { - var originalRequestedTemplate = await loader.LoadMausTemplate(format, formatVersion, pid); + var originalRequestedTemplate = await loader.LoadMausTemplate( + format, + formatVersion, + pid + ); if (originalRequestedTemplate is not null) { - return new Tuple(originalRequestedTemplate, formatVersion); + return new Tuple( + originalRequestedTemplate, + formatVersion + ); } - foreach (var olderFormatVersion in Enum.GetValues().Where(fv => fv < formatVersion).OrderByDescending(fv => fv)) + foreach ( + var olderFormatVersion in Enum.GetValues() + .Where(fv => fv < formatVersion) + .OrderByDescending(fv => fv) + ) { var olderMaus = await loader.LoadMausTemplate(format, olderFormatVersion, pid); if (olderMaus != null) { // Using the {PID} maus from format version {olderFormatVersion} as fallback for the requested {formatVersion} (DEV-20190), pid, olderFormatVersion, formatVersion); - return new Tuple(olderMaus, olderFormatVersion); + return new Tuple( + olderMaus, + olderFormatVersion + ); } if (olderFormatVersion == EdifactFormatVersion.FV1710) diff --git a/EDILibrary/StringSplitEnhacement.cs b/EDILibrary/StringSplitEnhacement.cs index 678689e..02402d1 100644 --- a/EDILibrary/StringSplitEnhacement.cs +++ b/EDILibrary/StringSplitEnhacement.cs @@ -6,10 +6,9 @@ namespace EDILibrary { public static class StringExtensions { - - // the string.Split() method from .NET tend to run out of memory on 80 Mb strings. - // this has been reported several places online. - // This version is fast and memory efficient and return no empty lines. + // the string.Split() method from .NET tend to run out of memory on 80 Mb strings. + // this has been reported several places online. + // This version is fast and memory efficient and return no empty lines. public static List LowMemSplit(this string s, string seperator) { var list = new List(); @@ -60,6 +59,7 @@ public ref struct LineSplitEnumerator { private ReadOnlySpan _str; private char separator; + public LineSplitEnumerator(ReadOnlySpan str, char separator) { _str = str; diff --git a/EDILibrary/TemplateHelper.cs b/EDILibrary/TemplateHelper.cs index 9b0e2e2..1f07b47 100644 --- a/EDILibrary/TemplateHelper.cs +++ b/EDILibrary/TemplateHelper.cs @@ -11,11 +11,15 @@ namespace EDILibrary { public class TemplateHelper { - - private static readonly Regex FormatVersionRegex = new(@"^(?[A-Z]{6,7})(?[A-Z]?\d+\.\d+[a-z]?)$"); - - private static void ParseAPERAKString(string aperak, out string dataType, out int length, - out List list) + private static readonly Regex FormatVersionRegex = + new(@"^(?[A-Z]{6,7})(?[A-Z]?\d+\.\d+[a-z]?)$"); + + private static void ParseAPERAKString( + string aperak, + out string dataType, + out int length, + out List list + ) { dataType = null; list = null; @@ -31,8 +35,10 @@ private static void ParseAPERAKString(string aperak, out string dataType, out in if (valueIndex > -1) { maxLength = valueIndex; - var valueListString = - aperak.Substring(valueIndex + 1, aperak.IndexOf('}', valueIndex) - valueIndex - 1); + var valueListString = aperak.Substring( + valueIndex + 1, + aperak.IndexOf('}', valueIndex) - valueIndex - 1 + ); list = new List(valueListString.Split(".".ToCharArray())); } @@ -46,7 +52,6 @@ private static void ParseAPERAKString(string aperak, out string dataType, out in } } - private static void Recurse(XElement cur, JArray refObj, TreeElement tree) { var i = cur.Descendants("field").Count(d => d.Parent == cur); @@ -179,13 +184,20 @@ private static void Recurse(XElement cur, JArray refObj, TreeElement tree) { try { - var key = elements[int.Parse(refKeys[1]) - 1].Split('*')[int.Parse(refKeys[2]) + 1]; + var key = elements[int.Parse(refKeys[1]) - 1].Split('*')[ + int.Parse(refKeys[2]) + 1 + ]; if (key.Contains("|")) { key = key.Split('|').First(); } - ParseAPERAKString(key, out var dataType, out var length, out var list); + ParseAPERAKString( + key, + out var dataType, + out var length, + out var list + ); if (meta.Property("typeInfo") == null) { meta.Add("typeInfo", dataType); @@ -228,27 +240,30 @@ private static void Recurse(XElement cur, JArray refObj, TreeElement tree) if (elem.Attribute("groupBy") != null) { var groupName = elem.Attribute("groupBy").Value; - var subGroup = refObj.Children().Where(child => - (child as JObject)?.Property("key")?.Value.Value() == groupName); + var subGroup = refObj + .Children() + .Where(child => + (child as JObject)?.Property("key")?.Value.Value() == groupName + ); if (subGroup.Any()) { if (elem.Attribute("groupKey")?.Value != null) { - (subGroup.First() as JObject).Property("_meta").Value.Value().Add("key", name); - } (subGroup.First() as JObject).Property("requires").Value.Value().Add(newField); + (subGroup.First() as JObject) + .Property("_meta") + .Value.Value() + .Add("key", name); + } + (subGroup.First() as JObject) + .Property("requires") + .Value.Value() + .Add(newField); } else { - var subObj = new JObject - { - {"key", groupName} - }; + var subObj = new JObject { { "key", groupName } }; var subArray = new JArray(); - var subMeta = new JObject - { - {"type", "group"}, - {"max", "1"} - }; + var subMeta = new JObject { { "type", "group" }, { "max", "1" } }; if (elem.Attribute("groupKey")?.Value != null) { subMeta.Add("key", name); @@ -274,10 +289,8 @@ private static void Recurse(XElement cur, JArray refObj, TreeElement tree) } var j = cur.Descendants("class").Count(d => d.Parent == cur); - if (j == 0 && !cur.Descendants("field").Any(d => d.Parent == cur) - ) // bei keinen fields und classes einen Key einfügen (momentan nur für Kontakt notwendig) - { - } + if (j == 0 && !cur.Descendants("field").Any(d => d.Parent == cur)) // bei keinen fields und classes einen Key einfügen (momentan nur für Kontakt notwendig) + { } foreach (var elem in cur.Descendants("class").Where(d => d.Parent == cur)) { @@ -307,7 +320,12 @@ private static void Recurse(XElement cur, JArray refObj, TreeElement tree) meta.Add("format", elem.Attribute("meta.format").Value); } - meta.Add("type", elem.Attribute("meta.type") != null ? elem.Attribute("meta.type").Value : "group"); + meta.Add( + "type", + elem.Attribute("meta.type") != null + ? elem.Attribute("meta.type").Value + : "group" + ); if (elem.Attribute("meta.objType") != null) { meta.Add("objType", elem.Attribute("meta.objType").Value); @@ -436,7 +454,11 @@ private static void Recurse(XElement cur, JArray refObj, TreeElement tree) } // Todo @JoschaMetze: add docstrings - public string ConvertFilesToJSON(string inputFileName, string outputFileName, string treeFileName) + public string ConvertFilesToJSON( + string inputFileName, + string outputFileName, + string treeFileName + ) { var srcXml = XElement.Parse(File.ReadAllText(inputFileName)); TreeElement tree = null; @@ -450,7 +472,6 @@ public string ConvertFilesToJSON(string inputFileName, string outputFileName, st ((tmp[0] as JObject)["_meta"] as JObject).Add("version", version); File.WriteAllText(outputFileName, JsonConvert.SerializeObject(tmp)); return JsonConvert.SerializeObject(tmp); - } /// @@ -461,7 +482,10 @@ public string ConvertFilesToJSON(string inputFileName, string outputFileName, st /// public static string RetrieveFormatVersionFromInputFileName(string inputFileName) { - var actualFileName = inputFileName.Split(new[] { ".template" }, StringSplitOptions.None)[0].Split(Path.DirectorySeparatorChar).Last(); + var actualFileName = inputFileName + .Split(new[] { ".template" }, StringSplitOptions.None)[0] + .Split(Path.DirectorySeparatorChar) + .Last(); var match = FormatVersionRegex.Match(actualFileName); if (match.Success) { @@ -470,9 +494,15 @@ public static string RetrieveFormatVersionFromInputFileName(string inputFileName if (inputFileName.Contains(".create.template")) { - throw new ArgumentException("Pass the name of the \".template\" file, not \".create.template\"", nameof(inputFileName)); + throw new ArgumentException( + "Pass the name of the \".template\" file, not \".create.template\"", + nameof(inputFileName) + ); } - throw new ArgumentException($"Format version could not be determined: {actualFileName}", nameof(inputFileName)); + throw new ArgumentException( + $"Format version could not be determined: {actualFileName}", + nameof(inputFileName) + ); } // the format version will be written to the json template file, thus needs to be passed diff --git a/EDILibrary/TreeElement.cs b/EDILibrary/TreeElement.cs index edca6cb..29f6b32 100644 --- a/EDILibrary/TreeElement.cs +++ b/EDILibrary/TreeElement.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Security.Cryptography; using System.Text; + namespace EDILibrary { public class TreeElement : IDisposable @@ -19,10 +20,12 @@ public class TreeElement : IDisposable public string APERAK_Status; public string CONTRL_Check_String; public string APERAK_Check_String; + public static string ExtractName(string name) { return name.Contains("_") ? name.Substring(0, name.IndexOf('_')) : name; } + public void AddChild(TreeElement child) { child.Parent = this; @@ -41,11 +44,13 @@ public void AddChild(TreeElement child) } } } + public TreeElement AddEdi(string edi, TreeElement currentRoot) { Edi.Add(edi); return Parent; } + public TreeElement(TreeElement old) { Name = old.Name; @@ -57,10 +62,12 @@ public TreeElement(TreeElement old) APERAK_Status = old.APERAK_Status; CONTRL_Check_String = old.CONTRL_Check_String; APERAK_Check_String = old.APERAK_Check_String; - foreach (var newChild in old.Children.Values.Select(child => new TreeElement(child) - { - Parent = this - })) + foreach ( + var newChild in old.Children.Values.Select(child => new TreeElement(child) + { + Parent = this, + }) + ) { if (newChild.Name.StartsWith("SG") || newChild.Name == "UNH") { @@ -91,6 +98,7 @@ public TreeElement(TreeElement old) Edi = new List(); Dirty = old.Dirty; } + public TreeElement(string name, int lineCounter = -1) { if (name.Contains('[')) @@ -123,7 +131,13 @@ public TreeElement(string name, int lineCounter = -1) Occurence = 0; Key = false; } - public void FindElements(string name, bool recursive, ref List list, int recursionDepth = int.MaxValue) + + public void FindElements( + string name, + bool recursive, + ref List list, + int recursionDepth = int.MaxValue + ) { if (Name == name) { @@ -180,7 +194,9 @@ public TreeElement FindElement(string name, bool recursive = true) if (recursive) { - return Children.Values.Select(child => child.FindElement(name)).FirstOrDefault(ret => ret != null); + return Children + .Values.Select(child => child.FindElement(name)) + .FirstOrDefault(ret => ret != null); } return null; } @@ -199,13 +215,18 @@ public TreeElement this[string name] set { Children[ExtractName(name)] = value; } } } + public class TreeHelper { public Dictionary treeCopyMap = new Dictionary(); public TreeElement treeRoot; + public void RefreshDirtyFlags(TreeElement root) { - var children = from elem in root.Children.Values where elem.Dirty && !elem.Children.Any() select elem; + var children = + from elem in root.Children.Values + where elem.Dirty && !elem.Children.Any() + select elem; if (!children.Any()) { root.Dirty = false; @@ -218,9 +239,10 @@ public void RefreshDirtyFlags(TreeElement root) treeRoot = null; treeCopyMap = new Dictionary(); } + public TreeElement FindEdiElement(ref TreeElement root, string segment) { - TreeElement oldRoot;// = null; + TreeElement oldRoot; // = null; var segName = segment.LowMemSplit("+").First(); /*if (segName.StartsWith("UNS")) { @@ -235,8 +257,11 @@ public TreeElement FindEdiElement(ref TreeElement root, string segment) //foreach (TreeElement child in root.Children.Values) // child.Dirty = true; } - TreeElement ele;// = null; - if (treeCopyMap.ContainsKey(root.Name) && treeCopyMap[root.Name].Occurence != root.Occurence) + TreeElement ele; // = null; + if ( + treeCopyMap.ContainsKey(root.Name) + && treeCopyMap[root.Name].Occurence != root.Occurence + ) { var linkRoot = treeCopyMap[root.Name]; ele = FindEdiElement(ref linkRoot, segment); @@ -267,7 +292,9 @@ public TreeElement FindEdiElement(ref TreeElement root, string segment) var child = treeRoot; treeRoot = copy; //bei UNH muss ich dann schon die Anzahl der UNH-Kinder zählen und die Occurence manuell setzen - var unhCounter = root.Children.Values.Count(tempChild => tempChild.Name.StartsWith("UNH")); + var unhCounter = root.Children.Values.Count(tempChild => + tempChild.Name.StartsWith("UNH") + ); foreach (var c in child.Children.Values) { c.Dirty = false; @@ -285,11 +312,9 @@ public TreeElement FindEdiElement(ref TreeElement root, string segment) root = child; return child; } - } if (root.Children[segName].Key) { - var child = root.Children[segName]; if (child.Parent.Name != "/" && child.Parent.Name != "UNH") { @@ -350,9 +375,11 @@ public TreeElement FindEdiElement(ref TreeElement root, string segment) //System.Diagnostics.Debug.Assert(root != null, segment, oldRoot.ToString()); return null; } + // static SHA1 hash = System.Security.Cryptography.SHA1.Create(); HashAlgorithm hash = Murmur.MurmurHash.Create128(seed: (uint)new DateTime().Ticks); UnicodeEncoding UE = new UnicodeEncoding(); + public string GetHash(string TextToHash) { //Prüfen ob Daten übergeben wurden. @@ -370,6 +397,7 @@ public string GetHash(string TextToHash) return BitConverter.ToString(result); } + public bool CleanTree(TreeElement ele) { if (ele.Edi.Count == 0 && ele.Children.Count == 0) diff --git a/EDILibraryTests/EDIHelperTests.cs b/EDILibraryTests/EDIHelperTests.cs index 5f04ede..7428847 100644 --- a/EDILibraryTests/EDIHelperTests.cs +++ b/EDILibraryTests/EDIHelperTests.cs @@ -41,22 +41,26 @@ public void TestRemoveBOM(string raw, string expectedResult, bool legacySupporte [DataRow("foo", "UNA:+.? 'oo")] // todo: I doubt this is the correct behaviour. it's probably because of the deprecated "RemoveBOM" function [DataRow("asd", "UNA:+.? 'sd")] // todo: I doubt this is the correct behaviour. it's probably because of the deprecated "RemoveBOM" function [DataRow("Usd", "UNA:+.? 'Usd")] // todo: I doubt this is the correct behaviour. it's probably because of the deprecated "RemoveBOM" function - [DataRow("UNH+WIM00000000901+UTILMD:D:11A:UN:5.2b", "UNA:+.? 'UNH+WIM00000000901+UTILMD:D:11A:UN:5.2b")] - [DataRow("UNA:+.? 'UNB+UNOC:3+123456789012345:500+123456789:500+210326:1553+WIM00000000901'UNH+WIM00000000901+UTILMD:D:11A:UN:5.2b'", - "UNA:+.? 'UNB+UNOC:3+123456789012345:500+123456789:500+210326:1553+WIM00000000901'UNH+WIM00000000901+UTILMD:D:11A:UN:5.2b'")] - [DataRow("UNA!;,= &UNB;UNOC!3;123456789012345!500;123456789!500;210326!1553;WIM00000000901&UNH;WIM00000000901;UTILMD!D!11A!UN!5,2b&", - "UNA:+.? 'UNB;UNOC!3;123456789012345!500;123456789!500;210326!1553;WIM00000000901&UNH;WIM00000000901;UTILMD!D!11A!UN!5.2b&")] // todo: I doubt this is the correct behaviour + [DataRow( + "UNH+WIM00000000901+UTILMD:D:11A:UN:5.2b", + "UNA:+.? 'UNH+WIM00000000901+UTILMD:D:11A:UN:5.2b" + )] + [DataRow( + "UNA:+.? 'UNB+UNOC:3+123456789012345:500+123456789:500+210326:1553+WIM00000000901'UNH+WIM00000000901+UTILMD:D:11A:UN:5.2b'", + "UNA:+.? 'UNB+UNOC:3+123456789012345:500+123456789:500+210326:1553+WIM00000000901'UNH+WIM00000000901+UTILMD:D:11A:UN:5.2b'" + )] + [DataRow( + "UNA!;,= &UNB;UNOC!3;123456789012345!500;123456789!500;210326!1553;WIM00000000901&UNH;WIM00000000901;UTILMD!D!11A!UN!5,2b&", + "UNA:+.? 'UNB;UNOC!3;123456789012345!500;123456789!500;210326!1553;WIM00000000901&UNH;WIM00000000901;UTILMD!D!11A!UN!5.2b&" + )] // todo: I doubt this is the correct behaviour public void TestNormalizeEdiHeader(string input, string expectedResult) { var actual = EDIHelper.NormalizeEDIHeader(input); Assert.AreEqual(expectedResult, actual); } - private static readonly JsonSerializerOptions JsonFieldOptions = new() - { - IncludeFields = true, - Converters = { new JsonStringEnumConverter() } - }; + private static readonly JsonSerializerOptions JsonFieldOptions = + new() { IncludeFields = true, Converters = { new JsonStringEnumConverter() } }; /// /// Tests @@ -66,20 +70,24 @@ public void TestNormalizeEdiHeader(string input, string expectedResult) [DataRow("foo", "{\"Format\":null}")] [DataRow( "UNA:+.? 'UNB+UNOC:3+123456789012345:500+123456789:500+210326:1553+WIM00000000901'UNH+WIM00000000901+UTILMD:D:11A:UN:5.2b'BGM+E03+WIM00000000901'DTM+137:202103261553:203'NAD+MS+123456789012345::293'CTA+IC+:Max Mustermann'COM+max@mustermann.de:EM'NAD+MR+123456789::293'IDE+24+WIMP0000000459'DTM+92:20210401:102'DTM+157:20210401:102'STS+7++ZE8'LOC+172+41234567896'RFF+Z13:11116'SEQ+Z01'CCI+Z30++Z06'", - "{\"Format\":\"UTILMD\", \"Nachrichtenversion\":\"D\",\"Version\":\"5.2b\", \"Sender\":{\"CodeList\":\"500\",\"ID\":\"123456789012345\"}, \"Freigabenummer\":\"11A\", \"Empfänger\":{\"CodeList\":\"500\",\"ID\":\"123456789\"}, \"ID\":\"WIM00000000901\"}")] + "{\"Format\":\"UTILMD\", \"Nachrichtenversion\":\"D\",\"Version\":\"5.2b\", \"Sender\":{\"CodeList\":\"500\",\"ID\":\"123456789012345\"}, \"Freigabenummer\":\"11A\", \"Empfänger\":{\"CodeList\":\"500\",\"ID\":\"123456789\"}, \"ID\":\"WIM00000000901\"}" + )] [DataRow( "UNA:+.?'UNB+UNOC:3+123456789012345:500+123456789:500+210326:1553+WIM00000000901'UNH+WIM00000000901+UTILMD:D:11A:UN:5.2b'BGM+E03+WIM00000000901'DTM+137:202103261553:203'NAD+MS+123456789012345::293'CTA+IC+:Max Mustermann'COM+max@mustermann.de:EM'NAD+MR+123456789::293'IDE+24+WIMP0000000459'DTM+92:20210401:102'DTM+157:20210401:102'STS+7++ZE8'LOC+172+41234567896'RFF+Z13:11116'SEQ+Z01'CCI+Z30++Z06'", - "{\"Format\":null}")] // wegen "UNA:+.?" ohne space vor "?" + "{\"Format\":null}" + )] // wegen "UNA:+.?" ohne space vor "?" [DataRow( "UNA:+.? 'UNB+UNOC:3+123456789012345:500+123456789:500+210326:1553+WIM00000000901'UNH+WIM00000000901+UTILMD:D:11A:UN:S1.1'BGM+E03+WIM00000000901'DTM+137:202103261553:203'NAD+MS+123456789012345::293'CTA+IC+:Max Mustermann'COM+max@mustermann.de:EM'NAD+MR+123456789::293'IDE+24+WIMP0000000459'DTM+92:20210401:102'DTM+157:20210401:102'STS+7++ZE8'LOC+172+41234567896'RFF+Z13:11116'SEQ+Z01'CCI+Z30++Z06'", - "{\"Format\":\"UTILMD\", \"Nachrichtenversion\":\"D\",\"Version\":\"S1.1\", \"Sender\":{\"CodeList\":\"500\",\"ID\":\"123456789012345\"}, \"Freigabenummer\":\"11A\", \"Empfänger\":{\"CodeList\":\"500\",\"ID\":\"123456789\"}, \"ID\":\"WIM00000000901\"}")] + "{\"Format\":\"UTILMD\", \"Nachrichtenversion\":\"D\",\"Version\":\"S1.1\", \"Sender\":{\"CodeList\":\"500\",\"ID\":\"123456789012345\"}, \"Freigabenummer\":\"11A\", \"Empfänger\":{\"CodeList\":\"500\",\"ID\":\"123456789\"}, \"ID\":\"WIM00000000901\"}" + )] [DataRow( "UNA:+.? 'UNB+UNOC:3+123456789012345:500+123456789:500+210326:1553+WIM00000000901'UNH+WIM00000000901+UTILMD:D:11A:UN:S1.1a'BGM+E03+WIM00000000901'DTM+137:202103261553:203'NAD+MS+123456789012345::293'CTA+IC+:Max Mustermann'COM+max@mustermann.de:EM'NAD+MR+123456789::293'IDE+24+WIMP0000000459'DTM+92:20210401:102'DTM+157:20210401:102'STS+7++ZE8'LOC+172+41234567896'RFF+Z13:11116'SEQ+Z01'CCI+Z30++Z06'", - "{\"Format\":\"UTILMD\", \"Nachrichtenversion\":\"D\",\"Version\":\"S1.1a\", \"Sender\":{\"CodeList\":\"500\",\"ID\":\"123456789012345\"}, \"Freigabenummer\":\"11A\", \"Empfänger\":{\"CodeList\":\"500\",\"ID\":\"123456789\"}, \"ID\":\"WIM00000000901\"}")] + "{\"Format\":\"UTILMD\", \"Nachrichtenversion\":\"D\",\"Version\":\"S1.1a\", \"Sender\":{\"CodeList\":\"500\",\"ID\":\"123456789012345\"}, \"Freigabenummer\":\"11A\", \"Empfänger\":{\"CodeList\":\"500\",\"ID\":\"123456789\"}, \"ID\":\"WIM00000000901\"}" + )] [DataRow( "UNA:+.? 'UNB+UNOC:3+L34SWH:500+L34SWH:500+210326:1553+WIM00000000901'UNH+WIM00000000901+UTILMD:D:11A:UN:G1.0a'BGM+E03+WIM00000000901'DTM+137:202103261553:203'NAD+MS+123456789012345::293'CTA+IC+:Max Mustermann'COM+max@mustermann.de:EM'NAD+MR+123456789::293'IDE+24+WIMP0000000459'DTM+92:20210401:102'DTM+157:20210401:102'STS+7++ZE8'LOC+172+41234567896'RFF+Z13:11116'SEQ+Z01'CCI+Z30++Z06'", - "{\"Format\":\"UTILMD\", \"Nachrichtenversion\":\"D\",\"Version\":\"G1.0a\", \"Sender\":{\"CodeList\":\"500\",\"ID\":\"L34SWH\"}, \"Freigabenummer\":\"11A\", \"Empfänger\":{\"CodeList\":\"500\",\"ID\":\"L34SWH\"}, \"ID\":\"WIM00000000901\"}")] - + "{\"Format\":\"UTILMD\", \"Nachrichtenversion\":\"D\",\"Version\":\"G1.0a\", \"Sender\":{\"CodeList\":\"500\",\"ID\":\"L34SWH\"}, \"Freigabenummer\":\"11A\", \"Empfänger\":{\"CodeList\":\"500\",\"ID\":\"L34SWH\"}, \"ID\":\"WIM00000000901\"}" + )] public void TestGetEdiFileInfo(string input, string expectedOutput) { var actual = EDIHelper.GetEdiFileInfo(input); @@ -89,7 +97,10 @@ public void TestGetEdiFileInfo(string input, string expectedOutput) } else { - var expected = JsonSerializer.Deserialize(expectedOutput, JsonFieldOptions); + var expected = JsonSerializer.Deserialize( + expectedOutput, + JsonFieldOptions + ); Assert.IsNotNull(expected); if (!expected.Format.HasValue) { @@ -111,23 +122,28 @@ public void TestGetEdiFileInfo(string input, string expectedOutput) [DataRow("foo", "{\"Format\":null}")] [DataRow( "UNA:+.? 'UNB+UNOC:3+123456789012345:500+123456789:500+210326:1553+WIM00000000901'UNH+WIM00000000901+UTILMD:D:11A:UN:5.2b'BGM+E03+WIM00000000901'DTM+137:202103261553:203'NAD+MS+123456789012345::293'CTA+IC+:Max Mustermann'COM+max@mustermann.de:EM'NAD+MR+123456789::293'IDE+24+WIMP0000000459'DTM+92:20210401:102'DTM+157:20210401:102'STS+7++ZE8'LOC+172+41234567896'RFF+Z13:11116'SEQ+Z01'CCI+Z30++Z06'", - "{\"Format\":\"UTILMD\", \"Nachrichtenversion\":\"D\",\"Version\":\"5.2b\", \"Sender\":{\"CodeList\":\"500\",\"ID\":\"123456789012345\"}, \"Freigabenummer\":\"11A\", \"Empfänger\":{\"CodeList\":\"500\",\"ID\":\"123456789\"}, \"ID\":\"WIM00000000901\"}")] + "{\"Format\":\"UTILMD\", \"Nachrichtenversion\":\"D\",\"Version\":\"5.2b\", \"Sender\":{\"CodeList\":\"500\",\"ID\":\"123456789012345\"}, \"Freigabenummer\":\"11A\", \"Empfänger\":{\"CodeList\":\"500\",\"ID\":\"123456789\"}, \"ID\":\"WIM00000000901\"}" + )] [DataRow( "UNA:+.?'UNB+UNOC:3+123456789012345:500+123456789:500+210326:1553+WIM00000000901'UNH+WIM00000000901+UTILMD:D:11A:UN:5.2b'BGM+E03+WIM00000000901'DTM+137:202103261553:203'NAD+MS+123456789012345::293'CTA+IC+:Max Mustermann'COM+max@mustermann.de:EM'NAD+MR+123456789::293'IDE+24+WIMP0000000459'DTM+92:20210401:102'DTM+157:20210401:102'STS+7++ZE8'LOC+172+41234567896'RFF+Z13:11116'SEQ+Z01'CCI+Z30++Z06'", - "{\"Format\":null}")] // wegen "UNA:+.?" ohne space vor "?" + "{\"Format\":null}" + )] // wegen "UNA:+.?" ohne space vor "?" [DataRow( "UNA:+.? 'UNB+UNOC:3+123456789012345:500+123456789:500+210326:1553+WIM00000000901'UNH+WIM00000000901+UTILMD:D:11A:UN:S1.1'BGM+E03+WIM00000000901'DTM+137:202103261553:203'NAD+MS+123456789012345::293'CTA+IC+:Max Mustermann'COM+max@mustermann.de:EM'NAD+MR+123456789::293'IDE+24+WIMP0000000459'DTM+92:20210401:102'DTM+157:20210401:102'STS+7++ZE8'LOC+172+41234567896'RFF+Z13:11116'SEQ+Z01'CCI+Z30++Z06'", - "{\"Format\":\"UTILMDS\", \"Nachrichtenversion\":\"D\",\"Version\":\"S1.1\", \"Sender\":{\"CodeList\":\"500\",\"ID\":\"123456789012345\"}, \"Freigabenummer\":\"11A\", \"Empfänger\":{\"CodeList\":\"500\",\"ID\":\"123456789\"}, \"ID\":\"WIM00000000901\"}")] + "{\"Format\":\"UTILMDS\", \"Nachrichtenversion\":\"D\",\"Version\":\"S1.1\", \"Sender\":{\"CodeList\":\"500\",\"ID\":\"123456789012345\"}, \"Freigabenummer\":\"11A\", \"Empfänger\":{\"CodeList\":\"500\",\"ID\":\"123456789\"}, \"ID\":\"WIM00000000901\"}" + )] [DataRow( "UNA:+.? 'UNB+UNOC:3+123456789012345:500+123456789:500+210326:1553+WIM00000000901'UNH+WIM00000000901+UTILMD:D:11A:UN:S1.1a'BGM+E03+WIM00000000901'DTM+137:202103261553:203'NAD+MS+123456789012345::293'CTA+IC+:Max Mustermann'COM+max@mustermann.de:EM'NAD+MR+123456789::293'IDE+24+WIMP0000000459'DTM+92:20210401:102'DTM+157:20210401:102'STS+7++ZE8'LOC+172+41234567896'RFF+Z13:11116'SEQ+Z01'CCI+Z30++Z06'", - "{\"Format\":\"UTILMDS\", \"Nachrichtenversion\":\"D\",\"Version\":\"S1.1a\", \"Sender\":{\"CodeList\":\"500\",\"ID\":\"123456789012345\"}, \"Freigabenummer\":\"11A\", \"Empfänger\":{\"CodeList\":\"500\",\"ID\":\"123456789\"}, \"ID\":\"WIM00000000901\"}")] + "{\"Format\":\"UTILMDS\", \"Nachrichtenversion\":\"D\",\"Version\":\"S1.1a\", \"Sender\":{\"CodeList\":\"500\",\"ID\":\"123456789012345\"}, \"Freigabenummer\":\"11A\", \"Empfänger\":{\"CodeList\":\"500\",\"ID\":\"123456789\"}, \"ID\":\"WIM00000000901\"}" + )] [DataRow( "UNA:+.? 'UNB+UNOC:3+L34SWH:500+L34SWH:500+210326:1553+WIM00000000901'UNH+WIM00000000901+UTILMD:D:11A:UN:G1.0a'BGM+E03+WIM00000000901'DTM+137:202103261553:203'NAD+MS+123456789012345::293'CTA+IC+:Max Mustermann'COM+max@mustermann.de:EM'NAD+MR+123456789::293'IDE+24+WIMP0000000459'DTM+92:20210401:102'DTM+157:20210401:102'STS+7++ZE8'LOC+172+41234567896'RFF+Z13:11116'SEQ+Z01'CCI+Z30++Z06'", - "{\"Format\":\"UTILMDW\", \"Nachrichtenversion\":\"D\",\"Version\":\"G1.0a\", \"Sender\":{\"CodeList\":\"500\",\"ID\":\"L34SWH\"}, \"Freigabenummer\":\"11A\", \"Empfänger\":{\"CodeList\":\"500\",\"ID\":\"L34SWH\"}, \"ID\":\"WIM00000000901\"}")] + "{\"Format\":\"UTILMDW\", \"Nachrichtenversion\":\"D\",\"Version\":\"G1.0a\", \"Sender\":{\"CodeList\":\"500\",\"ID\":\"L34SWH\"}, \"Freigabenummer\":\"11A\", \"Empfänger\":{\"CodeList\":\"500\",\"ID\":\"L34SWH\"}, \"ID\":\"WIM00000000901\"}" + )] [DataRow( "UNA:+.? 'UNB+UNOC:3+4041408700000:500+4043581000034:500+210326:1553+WIM00000000901'UNH+WIM00000000901+UTILMD:D:11A:UN:G1.0a'BGM+E03+WIM00000000901'DTM+137:202103261553:203'NAD+MS+123456789012345::293'CTA+IC+:Max Mustermann'COM+max@mustermann.de:EM'NAD+MR+123456789::293'IDE+24+WIMP0000000459'DTM+92:20210401:102'DTM+157:20210401:102'STS+7++ZE8'LOC+172+41234567896'RFF+Z13:11116'SEQ+Z01'CCI+Z30++Z06'", - "{\"Format\":\"UTILMDG\", \"Nachrichtenversion\":\"D\",\"Version\":\"G1.0a\", \"Sender\":{\"CodeList\":\"500\",\"ID\":\"4041408700000\"}, \"Freigabenummer\":\"11A\", \"Empfänger\":{\"CodeList\":\"500\",\"ID\":\"4043581000034\"}, \"ID\":\"WIM00000000901\"}")] - + "{\"Format\":\"UTILMDG\", \"Nachrichtenversion\":\"D\",\"Version\":\"G1.0a\", \"Sender\":{\"CodeList\":\"500\",\"ID\":\"4041408700000\"}, \"Freigabenummer\":\"11A\", \"Empfänger\":{\"CodeList\":\"500\",\"ID\":\"4043581000034\"}, \"ID\":\"WIM00000000901\"}" + )] public void TestGetEdiFileInfoNoMaskUTILMDX(string input, string expectedOutput) { var actual = EDIHelper.GetEdiFileInfo(input, maskUTILMDX: false); @@ -137,7 +153,10 @@ public void TestGetEdiFileInfoNoMaskUTILMDX(string input, string expectedOutput) } else { - var expected = JsonSerializer.Deserialize(expectedOutput, JsonFieldOptions); + var expected = JsonSerializer.Deserialize( + expectedOutput, + JsonFieldOptions + ); Assert.IsNotNull(expected); if (!expected.Format.HasValue) { diff --git a/EDILibraryTests/EdifactFormatVersionTests.cs b/EDILibraryTests/EdifactFormatVersionTests.cs index 21f6dc6..d7a7ab4 100644 --- a/EDILibraryTests/EdifactFormatVersionTests.cs +++ b/EDILibraryTests/EdifactFormatVersionTests.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using EDILibrary; - using Microsoft.VisualStudio.TestTools.UnitTesting; using NSubstitute; @@ -39,9 +38,17 @@ public void TestPruefiToFormat(string pruefi, EdifactFormat expectedFormat) [DataRow("55001", EdifactFormat.UTILMDS)] [DataRow("11001", EdifactFormat.UTILMDW, EdifactFormatVersion.FV2310)] [DataRow("11001", EdifactFormat.UTILMD)] - public void TestPruefiToFormatUnMaskUTILMDX(string pruefi, EdifactFormat expectedFormat, EdifactFormatVersion? formatPackage = null) + public void TestPruefiToFormatUnMaskUTILMDX( + string pruefi, + EdifactFormat expectedFormat, + EdifactFormatVersion? formatPackage = null + ) { - var actualFormat = EdifactFormatHelper.FromPruefidentifikator(pruefi, false, formatPackage); + var actualFormat = EdifactFormatHelper.FromPruefidentifikator( + pruefi, + false, + formatPackage + ); Assert.AreEqual(expectedFormat, actualFormat); } @@ -81,7 +88,9 @@ public void TestFormatVersionOrder() for (int j = i + 1; j < expectedNaturalOrder.Count; j++) { Assert.IsTrue(expectedNaturalOrder[i] < expectedNaturalOrder[j]); - Assert.IsTrue(comparer.Compare(expectedNaturalOrder[i], expectedNaturalOrder[j]) < 0); + Assert.IsTrue( + comparer.Compare(expectedNaturalOrder[i], expectedNaturalOrder[j]) < 0 + ); } } } @@ -89,14 +98,20 @@ public void TestFormatVersionOrder() [TestMethod] public void NoPruefiNoFormat() { - Assert.ThrowsException(() => EdifactFormatHelper.FromPruefidentifikator(null)); - Assert.ThrowsException(() => EdifactFormatHelper.FromPruefidentifikator(" ")); + Assert.ThrowsException( + () => EdifactFormatHelper.FromPruefidentifikator(null) + ); + Assert.ThrowsException( + () => EdifactFormatHelper.FromPruefidentifikator(" ") + ); } [TestMethod] public void UnmappedThrowsNotImplemented() { - Assert.ThrowsException(() => EdifactFormatHelper.FromPruefidentifikator("88888")); + Assert.ThrowsException( + () => EdifactFormatHelper.FromPruefidentifikator("88888") + ); } [TestMethod] @@ -115,7 +130,10 @@ public void UnmappedThrowsNotImplemented() [DataRow("04/24", EdifactFormatVersion.FV2404)] [DataRow("10/24", EdifactFormatVersion.FV2410)] [DataRow("04/25", EdifactFormatVersion.FV2504)] - public void TestLegacyStrings(string legacyString, EdifactFormatVersion expectedFormatVersion) + public void TestLegacyStrings( + string legacyString, + EdifactFormatVersion expectedFormatVersion + ) { var actualFormatVersion = legacyString.ToEdifactFormatVersion(); Assert.AreEqual(expectedFormatVersion, actualFormatVersion); @@ -165,7 +183,10 @@ public void TestMockingVersionProvider() [DataRow("2024-09-30T22:00:00+00:00", EdifactFormatVersion.FV2410)] [DataRow("2025-03-31T22:00:00+00:00", EdifactFormatVersion.FV2410)] [DataRow("2025-04-03T22:00:00+00:00", EdifactFormatVersion.FV2504)] - public void TestFormatVersionProvider(string dateTimeOffset, EdifactFormatVersion expectedVersion) + public void TestFormatVersionProvider( + string dateTimeOffset, + EdifactFormatVersion expectedVersion + ) { IEdifactFormatVersionProvider versionProvider = new EdifactFormatVersionHelper(); DateTimeOffset date = DateTimeOffset.Parse(dateTimeOffset); diff --git a/EDILibraryTests/TemplateHelperTests.cs b/EDILibraryTests/TemplateHelperTests.cs index b0a2e54..a9d88ee 100644 --- a/EDILibraryTests/TemplateHelperTests.cs +++ b/EDILibraryTests/TemplateHelperTests.cs @@ -11,7 +11,10 @@ public class TemplateHelperTests [DataRow("COMDIS1.0c.template", "1.0c")] [DataRow("UTILMDGG1.0a.template", "G1.0a")] [DataRow("UTILMDWG1.0a.template", "G1.0a")] - public void Test_RetrieveFormatVersionFromInputFileName(string filename, string expectedFormatVersion) + public void Test_RetrieveFormatVersionFromInputFileName( + string filename, + string expectedFormatVersion + ) { var actualFormatVersion = TemplateHelper.RetrieveFormatVersionFromInputFileName(filename); Assert.AreEqual(expectedFormatVersion, actualFormatVersion); @@ -20,9 +23,11 @@ public void Test_RetrieveFormatVersionFromInputFileName(string filename, string [TestMethod] public void Test_RetrieveFormatVersionFromInputFileName_ForPaths() { - var filepathAsString = $"Path{Path.DirectorySeparatorChar}To{Path.DirectorySeparatorChar}My{Path.DirectorySeparatorChar}Favourite{Path.DirectorySeparatorChar}Templates{Path.DirectorySeparatorChar}folder{Path.DirectorySeparatorChar}COMDIS1.0c.template"; - var actualFormatVersion = TemplateHelper.RetrieveFormatVersionFromInputFileName(filepathAsString); + var filepathAsString = + $"Path{Path.DirectorySeparatorChar}To{Path.DirectorySeparatorChar}My{Path.DirectorySeparatorChar}Favourite{Path.DirectorySeparatorChar}Templates{Path.DirectorySeparatorChar}folder{Path.DirectorySeparatorChar}COMDIS1.0c.template"; + var actualFormatVersion = TemplateHelper.RetrieveFormatVersionFromInputFileName( + filepathAsString + ); Assert.AreEqual("1.0c", actualFormatVersion); } - } diff --git a/EDILibraryTests/TemplateLoaderExtensionTests.cs b/EDILibraryTests/TemplateLoaderExtensionTests.cs index f0d96e0..a5e9d42 100644 --- a/EDILibraryTests/TemplateLoaderExtensionTests.cs +++ b/EDILibraryTests/TemplateLoaderExtensionTests.cs @@ -7,7 +7,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using NSubstitute; - namespace EDILibraryTests { [TestClass] @@ -20,9 +19,15 @@ public class TemplateLoaderExtensionTests public async Task TestLoadingRegularTemplateIfExists() { var loaderMock = Substitute.For(); - loaderMock.LoadMausTemplate(EdifactFormat.MSCONS, EdifactFormatVersion.FV2304, "13002").Returns(Task.FromResult(new Anwendungshandbuch())); + loaderMock + .LoadMausTemplate(EdifactFormat.MSCONS, EdifactFormatVersion.FV2304, "13002") + .Returns(Task.FromResult(new Anwendungshandbuch())); - var (actualMaus, actualFormatVersion) = await loaderMock.LoadMausTemplateOrFallback(EdifactFormat.MSCONS, EdifactFormatVersion.FV2304, "13002"); + var (actualMaus, actualFormatVersion) = await loaderMock.LoadMausTemplateOrFallback( + EdifactFormat.MSCONS, + EdifactFormatVersion.FV2304, + "13002" + ); actualMaus.Should().NotBeNull(); actualFormatVersion.Should().Be(EdifactFormatVersion.FV2304); @@ -36,12 +41,23 @@ public async Task TestLoadingRegularTemplateIfExists() public async Task TestLoadingFallbackTemplateIfExists() { var loaderMock = Substitute.For(); - loaderMock.LoadMausTemplate(EdifactFormat.MSCONS, EdifactFormatVersion.FV2304, "13002").Returns(Task.FromResult((Anwendungshandbuch)null)); - loaderMock.LoadMausTemplate(EdifactFormat.MSCONS, EdifactFormatVersion.FV2210, "13002").Returns(Task.FromResult((Anwendungshandbuch)null)); - loaderMock.LoadMausTemplate(EdifactFormat.MSCONS, EdifactFormatVersion.FV2110, "13002").Returns(Task.FromResult(new Anwendungshandbuch())); + loaderMock + .LoadMausTemplate(EdifactFormat.MSCONS, EdifactFormatVersion.FV2304, "13002") + .Returns(Task.FromResult((Anwendungshandbuch)null)); + loaderMock + .LoadMausTemplate(EdifactFormat.MSCONS, EdifactFormatVersion.FV2210, "13002") + .Returns(Task.FromResult((Anwendungshandbuch)null)); + loaderMock + .LoadMausTemplate(EdifactFormat.MSCONS, EdifactFormatVersion.FV2110, "13002") + .Returns(Task.FromResult(new Anwendungshandbuch())); var loaderUnderTest = loaderMock; - var (actualMaus, actualFormatVersion) = await loaderUnderTest.LoadMausTemplateOrFallback(EdifactFormat.MSCONS, EdifactFormatVersion.FV2304, "13002"); + var (actualMaus, actualFormatVersion) = + await loaderUnderTest.LoadMausTemplateOrFallback( + EdifactFormat.MSCONS, + EdifactFormatVersion.FV2304, + "13002" + ); actualMaus.Should().NotBeNull(); actualFormatVersion.Should().Be(EdifactFormatVersion.FV2110); @@ -55,10 +71,15 @@ public async Task TestLoadingFallbackTemplateIfExists() public async Task TestLoadingNothingIfNotEvenAFallbackExists() { var loaderMock = Substitute.For(); - loaderMock.LoadMausTemplate(EdifactFormat.MSCONS, Arg.Any(), "13002").Returns(Task.FromResult((Anwendungshandbuch)null)); - + loaderMock + .LoadMausTemplate(EdifactFormat.MSCONS, Arg.Any(), "13002") + .Returns(Task.FromResult((Anwendungshandbuch)null)); - var (actualMaus, actualFormatVersion) = await loaderMock.LoadMausTemplateOrFallback(EdifactFormat.MSCONS, EdifactFormatVersion.FV2304, "13002"); + var (actualMaus, actualFormatVersion) = await loaderMock.LoadMausTemplateOrFallback( + EdifactFormat.MSCONS, + EdifactFormatVersion.FV2304, + "13002" + ); actualMaus.Should().BeNull(); actualFormatVersion.Should().BeNull(); diff --git a/EDILibraryTests/TestSpartenFinder.cs b/EDILibraryTests/TestSpartenFinder.cs index 10eb5c9..b8e5e58 100644 --- a/EDILibraryTests/TestSpartenFinder.cs +++ b/EDILibraryTests/TestSpartenFinder.cs @@ -3,12 +3,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; - using EDILibrary.Helper; using EDILibrary.Interfaces; - using FluentAssertions; - using Microsoft.VisualStudio.TestTools.UnitTesting; namespace EDILibraryTests @@ -27,11 +24,7 @@ public class TestSpartenFinder [DataRow("4041408700013", "4038777000004", Sparte.GAS)] [DataRow("4260016042005", "4041408700013", Sparte.GAS)] [DataRow("5260016042005", "4041408700013", Sparte.WASSER)] - public async Task TestSparte( - string sender, - string receiver, - Sparte expectedSparte - ) + public async Task TestSparte(string sender, string receiver, Sparte expectedSparte) { Sparten s = new(); s.STROM.Add("4033872000041");