Skip to content

Commit

Permalink
* package container
Browse files Browse the repository at this point in the history
* GET und PUT
* tainting of Identifiables
* Visual feedback
* first UI
  • Loading branch information
festo-i40 committed Sep 20, 2024
1 parent 94d5bff commit 6c9c7af
Show file tree
Hide file tree
Showing 40 changed files with 2,149 additions and 187 deletions.
13 changes: 13 additions & 0 deletions src/AasCore.Aas3_0/DiaryData/ITaintedData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdminShellNS.DiaryData
{
public interface ITaintedData
{
TaintedDataDef TaintedData { get; }
}
}
45 changes: 45 additions & 0 deletions src/AasCore.Aas3_0/DiaryData/TaintedDataDef.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using AasCore.Aas3_0;
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Xml.Serialization;

namespace AdminShellNS.DiaryData
{
public class TaintedDataDef
{
[XmlIgnore]
[JsonIgnore]
private DateTime? _tainted = null;

[XmlIgnore]
[JsonIgnore]
public DateTime? Tainted
{
get { return _tainted; }
set { _tainted = value; }
}

public static void TaintIdentifiable(IReferable element)
{
// trivial
if (element == null)
return;

// find identifiable
var el = element;
while (el != null)
{
// found?
if (el is IIdentifiable && el is ITaintedData itd)
{
itd.TaintedData.Tainted = DateTime.UtcNow;
return;
}

// up
el = (el as IReferable)?.Parent as IReferable;
}
}
}
}
38 changes: 28 additions & 10 deletions src/AasCore.Aas3_0/types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ public interface IReferable : IHasExtensions, IDiaryData
/// <summary>
/// An element that has a globally unique identifier.
/// </summary>
public interface IIdentifiable : IReferable
public interface IIdentifiable : IReferable, ITaintedData
{
/// <summary>
/// Administrative information of an identifiable element.
Expand Down Expand Up @@ -1317,6 +1317,12 @@ public class AssetAdministrationShell : IAssetAdministrationShell
[JsonIgnore]
public DiaryDataDef DiaryData { get { return _diaryData; } }

[JsonIgnore]
private TaintedDataDef _taintedData = new TaintedDataDef();

[JsonIgnore]
public TaintedDataDef TaintedData { get { return _taintedData; } }

#endregion

/// <summary>
Expand Down Expand Up @@ -2460,6 +2466,12 @@ public class Submodel : ISubmodel
[JsonIgnore]
public DiaryDataDef DiaryData { get { return _diaryData; } }

[JsonIgnore]
private TaintedDataDef _taintedData = new TaintedDataDef();

[JsonIgnore]
public TaintedDataDef TaintedData { get { return _taintedData; } }

#endregion

/// <summary>
Expand Down Expand Up @@ -10741,6 +10753,12 @@ public class ConceptDescription : IConceptDescription
[JsonIgnore]
public DiaryDataDef DiaryData { get { return _diaryData; } }

[JsonIgnore]
private TaintedDataDef _taintedData = new TaintedDataDef();

[JsonIgnore]
public TaintedDataDef TaintedData { get { return _taintedData; } }

#endregion

/// <summary>
Expand Down Expand Up @@ -11910,17 +11928,17 @@ public interface IEnvironment : IClass, IDiaryData
/// <summary>
/// Asset administration shell
/// </summary>
public List<IAssetAdministrationShell>? AssetAdministrationShells { get; set; }
public IList<IAssetAdministrationShell>? AssetAdministrationShells { get; set; }

/// <summary>
/// Submodel
/// </summary>
public List<ISubmodel>? Submodels { get; set; }
public IList<ISubmodel>? Submodels { get; set; }

/// <summary>
/// Concept description
/// </summary>
public List<IConceptDescription>? ConceptDescriptions { get; set; }
public IList<IConceptDescription>? ConceptDescriptions { get; set; }

/// <summary>
/// Iterate over AssetAdministrationShells, if set, and otherwise return an empty enumerable.
Expand Down Expand Up @@ -11951,17 +11969,17 @@ public class Environment : IEnvironment
/// <summary>
/// Asset administration shell
/// </summary>
public List<IAssetAdministrationShell>? AssetAdministrationShells { get; set; }
public IList<IAssetAdministrationShell>? AssetAdministrationShells { get; set; }

/// <summary>
/// Submodel
/// </summary>
public List<ISubmodel>? Submodels { get; set; }
public IList<ISubmodel>? Submodels { get; set; }

/// <summary>
/// Concept description
/// </summary>
public List<IConceptDescription>? ConceptDescriptions { get; set; }
public IList<IConceptDescription>? ConceptDescriptions { get; set; }

/// <summary>
/// Iterate over AssetAdministrationShells, if set, and otherwise return an empty enumerable.
Expand Down Expand Up @@ -12116,9 +12134,9 @@ public T Transform<TContext, T>(
}

public Environment(
List<IAssetAdministrationShell>? assetAdministrationShells = null,
List<ISubmodel>? submodels = null,
List<IConceptDescription>? conceptDescriptions = null)
IList<IAssetAdministrationShell>? assetAdministrationShells = null,
IList<ISubmodel>? submodels = null,
IList<IConceptDescription>? conceptDescriptions = null)
{
AssetAdministrationShells = assetAdministrationShells;
Submodels = submodels;
Expand Down
1 change: 1 addition & 0 deletions src/AasxCsharpLibrary/AasxCsharpLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.0.2" />
<PackageReference Include="Namotion.Reflection" Version="2.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NJsonSchema" Version="10.8.0" />
Expand Down
8 changes: 8 additions & 0 deletions src/AasxCsharpLibrary/AdminShellBasicExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public static IEnumerable<T> ForEachSafe<T>(this List<T> list)
yield return x;
}

public static void ForEach<T>(this IList<T> list, Action <T> action)
{
if (list == null)
return;
foreach (var x in list)
action?.Invoke(x);
}

/// <summary>
/// Multiple a string into a iterable list
/// </summary>
Expand Down
47 changes: 45 additions & 2 deletions src/AasxCsharpLibrary/AdminShellPackageFileBasedEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,14 @@ public virtual Stream GetStreamFromUriOrLocalPackage(string uriString,
return null;
}

/// <summary>
/// This is intended to be the "new" one
/// </summary>
public virtual Stream GetThumbnailStreamFromAasOrPackage(string aasId)
{
return null;
}

public virtual ListOfAasSupplementaryFile GetListOfSupplementaryFiles()
{
return null;
Expand Down Expand Up @@ -1633,7 +1641,7 @@ public long GetStreamSizeFromPackage(string uriString)
/// Ensures:
/// <ul><li><c>result == null || result.CanRead</c></li></ul>
/// </remarks>
public virtual Stream GetLocalThumbnailStream(ref Uri thumbUri)
public override Stream GetLocalThumbnailStream(ref Uri thumbUri)
{
// access
if (_openPackage == null)
Expand Down Expand Up @@ -1664,7 +1672,42 @@ public virtual Stream GetLocalThumbnailStream(ref Uri thumbUri)
}

return result;
}
}

public override Stream GetThumbnailStreamFromAasOrPackage(string aasId)
{
// find aas?
var aas = AasEnv?.FindAasById(aasId);
if (aas?.AssetInformation?.DefaultThumbnail?.Path?.HasContent() == true)
{
try
{
// Note: could also use http://...
var s1 = GetLocalStreamFromPackage(uriString: aas.AssetInformation.DefaultThumbnail.Path);
if (s1 != null)
return s1;
} catch (Exception ex)
{
LogInternally.That.CompletelyIgnoredError(ex);
}
}

// or local package?
try
{
Uri dummy = null;
var s2 = GetLocalThumbnailStream(ref dummy);
if (s2 != null)
return s2;
}
catch (Exception ex)
{
LogInternally.That.CompletelyIgnoredError(ex);
}

// no
return null;
}

public override ListOfAasSupplementaryFile GetListOfSupplementaryFiles()
{
Expand Down
17 changes: 17 additions & 0 deletions src/AasxCsharpLibrary/AdminShellUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This source code may use other Open Source software components (see LICENSE.txt)

using AasxCompatibilityModels;
using Extensions;
using Microsoft.IdentityModel.Tokens;
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -1193,6 +1194,22 @@ public static string Base64Decode(string base64EncodedData)
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
}

//
// Base 64 URL
//

// Note: requires Microsoft.IdentityModel.Tokens

public static string Base64UrlEncode(string plainUrl)
{
return Base64UrlEncoder.Encode(plainUrl);
}

public static string Base64UrlDecode(string base64Url)
{
return Base64UrlEncoder.Decode(base64Url);
}

/// <summary>
/// Tries to add scheme etc. to form a valid URI.
/// <c>uri</c> with starting '/' are left untouched.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ public static Tuple<string, string> ToCaptionInfo(this IAssetAdministrationShell

public static IEnumerable<LocatedReference> FindAllReferences(this IAssetAdministrationShell assetAdministrationShell)
{
// dead-csharp off
// Asset
//TODO (jtikekar, 0000-00-00): support asset
//if (assetAdministrationShell.AssetInformation != null)
// yield return new LocatedReference(assetAdministrationShell, assetAdministrationShell.AssetInformation);
// dead-csharp on
// Submodel references
foreach (var r in assetAdministrationShell.AllSubmodels())
yield return new LocatedReference(assetAdministrationShell, r);
}

public static IEnumerable<LocatedReference> FindAllSubmodelReferences(this IAssetAdministrationShell assetAdministrationShell)
{
// unique set of references
var refs = new List<LocatedReference>();
foreach (var smr in assetAdministrationShell.AllSubmodels())
refs.AddIfNew(new LocatedReference() { Identifiable = assetAdministrationShell, Reference = smr });
return refs;
}

#endregion

public static IReference FindSubmodelReference(this IAssetAdministrationShell aas, IReference smRef)
Expand Down
10 changes: 10 additions & 0 deletions src/AasxCsharpLibrary/Extensions/ExtendCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,15 @@ public static bool IsNullOrEmpty<T>(this List<T> list)

return true;
}

public static bool IsNullOrEmpty<T>(this IList<T> list)
{
if (list != null && list.Count != 0)
{
return false;
}

return true;
}
}
}
4 changes: 2 additions & 2 deletions src/AasxCsharpLibrary/Extensions/ExtendConceptDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public static void AddIsCaseOf(this IConceptDescription cd,
/// <summary>
/// Returns false, if there is another element with same idShort in the list
/// </summary>
public static bool CheckIdShortIsUnique(this List<IConceptDescription> cds, string idShort)
public static bool CheckIdShortIsUnique(this IList<IConceptDescription> cds, string idShort)
{
idShort = idShort?.Trim();
if (idShort == null || idShort.Length < 1)
Expand All @@ -318,7 +318,7 @@ public static bool CheckIdShortIsUnique(this List<IConceptDescription> cds, stri
/// <summary>
/// Creates ids with numerical index according to template string, until a unique idShort is found
/// </summary>
public static string IterateIdShortTemplateToBeUnique(this List<IConceptDescription> cds, string idShortTemplate, int maxNum)
public static string IterateIdShortTemplateToBeUnique(this IList<IConceptDescription> cds, string idShortTemplate, int maxNum)
{
if (idShortTemplate == null || maxNum < 1 || !idShortTemplate.Contains("{0"))
return null;
Expand Down
Loading

0 comments on commit 6c9c7af

Please sign in to comment.