diff --git a/src/AasxCsharpLibrary/AdminShellPackageEnv.cs b/src/AasxCsharpLibrary/AdminShellPackageEnv.cs index dfe265e9b..bf0a81efb 100644 --- a/src/AasxCsharpLibrary/AdminShellPackageEnv.cs +++ b/src/AasxCsharpLibrary/AdminShellPackageEnv.cs @@ -21,7 +21,6 @@ This source code may use other Open Source software components (see LICENSE.txt) using System.Threading.Tasks; using System.Xml; using System.Xml.Serialization; -using static AasCore.Aas3_0.Reporting; namespace AdminShellNS { @@ -385,7 +384,12 @@ private static (AasCore.Aas3_0.Environment, Package) LoadPackageAasx(string fn, foreach (var x in xs) if (x.SourceUri.ToString() == "/") { - originPart = package.GetPart(x.TargetUri); + //originPart = package.GetPart(x.TargetUri); + var absoluteURI = PackUriHelper.ResolvePartUri(x.SourceUri, x.TargetUri); + if (package.PartExists(absoluteURI)) + { + originPart = package.GetPart(absoluteURI); + } break; } @@ -397,7 +401,12 @@ private static (AasCore.Aas3_0.Environment, Package) LoadPackageAasx(string fn, xs = originPart.GetRelationshipsByType("http://www.admin-shell.io/aasx/relationships/aas-spec"); foreach (var x in xs) { - specPart = package.GetPart(x.TargetUri); + //specPart = package.GetPart(x.TargetUri); + var absoluteURI = PackUriHelper.ResolvePartUri(x.SourceUri, x.TargetUri); + if (package.PartExists(absoluteURI)) + { + specPart = package.GetPart(absoluteURI); + } break; } @@ -748,7 +757,12 @@ public bool SaveAs(string fn, bool writeFreshly = false, SerializationFormat pre foreach (var x in xs) if (x.SourceUri.ToString() == "/") { - originPart = package.GetPart(x.TargetUri); + //originPart = package.GetPart(x.TargetUri); + var absoluteURI = PackUriHelper.ResolvePartUri(x.SourceUri, x.TargetUri); + if (package.PartExists(absoluteURI)) + { + originPart = package.GetPart(absoluteURI); + } break; } if (originPart == null) @@ -774,7 +788,12 @@ public bool SaveAs(string fn, bool writeFreshly = false, SerializationFormat pre foreach (var x in xs) { specRel = x; - specPart = package.GetPart(x.TargetUri); + //specPart = package.GetPart(x.TargetUri); + var absoluteURI = PackUriHelper.ResolvePartUri(x.SourceUri, x.TargetUri); + if (package.PartExists(absoluteURI)) + { + specPart = package.GetPart(absoluteURI); + } break; } @@ -921,7 +940,12 @@ public bool SaveAs(string fn, bool writeFreshly = false, SerializationFormat pre foreach (var x in xs) if (x.TargetUri == psfAdd.Uri) { - filePart = package.GetPart(x.TargetUri); + //filePart = package.GetPart(x.TargetUri); + var absoluteURI = PackUriHelper.ResolvePartUri(x.SourceUri, x.TargetUri); + if (package.PartExists(absoluteURI)) + { + filePart = package.GetPart(absoluteURI); + } break; } } @@ -933,7 +957,12 @@ public bool SaveAs(string fn, bool writeFreshly = false, SerializationFormat pre foreach (var x in xs) if (x.SourceUri.ToString() == "/" && x.TargetUri == psfAdd.Uri) { - filePart = package.GetPart(x.TargetUri); + //filePart = package.GetPart(x.TargetUri); + var absoluteURI = PackUriHelper.ResolvePartUri(x.SourceUri, x.TargetUri); + if (package.PartExists(absoluteURI)) + { + filePart = package.GetPart(absoluteURI); + } break; } } @@ -1299,10 +1328,19 @@ public long GetStreamSizeFromPackage(string uriString) { if (_openPackage == null) return 0; - var part = _openPackage.GetPart(new Uri(uriString, UriKind.RelativeOrAbsolute)); - using (var s = part.GetStream(FileMode.Open)) + + PackagePart part = null; + var uri = new Uri(uriString, UriKind.RelativeOrAbsolute); + if (_openPackage.PartExists(uri)) { - res = s.Length; + part = _openPackage.GetPart(uri); + } + if (part != null) + { + using (var s = part.GetStream(FileMode.Open)) + { + res = s.Length; + } } } catch (Exception ex) @@ -1329,7 +1367,12 @@ public Stream GetLocalThumbnailStream(ref Uri thumbUri) foreach (var x in xs) if (x.SourceUri.ToString() == "/") { - thumbPart = _openPackage.GetPart(x.TargetUri); + //thumbPart = _openPackage.GetPart(x.TargetUri); + var absoluteURI = PackUriHelper.ResolvePartUri(x.SourceUri, x.TargetUri); + if (_openPackage.PartExists(absoluteURI)) + { + thumbPart = _openPackage.GetPart(absoluteURI); + } thumbUri = x.TargetUri; break; } @@ -1393,7 +1436,12 @@ public ListOfAasSupplementaryFile GetListOfSupplementaryFiles() foreach (var x in xs) if (x.SourceUri.ToString() == "/") { - originPart = _openPackage.GetPart(x.TargetUri); + //originPart = _openPackage.GetPart(x.TargetUri); + var absoluteURI = PackUriHelper.ResolvePartUri(x.SourceUri, x.TargetUri); + if (_openPackage.PartExists(absoluteURI)) + { + originPart = _openPackage.GetPart(absoluteURI); + } break; } @@ -1404,7 +1452,12 @@ public ListOfAasSupplementaryFile GetListOfSupplementaryFiles() xs = originPart.GetRelationshipsByType("http://www.admin-shell.io/aasx/relationships/aas-spec"); foreach (var x in xs) { - specPart = _openPackage.GetPart(x.TargetUri); + //specPart = _openPackage.GetPart(x.TargetUri); + var absoluteURI = PackUriHelper.ResolvePartUri(x.SourceUri, x.TargetUri); + if (_openPackage.PartExists(absoluteURI)) + { + specPart = _openPackage.GetPart(absoluteURI); + } break; }