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

Commit

Permalink
fixing namespace for relationships and making it backwards compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWollbrink committed Feb 7, 2024
1 parent a5bba3f commit ca5acaa
Showing 1 changed file with 75 additions and 7 deletions.
82 changes: 75 additions & 7 deletions src/AasxCsharpLibrary/AdminShellPackageEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ private static (AasCore.Aas3_0.Environment, Package) LoadPackageAasx(string fn,
// get the origin from the package
PackagePart originPart = null;
var xs = package.GetRelationshipsByType(
"http://www.admin-shell.io/aasx/relationships/aasx-origin");
"http://admin-shell.io/aasx/relationships/aasx-origin");
foreach (var x in xs)
if (x.SourceUri.ToString() == "/")
{
Expand All @@ -394,11 +394,25 @@ private static (AasCore.Aas3_0.Environment, Package) LoadPackageAasx(string fn,
}

if (originPart == null)
throw (new Exception("Unable to find AASX origin. Aborting!"));
xs = package.GetRelationshipsByType(
"http://www.admin-shell.io/aasx/relationships/aasx-origin");
foreach (var x in xs)
if (x.SourceUri.ToString() == "/")
{
//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)
throw (new Exception("Unable to find AASX origin. Aborting!"));

// get the specs from the package
PackagePart specPart = null;
xs = originPart.GetRelationshipsByType("http://www.admin-shell.io/aasx/relationships/aas-spec");
xs = originPart.GetRelationshipsByType("http://admin-shell.io/aasx/relationships/aas-spec");
foreach (var x in xs)
{
//specPart = package.GetPart(x.TargetUri);
Expand All @@ -411,7 +425,19 @@ private static (AasCore.Aas3_0.Environment, Package) LoadPackageAasx(string fn,
}

if (specPart == null)
throw (new Exception("Unable to find AASX spec(s). Aborting!"));
xs = originPart.GetRelationshipsByType("http://www.admin-shell.io/aasx/relationships/aas-spec");
foreach (var x in xs)
{
//specPart = package.GetPart(x.TargetUri);
var absoluteURI = PackUriHelper.ResolvePartUri(x.SourceUri, x.TargetUri);
if (package.PartExists(absoluteURI))
{
specPart = package.GetPart(absoluteURI);
}
break;
}
if (specPart == null)
throw (new Exception("Unable to find AASX spec(s). Aborting!"));

// open spec part to read
try
Expand Down Expand Up @@ -754,6 +780,26 @@ public bool SaveAs(string fn, bool writeFreshly = false, SerializationFormat pre
PackagePart originPart = null;
var xs = package.GetRelationshipsByType(
"http://www.admin-shell.io/aasx/relationships/aasx-origin");
foreach (var x in xs)
if (x.SourceUri.ToString() == "/")
{
//originPart = package.GetPart(x.TargetUri);

var absoluteURI = PackUriHelper.ResolvePartUri(x.SourceUri, x.TargetUri);
if (package.PartExists(absoluteURI))
{
originPart = package.GetPart(absoluteURI);
}
//delete old type, because its not according to spec or something
//then replace with the current type
package.DeleteRelationship(x.Id);
package.CreateRelationship(
originPart.Uri, TargetMode.Internal,
"http://admin-shell.io/aasx/relationships/aasx-origin");
originPart = null;
break;
}
xs = package.GetRelationshipsByType("http://admin-shell.io/aasx/relationships/aasx-origin");
foreach (var x in xs)
if (x.SourceUri.ToString() == "/")
{
Expand All @@ -778,7 +824,7 @@ public bool SaveAs(string fn, bool writeFreshly = false, SerializationFormat pre
}
package.CreateRelationship(
originPart.Uri, TargetMode.Internal,
"http://www.admin-shell.io/aasx/relationships/aasx-origin");
"http://admin-shell.io/aasx/relationships/aasx-origin");
}

// get the specs from the package
Expand All @@ -794,8 +840,30 @@ public bool SaveAs(string fn, bool writeFreshly = false, SerializationFormat pre
{
specPart = package.GetPart(absoluteURI);
}
//delete old type, because its not according to spec or something
//then replace with the current type
package.DeleteRelationship(x.Id);
originPart.CreateRelationship(
specPart.Uri, TargetMode.Internal,
"http://admin-shell.io/aasx/relationships/aas-spec");
specPart = null;
specRel = null;
break;
}
xs = originPart.GetRelationshipsByType("http://admin-shell.io/aasx/relationships/aas-spec");
foreach (var x in xs)
{
specRel = x;
//specPart = package.GetPart(x.TargetUri);
var absoluteURI = PackUriHelper.ResolvePartUri(x.SourceUri, x.TargetUri);
if (package.PartExists(absoluteURI))
{
specPart = package.GetPart(absoluteURI);
}

break;
}


// check, if we have to change the spec part
if (specPart != null && specRel != null)
Expand Down Expand Up @@ -838,7 +906,7 @@ public bool SaveAs(string fn, bool writeFreshly = false, SerializationFormat pre
System.Net.Mime.MediaTypeNames.Text.Xml, CompressionOption.Maximum);
originPart.CreateRelationship(
specPart.Uri, TargetMode.Internal,
"http://www.admin-shell.io/aasx/relationships/aas-spec");
"http://admin-shell.io/aasx/relationships/aas-spec");
}

// now, specPart shall be != null!
Expand Down Expand Up @@ -1432,7 +1500,7 @@ public ListOfAasSupplementaryFile GetListOfSupplementaryFiles()
// get the origin from the package
PackagePart originPart = null;
xs = _openPackage.GetRelationshipsByType(
"http://www.admin-shell.io/aasx/relationships/aasx-origin");
"http://admin-shell.io/aasx/relationships/aasx-origin");
foreach (var x in xs)
if (x.SourceUri.ToString() == "/")
{
Expand Down

0 comments on commit ca5acaa

Please sign in to comment.