ValueChangedEvent added as example implementation
Logging added
diff --git a/sdks/dotnet/basyx-examples/SimpleAssetAdministrationShell/NLog.config b/sdks/dotnet/basyx-examples/SimpleAssetAdministrationShell/NLog.config
new file mode 100644
index 0000000..f9bb05a
--- /dev/null
+++ b/sdks/dotnet/basyx-examples/SimpleAssetAdministrationShell/NLog.config
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true">
+ <targets>
+ <target name="console" xsi:type="ColoredConsole" layout="${longdate} - ${level} - ${logger} - ${message} ${exception:format=ToString,StackTrace}${newline}" />
+ <target name="file" xsi:type="File"
+ layout="${longdate} - ${level} - ${logger} - ${message} ${exception:format=ToString,StackTrace}${newline}"
+ fileName="${basedir}/logs/logfile.txt"
+ keepFileOpen="true"
+ maxArchiveFiles="10"
+ archiveAboveSize="1048576"
+ encoding="utf-8" />
+ </targets>
+ <rules>
+ <logger name="*" minlevel="Info" writeTo="console" />
+ <logger name="*" minlevel="Info" writeTo="file" />
+ </rules>
+</nlog>
\ No newline at end of file
diff --git a/sdks/dotnet/basyx-examples/SimpleAssetAdministrationShell/SimpleAssetAdministrationShell.cs b/sdks/dotnet/basyx-examples/SimpleAssetAdministrationShell/SimpleAssetAdministrationShell.cs
index 26c912e..069c6e7 100644
--- a/sdks/dotnet/basyx-examples/SimpleAssetAdministrationShell/SimpleAssetAdministrationShell.cs
+++ b/sdks/dotnet/basyx-examples/SimpleAssetAdministrationShell/SimpleAssetAdministrationShell.cs
@@ -9,12 +9,14 @@
*
*******************************************************************************/
using BaSyx.Models.Core.AssetAdministrationShell;
+using BaSyx.Models.Core.AssetAdministrationShell.Generics;
using BaSyx.Models.Core.AssetAdministrationShell.Identification;
using BaSyx.Models.Core.AssetAdministrationShell.Identification.BaSyx;
using BaSyx.Models.Core.AssetAdministrationShell.Implementations;
using BaSyx.Models.Core.Common;
using BaSyx.Models.Extensions;
using BaSyx.Utils.ResultHandling;
+using NLog;
using System;
using System.Threading.Tasks;
@@ -22,6 +24,7 @@
{
public static class SimpleAssetAdministrationShell
{
+ private static readonly ILogger logger = LogManager.GetCurrentClassLogger();
public static AssetAdministrationShell GetAssetAdministrationShell()
{
AssetAdministrationShell aas = new AssetAdministrationShell("SimpleAAS", new BaSyxShellIdentifier("SimpleAAS", "1.0.0"))
@@ -84,6 +87,17 @@
Set = (prop, val) => y = val,
Get = prop => { return Math.Pow(y, i); }
},
+ new Property<string>("TestPropertyNull")
+ {
+ Set = (prop, val) => propertyValue = val,
+ Get = prop => { return null; }
+ },
+ new Property<string>("TestPropertyNoSetter")
+ {
+ Set = null,
+ Get = prop => { return "You can't change me!"; }
+ },
+ new Property<string>("TestValueChanged1", "InitialValue"),
new SubmodelElementCollection("TestSubmodelElementCollection")
{
Value =
@@ -178,9 +192,17 @@
}
};
+
+ testSubmodel.SubmodelElements["TestProperty4"].Cast<IProperty>().ValueChanged += SimpleAssetAdministrationShell_ValueChanged;
+
return testSubmodel;
}
+ private static void SimpleAssetAdministrationShell_ValueChanged(object sender, ValueChangedArgs e)
+ {
+ logger.Info($"Property {e.IdShort} changed to {e.Value}");
+ }
+
public static double CalulcateExpression(string expression)
{
string columnName = "Evaluation";