Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
Supporting package.GetPart with absolute URI (#687)
Browse files Browse the repository at this point in the history
Co-authored-by: juileetikekar <[email protected]>
Co-authored-by: Frank Schnicke <[email protected]>
  • Loading branch information
3 people authored Jan 22, 2024
1 parent 2d1b402 commit a5bba3f
Showing 1 changed file with 66 additions and 13 deletions.
79 changes: 66 additions & 13 deletions src/AasxCsharpLibrary/AdminShellPackageEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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)
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down

0 comments on commit a5bba3f

Please sign in to comment.