Manages the AE COM connections used by the UA server.
Inheritance: ComClientManager
        /// <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.");
            }
        }
Example #2
0
        /// <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>
        /// Initializes the node manager.
        /// </summary>
        public ComAeClientNodeManager(IServerInternal server, string namespaceUri, ComAeClientConfiguration configuration, bool ownsTypeModel)
            :
            base(server, namespaceUri, ownsTypeModel)
        {
            SystemContext.SystemHandle  = m_system = new ComAeClientManager();
            SystemContext.NodeIdFactory = this;

            // save the configuration for the node manager.
            m_configuration = configuration;

            // set the alias root.
            AliasRoot = m_configuration.ServerName;

            if (String.IsNullOrEmpty(AliasRoot))
            {
                AliasRoot = "AE";
            }

            m_subscriptions  = new Dictionary <SubscriptionIndex, ComAeSubscriptionClient>();
            m_monitoredItems = new Dictionary <uint, ComAeSubscriptionClient>();
        }
        /// <summary>
        /// Initializes the node manager.
        /// </summary>
        public ComAeClientNodeManager(IServerInternal server, string namespaceUri, ComAeClientConfiguration configuration, bool ownsTypeModel)
        :
            base(server, namespaceUri, ownsTypeModel)
        {
            SystemContext.SystemHandle = m_system = new ComAeClientManager();
            SystemContext.NodeIdFactory = this;

            // save the configuration for the node manager.
            m_configuration = configuration;
            
            // set the alias root.
            AliasRoot = m_configuration.ServerName;

            if (String.IsNullOrEmpty(AliasRoot))
            {
                AliasRoot = "AE";
            }

            m_subscriptions = new Dictionary<SubscriptionIndex,ComAeSubscriptionClient>();
            m_monitoredItems = new Dictionary<uint,ComAeSubscriptionClient>();
        }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ComAeSubscriptionClient"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="cache">The cache for known types.</param>
        /// <param name="namespaceIndex">The namespace index for the event types.</param>
        /// <param name="manager">The manager.</param>
        /// <param name="monitoredItem">The monitored item.</param>
        public ComAeSubscriptionClient(
            ServerSystemContext context,
            ComAeClientConfiguration configuration,
            AeTypeCache cache,
            ushort namespaceIndex,
            ComAeClientManager manager,
            MonitoredItem monitoredItem)
        {
            m_defaultContext  = context;
            m_separators      = configuration.SeperatorChars;
            m_cache           = cache;
            m_namespaceIndex  = namespaceIndex;
            m_manager         = manager;
            m_refreshComplete = new ManualResetEvent(false);
            m_monitoredItems  = new List <MonitoredItem>();
            m_monitoredItems.Add(monitoredItem);
            m_qualifiedName = null;
            m_isSource      = false;

            NodeHandle  handle = monitoredItem.ManagerHandle as NodeHandle;
            AeAreaState area   = handle.Node as AeAreaState;

            if (area != null)
            {
                m_qualifiedName = area.QualifiedName;
                m_isSource      = false;
            }
            else
            {
                AeSourceState source = handle.Node as AeSourceState;

                if (source != null)
                {
                    m_qualifiedName = source.QualifiedName;
                    m_isSource      = true;
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ComAeSubscriptionClient"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="cache">The cache for known types.</param>
        /// <param name="namespaceIndex">The namespace index for the event types.</param>
        /// <param name="manager">The manager.</param>
        /// <param name="monitoredItem">The monitored item.</param>
        public ComAeSubscriptionClient(
            ServerSystemContext context,
            ComAeClientConfiguration configuration,
            AeTypeCache cache,
            ushort namespaceIndex,
            ComAeClientManager manager,
            MonitoredItem monitoredItem)
        {
            m_defaultContext = context;
            m_separators = configuration.SeperatorChars;
            m_cache = cache;
            m_namespaceIndex = namespaceIndex;
            m_manager = manager;
            m_refreshComplete = new ManualResetEvent(false);
            m_monitoredItems = new List<MonitoredItem>();
            m_monitoredItems.Add(monitoredItem);
            m_qualifiedName = null;
            m_isSource = false;

            NodeHandle handle = monitoredItem.ManagerHandle as NodeHandle;
            AeAreaState area = handle.Node as AeAreaState;

            if (area != null)
            {
                m_qualifiedName = area.QualifiedName;
                m_isSource = false;
            }
            else
            {
                AeSourceState source = handle.Node as AeSourceState;

                if (source != null)
                {
                    m_qualifiedName = source.QualifiedName;
                    m_isSource = true;
                }
            }
        }
        /// <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);
        }