Skip to content

Commit 12820b0

Browse files
committed
* update
* introduce plugin for product change notifications * export AsciiDoc
1 parent 9412e93 commit 12820b0

File tree

65 files changed

+3413
-515
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+3413
-515
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
Copyright (c) 2018-2023 Festo SE & Co. KG <https://www.festo.com/net/de_de/Forms/web/contact_international>
3+
Author: Michael Hoffmeister
4+
5+
This source code is licensed under the Apache License 2.0 (see LICENSE.txt).
6+
7+
This source code may use other Open Source software components (see LICENSE.txt).
8+
*/
9+
10+
using AasxCompatibilityModels;
11+
using Extensions;
12+
using System;
13+
using System.Collections;
14+
using System.Collections.Generic;
15+
using System.ComponentModel;
16+
using System.Globalization;
17+
using System.IO;
18+
using System.IO.Packaging;
19+
using System.Linq;
20+
using System.Reflection;
21+
using System.Runtime.Serialization;
22+
using System.Text;
23+
using System.Text.RegularExpressions;
24+
25+
namespace AdminShellNS
26+
{
27+
/// <summary>
28+
/// Some string based flags to attach to the property
29+
/// </summary>
30+
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple = true)]
31+
public class ExtensionFlagsAttribute : System.Attribute
32+
{
33+
public string Flags = "";
34+
35+
public ExtensionFlagsAttribute(string flags)
36+
{
37+
Flags = flags;
38+
}
39+
}
40+
41+
/// <summary>
42+
/// This attribute attaches some hint text.
43+
/// </summary>
44+
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple = false)]
45+
public class ExtensionHintAttributeAttribute : System.Attribute
46+
{
47+
public string HintText = "";
48+
49+
public ExtensionHintAttributeAttribute(string hintText)
50+
{
51+
if (hintText != null)
52+
HintText = hintText;
53+
}
54+
}
55+
56+
/// <summary>
57+
/// This attribute attaches a max lines number to a property.
58+
/// </summary>
59+
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property)]
60+
public class ExtensionMultiLineAttribute : System.Attribute
61+
{
62+
public int? MaxLines = null;
63+
64+
public ExtensionMultiLineAttribute(int maxLines = -1)
65+
{
66+
if (maxLines > 0)
67+
MaxLines = maxLines;
68+
}
69+
}
70+
71+
/// <summary>
72+
/// This attribute attaches a display text.
73+
/// </summary>
74+
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property)]
75+
public class EnumMemberDisplayAttribute : System.Attribute
76+
{
77+
public string Text = "";
78+
79+
public EnumMemberDisplayAttribute(string text)
80+
{
81+
if (text != null)
82+
Text = text;
83+
}
84+
}
85+
86+
/// <summary>
87+
/// This class adds some helpers for handling enums.
88+
/// </summary>
89+
public static class AdminShellEnumHelper
90+
{
91+
public class EnumHelperMemberInfo
92+
{
93+
public string MemberValue = "";
94+
public string MemberDisplay = "";
95+
public object MemberInstance;
96+
}
97+
98+
public static IEnumerable<EnumHelperMemberInfo> EnumHelperGetMemberInfo(Type underlyingType)
99+
{
100+
foreach (var enumMemberInfo in underlyingType.GetFields(BindingFlags.Public | BindingFlags.Static))
101+
{
102+
var enumInst = Activator.CreateInstance(underlyingType);
103+
104+
var memVal = enumMemberInfo.GetCustomAttribute<EnumMemberAttribute>()?.Value;
105+
var memDisp = enumMemberInfo.GetCustomAttribute<EnumMemberDisplayAttribute>()?.Text;
106+
107+
if (memVal?.HasContent() == true)
108+
{
109+
var ev = enumMemberInfo.GetValue(enumInst);
110+
111+
yield return new EnumHelperMemberInfo()
112+
{
113+
MemberValue = memVal,
114+
MemberDisplay = (memDisp?.HasContent() == true) ? memDisp : memVal,
115+
MemberInstance = ev
116+
};
117+
}
118+
}
119+
}
120+
121+
public static T GetEnumMemberFromValueString<T>(string valStr, T valElse = default(T)) where T : struct
122+
{
123+
foreach (var em in EnumHelperGetMemberInfo(typeof(T)))
124+
if (em.MemberValue.Equals(valStr?.Trim(), StringComparison.InvariantCultureIgnoreCase))
125+
return (T)em.MemberInstance;
126+
return (T)valElse;
127+
}
128+
129+
/// <summary>
130+
/// Use the EnumMemberDisplay attribute to resolve the text
131+
/// </summary>
132+
public static string GetEnumMemberDisplay(Type enumType, object enumValue)
133+
{
134+
// access
135+
if (enumType == null || enumValue == null)
136+
return "";
137+
138+
// see: https://stackoverflow.com/questions/1799370/getting-attributes-of-enums-value
139+
var memberInfos = enumType.GetFields(BindingFlags.Public | BindingFlags.Static);
140+
var enumValueMemberInfo = memberInfos.FirstOrDefault(m =>
141+
m.Name == enumValue.ToString()
142+
&& m.DeclaringType == enumType);
143+
var valueAttributes =
144+
enumValueMemberInfo.GetCustomAttributes(typeof(EnumMemberDisplayAttribute), false);
145+
return ((EnumMemberDisplayAttribute)valueAttributes[0]).Text;
146+
}
147+
}
148+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
Copyright (c) 2018-2023 Festo SE & Co. KG <https://www.festo.com/net/de_de/Forms/web/contact_international>
3+
Author: Michael Hoffmeister
4+
5+
This source code is licensed under the Apache License 2.0 (see LICENSE.txt).
6+
7+
This source code may use other Open Source software components (see LICENSE.txt).
8+
*/
9+
10+
using AasxCompatibilityModels;
11+
using Extensions;
12+
using System;
13+
using System.Collections;
14+
using System.Collections.Generic;
15+
using System.Globalization;
16+
using System.IO;
17+
using System.IO.Packaging;
18+
using System.Linq;
19+
using System.Reflection;
20+
using System.Text;
21+
using System.Text.RegularExpressions;
22+
23+
namespace AdminShellNS
24+
{
25+
public static class AdminShellStringExtensions
26+
{
27+
public static bool HasContent(this string str)
28+
{
29+
return str != null && str.Trim() != "";
30+
}
31+
32+
public static string SubstringMax(this string str, int pos, int len)
33+
{
34+
if (!str.HasContent() || str.Length <= pos)
35+
return "";
36+
return str.Substring(pos, Math.Min(len, str.Length));
37+
}
38+
39+
public static void SetIfNoContent(ref string s, string input)
40+
{
41+
if (!input.HasContent())
42+
return;
43+
if (!s.HasContent())
44+
s = input;
45+
}
46+
47+
public static string AddWithDelimiter(this string str, string content, string delimter = "")
48+
{
49+
var res = str;
50+
if (res == null)
51+
return null;
52+
53+
if (res.HasContent())
54+
res += "" + delimter;
55+
56+
res += content;
57+
58+
return res;
59+
}
60+
61+
}
62+
}

src/AasxCsharpLibrary/Extensions/ExtendEnvironment.cs

+17-15
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,17 @@ public static AasCore.Aas3_0.IEnvironment ConvertFromV10(this AasCore.Aas3_0.IEn
174174
}
175175
foreach (var sourceAas in sourceEnvironement.AdministrationShells)
176176
{
177+
var newAssetInformation = new AssetInformation(AssetKind.Instance);
178+
var newAas = new AssetAdministrationShell(
179+
id: sourceAas.identification.id, newAssetInformation);
180+
environment.AssetAdministrationShells.Add(newAas);
181+
177182
var sourceAsset = sourceEnvironement?.FindAsset(sourceAas.assetRef);
178183
if (sourceAsset != null)
179184
{
180-
var newAssetInformation = new AssetInformation(AssetKind.Instance);
181185
newAssetInformation = newAssetInformation.ConvertFromV10(sourceAsset);
182-
183-
var newAas = new AssetAdministrationShell(id: sourceAas.identification.id, newAssetInformation);
184-
newAas = newAas.ConvertFromV10(sourceAas);
185-
186-
environment.AssetAdministrationShells.Add(newAas);
186+
newAas.AssetInformation = newAssetInformation;
187187
}
188-
189188
}
190189
}
191190

@@ -766,17 +765,20 @@ public static IReferable FindReferableByReference(
766765
{
767766
var submodelElement = submodelElems.Where(
768767
sme => sme.IdShort.Equals(keyList[keyIndex].Value,
769-
StringComparison.OrdinalIgnoreCase)).First();
768+
StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
770769

771-
//This is required element
772-
if (keyIndex + 1 >= keyList.Count)
770+
if (submodelElement != null)
773771
{
774-
return submodelElement;
775-
}
772+
//This is required element
773+
if (keyIndex + 1 >= keyList.Count)
774+
{
775+
return submodelElement;
776+
}
776777

777-
//Recurse again
778-
if (submodelElement?.EnumeratesChildren() == true)
779-
return environment.FindReferableByReference(reference, ++keyIndex, submodelElement.EnumerateChildren());
778+
//Recurse again
779+
if (submodelElement?.EnumeratesChildren() == true)
780+
return environment.FindReferableByReference(reference, ++keyIndex, submodelElement.EnumerateChildren());
781+
}
780782
}
781783

782784
//Nothing in this environment

src/AasxCsharpLibrary/Extensions/ExtendQualifier.cs

+15-8
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,31 @@ public static string ToStringExtended(this IQualifier q,
130130

131131
#region QualifierCollection
132132

133-
public static IQualifier FindQualifierOfType(this List<IQualifier> qualifiers, string qualifierType)
133+
public static IQualifier FindQualifierOfType(this IEnumerable<IQualifier> qualifiers, string qualifierType)
134134
{
135-
if (qualifierType == null)
136-
{
135+
if (qualifiers == null || qualifierType == null)
137136
return null;
138-
}
139137

140138
foreach (var qualifier in qualifiers)
141-
{
142139
if (qualifier != null && qualifierType.Equals(qualifier.Type))
143-
{
144140
return qualifier;
145-
}
146-
}
147141

148142
return null;
149143
}
150144

145+
public static IEnumerable<IQualifier> FindQualifierOfAnyType(
146+
this IEnumerable<IQualifier> qualifiers, string[] qualifierTypes)
147+
{
148+
if (qualifierTypes == null || qualifierTypes.Length < 1)
149+
yield break;
150+
foreach (var qualifierType in qualifierTypes)
151+
{
152+
var res = FindQualifierOfType(qualifiers, qualifierType);
153+
if (res != null)
154+
yield return res;
155+
}
156+
}
157+
151158
// ReSharper disable MethodOverloadWithOptionalParameter .. this seems to work, anyhow
152159
// ReSharper disable RedundantArgumentDefaultValue
153160
public static string ToStringExtended(this List<IQualifier> qualifiers,

src/AasxIntegrationBase/AasxSearchUtil.cs

+22-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This source code is licensed under the Apache License 2.0 (see LICENSE.txt).
77
This source code may use other Open Source software components (see LICENSE.txt).
88
*/
99

10+
using AdminShellNS;
1011
using Extensions;
1112
using System;
1213
using System.Collections;
@@ -263,7 +264,9 @@ public static IEnumerable<EmulateAttribute> EnumerateEmulateAttributes(Aas.IClas
263264
/// </summary>
264265
public static void CheckSearchable(
265266
SearchResults results, SearchOptions options, string qualifiedNameHead, object businessObject,
266-
MemberInfo mi, object memberValue, object containingObject, Func<int> getMemberHash,
267+
MemberInfo mi, object memberValue, object containingObject,
268+
Func<int> getMemberHash,
269+
object foundObjectToDisplay,
267270
Action<bool, int> progress = null, LogInstance log = null)
268271
{
269272
// try get a speaking name
@@ -294,7 +297,6 @@ public static void CheckSearchable(
294297

295298
var isMLP = (businessObject is Aas.MultiLanguageProperty);
296299

297-
298300
if (!options.SearchCollection && isColl)
299301
return;
300302

@@ -340,7 +342,7 @@ public static void CheckSearchable(
340342
sri.metaModelName = metaModelName;
341343
sri.businessObject = businessObject;
342344
sri.foundText = foundText;
343-
sri.foundObject = memberValue;
345+
sri.foundObject = foundObjectToDisplay;
344346
sri.containingObject = containingObject;
345347
if (getMemberHash != null)
346348
sri.foundHash = getMemberHash();
@@ -666,6 +668,11 @@ public static void EnumerateSearchableNew(
666668
// report a "false" progress
667669
progress?.Invoke(false, 0);
668670

671+
if (businessObject is Aas.Blob)
672+
{
673+
;
674+
}
675+
669676
// look at fields, first
670677
var fields = objType.GetFields();
671678
foreach (var fi in fields)
@@ -684,7 +691,7 @@ public static void EnumerateSearchableNew(
684691
// field is a single entity .. check it
685692
CheckSearchable(
686693
results, options, qualifiedName, businessObject, fi, fieldValue, obj,
687-
() => { return fieldValue.GetHashCode(); }, progress, log);
694+
() => { return fieldValue.GetHashCode(); }, fieldValue, progress, log);
688695
}
689696
}
690697

@@ -705,13 +712,23 @@ public static void EnumerateSearchableNew(
705712
if (valueElems != null)
706713
{
707714
// property is a collection
715+
// some special case: Blob having a text inside
716+
if (propValue is byte[] pvbytes
717+
&& businessObject is Aas.IBlob blb
718+
&& AdminShellUtil.CheckForTextContentType(blb.ContentType))
719+
{
720+
string strData = System.Text.Encoding.UTF8.GetString(pvbytes);
721+
CheckSearchable(
722+
results, options, qualifiedName, businessObject, pi, strData, obj,
723+
() => { return propValue.GetHashCode(); }, propValue, progress, log);
724+
}
708725
}
709726
else
710727
{
711728
// field is a single entity .. check it
712729
CheckSearchable(
713730
results, options, qualifiedName, businessObject, pi, propValue, obj,
714-
() => { return propValue.GetHashCode(); }, progress, log);
731+
() => { return propValue.GetHashCode(); }, propValue, progress, log);
715732
}
716733
}
717734

0 commit comments

Comments
 (0)