diff --git a/src/AasxCsharpLibrary/AdminShellPackageEnv.cs b/src/AasxCsharpLibrary/AdminShellPackageEnv.cs index 3f02303a..1d726e98 100644 --- a/src/AasxCsharpLibrary/AdminShellPackageEnv.cs +++ b/src/AasxCsharpLibrary/AdminShellPackageEnv.cs @@ -1090,7 +1090,8 @@ public void TemporarilySaveCloseAndReOpenPackage( { _openPackage = Package.Open(Filename, FileMode.OpenOrCreate); - } } + } + } } private int BackupIndex = 0; diff --git a/src/AasxCsharpLibrary/Extensions/ExtendBlob.cs b/src/AasxCsharpLibrary/Extensions/ExtendBlob.cs index 1812b97d..d8ee065e 100644 --- a/src/AasxCsharpLibrary/Extensions/ExtendBlob.cs +++ b/src/AasxCsharpLibrary/Extensions/ExtendBlob.cs @@ -29,7 +29,10 @@ public static Blob ConvertFromV10(this Blob blob, AasxCompatibilityModels.AdminS public static Blob ConvertFromV20(this Blob blob, AasxCompatibilityModels.AdminShellV20.Blob sourceBlob) { blob.ContentType = sourceBlob.mimeType; - blob.Value = Encoding.ASCII.GetBytes(sourceBlob.value); + if (!string.IsNullOrEmpty(sourceBlob.value)) + { + blob.Value = Encoding.ASCII.GetBytes(sourceBlob.value); + } return blob; } diff --git a/src/AasxCsharpLibrary/Extensions/ExtendConceptDescription.cs b/src/AasxCsharpLibrary/Extensions/ExtendConceptDescription.cs index 1cdae0f4..7bb64c7e 100644 --- a/src/AasxCsharpLibrary/Extensions/ExtendConceptDescription.cs +++ b/src/AasxCsharpLibrary/Extensions/ExtendConceptDescription.cs @@ -260,13 +260,19 @@ public static ConceptDescription ConvertFromV20( if (srcCD.IsCaseOf != null && srcCD.IsCaseOf.Count != 0) { - if (cd.IsCaseOf == null) - { - cd.IsCaseOf = new List(); - } foreach (var caseOf in srcCD.IsCaseOf) { - cd.IsCaseOf.Add(ExtensionsUtil.ConvertReferenceFromV20(caseOf, ReferenceTypes.ModelReference)); + IReference newCaseOf = null; + if(caseOf != null && !caseOf.IsEmpty) + { + newCaseOf = ExtensionsUtil.ConvertReferenceFromV20(caseOf, ReferenceTypes.ModelReference); + } + + if(newCaseOf != null) + { + cd.IsCaseOf ??= new List(); + cd.IsCaseOf.Add(newCaseOf); + } } } diff --git a/src/AasxCsharpLibrary/Extensions/ExtendEmbeddedDataSpecification.cs b/src/AasxCsharpLibrary/Extensions/ExtendEmbeddedDataSpecification.cs index 1f72ab79..f914e75f 100644 --- a/src/AasxCsharpLibrary/Extensions/ExtendEmbeddedDataSpecification.cs +++ b/src/AasxCsharpLibrary/Extensions/ExtendEmbeddedDataSpecification.cs @@ -49,31 +49,38 @@ public static EmbeddedDataSpecification ConvertFromV20(this EmbeddedDataSpecific { if (sourceEmbeddedSpec != null) { - embeddedDataSpecification.DataSpecification = ExtensionsUtil.ConvertReferenceFromV20(sourceEmbeddedSpec.dataSpecification, ReferenceTypes.ExternalReference); + if (sourceEmbeddedSpec.dataSpecification != null) + { + embeddedDataSpecification.DataSpecification = ExtensionsUtil.ConvertReferenceFromV20(sourceEmbeddedSpec.dataSpecification, ReferenceTypes.ExternalReference); - // TODO (MIHO, 2022-19-12): check again, see questions - var oldid = new[] { + // TODO (MIHO, 2022-19-12): check again, see questions + var oldid = new[] { "http://admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360/2/0", "http://admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360", "www.admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360" - }; - var newid = "http://admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360/3/0"; + }; + var newid = "http://admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360/3/0"; - // map all "usable" old ids to new one .. - foreach (var oi in oldid) - if (sourceEmbeddedSpec.dataSpecification?.Matches("", false, "IRI", oi, - AasxCompatibilityModels.AdminShellV20.Key.MatchMode.Identification) == true) - { - embeddedDataSpecification.DataSpecification.Keys[0].Value = newid; - } - } + // map all "usable" old ids to new one .. + foreach (var oi in oldid) + if (sourceEmbeddedSpec.dataSpecification?.Matches("", false, "IRI", oi, + AasxCompatibilityModels.AdminShellV20.Key.MatchMode.Identification) == true) + { + embeddedDataSpecification.DataSpecification.Keys[0].Value = newid; + } + } - if (sourceEmbeddedSpec.dataSpecificationContent?.dataSpecificationIEC61360 != null) - { - embeddedDataSpecification.DataSpecificationContent = - new DataSpecificationIec61360(null).ConvertFromV20( - sourceEmbeddedSpec.dataSpecificationContent.dataSpecificationIEC61360); + if (sourceEmbeddedSpec.dataSpecificationContent != null) + { + if (sourceEmbeddedSpec.dataSpecificationContent?.dataSpecificationIEC61360 != null) + { + embeddedDataSpecification.DataSpecificationContent = + new DataSpecificationIec61360(null).ConvertFromV20( + sourceEmbeddedSpec.dataSpecificationContent.dataSpecificationIEC61360); + } + } } + return embeddedDataSpecification; } diff --git a/src/AasxCsharpLibrary/Extensions/ExtendISubmodelElement.cs b/src/AasxCsharpLibrary/Extensions/ExtendISubmodelElement.cs index 9c4d2f85..1d8e9fa3 100644 --- a/src/AasxCsharpLibrary/Extensions/ExtendISubmodelElement.cs +++ b/src/AasxCsharpLibrary/Extensions/ExtendISubmodelElement.cs @@ -557,16 +557,15 @@ private static void BasicConversionFromV20(this ISubmodelElement submodelElement if (sourceSubmodelElement.hasDataSpecification != null && sourceSubmodelElement.hasDataSpecification.Count > 0) { - //TODO (jtikekar, 0000-00-00): EmbeddedDataSpecification?? (as per old implementation) - submodelElement.EmbeddedDataSpecifications ??= new List(); - - //TODO (jtikekar, 0000-00-00): DataSpecificationContent?? (as per old implementation) - foreach (var sourceDataSpec in sourceSubmodelElement.hasDataSpecification) + foreach (var sourceEmbeddedDataSpec in sourceSubmodelElement.hasDataSpecification) { - submodelElement.EmbeddedDataSpecifications.Add( - new EmbeddedDataSpecification( - ExtensionsUtil.ConvertReferenceFromV20(sourceDataSpec.dataSpecification, ReferenceTypes.ExternalReference), - null)); + var newEmbeddedDataSpec = new EmbeddedDataSpecification (null, null); + newEmbeddedDataSpec.ConvertFromV20(sourceEmbeddedDataSpec); + if(newEmbeddedDataSpec.DataSpecification != null || newEmbeddedDataSpec.DataSpecificationContent != null) + { + submodelElement.EmbeddedDataSpecifications ??= new List(); + submodelElement.EmbeddedDataSpecifications.Add(newEmbeddedDataSpec); + } } }