Skip to content

aas-core-works/aas-package3-csharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aas-package3-csharp

Test Check style Check Doc Coverage Status Nuget

Aas-package3-csharp is a library for reading and writing packaged file format of an Asset Administration Shell (AAS) in C#.

Status

The library is thoroughly tested and meant to be used in production.

NET Standard 2.0, NET Standard 2.1 and NET 6 are supported.

Documentation

The documentation is available at https://aas-core-works.github.io/aas-package3-csharp/doc.

Teaser

Here is are short snippets to demonstrate how you can use the library.

To create and write to a package:

// General packaging handler to be shared accross the program
var packaging = new AasCore.Aas3.Package.Packaging();

// Create a package
{
    byte[] specContent = ...;
    byte[] thumbnailContent = ...;
    byte[] supplementaryContent = ...;

    using var pkg = packaging.Create("/path/to/some/file");
    var spec = pkg.MakeSpec(
        pkg.PutPart(
            new Uri(
                "/aasx/some-company/data.json", 
                UriKind.Relative),
            "text/json",
            specContent);

    pkg.MakeThumbnail(
        pkg.PutPart(
            new Uri(
                "/some-thumbnail.png", 
                UriKind.Relative),
            "image/png",
            thumbnailContent));

    pkg.RelateSupplementaryToSpec(
        pkg.PutPart(
            new Uri(
                "/aasx-suppl/some-company/some-manual.pdf",
                 UriKind.Relative),
            "application/pdf",
            supplementaryContent),
        spec);

    pkg.Flush();
}

To read from the package:

// General packaging handler to be shared accross the program
var packaging = new AasCore.Aas3.Package.Packaging();

// Read from the package
byte[] specContent;
byte[] thumbnailContent;
byte[] supplementaryContent;

{
    using var pkgOrErr = packaging.OpenRead(
        "/path/to/some/file");

    var pkg = pkgOrErr.Must();

    // Read the specs
    var specsByContentType = pkg.SpecsByContentType();
    if (!specsByContentType.ContainsKey("text/json"))
    {
        throw new ArgumentException("No json specs");
    }
    var spec = specsByContentType["text/json"].First();
    specContent = spec.ReadAllBytes();

    // Read the thumbnail
    var thumbnail = pkg.Thumbnail();
    if(thumbnail != null)
    {
        thumbnailContent = pkg.Thumbnail().ReadAllBytes();

        // Do something with the thumbnail content
    }

    // Read the supplementary file
    supplementaryContent = pkg
        .MustPart(
            new Uri(
                "/aasx-suppl/some-company/some-manual.pdf",
                 UriKind.Relative))
        .ReadAllBytes();
}

Please see the full documentation at [https://aas-core-works.github.io/aas-package3-csharp/doc] for more details.

Installation

The library is available on NuGet at: https://www.nuget.org/packages/AasCore.Aas3.Package/

Versioning

The name of the library indicates the supported version of the Asset Administration Shell (AAS).

In case of aas-package3-csharp, this means that the Version 3 of the Asset Administration Shell (AAS) is supported.

We follow Semantic Versioning to version the library. The version X.Y.Z indicates:

  • X is the major version (backward-incompatible),
  • Y is the minor version (backward-compatible), and
  • Z is the patch version (backward-compatible bug fix).