blob: be8ba8eb6fa7e321f0cb73d5bffca9453249c771 [file] [log] [blame]
Constantin Ziesche8b4a64d2020-06-25 11:52:09 +02001/*******************************************************************************
2* Copyright (c) 2020 Robert Bosch GmbH
3* Author: Constantin Ziesche (constantin.ziesche@bosch.com)
4*
5* This program and the accompanying materials are made available under the
6* terms of the Eclipse Distribution License 1.0 which is available at
7* https://www.eclipse.org/org/documents/edl-v10.html
8*
9*
10*******************************************************************************/
11using BaSyx.Models.Core.AssetAdministrationShell.Enums;
12using BaSyx.Models.Core.AssetAdministrationShell.Generics;
13using BaSyx.Models.Core.AssetAdministrationShell.Generics.SubmodelElementTypes;
14using BaSyx.Models.Core.AssetAdministrationShell.Identification;
15using BaSyx.Models.Core.AssetAdministrationShell.Implementations;
16using BaSyx.Models.Core.AssetAdministrationShell.Implementations.SubmodelElementTypes;
17using BaSyx.Models.Core.AssetAdministrationShell.References;
18using BaSyx.Models.Core.Common;
19using BaSyx.Models.Extensions;
20using BaSyx.Utils.ResultHandling;
21using System;
22using System.Threading.Tasks;
23
24namespace SimpleAssetAdministrationShell
25{
26 public static class SimpleAssetAdministrationShell
27 {
28 public static AssetAdministrationShell GetAssetAdministrationShell()
29 {
30 AssetAdministrationShell aas = new AssetAdministrationShell()
31 {
32 IdShort = "SimpleAAS",
33 Identification = new Identifier("http://basys40.de/shells/SimpleAAS/" + Guid.NewGuid().ToString(), KeyType.IRI),
34 Description = new LangStringSet()
35 {
36 new LangString("de-DE", "Einfache VWS"),
37 new LangString("en-US", "Simple AAS")
38 },
39 Administration = new AdministrativeInformation()
40 {
41 Version = "1.0",
42 Revision = "120"
43 },
44 Asset = new Asset()
45 {
46 IdShort = "SimpleAsset",
47 Identification = new Identifier("http://basys40.de/assets/SimpleAsset/" + Guid.NewGuid().ToString(), KeyType.IRI),
48 Kind = AssetKind.Instance,
49 Description = new LangStringSet()
50 {
51 new LangString("de-DE", "Einfaches Asset"),
52 new LangString("en-US", "Simple Asset")
53 }
54 }
55 };
56
57 Submodel testSubmodel = GetTestSubmodel();
58
59 aas.Submodels.Add(testSubmodel);
60
61 return aas;
62 }
63
64 public static Submodel GetTestSubmodel()
65 {
66 string propertyValue = "TestFromInside";
67 int i = 0;
68 double y = 2.0;
69
70 Submodel testSubmodel = new Submodel()
71 {
72 IdShort = "TestSubmodel",
73 Identification = new Identifier(Guid.NewGuid().ToString(), KeyType.Custom),
74 SubmodelElements = new ElementContainer<ISubmodelElement>()
75 {
76 new Property<string>()
77 {
78 IdShort = "TestProperty1",
79 Set = (prop, val) => propertyValue = val,
80 Get = prop => { return propertyValue + "_" + i++; }
81 },
82 new Property<string>()
83 {
84 IdShort = "TestProperty2",
85 Set = (prop, val) => propertyValue = val,
86 Get = prop => { return propertyValue + "_" + i++; }
87 },
88 new Property<int>()
89 {
90 IdShort = "TestProperty3",
91 Set = (prop, val) => i = val,
92 Get = prop => { return i++; }
93 },
94 new Property<double>()
95 {
96 IdShort = "TestProperty4",
97 Set = (prop, val) => y = val,
98 Get = prop => { return Math.Pow(y, i); }
99 },
100 new Operation()
101 {
102 IdShort = "GetTime",
103 OutputVariables = new OperationVariableSet()
104 {
105 new Property<string>()
106 {
107 IdShort = "Date"
108 },
109 new Property<string>()
110 {
111 IdShort = "Time"
112 },
113 new Property<string>()
114 {
115 IdShort = "Ticks"
116 },
117 },
118 OnMethodCalled = (op, inArgs, outArgs) =>
119 {
120 outArgs.Add(new Property<string>() { IdShort = "Date", Value = "Heute ist der " + DateTime.Now.Date.ToString() });
121 outArgs.Add(new Property<string>() { IdShort = "Time", Value = "Es ist " + DateTime.Now.TimeOfDay.ToString() + " Uhr" });
122 outArgs.Add(new Property<string>() { IdShort = "Ticks", Value = "Ticks: " + DateTime.Now.Ticks.ToString() });
123 return new OperationResult(true);
124 }
125 },
126 new Operation()
127 {
128 IdShort = "Calculate",
129 Description = new LangStringSet()
130 {
131 new LangString("DE", "Taschenrechner mit simulierter langer Rechenzeit zum Testen von asynchronen Aufrufen"),
132 new LangString("EN", "Calculator with simulated long-running computing time for testing asynchronous calls")
133 },
134 InputVariables = new OperationVariableSet()
135 {
136 new Property<string>()
137 {
138 IdShort = "Expression",
139 Description = new LangStringSet()
140 {
141 new LangString("DE", "Ein mathematischer Ausdruck (z.B. 5*9)"),
142 new LangString("EN", "A mathematical expression (e.g. 5*9)")
143 }
144 },
145 new Property<int>()
146 {
147 IdShort = "ComputingTime",
148 Description = new LangStringSet()
149 {
150 new LangString("DE", "Die Bearbeitungszeit in Millisekunden"),
151 new LangString("EN", "The computation time in milliseconds")
152 }
153 }
154 },
155 OutputVariables = new OperationVariableSet()
156 {
157 new Property<double>()
158 {
159 IdShort = "Result"
160 }
161 },
162 OnMethodCalled = async (op, inArgs, outArgs) =>
163 {
Constantin Ziescheb4a60112020-08-05 12:08:10 +0200164 string expression = inArgs.Get("Expression")?.Cast<IProperty>()?.ToObject<string>();
165 int? computingTime = inArgs.Get("ComputingTime")?.Cast<IProperty>()?.ToObject<int>();
Constantin Ziesche8b4a64d2020-06-25 11:52:09 +0200166
167 if(computingTime.HasValue)
168 await Task.Delay(computingTime.Value);
169
170 double value = CalulcateExpression(expression);
171
172 outArgs.Add(new Property<double>() { IdShort = "Result", Value = value });
173
174 return new OperationResult(true);
175 }
176 }
177
178 }
179 };
180 return testSubmodel;
181 }
182
183 public static double CalulcateExpression(string expression)
184 {
185 string columnName = "Evaluation";
186 System.Data.DataTable dataTable = new System.Data.DataTable();
187 System.Data.DataColumn dataColumn = new System.Data.DataColumn(columnName, typeof(double), expression);
188 dataTable.Columns.Add(dataColumn);
189 dataTable.Rows.Add(0);
190 return (double)(dataTable.Rows[0][columnName]);
191 }
192 }
193}