Esempio n. 1
0
        /// <summary>
        /// Reads the value for the specified attribute.
        /// </summary>
        public override void Read(
            OperationContext context,
            double maxAge,
            IList<ReadValueId> nodesToRead,
            IList<DataValue> values,
            IList<ServiceResult> errors)
        {
            ServerSystemContext systemContext = SystemContext.Copy(context);
            IDictionary<NodeId, NodeState> operationCache = new NodeIdDictionary<NodeState>();
            List<DataSourceClient.ReadRequest> readRequests = new List<DataSourceClient.ReadRequest>();

            lock (Lock)
            {
                for (int ii = 0; ii < nodesToRead.Count; ii++)
                {
                    ReadValueId nodeToRead = nodesToRead[ii];

                    // skip items that have already been processed.
                    if (nodeToRead.Processed)
                    {
                        continue;
                    }

                    // check for valid handle.
                    NodeHandle handle = GetManagerHandle(systemContext, nodeToRead.NodeId, operationCache);

                    if (handle == null)
                    {
                        continue;
                    }

                    // owned by this node manager.
                    nodeToRead.Processed = true;

                    // create an initial value.
                    DataValue value = values[ii] = new DataValue();

                    value.Value = null;
                    value.ServerTimestamp = DateTime.UtcNow;
                    value.SourceTimestamp = DateTime.MinValue;
                    value.StatusCode = StatusCodes.Good;

                    // check if the node is a area in memory.
                    if (handle.Node == null)
                    {
                        errors[ii] = StatusCodes.BadNodeIdUnknown;
                        continue;
                    }

                    if (nodeToRead.AttributeId == Attributes.Value)
                    {
                        // check if the request if for a remote node.
                        RemoteNode remoteNode = null;

                        if (m_remoteNodes.TryGetValue(handle.NodeId, out remoteNode))
                        {
                            DataSourceClient.ReadRequest request = new DataSourceClient.ReadRequest();
                            request.RemoteId = remoteNode.RemoteId;
                            request.ReadValueId = nodeToRead;
                            request.Value = value;
                            request.Index = ii;
                            readRequests.Add(request);

                            errors[ii] = StatusCodes.BadNoCommunication;
                            continue;
                        }
                    }

                    // read the attribute value.
                    errors[ii] = handle.Node.ReadAttribute(
                        systemContext,
                        nodeToRead.AttributeId,
                        nodeToRead.ParsedIndexRange,
                        nodeToRead.DataEncoding,
                        value);
                }

                // check for nothing to do.
                if (readRequests.Count == 0)
                {
                    return;
                }
            }

            // read from the remote data source.
            List<ServiceResult> results = m_source.Read(readRequests);

            for (int ii = 0; ii < readRequests.Count; ii++)
            {
                values[readRequests[ii].Index] = readRequests[ii].Value;
                errors[readRequests[ii].Index] = results[ii];
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Reads the value for the specified attribute.
        /// </summary>
        public override void Read(
            OperationContext context,
            double maxAge,
            IList <ReadValueId> nodesToRead,
            IList <DataValue> values,
            IList <ServiceResult> errors)
        {
            ServerSystemContext                 systemContext  = SystemContext.Copy(context);
            IDictionary <NodeId, NodeState>     operationCache = new NodeIdDictionary <NodeState>();
            List <DataSourceClient.ReadRequest> readRequests   = new List <DataSourceClient.ReadRequest>();

            lock (Lock)
            {
                for (int ii = 0; ii < nodesToRead.Count; ii++)
                {
                    ReadValueId nodeToRead = nodesToRead[ii];

                    // skip items that have already been processed.
                    if (nodeToRead.Processed)
                    {
                        continue;
                    }

                    // check for valid handle.
                    NodeHandle handle = GetManagerHandle(systemContext, nodeToRead.NodeId, operationCache);

                    if (handle == null)
                    {
                        continue;
                    }

                    // owned by this node manager.
                    nodeToRead.Processed = true;

                    // create an initial value.
                    DataValue value = values[ii] = new DataValue();

                    value.Value           = null;
                    value.ServerTimestamp = DateTime.UtcNow;
                    value.SourceTimestamp = DateTime.MinValue;
                    value.StatusCode      = StatusCodes.Good;

                    // check if the node is a area in memory.
                    if (handle.Node == null)
                    {
                        errors[ii] = StatusCodes.BadNodeIdUnknown;
                        continue;
                    }

                    if (nodeToRead.AttributeId == Attributes.Value)
                    {
                        // check if the request if for a remote node.
                        RemoteNode remoteNode = null;

                        if (m_remoteNodes.TryGetValue(handle.NodeId, out remoteNode))
                        {
                            DataSourceClient.ReadRequest request = new DataSourceClient.ReadRequest();
                            request.RemoteId    = remoteNode.RemoteId;
                            request.ReadValueId = nodeToRead;
                            request.Value       = value;
                            request.Index       = ii;
                            readRequests.Add(request);

                            errors[ii] = StatusCodes.BadNoCommunication;
                            continue;
                        }
                    }

                    // read the attribute value.
                    errors[ii] = handle.Node.ReadAttribute(
                        systemContext,
                        nodeToRead.AttributeId,
                        nodeToRead.ParsedIndexRange,
                        nodeToRead.DataEncoding,
                        value);
                }

                // check for nothing to do.
                if (readRequests.Count == 0)
                {
                    return;
                }
            }

            // read from the remote data source.
            List <ServiceResult> results = m_source.Read(readRequests);

            for (int ii = 0; ii < readRequests.Count; ii++)
            {
                values[readRequests[ii].Index] = readRequests[ii].Value;
                errors[readRequests[ii].Index] = results[ii];
            }
        }