public SelectClient ( |
||
context | The context. | |
useDefault | bool | If true the default instance is used. |
리턴 |
/// <summary> /// Updates the type cache. /// </summary> private void DoMetadataUpdate(object state) { try { if (!Server.IsRunning) { return; } ComAeClientManager system = (ComAeClientManager)SystemContext.SystemHandle; ComAeClient client = (ComAeClient)system.SelectClient(SystemContext, true); AeTypeCache cache = new AeTypeCache(); cache.LoadEventTypes(client); lock (Lock) { if (m_typeCache == null) { m_typeCache = cache; } m_typeCache.EventTypes = cache.EventTypes; m_typeCache.UpdateCache(SystemContext, NamespaceIndex); } } catch (Exception e) { Utils.Trace(e, "Unexpected error updating event type cache."); } }
/// <summary> /// Initializes the next stage of browsing. /// </summary> private void NextStage() { ComAeClientManager system = (ComAeClientManager)this.SystemContext.SystemHandle; ComAeClient client = system.SelectClient((ServerSystemContext)SystemContext, false); // determine which stage is next based on the reference types requested. for (Stage next = m_stage + 1; next <= Stage.Done; next++) { if (next == Stage.Children) { if (IsRequired(ReferenceTypeIds.HasNotifier, false)) { m_stage = next; break; } } else if (next == Stage.Parents) { if (IsRequired(ReferenceTypeIds.HasNotifier, true)) { m_stage = next; break; } } else if (next == Stage.Done) { m_stage = next; break; } } // start enumerating areas. if (m_stage == Stage.Children) { m_browser = new ComAeBrowserClient(client, m_qualifiedName); return; } // start enumerating parents. if (m_stage == Stage.Parents) { return; } // all done. }
/// <summary> /// Called when the alarm is acknowledged. /// </summary> private ServiceResult OnAcknowledge( ISystemContext context, MethodState method, NodeId objectId, byte[] eventId, LocalizedText comment) { ComAeClientManager system = (ComAeClientManager)this.SystemContext.SystemHandle; ComAeClient client = (ComAeClient)system.SelectClient((ServerSystemContext)context, false); try { return(client.Acknowledge((ServerSystemContext)context, eventId, comment)); } catch (Exception e) { return(ServiceResult.Create(e, StatusCodes.BadUnexpectedError, "Could not acknowledge event.")); } }
/// <summary> /// Subscribes to events. /// </summary> protected override ServiceResult SubscribeToEvents( ServerSystemContext context, NodeState source, IEventMonitoredItem monitoredItem, bool unsubscribe) { ComAeClientManager system = (ComAeClientManager)this.SystemContext.SystemHandle; ComAeClient client = (ComAeClient)system.SelectClient(context, false); // need to wait until the cache is refreshed for the first time. if (!WaitForTypeCache()) { return(StatusCodes.BadOutOfService); } lock (Lock) { SubscriptionIndex index = new SubscriptionIndex(); index.NodeId = source.NodeId; index.LocaleId = client.LocaleId; if (unsubscribe) { ComAeSubscriptionClient subscription = null; if (!m_monitoredItems.TryGetValue(monitoredItem.Id, out subscription)) { return(ServiceResult.Good); } m_monitoredItems.Remove(monitoredItem.Id); // Utils.Trace("REMOVED ITEM {0}", monitoredItem.Id); if (subscription.RemoveItem(monitoredItem as MonitoredItem) == 0) { subscription.Delete(); m_subscriptions.Remove(index); // Utils.Trace("DELETED SUBSCRIPTION {0}", index.NodeId); } } else { ComAeSubscriptionClient subscription = null; if (!m_subscriptions.TryGetValue(index, out subscription)) { subscription = new ComAeSubscriptionClient(context, m_configuration, m_typeCache, NamespaceIndex, system, monitoredItem as MonitoredItem); m_subscriptions.Add(index, subscription); subscription.Create(); // Utils.Trace("ADDED NEW SUBSCRIPTION {0}", index.NodeId); } else { subscription.AddItem(monitoredItem as MonitoredItem); } m_monitoredItems[monitoredItem.Id] = subscription; // Utils.Trace("ADDED NEW ITEM {0}", monitoredItem.Id); } } // all done. return(ServiceResult.Good); }