Skip to content

Commit

Permalink
Namespace fix (#245)
Browse files Browse the repository at this point in the history
* adding namespace changes from AASPE

* changing serving path back
  • Loading branch information
AlexanderWollbrink committed May 8, 2024
1 parent fccdace commit f6e3911
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 12 deletions.
130 changes: 119 additions & 11 deletions src/AasxCsharpLibrary/AdminShellPackageEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,7 @@ private static (AasCore.Aas3_0.Environment, Package, String) LoadPackageAasx(str

if (originPart == null)
{
xs = package.GetRelationshipsByType(
"http://www.admin-shell.io/aasx/relationships/aasx-origin");
xs = package.GetRelationshipsByType("http://www.admin-shell.io/aasx/relationships/aasx-origin");
foreach (var x in xs)
if (x.SourceUri.ToString() == "/")
{
Expand Down Expand Up @@ -843,6 +842,26 @@ public enum SerializationFormat { None, Xml, Json };
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 @@ -867,7 +886,7 @@ public enum SerializationFormat { None, Xml, Json };
}
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 @@ -883,6 +902,27 @@ public enum SerializationFormat { None, Xml, Json };
{
specPart = package.GetPart(absoluteURI);
}
//delete old type, because its not according to spec or something
//then replace with the current type
originPart.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;
}

Expand Down Expand Up @@ -927,7 +967,7 @@ public enum SerializationFormat { None, Xml, Json };
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 @@ -969,6 +1009,33 @@ public enum SerializationFormat { None, Xml, Json };
}
}

//Handling of aas_suppl namespace from v2 to v3
//Need to check/test in detail, with thumbnails as well
if (specPart != null)
{

xs = specPart.GetRelationshipsByType("http://www.admin-shell.io/aasx/relationships/aas-suppl");
if (xs != null)
{
foreach (var x in xs.ToList())
{
var uri = x.TargetUri;
PackagePart filePart = null;
var absoluteURI = PackUriHelper.ResolvePartUri(x.SourceUri, x.TargetUri);
if (package.PartExists(absoluteURI))
{
filePart = package.GetPart(absoluteURI);
}
//delete old type, because its not according to spec or something
//then replace with the current type
specPart.DeleteRelationship(x.Id);
specPart.CreateRelationship(
filePart.Uri, TargetMode.Internal,
"http://admin-shell.io/aasx/relationships/aas-suppl");
}
}
}

// there might be pending files to be deleted (first delete, then add,
// in case of identical files in both categories)
foreach (var psfDel in _pendingFilesToDelete)
Expand All @@ -977,7 +1044,8 @@ public enum SerializationFormat { None, Xml, Json };
var found = false;

// normal files
xs = specPart.GetRelationshipsByType("http://www.admin-shell.io/aasx/relationships/aas-suppl");
xs = specPart.GetRelationshipsByType("http://admin-shell.io/aasx/relationships/aas-suppl");
if (xs == null) xs = specPart.GetRelationshipsByType("http://www.admin-shell.io/aasx/relationships/aas-suppl");
foreach (var x in xs)
if (x.TargetUri == psfDel.Uri)
{
Expand Down Expand Up @@ -1027,8 +1095,8 @@ public enum SerializationFormat { None, Xml, Json };
PackagePart filePart = null;
if (psfAdd.SpecialHandling == AdminShellPackageSupplementaryFile.SpecialHandlingType.None)
{
xs = specPart.GetRelationshipsByType(
"http://www.admin-shell.io/aasx/relationships/aas-suppl");
xs = specPart.GetRelationshipsByType("http://admin-shell.io/aasx/relationships/aas-suppl");
if (xs == null) xs = specPart.GetRelationshipsByType("http://www.admin-shell.io/aasx/relationships/aas-suppl");
foreach (var x in xs)
if (x.TargetUri == psfAdd.Uri)
{
Expand Down Expand Up @@ -1078,7 +1146,7 @@ public enum SerializationFormat { None, Xml, Json };
AdminShellPackageSupplementaryFile.SpecialHandlingType.None)
specPart.CreateRelationship(
filePart.Uri, TargetMode.Internal,
"http://www.admin-shell.io/aasx/relationships/aas-suppl");
"http://admin-shell.io/aasx/relationships/aas-suppl");
if (psfAdd.SpecialHandling ==
AdminShellPackageSupplementaryFile.SpecialHandlingType.EmbedAsThumbnail)
package.CreateRelationship(
Expand Down Expand Up @@ -1467,7 +1535,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 All @@ -1479,12 +1547,28 @@ public ListOfAasSupplementaryFile GetListOfSupplementaryFiles()
}
break;
}
if(xs == null)
{
xs = _openPackage.GetRelationshipsByType(
"http://www.admin-shell.io/aasx/relationships/aasx-origin");
foreach (var x in xs)
if (x.SourceUri.ToString() == "/")
{
//originPart = _openPackage.GetPart(x.TargetUri);
var absoluteURI = PackUriHelper.ResolvePartUri(x.SourceUri, x.TargetUri);
if (_openPackage.PartExists(absoluteURI))
{
originPart = _openPackage.GetPart(absoluteURI);
}
break;
}
}

if (originPart != null)
{
// get the specs from the origin
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 = _openPackage.GetPart(x.TargetUri);
Expand All @@ -1495,17 +1579,41 @@ public ListOfAasSupplementaryFile GetListOfSupplementaryFiles()
}
break;
}
if(xs == null)
{
xs = originPart.GetRelationshipsByType("http://www.admin-shell.io/aasx/relationships/aas-spec");
foreach (var x in xs)
{
//specPart = _openPackage.GetPart(x.TargetUri);
var absoluteURI = PackUriHelper.ResolvePartUri(x.SourceUri, x.TargetUri);
if (_openPackage.PartExists(absoluteURI))
{
specPart = _openPackage.GetPart(absoluteURI);
}
break;
}
}

if (specPart != null)
{
// get the supplementaries from the package, derived from spec
xs = specPart.GetRelationshipsByType("http://www.admin-shell.io/aasx/relationships/aas-suppl");
xs = specPart.GetRelationshipsByType("http://admin-shell.io/aasx/relationships/aas-suppl");
foreach (var x in xs)
{
result.Add(
new AdminShellPackageSupplementaryFile(
x.TargetUri, location: AdminShellPackageSupplementaryFile.LocationType.InPackage));
}
if(xs == null)
{
xs = specPart.GetRelationshipsByType("http://www.admin-shell.io/aasx/relationships/aas-suppl");
foreach (var x in xs)
{
result.Add(
new AdminShellPackageSupplementaryFile(
x.TargetUri, location: AdminShellPackageSupplementaryFile.LocationType.InPackage));
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/AasxServerBlazor/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"AasxServerBlazor": {
"commandName": "Project",
"commandLineArgs": "--no-security --secret-string-api 1234 --aasx-in-memory 1000 --data-path \"C:\\Users\\7wrmhx\\Downloads\\Krohne OneDrive_1_2.4.2024\" --edit --external-blazor http://localhost:5001",
"commandLineArgs": "--no-security --secret-string-api 1234 --aasx-in-memory 1000 --data-path \"C:\\Development\" --edit --external-blazor http://localhost:5001",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
Expand Down

0 comments on commit f6e3911

Please sign in to comment.