SelectClient() public method

Selects the DA COM client to use for the current context.
public SelectClient ( ServerSystemContext context, bool useDefault ) : ComDaClient
context Opc.Ua.Server.ServerSystemContext The context.
useDefault bool True if the the default instance should be returned.
return ComDaClient
Exemplo n.º 1
0
        /// <summary>
        /// Validates the nodes and writes the value to the underlying system.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="nodesToWrite">The nodes to write.</param>
        /// <param name="errors">The errors.</param>
        /// <param name="nodesToValidate">The nodes to validate.</param>
        /// <param name="cache">The cache.</param>
        protected override void Write(
            ServerSystemContext context,
            IList <WriteValue> nodesToWrite,
            IList <ServiceResult> errors,
            List <NodeHandle> nodesToValidate,
            IDictionary <NodeId, NodeState> cache)
        {
            ComDaClientManager system = (ComDaClientManager)this.SystemContext.SystemHandle;
            ComDaClient        client = system.SelectClient((ServerSystemContext)SystemContext, false);

            WriteRequestCollection requests = new WriteRequestCollection();

            // validates the nodes and queues an write requests.
            for (int ii = 0; ii < nodesToValidate.Count; ii++)
            {
                NodeHandle handle = nodesToValidate[ii];

                lock (Lock)
                {
                    // validate node.
                    NodeState source = ValidateNode(context, handle, cache);

                    if (source == null)
                    {
                        continue;
                    }

                    // determine if request can be sent to the server.
                    bool       queued      = false;
                    WriteValue nodeToWrite = nodesToWrite[handle.Index];
                    errors[handle.Index] = requests.Add(source, nodeToWrite, handle.Index, out queued);

                    if (queued)
                    {
                        continue;
                    }

                    // write the attribute value.
                    errors[handle.Index] = source.WriteAttribute(
                        context,
                        nodeToWrite.AttributeId,
                        nodeToWrite.ParsedIndexRange,
                        nodeToWrite.Value);

                    // updates to source finished - report changes to monitored items.
                    source.ClearChangeMasks(context, false);
                }
            }

            // write to the server.
            client.Write(requests);

            // get the results from the requests sent to the server.
            for (int ii = 0; ii < requests.Count; ii++)
            {
                WriteRequest request = requests[ii];
                errors[request.Index] = request.GetResult();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called when a batch of monitored items has been created.
        /// </summary>
        protected override void OnCreateMonitoredItemsComplete(ServerSystemContext context, IList <IMonitoredItem> monitoredItems)
        {
            ComDaClientManager system = (ComDaClientManager)this.SystemContext.SystemHandle;
            ComDaClient        client = system.SelectClient(context, false);

            // use locale for session to find a subscription manager.
            SubscribeRequestManager manager = null;

            if (!m_subscriptionManagers.TryGetValue(client.Key, out manager))
            {
                m_subscriptionManagers[client.Key] = manager = new SubscribeRequestManager(context, client, 1000);
            }

            manager.CreateItems(context, monitoredItems);

            for (int ii = 0; ii < monitoredItems.Count; ii++)
            {
                m_monitoredItems[monitoredItems[ii].Id] = manager;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Called when a batch of monitored items has been deleted.
        /// </summary>
        protected override void OnDeleteMonitoredItemsComplete(ServerSystemContext context, IList <IMonitoredItem> monitoredItems)
        {
            ComDaClientManager system = (ComDaClientManager)this.SystemContext.SystemHandle;
            ComDaClient        client = system.SelectClient(context, false);

            // sort monitored items by the locale id used to create them.
            Dictionary <string, List <IMonitoredItem> > monitoredItemsByLocaleId = new Dictionary <string, List <IMonitoredItem> >();

            for (int ii = 0; ii < monitoredItems.Count; ii++)
            {
                // look up the manager that was previously used to create the monitor item.
                SubscribeRequestManager manager = null;

                if (!m_monitoredItems.TryGetValue(monitoredItems[ii].Id, out manager))
                {
                    manager = m_subscriptionManagers[client.Key];
                }

                // add monitored item to a list of items for the locale of the manager.
                List <IMonitoredItem> subset = null;

                if (!monitoredItemsByLocaleId.TryGetValue(manager.Key, out subset))
                {
                    monitoredItemsByLocaleId[manager.Key] = subset = new List <IMonitoredItem>();
                }

                subset.Add(monitoredItems[ii]);
            }

            // delete the items.
            foreach (KeyValuePair <string, List <IMonitoredItem> > entry in monitoredItemsByLocaleId)
            {
                SubscribeRequestManager manager = null;

                if (m_subscriptionManagers.TryGetValue(entry.Key, out manager))
                {
                    manager.DeleteItems(context, entry.Value);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Validates the nodes and reads the values from the underlying source.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="nodesToRead">The nodes to read.</param>
        /// <param name="values">The values.</param>
        /// <param name="errors">The errors.</param>
        /// <param name="nodesToValidate">The nodes to validate.</param>
        /// <param name="cache">The cache.</param>
        protected override void Read(
            ServerSystemContext context,
            IList <ReadValueId> nodesToRead,
            IList <DataValue> values,
            IList <ServiceResult> errors,
            List <NodeHandle> nodesToValidate,
            IDictionary <NodeId, NodeState> cache)
        {
            ComDaClientManager system = (ComDaClientManager)this.SystemContext.SystemHandle;
            ComDaClient        client = system.SelectClient((ServerSystemContext)SystemContext, false);

            ReadRequestCollection requests = new ReadRequestCollection();

            for (int ii = 0; ii < nodesToValidate.Count; ii++)
            {
                NodeHandle handle = nodesToValidate[ii];

                lock (Lock)
                {
                    NodeState source = ValidateNode(context, handle, cache);

                    if (source == null)
                    {
                        continue;
                    }

                    DataValue   value      = values[handle.Index];
                    ReadValueId nodeToRead = nodesToRead[handle.Index];

                    // determine if request can be sent to the server.
                    bool queued = false;
                    errors[handle.Index] = requests.Add(source, nodeToRead, value, out queued);

                    if (queued)
                    {
                        continue;
                    }

                    // read built-in metadata.
                    errors[handle.Index] = source.ReadAttribute(
                        context,
                        nodeToRead.AttributeId,
                        nodeToRead.ParsedIndexRange,
                        nodeToRead.DataEncoding,
                        value);
                }
            }

            // read the values from the server.
            client.Read(requests);

            // extract the values from the results.
            for (int ii = 0; ii < nodesToValidate.Count; ii++)
            {
                NodeHandle  handle     = nodesToValidate[ii];
                DataValue   value      = values[handle.Index];
                ReadValueId nodeToRead = nodesToRead[handle.Index];

                lock (Lock)
                {
                    if (!requests.HasResult(nodeToRead))
                    {
                        continue;
                    }

                    errors[handle.Index] = requests.GetResult(context, handle.Node, nodeToRead, value, context.DiagnosticsMask);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes the next stage of browsing.
        /// </summary>
        private void NextStage()
        {
            ComDaClientManager system = (ComDaClientManager)this.SystemContext.SystemHandle;
            ComDaClient        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.Organizes, false))
                    {
                        m_stage = next;
                        break;
                    }
                }

                else if (next == Stage.Properties)
                {
                    if (IsRequired(ReferenceTypeIds.HasProperty, false))
                    {
                        m_stage = next;
                        break;
                    }
                }

                else if (next == Stage.Parents)
                {
                    if (IsRequired(ReferenceTypeIds.Organizes, true))
                    {
                        m_stage = next;
                        break;
                    }
                }

                else if (next == Stage.Done)
                {
                    m_stage = next;
                    break;
                }
            }

            m_position = 0;

            // start enumerating branches.
            if (m_stage == Stage.Children)
            {
                m_browser = client.CreateBrowser(m_itemId);
                return;
            }

            // start enumerating properties.
            if (m_stage == Stage.Properties)
            {
                m_properties = client.ReadAvailableProperties(m_itemId, true);
                m_position   = 0;
                return;
            }

            // start enumerating parents.
            if (m_stage == Stage.Parents)
            {
                m_parentId = client.FindElementParentId(m_itemId);
                return;
            }

            // all done.
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns the next child.
        /// </summary>
        private NodeStateReference NextChild(Stage stage)
        {
            ComDaClientManager system = (ComDaClientManager)this.SystemContext.SystemHandle;
            ComDaClient        client = system.SelectClient((ServerSystemContext)SystemContext, false);

            DaElement element = null;

            if (stage == Stage.Children)
            {
                if (m_browser == null)
                {
                    return(null);
                }

                element = m_browser.Next();

                if (element == null)
                {
                    return(null);
                }

                // construct the node.
                NodeState node = DaModelUtils.ConstructElement(SystemContext, element, m_namespaceIndex);

                // return the reference.
                return(new NodeStateReference(ReferenceTypeIds.Organizes, false, node));
            }

            if (stage == Stage.Properties)
            {
                if (m_properties == null)
                {
                    return(null);
                }

                for (int ii = m_position; ii < m_properties.Length; ii++)
                {
                    if (m_properties[ii].PropertyId <= PropertyIds.TimeZone)
                    {
                        continue;
                    }

                    m_position = ii + 1;

                    // construct the node.
                    NodeState node = DaModelUtils.ConstructProperty(SystemContext, m_itemId, m_properties[ii], m_namespaceIndex);

                    // return the reference.
                    return(new NodeStateReference(ReferenceTypeIds.HasProperty, false, node));
                }

                // all done.
                return(null);
            }

            if (stage == Stage.Parents)
            {
                if (m_parentId != null)
                {
                    NodeId parentId = DaModelUtils.ConstructIdForDaElement(m_parentId, -1, m_namespaceIndex);
                    m_parentId = null;
                    return(new NodeStateReference(ReferenceTypeIds.Organizes, true, parentId));
                }
            }

            return(null);
        }