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

Code cleanup #648

Merged
merged 6 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/AASXPackageExplorerSetup/wix-main/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# wix
wix standalone - checkout this repo to build wix project inside github action

## Workflow example

```yaml
name: .NET Core Build

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- name: Install Wix
uses: actions/checkout@v2
with:
repository: fbarresi/wix
path: wix
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.101
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --no-restore --verbosity normal
- name: Build Setup
run: |
wix\tools\candle.exe Product.wxs -o obj\ -ext WixUtilExtension -ext WixUIExtension
wix\tools\light.exe obj\*.wixobj -o bin\Installer.msi -ext WixUtilExtension -ext WixUIExtension -dWixUILicenseRtf="License.rtf"
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: 1.0.${{ github.run_number }}
release_name: 1.0.${{ github.run_number }}
draft: false
prerelease: false
- name: Upload Installer
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: bin\Installer.msi
asset_name: Installer_v1.0.${{ github.run_number }}.msi
asset_content_type: application/x-msi

```
2 changes: 1 addition & 1 deletion src/AasxCsharpLibrary/AdminShellConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
jsonStr = jsonStr.TrimStart('{').TrimEnd('}');
writer.WriteRaw(jsonStr);
writer.WriteEndObject();
}
}
else
{
// double-digest by a text reader and rewrite token stream
Expand Down
2 changes: 1 addition & 1 deletion src/AasxCsharpLibrary/AdminShellUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public static ISubmodelElement CreateSubmodelElementFromEnum(AasSubmodelElements
}
case AasSubmodelElements.ReferenceElement:
{
// TODO: AAS core crashes without this
// TODO (??, 0000-00-00): AAS core crashes without this
return new ReferenceElement(
value: new Reference(ReferenceTypes.ExternalReference, new List<IKey>())
).UpdateFrom(sourceSme);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public static void Remove(this AnnotatedRelationshipElement annotatedRelationshi
}

public static object AddChild(
this AnnotatedRelationshipElement annotatedRelationshipElement,
ISubmodelElement childSubmodelElement,
this AnnotatedRelationshipElement annotatedRelationshipElement,
ISubmodelElement childSubmodelElement,
EnumerationPlacmentBase placement = null)
{
if (childSubmodelElement == null || childSubmodelElement is not IDataElement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public static EmbeddedDataSpecification ConvertFromV20(this EmbeddedDataSpecific
// TODO (MIHO, 2022-19-12): check again, see questions
var oldid = new[] {
"http://admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360/2/0",
"http://admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360",
"www.admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360"
};
"http://admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360",
"www.admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360"
};
var newid = "http://admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360/3/0";

// map all "usable" old ids to new one ..
Expand Down
10 changes: 5 additions & 5 deletions src/AasxCsharpLibrary/Extensions/ExtendEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ public static ISubmodel FindSubmodelById(this AasCore.Aas3_0.Environment environ

return null;
}

// dead-csharp off
//public static IEnumerable<ISubmodel> FindAllSubmodelsGroupedByAAS(this AasCore.Aas3_0.Environment environment, Func<IAssetAdministrationShell, ISubmodel, bool> p = null)
//{
// if (environment.AssetAdministrationShells == null || environment.Submodels == null)
Expand All @@ -555,7 +555,7 @@ public static ISubmodel FindSubmodelById(this AasCore.Aas3_0.Environment environ
// }
// }
//}

// dead-csharp on
public static IEnumerable<ISubmodel> FindAllSubmodelBySemanticId(this AasCore.Aas3_0.Environment environment, string semanticId)
{
if (semanticId == null)
Expand Down Expand Up @@ -1064,20 +1064,20 @@ private static void CopyConceptDescriptionsFrom(this AasCore.Aas3_0.Environment
// access
if (srcEnv == null || src == null || src.SemanticId == null)
return;

// check for this SubmodelElement in Source
var cdSrc = srcEnv.FindConceptDescriptionByReference(src.SemanticId);
if (cdSrc == null)
return;

// check for this SubmodelElement in Destnation (this!)
var cdDest = environment.FindConceptDescriptionByReference(src.SemanticId);
if (cdDest == null)
{
// copy new
environment.ConceptDescriptions.Add(cdSrc.Copy());
}

// recurse?
if (!shallowCopy)
foreach (var m in src.EnumerateChildren())
Expand Down
26 changes: 13 additions & 13 deletions src/AasxCsharpLibrary/Extensions/ExtendIReferable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ namespace Extensions
{
public static class ExtendIReferable
{
#region AasxPackageExplorer

/// <summary>
/// Recurses on all Submodel elements of a Submodel or SME, which allows children.
/// The <c>state</c> object will be passed to the lambda function in order to provide
/// stateful approaches. Include this element, as well.
/// </summary>
/// <param name="state">State object to be provided to lambda. Could be <c>null.</c></param>
/// <param name="lambda">The lambda function as <c>(state, parents, SME)</c>
/// The lambda shall return <c>TRUE</c> in order to deep into recursion.</param>
/// <param name="includeThis">Include this element as well. <c>parents</c> will then
/// include this element as well!</param>
public static void RecurseOnReferables(this IReferable referable,
#region AasxPackageExplorer

/// <summary>
/// Recurses on all Submodel elements of a Submodel or SME, which allows children.
/// The <c>state</c> object will be passed to the lambda function in order to provide
/// stateful approaches. Include this element, as well.
/// </summary>
/// <param name="state">State object to be provided to lambda. Could be <c>null.</c></param>
/// <param name="lambda">The lambda function as <c>(state, parents, SME)</c>
/// The lambda shall return <c>TRUE</c> in order to deep into recursion.</param>
/// <param name="includeThis">Include this element as well. <c>parents</c> will then
/// include this element as well!</param>
public static void RecurseOnReferables(this IReferable referable,
object state, Func<object, List<IReferable>, IReferable, bool> lambda,
bool includeThis = false)
{
Expand Down
38 changes: 19 additions & 19 deletions src/AasxCsharpLibrary/Extensions/ExtendISubmodelElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,37 +1014,37 @@ public static T FindFirstSemanticIdAs<T>(this List<ISubmodelElement> submodelEle
return submodelElements.FindAllSemanticIdAs<T>(semId, matchMode).FirstOrDefault<T>();
}

public static List<ISubmodelElement> GetChildListFromFirstSemanticId(
public static List<ISubmodelElement> GetChildListFromFirstSemanticId(
this List<ISubmodelElement> submodelElements,
IKey semKey, MatchMode matchMode = MatchMode.Strict)
{
IKey semKey, MatchMode matchMode = MatchMode.Strict)
{
return FindFirstSemanticIdAs<ISubmodelElement>(submodelElements, semKey, matchMode)?.GetChildsAsList();
}
}

public static List<ISubmodelElement> GetChildListFromFirstSemanticId(
public static List<ISubmodelElement> GetChildListFromFirstSemanticId(
this List<ISubmodelElement> submodelElements,
IReference semId, MatchMode matchMode = MatchMode.Strict)
IReference semId, MatchMode matchMode = MatchMode.Strict)
{
return FindFirstSemanticIdAs<ISubmodelElement>(submodelElements, semId, matchMode)?.GetChildsAsList();
}
return FindFirstSemanticIdAs<ISubmodelElement>(submodelElements, semId, matchMode)?.GetChildsAsList();
}

public static IEnumerable<List<ISubmodelElement>> GetChildListsFromAllSemanticId(
public static IEnumerable<List<ISubmodelElement>> GetChildListsFromAllSemanticId(
this List<ISubmodelElement> submodelElements,
IKey semKey, MatchMode matchMode = MatchMode.Strict)
{
IKey semKey, MatchMode matchMode = MatchMode.Strict)
{
foreach (var child in FindAllSemanticIdAs<ISubmodelElement>(submodelElements, semKey, matchMode))
yield return child.GetChildsAsList()?.ToList();
}
}

public static IEnumerable<List<ISubmodelElement>> GetChildListsFromAllSemanticId(
public static IEnumerable<List<ISubmodelElement>> GetChildListsFromAllSemanticId(
this List<ISubmodelElement> submodelElements,
IReference semId, MatchMode matchMode = MatchMode.Strict)
{
foreach (var child in FindAllSemanticIdAs<ISubmodelElement>(submodelElements, semId, matchMode))
yield return child.GetChildsAsList()?.ToList();
}
IReference semId, MatchMode matchMode = MatchMode.Strict)
{
foreach (var child in FindAllSemanticIdAs<ISubmodelElement>(submodelElements, semId, matchMode))
yield return child.GetChildsAsList()?.ToList();
}

public static IEnumerable<ISubmodelElement> Join(params IEnumerable<ISubmodelElement>[] lists)
public static IEnumerable<ISubmodelElement> Join(params IEnumerable<ISubmodelElement>[] lists)
{
if (lists == null || lists.Length < 1)
yield break;
Expand Down
92 changes: 46 additions & 46 deletions src/AasxCsharpLibrary/Extensions/ExtendKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public static Key Parse(string cell, KeyTypes typeIfNotSet = KeyTypes.GlobalRefe
return null;
}

#region Guess identification types
#region Guess identification types

public enum IdType { Unknown = 0, IRI, IRDI };

Expand All @@ -213,56 +213,56 @@ public static IdType GuessIdType(string id)
return IdType.IRDI;

// IRI?
// TODO: check for escaping
// TODO (??, 0000-00-00): check for escaping
if (Regex.IsMatch(id, @"(\w{3,5})://"))
return IdType.IRI;

// unsure
return IdType.Unknown;
}

#endregion

// dead-csharp off
// -------------------------------------------------------------------------------------------------------------
#region Handling with enums for KeyTypes

// see: https://stackoverflow.com/questions/27372816/how-to-read-the-value-for-an-enummember-attribute
//public static string? GetEnumMemberValue<T>(this T value)
// where T : Enum
//{
// return typeof(T)
// .GetTypeInfo()
// .DeclaredMembers
// .SingleOrDefault(x => x.Name == value.ToString())
// ?.GetCustomAttribute<EnumMemberAttribute>(false)
// ?.Value;
//}

//public static KeyTypes? MapFrom(AasReferables input)
//{
// var st = input.GetEnumMemberValue();
// var res = Stringification.KeyTypesFromString(st);
// return res;
//}

//public static List<KeyTypes> MapFrom(IEnumerable<AasReferables> input)
//{
// List<KeyTypes> res = new();
// foreach (var i in input)
// {
// var x = MapFrom(i);
// if (x.HasValue)
// res.Add(x.Value);
// }
// return res;
//}

//public static List<KeyTypes> GetAllKeyTypesForAasReferables()
// => ExtendKey.MapFrom(Enum.GetValues(typeof(AasReferables)).OfType<AasReferables>());

#endregion
// dead-csharp on

}
#endregion

// dead-csharp off
// -------------------------------------------------------------------------------------------------------------
#region Handling with enums for KeyTypes

// see: https://stackoverflow.com/questions/27372816/how-to-read-the-value-for-an-enummember-attribute
//public static string? GetEnumMemberValue<T>(this T value)
// where T : Enum
//{
// return typeof(T)
// .GetTypeInfo()
// .DeclaredMembers
// .SingleOrDefault(x => x.Name == value.ToString())
// ?.GetCustomAttribute<EnumMemberAttribute>(false)
// ?.Value;
//}

//public static KeyTypes? MapFrom(AasReferables input)
//{
// var st = input.GetEnumMemberValue();
// var res = Stringification.KeyTypesFromString(st);
// return res;
//}

//public static List<KeyTypes> MapFrom(IEnumerable<AasReferables> input)
//{
// List<KeyTypes> res = new();
// foreach (var i in input)
// {
// var x = MapFrom(i);
// if (x.HasValue)
// res.Add(x.Value);
// }
// return res;
//}

//public static List<KeyTypes> GetAllKeyTypesForAasReferables()
// => ExtendKey.MapFrom(Enum.GetValues(typeof(AasReferables)).OfType<AasReferables>());

#endregion
// dead-csharp on

}
}
2 changes: 1 addition & 1 deletion src/AasxCsharpLibrary/Extensions/ExtendReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public static bool Matches(this IReference reference, string id)

public static bool Matches(this IReference reference, IReference otherReference, MatchMode matchMode = MatchMode.Strict)
{
if (reference.Keys == null || reference.Keys.Count == 0
if (reference.Keys == null || reference.Keys.Count == 0
|| otherReference?.Keys == null || otherReference.Keys.Count == 0
|| reference.Keys.Count != otherReference.Keys.Count)
{
Expand Down
26 changes: 13 additions & 13 deletions src/AasxCsharpLibrary/Extensions/ExtendSubmodel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void Remove(this Submodel submodel, ISubmodelElement submodelEleme
}

public static object AddChild(
this ISubmodel submodel, ISubmodelElement childSubmodelElement,
this ISubmodel submodel, ISubmodelElement childSubmodelElement,
EnumerationPlacmentBase placement = null)
{
if (childSubmodelElement == null)
Expand Down Expand Up @@ -346,20 +346,20 @@ public static Key GetSemanticKey(this Submodel submodel)
return new Key(KeyTypes.Submodel, submodel.Id);
}

/// <summary>
/// If instance, return semanticId as one key.
/// If template, return identification as key.
/// </summary>
public static IReference GetSemanticRef(this Submodel submodel)
{
if (submodel.Kind == ModellingKind.Instance)
return submodel.SemanticId;
else
return new Reference(ReferenceTypes.ModelReference, new[] {
/// <summary>
/// If instance, return semanticId as one key.
/// If template, return identification as key.
/// </summary>
public static IReference GetSemanticRef(this Submodel submodel)
{
if (submodel.Kind == ModellingKind.Instance)
return submodel.SemanticId;
else
return new Reference(ReferenceTypes.ModelReference, new[] {
new Key(KeyTypes.Submodel, submodel.Id) }.Cast<IKey>().ToList());
}
}

public static List<ISubmodelElement> SmeForWrite(this Submodel submodel)
public static List<ISubmodelElement> SmeForWrite(this Submodel submodel)
{
if (submodel.SubmodelElements == null)
submodel.SubmodelElements = new();
Expand Down
Loading
Loading