public static bool operation_message(AdminShell.Operation op, i40LanguageAutomaton auto) { // inputVariable property value = text foreach (var v in op.inputVariable) { if (v.value.submodelElement is AdminShell.Property) { var p = v.value.submodelElement as AdminShell.Property; auto.getMessages.Add(p.value); Console.WriteLine("operation message: " + p.idShort + " = " + p.value); } } return(true); }
public static bool operation_checkCollection(AdminShell.Operation op, i40LanguageAutomaton auto) { // inputVariable property checkType: isEmpty, isNotEmpty; // inputVariable reference collection proposal if (auto.name == debugAutomaton) { int i = 0; // set breakpoint here to debug specific automaton } if (op.inputVariable.Count != 2 && op.outputVariable.Count != 0) { return(false); } AdminShell.Property checkType = null; AdminShell.SubmodelElementCollection refCollection = null; foreach (var input in op.inputVariable) { var inputRef = input.value.submodelElement; if (inputRef is AdminShell.Property) { checkType = (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.SubmodelElementCollection) { refCollection = refElement as AdminShell.SubmodelElementCollection; } } int count = refCollection.value.Count; switch (checkType.idShort) { case "isEmpty": return(count == 0); case "isNotEmpty": return(count != 0); } return(false); }
public static bool operation_clear(AdminShell.Operation op, i40LanguageAutomaton auto) { // outputVariables are references to collections // alle elements will be removed from collections if (auto.name == debugAutomaton) { int i = 0; // set breakpoint here to debug specific automaton } if (op.outputVariable.Count == 0) { return(false); } 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.SubmodelElementCollection) { var refSMEC = refElement as AdminShell.SubmodelElementCollection; List <AdminShell.SubmodelElement> list = new List <AdminShell.SubmodelElement>(); foreach (var sme in refSMEC.value) { list.Add(sme.submodelElement); } foreach (var sme2 in list) { refSMEC.Remove(sme2); treeChanged = true; } } } return(true); }
public static bool operation_sendFrame(AdminShell.Operation op, i40LanguageAutomaton auto) { // inputVariable property protocol: memory, connect // inputVariable reference frame proposal: collection // inputVariable reference submodel // outputVariable reference property sendFrameJSON if (auto.name == debugAutomaton) { int i = 0; // set breakpoint here to debug specific automaton } if (op.inputVariable.Count != 3 && op.outputVariable.Count != 1) { return(false); } AdminShell.Property protocol = null; AdminShell.SubmodelElementCollection refFrame = null; AdminShell.Submodel refSubmodel = null; AdminShell.Property sendFrameJSON = 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.SubmodelElementCollection) { refFrame = refElement as AdminShell.SubmodelElementCollection; } 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) { sendFrameJSON = refElement as AdminShell.Property; } } if (protocol.value != "memory" && protocol.value != "connect") { return(false); } int frameCount = refFrame.value.Count; string frame = "{ \"frame\": { "; foreach (var smew in refFrame.value) { var sme = smew.submodelElement; if (sme.idShort == "_insert_submodel_into_frame") { frame += "\"" + "submodel" + "\" : "; var smJson = JsonConvert.SerializeObject(refSubmodel, Newtonsoft.Json.Formatting.Indented); frame += smJson; } else { frame += "\"" + sme.idShort + "\" : "; if (sme is AdminShell.Property) { frame += "\"" + (sme as AdminShell.Property).value + "\""; } else { frame += "\"\""; } } if (frameCount-- != 1) { frame += ","; } } frame += " } }"; sendFrameJSON.value = frame; Console.WriteLine(frame); if (auto.name == "automatonServiceRequester") { switch (protocol.value) { case "memory": receivedFrameJSONProvider.Add(frame); break; case "connect": sendFrameJSONRequester.Add(frame); break; } } if (auto.name == "automatonServiceProvider") { switch (protocol.value) { case "memory": receivedFrameJSONRequester.Add(frame); break; case "connect": sendFrameJSONProvider.Add(frame); break; } } return(true); }
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); }
public static bool operation_wait(AdminShell.Operation op, i40LanguageAutomaton auto) { // inputVariable reference waitingTime: property value // outputVariable reference endTime: property value if (op.inputVariable.Count != 1 && op.outputVariable.Count != 1) { return(false); } var in1 = op.inputVariable.First(); var r1 = in1.value.submodelElement; if (!(r1 is AdminShell.ReferenceElement)) { return(false); } var ref1 = Program.env[0].AasEnv.FindReferableByReference((r1 as AdminShell.ReferenceElement).value); if (!(ref1 is AdminShell.Property)) { return(false); } var p1 = ref1 as AdminShell.Property; int waitingTime = Convert.ToInt32(p1.value); 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.Property)) { return(false); } var p2 = ref2 as AdminShell.Property; DateTime localTime = DateTime.Now; if (p2.value == "") // start { var endTime = localTime.AddSeconds(waitingTime); p2.value = endTime.ToString(); Console.WriteLine("endTime = " + p2.value); } else // test if time has elapsed { Console.WriteLine("localTime = " + localTime); var endTime = DateTime.Parse(p2.value); if (DateTime.Compare(localTime, endTime) > 0) { p2.value = ""; return(true); } } return(false); }
public static bool operation_clearMessages(AdminShell.Operation op, i40LanguageAutomaton auto) { auto.getMessages.Clear(); return(true); }