public static void createSubmodelElements( UaNode n, AdminShell.AdministrationShellEnv env, AdminShell.SubmodelElementCollection smec, AdminShell.SubmodelRef smref, string path, AdminShell.SubmodelElementCollection concepts) { String name = n.BrowseName; if (n.SymbolicName != null && n.SymbolicName != "") { name = n.SymbolicName; } var semanticID = AdminShell.Key.CreateNew("GlobalReference", false, "IRI", path + name); if ((n.children != null && n.children.Count != 0) || (n.fields != null && n.fields.Count != 0)) { var sme = AdminShell.SubmodelElementCollection.CreateNew(name, null, semanticID); sme.semanticId.Keys.Add(AdminShell.Key.CreateNew("UATypeName", false, "OPC", n.UAObjectTypeName)); smec.Add(sme); if (n.Value != "") { var p = createSE(n, path); sme.Add(p); addLeaf(concepts, p); } foreach (field f in n.fields) { sme.semanticId.Keys.Add( AdminShell.Key.CreateNew( "UAField", false, "OPC", f.name + " = " + f.value + " : " + f.description)); semanticID = AdminShell.Key.CreateNew("GlobalReference", false, "IRI", path + name + "/" + f.name); var p = AdminShell.Property.CreateNew(f.name, null, semanticID); p.valueType = "string"; p.value = f.value; sme.Add(p); addLeaf(concepts, p); } if (n.children != null) { foreach (UaNode c in n.children) { createSubmodelElements(c, env, sme, smref, path + name + "/", concepts); } } } else { var se = createSE(n, path); smec.Add(se); addLeaf(concepts, se); } }
private void RecurseToCopyTechnicalProperties( AasxPredefinedConcepts.ZveiTechnicalDataV11 defsV11, AasxPredefinedConcepts.DefinitionsZveiTechnicalData.SetOfDefs defsV10, AdminShell.SubmodelElementCollection smcDest, AdminShell.SubmodelElementCollection smcSrc) { // access if (defsV10 == null || defsV11 == null || smcDest?.value == null || smcSrc?.value == null) { return; } // for EACH property foreach (var sme in smcSrc.value) { // access if (sme?.submodelElement == null) { continue; } var special = false; // Submodel Handling if (sme.submodelElement is AdminShell.SubmodelElementCollection smcSectSrc) { // what to create? AdminShell.SubmodelElementCollection smcSectDst = null; if (smcSectSrc.semanticId?.Matches(defsV10.CD_MainSection.GetSingleKey()) == true) { smcSectDst = smcDest.value.CreateSMEForCD <AdminShell.SubmodelElementCollection>( defsV11.CD_MainSection, addSme: false); } if (smcSectSrc.semanticId?.Matches(defsV10.CD_SubSection.GetSingleKey()) == true) { smcSectDst = smcDest.value.CreateSMEForCD <AdminShell.SubmodelElementCollection>( defsV11.CD_SubSection, addSme: false); } smcSectDst ??= new AdminShell.SubmodelElementCollection(smcSectSrc, shallowCopy: true); // add manually smcSectDst.idShort = smcSectSrc.idShort; smcSectDst.category = smcSectSrc.category; if (smcSectSrc.description != null) { smcSectDst.description = new AdminShell.Description(smcSectSrc.description); } smcDest.value.Add(smcSectDst); // recurse RecurseToCopyTechnicalProperties(defsV11, defsV10, smcSectDst, smcSectSrc); // was special special = true; } if (!special) { // just move "by hand", as the old SMEs are already detached smcDest.Add(sme.submodelElement); // do some fix for "non-standardized" if (sme.submodelElement.semanticId? .MatchesExactlyOneKey(defsV10.CD_NonstandardizedProperty.GetSingleKey(), AdminShell.Key.MatchMode.Relaxed) == true) { // fix sme.submodelElement.semanticId = new AdminShell.SemanticId( defsV11.CD_SemanticIdNotAvailable.GetReference()); } } } }
public static void addLeaf(AdminShell.SubmodelElementCollection concepts, AdminShell.SubmodelElement sme) { var se = AdminShell.Property.CreateNew(sme.idShort, null, sme.semanticId[0]); concepts.Add(se); }
public static bool operation_receiveProposals(AdminShell.Operation op, i40LanguageAutomaton auto) { // inputVariable property protocol: memory, connect // inputVariable reference frame proposal: collection // inputVariable reference submodel // outputVariable reference collected proposals: collection // outputVariable reference collected not understood proposals: collection // outputVariable reference collected refused proposals: collection // outputVariable reference property receivedFrameJSON if (auto.name == debugAutomaton) { int i = 0; // set breakpoint here to debug specific automaton } if (op.inputVariable.Count != 3 && op.outputVariable.Count != 4) { return(false); } AdminShell.Submodel refSubmodel = null; AdminShell.Property protocol = null; AdminShell.Property receivedFrameJSON = null; foreach (var input in op.inputVariable) { var inputRef = input.value.submodelElement; if (inputRef is AdminShell.Property) { protocol = (inputRef as AdminShell.Property); continue; } if (!(inputRef is AdminShell.ReferenceElement)) { return(false); } var refElement = Program.env[0].AasEnv.FindReferableByReference((inputRef as AdminShell.ReferenceElement).value); if (refElement is AdminShell.Submodel) { refSubmodel = refElement as AdminShell.Submodel; } } foreach (var output in op.outputVariable) { var outputRef = output.value.submodelElement; if (!(outputRef is AdminShell.ReferenceElement)) { return(false); } var refElement = Program.env[0].AasEnv.FindReferableByReference((outputRef as AdminShell.ReferenceElement).value); if (refElement is AdminShell.Property) { receivedFrameJSON = refElement as AdminShell.Property; } } var out1 = op.outputVariable.First(); var r2 = out1.value.submodelElement; if (!(r2 is AdminShell.ReferenceElement)) { return(false); } var ref2 = Program.env[0].AasEnv.FindReferableByReference((r2 as AdminShell.ReferenceElement).value); if (!(ref2 is AdminShell.SubmodelElementCollection)) { return(false); } var smc2 = ref2 as AdminShell.SubmodelElementCollection; if (protocol.value != "memory" && protocol.value != "connect") { return(false); } while ((auto.name == "automatonServiceRequester" && receivedFrameJSONRequester.Count != 0) || (auto.name == "automatonServiceProvider" && receivedFrameJSONProvider.Count != 0)) { string receivedFrame = ""; if (auto.name == "automatonServiceRequester") { // receivedFrame = sendFrameJSONProvider; // sendFrameJSONProvider = ""; if (receivedFrameJSONRequester.Count != 0) { receivedFrame = receivedFrameJSONRequester[0]; receivedFrameJSONRequester.RemoveAt(0); } } if (auto.name == "automatonServiceProvider") { // receivedFrame = sendFrameJSONRequester; // sendFrameJSONRequester = ""; if (receivedFrameJSONProvider.Count != 0) { receivedFrame = receivedFrameJSONProvider[0]; receivedFrameJSONProvider.RemoveAt(0); } } receivedFrameJSON.value = receivedFrame; AdminShell.Submodel submodel = null; if (receivedFrame != "") { try { if (auto.name == debugAutomaton) { int i = 0; // set breakpoint here to debug specific automaton } JObject parsed = JObject.Parse(receivedFrame); foreach (JProperty jp1 in (JToken)parsed) { if (jp1.Name == "frame") { foreach (JProperty jp2 in jp1.Value) { if (jp2.Name == "submodel") { string text = jp2.Value.ToString(); submodel = JsonConvert.DeserializeObject <AdminShell.Submodel>(text, new AdminShellConverters.JsonAasxConverter("modelType", "name")); } } } } } catch { } } if (submodel != null) { AdminShell.SubmodelElementCollection smcSubmodel = new AdminShell.SubmodelElementCollection(); smcSubmodel.idShort = submodel.idShort; foreach (var sme in submodel.submodelElements) { smcSubmodel.Add(sme.submodelElement); } smc2.Add(smcSubmodel); } } return(true); }