// // Constructor // public AasPayloadStructuralChangeItem( ChangeReason reason, AdminShell.KeyList path = null) { Reason = reason; Path = path; }
// // Constructor // public AasPayloadUpdateValueItem( AdminShell.KeyList path = null, string value = null, AdminShell.Reference valueId = null) { Path = path; Value = value; ValueId = valueId; }
// // Constructor // public AasPayloadStructuralChangeItem( ulong count, DateTime timeStamp, ChangeReason reason, AdminShell.KeyList path = null, string data = null) { Count = count; TimeStamp = timeStamp; Reason = reason; Path = path; Data = data; }
// // Constructor // public AasPayloadStructuralChangeItem( DateTime timeStamp, StructuralChangeReason reason, AdminShell.KeyList path = null, int createAtIndex = -1, string data = null) { Timestamp = timeStamp; Reason = reason; Path = path; CreateAtIndex = createAtIndex; Data = data; }
private void PublishSingleValues_FirstTimeSubmodel( AdminShell.AdministrationShell aas, AdminShell.Submodel sm, AdminShell.KeyList startPath) { // trivial if (aas == null || sm == null) { return; } // give this to (recursive) function sm.RecurseOnSubmodelElements(null, (o, parents, sme) => { // assumption is, the sme is now "leaf" of a SME-hierarchy if (sme is AdminShell.IEnumerateChildren) { return(true); } // value of the leaf var valStr = sme.ValueAsText(); // build a complete path of keys var path = startPath + parents.ToKeyList() + sme?.ToKey(); var pathStr = path.BuildIdShortPath(); // publish if (_diaData.LogDebug) { _logger?.Info("Publish single value (first time)"); } var msg = new MqttApplicationMessageBuilder() .WithTopic(GenerateTopic( _diaData.SingleValueTopic, defaultIfNull: "SingleValue", aasIdShort: aas.idShort, aasId: aas.identification, smIdShort: sm.idShort, smId: sm.identification, path: pathStr)) .WithPayload(valStr) .WithExactlyOnceQoS() .WithRetainFlag(_diaData.MqttRetain) .Build(); _mqttClient.PublishAsync(msg).GetAwaiter().GetResult(); LogStatus(incSingleValue: 1); // recurse return(true); }); }
public static Tuple <string[], AdminShell.KeyList[]> PreparePresetsForListKeys( CopyPasteBuffer cpb, string label = "Paste") { // add from Copy Buffer AdminShell.KeyList bufferKey = null; if (cpb != null && cpb.Valid && cpb.Items != null && cpb.Items.Count == 1) { if (cpb.Items[0] is CopyPasteItemIdentifiable cpbi && cpbi.entity?.identification != null) { bufferKey = AdminShell.KeyList.CreateNew( new AdminShell.Key("" + cpbi.entity.GetElementName(), false, cpbi.entity.identification.idType, cpbi.entity.identification.id)); } if (cpb.Items[0] is CopyPasteItemSubmodel cpbsm && cpbsm.sm?.GetSemanticKey() != null) { bufferKey = AdminShell.KeyList.CreateNew(cpbsm.sm.GetSemanticKey()); } if (cpb.Items[0] is CopyPasteItemSME cpbsme && cpbsme.sme != null && cpbsme.env.Submodels != null) { // index parents for ALL Submodels -> parent for our SME shall be set by this .. foreach (var sm in cpbsme.env?.Submodels) { sm?.SetAllParents(); } // collect buffer list bufferKey = new AdminShell.KeyList(); cpbsme.sme.CollectReferencesByParent(bufferKey); } } // result return(new Tuple <string[], AdminShell.KeyList[]>( (bufferKey == null) ? null : new[] { label }, (bufferKey == null) ? null : new[] { bufferKey } )); }
private void PublishSingleValues_UpdateItem( AasEventMsgEnvelope ev, AdminShell.ReferableRootInfo ri, AdminShell.KeyList startPath, AasPayloadUpdateValueItem ui) { // trivial if (ev == null || ui == null || startPath == null || ui.Path == null) { return; } // value of the leaf var valStr = "" + ui.Value; // build a complete path of keys var path = startPath + ui.Path; var pathStr = path.BuildIdShortPath(); // publish if (_diaData.LogDebug) { _logger?.Info("Publish single value (update value)"); } var message = new MqttApplicationMessageBuilder() .WithTopic(GenerateTopic( _diaData.EventTopic, defaultIfNull: "SingleValue", aasIdShort: ri?.AAS?.idShort, aasId: ri?.AAS?.identification, smIdShort: ri?.Submodel?.idShort, smId: ri?.Submodel?.identification, path: pathStr)) .WithPayload(valStr) .WithExactlyOnceQoS() .WithRetainFlag(_diaData.MqttRetain) .Build(); // publish _mqttClient.PublishAsync(message).GetAwaiter().GetResult(); LogStatus(incSingleValue: 1); }
public async Task <bool> PullEvents() { // access if (!IsValid()) { throw new PackageConnectorException("PackageConnector::PullEvents() " + "connection not valid!"); } // do the query var qst = "/geteventmessages"; var response = await _client.GetAsync(qst); if (!response.IsSuccessStatusCode) { throw new PackageConnectorException($"PackageConnector::PullEvents() " + $"Server did not respond correctly on query {qst} !"); } // ok // parse dynamic response object var frame = Newtonsoft.Json.Linq.JObject.Parse(await response.Content.ReadAsStringAsync()); // change handler, start? var handler = Container?.ChangeEventHandler; handler?.Invoke(Container, PackCntChangeEventReason.StartOfChanges); // which events? if (frame != null && frame.ContainsKey("Changes") && (frame["Changes"] is Newtonsoft.Json.Linq.JArray changes) && changes.Count > 0) { foreach (var changeJO in changes) { // access if (changeJO == null) { continue; } // try deserialize var change = changeJO.ToObject <AasPayloadStructuralChangeItem>(); if (change == null) { throw new PackageConnectorException($"PackageConnector::PullEvents() " + "Cannot deserize payload StructuralChangeItem!"); } // try determine tarket of {Observavle}/{path} AdminShell.Referable target = null; if (change.Path?.IsEmpty == false) { AdminShell.KeyList kl = null; if (change.Path.First().IsAbsolute()) { kl = change.Path; } else { // { Observavle}/{ path} // need outer event! throw new NotImplementedException("Outer Event Message!"); } target = Env?.AasEnv?.FindReferableByReference(kl); } // create if (change.Reason == AasPayloadStructuralChangeItem.ChangeReason.Create) { // need data object var dataRef = change.GetDataAsReferable(); if (dataRef == null) { throw new PackageConnectorException($"PackageConnector::PullEvents() " + "Cannot deserize StructuralChangeItem Referable data!"); } // go through some cases // all SM, SME with dependent elements if (target is AdminShell.IManageSubmodelElements targetMgr && dataRef is AdminShell.SubmodelElement sme && change.CreateAtIndex < 0) { targetMgr.Add(sme); } else // at least for SMC, handle CreateAtIndex if (target is AdminShell.SubmodelElementCollection targetSmc && dataRef is AdminShell.SubmodelElement sme2 && change.CreateAtIndex >= 0 && targetSmc.value != null && change.CreateAtIndex < targetSmc.value.Count) { targetSmc.value.Insert(change.CreateAtIndex, sme2); } else // add to AAS if (target is AdminShell.AdministrationShell targetAas && dataRef is AdminShell.Submodel sm && Env?.AasEnv != null) { Env.AasEnv.Submodels.Add(sm); targetAas.AddSubmodelRef(sm?.GetSubmodelRef()); }
private void ButtonClose_Click(object sender, RoutedEventArgs e) { this.ResultKeys = null; ControlClosed?.Invoke(); }
private bool PrepareResult() { // access if (DisplayElements == null || DisplayElements.SelectedItem == null) { return(false); } var si = DisplayElements.SelectedItem; var siMdo = si.GetMainDataObject(); // already one result this.ResultVisualElement = si; // // Referable // if (siMdo is AdminShell.Referable dataRef) { // check if a valuable item was selected var elemname = dataRef.GetElementName(); var fullFilter = ApplyFullFilterString(theFilter); if (fullFilter != null && !(fullFilter.IndexOf(elemname + " ", StringComparison.Ordinal) >= 0)) { return(false); } // ok, prepare list of keys this.ResultKeys = new AdminShell.KeyList(); var de = si; while (de != null) { if (de is VisualElementSubmodelRef) { // import special case, as Submodel ref is important part of the chain! var elem = de as VisualElementSubmodelRef; if (elem.theSubmodel != null) { this.ResultKeys.Insert( 0, AdminShell.Key.CreateNew( elem.theSubmodel.GetElementName(), true, elem.theSubmodel.identification.idType, elem.theSubmodel.identification.id)); } break; } else if (de.GetMainDataObject() is AdminShell.Identifiable) { // a Identifiable will terminate the list of keys var data = de.GetMainDataObject() as AdminShell.Identifiable; if (data != null) { this.ResultKeys.Insert( 0, AdminShell.Key.CreateNew( data.GetElementName(), true, data.identification.idType, data.identification.id)); } break; } else if (de.GetMainDataObject() is AdminShell.Referable) { // add a key and go up .. var data = de.GetMainDataObject() as AdminShell.Referable; if (data != null) { this.ResultKeys.Insert( 0, AdminShell.Key.CreateNew(data.GetElementName(), true, "IdShort", data.idShort)); } } else // uups! { } // need to go up de = de.Parent; } return(true); } // // other special cases // if (siMdo is AdminShell.SubmodelRef smref && (theFilter == null || ApplyFullFilterString(theFilter) .ToLower().IndexOf("submodelref ", StringComparison.Ordinal) >= 0)) { this.ResultKeys = new AdminShell.KeyList(); this.ResultKeys.AddRange(smref.Keys); return(true); } // uups return(false); }
private bool PrepareResult() { // access if (DisplayElements == null || DisplayElements.SelectedItem == null) { return(false); } var si = DisplayElements.SelectedItem; var siMdo = si.GetMainDataObject(); // already one result this.ResultVisualElement = si; // // Referable // if (siMdo is AdminShell.Referable dataRef) { // check if a valuable item was selected var elemname = dataRef.GetElementName(); var fullFilter = ApplyFullFilterString(theFilter); if (fullFilter != null && !(fullFilter.IndexOf(elemname + " ", StringComparison.Ordinal) >= 0)) { return(false); } // ok, prepare list of keys this.ResultKeys = si.BuildKeyListToTop(); return(true); } // // other special cases // if (siMdo is AdminShell.SubmodelRef smref && (theFilter == null || ApplyFullFilterString(theFilter) .ToLower().IndexOf("submodelref ", StringComparison.Ordinal) >= 0)) { this.ResultKeys = new AdminShell.KeyList(); this.ResultKeys.AddRange(smref.Keys); return(true); } if (si is VisualElementPluginExtension vepe) { // get main data object of the parent of the plug in .. var parentMdo = vepe.Parent.GetMainDataObject(); if (parentMdo != null) { // safe to return a list for the parent .. // (include AAS, as this is important to plug-ins) this.ResultKeys = si.BuildKeyListToTop(includeAas: true); // .. enriched by a last element this.ResultKeys.Add(new AdminShell.Key(AdminShell.Key.FragmentReference, true, AdminShell.Key.Custom, "Plugin:" + vepe.theExt.Tag)); // ok return(true); } } // uups return(false); }
private AdminShell.KeyList BuildKeyListToTop( VisualElementGeneric visElem, bool includeAas = false) { // access if (visElem == null) { return(null); } // prepare result var res = new AdminShell.KeyList(); var ve = visElem; while (ve != null) { if (ve is VisualElementSubmodelRef) { // import special case, as Submodel ref is important part of the chain! var elem = ve as VisualElementSubmodelRef; if (elem.theSubmodel != null) { res.Insert( 0, AdminShell.Key.CreateNew( elem.theSubmodel.GetElementName(), true, elem.theSubmodel.identification.idType, elem.theSubmodel.identification.id)); } // include aas if (includeAas && ve.Parent is VisualElementAdminShell veAas && veAas.theAas?.identification != null) { res.Insert( 0, AdminShell.Key.CreateNew( AdminShell.Key.AAS, true, veAas.theAas.identification.idType, veAas.theAas.identification.id)); } break; } else if (ve.GetMainDataObject() is AdminShell.Identifiable) { // a Identifiable will terminate the list of keys var data = ve.GetMainDataObject() as AdminShell.Identifiable; if (data != null) { res.Insert( 0, AdminShell.Key.CreateNew( data.GetElementName(), true, data.identification.idType, data.identification.id)); } break; } else if (ve.GetMainDataObject() is AdminShell.Referable) { // add a key and go up .. var data = ve.GetMainDataObject() as AdminShell.Referable; if (data != null) { res.Insert( 0, AdminShell.Key.CreateNew(data.GetElementName(), true, "IdShort", data.idShort)); } } else // uups! { } // need to go up ve = ve.Parent; } return(res); }
public void PublishEventAsync(AasEventMsgEnvelope ev, AdminShell.ReferableRootInfo ri = null) { // access if (ev == null || _mqttClient == null || !_mqttClient.IsConnected) { return; } // serialize the event var settings = AasxIntegrationBase.AasxPluginOptionSerialization.GetDefaultJsonSettings( new[] { typeof(AasEventMsgEnvelope) }); settings.TypeNameHandling = TypeNameHandling.Auto; settings.Formatting = Formatting.Indented; var json = JsonConvert.SerializeObject(ev, settings); // aas / sm already available in rootInfo, prepare idShortPath var sourcePathStr = ""; var sourcePath = new AdminShell.KeyList(); if (ev.Source?.Keys != null && ri != null && ev.Source.Keys.Count > ri.NrOfRootKeys) { sourcePath = ev.Source.Keys.SubList(ri.NrOfRootKeys); sourcePathStr = sourcePath.BuildIdShortPath(); } var observablePath = new AdminShell.KeyList(); if (ev.ObservableReference?.Keys != null && ri != null && ev.ObservableReference.Keys.Count > ri.NrOfRootKeys) { observablePath = ev.ObservableReference.Keys.SubList(ri.NrOfRootKeys); } // publish the full event? if (_diaData.EnableEventPublish) { if (_diaData.LogDebug) { _logger?.Info("Publish Event"); } var message = new MqttApplicationMessageBuilder() .WithTopic(GenerateTopic( _diaData.EventTopic, defaultIfNull: "Event", aasIdShort: ri?.AAS?.idShort, aasId: ri?.AAS?.identification, smIdShort: ri?.Submodel?.idShort, smId: ri?.Submodel?.identification, path: sourcePathStr)) .WithPayload(json) .WithExactlyOnceQoS() .WithRetainFlag(_diaData.MqttRetain) .Build(); // convert to synchronous behaviour _mqttClient.PublishAsync(message).GetAwaiter().GetResult(); LogStatus(incEvent: 1); } // deconstruct the event into single units? if (_diaData.SingleValuePublish) { if (_diaData.LogDebug) { _logger?.Info("Publish single values .."); } if (ev.Payloads != null) { foreach (var epl in ev.Payloads) { if (epl is AasPayloadStructuralChange apsc && apsc.Changes != null) { foreach (var ci in apsc.Changes) { PublishSingleValues_ChangeItem(ev, ri, observablePath, ci); } } if (epl is AasPayloadUpdateValue apuv && apuv.Values != null) { foreach (var ui in apuv.Values) { PublishSingleValues_UpdateItem(ev, ri, observablePath, ui); } } } } } }
private void PublishSingleValues_ChangeItem( AasEventMsgEnvelope ev, AdminShell.ReferableRootInfo ri, AdminShell.KeyList startPath, AasPayloadStructuralChangeItem ci) { // trivial if (ev == null || ci == null || startPath == null) { return; } // only specific reasons if (!(ci.Reason == AasPayloadStructuralChangeItem.ChangeReason.Create || ci.Reason == AasPayloadStructuralChangeItem.ChangeReason.Modify)) { return; } // need a payload if (ci.Path == null || ci.Data == null) { return; } var dataRef = ci.GetDataAsReferable(); // give this to (recursive) function var messages = new List <MqttApplicationMessage>(); if (dataRef is AdminShell.SubmodelElement dataSme) { var smwc = new AdminShell.SubmodelElementWrapperCollection(dataSme); smwc.RecurseOnSubmodelElements(null, null, (o, parents, sme) => { // assumption is, the sme is now "leaf" of a SME-hierarchy if (sme is AdminShell.IEnumerateChildren) { return; } // value of the leaf var valStr = sme.ValueAsText(); // build a complete path of keys var path = startPath + ci.Path + parents.ToKeyList() + sme?.ToKey(); var pathStr = path.BuildIdShortPath(); // publish if (_diaData.LogDebug) { _logger?.Info("Publish single value (create/ update)"); } messages.Add( new MqttApplicationMessageBuilder() .WithTopic(GenerateTopic( _diaData.EventTopic, defaultIfNull: "SingleValue", aasIdShort: ri?.AAS?.idShort, aasId: ri?.AAS?.identification, smIdShort: ri?.Submodel?.idShort, smId: ri?.Submodel?.identification, path: pathStr)) .WithPayload(valStr) .WithExactlyOnceQoS() .WithRetainFlag(_diaData.MqttRetain) .Build()); }); } // publish these // convert to synchronous behaviour int count = 0; foreach (var msg in messages) { count++; _mqttClient.PublishAsync(msg).GetAwaiter().GetResult(); } LogStatus(incSingleValue: count); }
public AdminShell.KeyList BuildKeyListToTop( bool includeAas = false) { // prepare result var res = new AdminShell.KeyList(); var ve = this; while (ve != null) { if (ve is VisualElementSubmodelRef smr) { // import special case, as Submodel ref is important part of the chain! if (smr.theSubmodel != null) { res.Insert( 0, AdminShell.Key.CreateNew( smr.theSubmodel.GetElementName(), true, smr.theSubmodel.identification.idType, smr.theSubmodel.identification.id)); } // include aas if (includeAas && ve.Parent is VisualElementAdminShell veAas && veAas.theAas?.identification != null) { res.Insert( 0, AdminShell.Key.CreateNew( AdminShell.Key.AAS, true, veAas.theAas.identification.idType, veAas.theAas.identification.id)); } break; } else if (ve.GetMainDataObject() is AdminShell.Identifiable iddata) { // a Identifiable will terminate the list of keys res.Insert( 0, AdminShell.Key.CreateNew( iddata.GetElementName(), true, iddata.identification.idType, iddata.identification.id)); break; } else if (ve.GetMainDataObject() is AdminShell.Referable rf) { // add a key and go up .. res.Insert( 0, AdminShell.Key.CreateNew(rf.GetElementName(), true, "IdShort", rf.idShort)); } else // uups! { } // need to go up ve = ve.Parent; } return(res); }