Browses areas and sources in the AE server.
Inheritance: ComObject
        /// <summary>
        /// Initializes the object with the containing subscription object.
        /// </summary>
        public ComAeEventSink(ComAeSubscriptionClient subscription)
        {
            // save group.
            m_subscription = subscription;

            // create connection point.
            m_connectionPoint = new ConnectionPoint(subscription.Unknown, typeof(IOPCEventSink).GUID);

            // advise.
            m_connectionPoint.Advise(this);
        }
	    /// <summary>
	    /// Initializes the object with the containing subscription object.
	    /// </summary>
	    public ComAeEventSink(ComAeSubscriptionClient subscription)
	    { 
            // save group.
            m_subscription = subscription;

		    // create connection point.
		    m_connectionPoint = new ConnectionPoint(subscription.Unknown, typeof(IOPCEventSink).GUID);

		    // advise.
		    m_connectionPoint.Advise(this);
	    }
        /// <summary>
        /// Tells the node manager to refresh any conditions associated with the specified monitored items.
        /// </summary>
        public override ServiceResult ConditionRefresh(
            OperationContext context,
            IList <IEventMonitoredItem> monitoredItems)
        {
            List <MonitoredItem>           itemsToRefresh         = new List <MonitoredItem>();
            List <ComAeSubscriptionClient> subscriptionsToRefresh = new List <ComAeSubscriptionClient>();

            lock (Lock)
            {
                // build list of subscriptions that have to be refreshed.
                for (int ii = 0; ii < monitoredItems.Count; ii++)
                {
                    MonitoredItem monitoredItem = monitoredItems[ii] as MonitoredItem;

                    if (monitoredItem == null)
                    {
                        continue;
                    }

                    ComAeSubscriptionClient subscription = null;

                    if (!m_monitoredItems.TryGetValue(monitoredItem.Id, out subscription))
                    {
                        continue;
                    }

                    itemsToRefresh.Add(monitoredItem);
                    subscriptionsToRefresh.Add(subscription);
                }
            }

            for (int ii = 0; ii < subscriptionsToRefresh.Count; ii++)
            {
                // collect the events.
                List <IFilterTarget> events = new List <IFilterTarget>();
                subscriptionsToRefresh[ii].Refresh(events);

                // queue the events.
                for (int jj = 0; jj < events.Count; jj++)
                {
                    itemsToRefresh[ii].QueueEvent(events[jj]);
                }
            }

            return(ServiceResult.Good);
        }
        /// <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);
        }
        /// <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;
        }