예제 #1
0
        /// <summary>
        /// Specifies one or more nodes to monitor for data changes or events.
        /// </summary>
        public CreateMonitoredItemsResponseMessage CreateMonitoredItems(CreateMonitoredItemsMessage request)
        {
            try
            {
                lock (m_lock)
                {
                    // verify session.
                    VerifySession(request.RequestHeader, false);

                    // look up subscription.
                    Subscription subscription = null;

                    if (!m_subscriptions.TryGetValue(request.SubscriptionId, out subscription))
                    {
                        throw new StatusCodeException(StatusCodes.BadSubscriptionIdInvalid, "Could not find subscription");
                    }

                    // process each item.
                    ListOfMonitoredItemCreateResult results         = new ListOfMonitoredItemCreateResult();
                    ListOfDiagnosticInfo            diagnosticInfos = new ListOfDiagnosticInfo();

                    for (int ii = 0; ii < request.ItemsToCreate.Count; ii++)
                    {
                        MonitoredItemCreateResult result         = new MonitoredItemCreateResult();
                        DiagnosticInfo            diagnosticInfo = new DiagnosticInfo();

                        subscription.CreateMonitoredItem(
                            request.TimestampsToReturn,
                            request.ItemsToCreate[ii],
                            result,
                            diagnosticInfo);

                        results.Add(result);
                        diagnosticInfos.Add(diagnosticInfo);
                    }

                    // return the response.
                    CreateMonitoredItemsResponseMessage response = new CreateMonitoredItemsResponseMessage();

                    response.ResponseHeader  = CreateResponseHeader(request.RequestHeader);
                    response.Results         = results;
                    response.DiagnosticInfos = diagnosticInfos;

                    return(response);
                }
            }
            catch (Exception e)
            {
                throw CreateSoapFault(request.RequestHeader, e);
            }
        }
예제 #2
0
        /// <summary>
        /// Returns the target nodes found by following a browse path from a starting node.
        /// </summary>
        public TranslateBrowsePathsToNodeIdsResponseMessage TranslateBrowsePathsToNodeIds(TranslateBrowsePathsToNodeIdsMessage request)
        {
            try
            {
                lock (m_lock)
                {
                    // verify that the session is still valid.
                    VerifySession(request.RequestHeader, false);

                    // process each path being followed.
                    ListOfBrowsePathResult results         = new ListOfBrowsePathResult();
                    ListOfDiagnosticInfo   diagnosticInfos = new ListOfDiagnosticInfo();

                    for (int ii = 0; ii < request.BrowsePaths.Count; ii++)
                    {
                        BrowsePathResult result         = new BrowsePathResult();
                        DiagnosticInfo   diagnosticInfo = new DiagnosticInfo();

                        m_nodeManager.TranslateBrowsePath(
                            request.BrowsePaths[ii],
                            result,
                            diagnosticInfo);

                        results.Add(result);
                        diagnosticInfos.Add(diagnosticInfo);
                    }

                    // return the response.
                    TranslateBrowsePathsToNodeIdsResponseMessage response = new TranslateBrowsePathsToNodeIdsResponseMessage();

                    response.ResponseHeader  = CreateResponseHeader(request.RequestHeader);
                    response.Results         = results;
                    response.DiagnosticInfos = diagnosticInfos;

                    return(response);
                }
            }
            catch (Exception e)
            {
                throw CreateSoapFault(request.RequestHeader, e);
            }
        }
예제 #3
0
        /// <summary>
        /// Reads the values for one or more attributes.
        /// </summary>
        public ReadResponseMessage Read(ReadMessage request)
        {
            try
            {
                lock (m_lock)
                {
                    // verify that the session is still valid.
                    VerifySession(request.RequestHeader, false);

                    // process each attribute.
                    ListOfDataValue      results         = new ListOfDataValue();
                    ListOfDiagnosticInfo diagnosticInfos = new ListOfDiagnosticInfo();

                    for (int ii = 0; ii < request.NodesToRead.Count; ii++)
                    {
                        DataValue      result         = new DataValue();
                        DiagnosticInfo diagnosticInfo = new DiagnosticInfo();

                        m_nodeManager.Read(
                            request.NodesToRead[ii],
                            result,
                            diagnosticInfo);

                        results.Add(result);
                        diagnosticInfos.Add(diagnosticInfo);
                    }

                    // return the response.
                    ReadResponseMessage response = new ReadResponseMessage();

                    response.ResponseHeader  = CreateResponseHeader(request.RequestHeader);
                    response.Results         = results;
                    response.DiagnosticInfos = diagnosticInfos;

                    return(response);
                }
            }
            catch (Exception e)
            {
                throw CreateSoapFault(request.RequestHeader, e);
            }
        }
예제 #4
0
        /// <summary>
        /// Returns the references that meet the filter criteria for one or more nodes.
        /// </summary>
        public BrowseResponseMessage Browse(BrowseMessage request)
        {
            try
            {
                lock (m_lock)
                {
                    // verify the session.
                    VerifySession(request.RequestHeader, false);

                    // process each node being browsed.
                    ListOfBrowseResult   results         = new ListOfBrowseResult();
                    ListOfDiagnosticInfo diagnosticInfos = new ListOfDiagnosticInfo();

                    for (int ii = 0; ii < request.NodesToBrowse.Count; ii++)
                    {
                        BrowseResult   result         = new BrowseResult();
                        DiagnosticInfo diagnosticInfo = new DiagnosticInfo();

                        m_nodeManager.Browse(
                            request.NodesToBrowse[ii],
                            result,
                            diagnosticInfo);

                        results.Add(result);
                        diagnosticInfos.Add(diagnosticInfo);
                    }

                    // return the response.
                    BrowseResponseMessage response = new BrowseResponseMessage();

                    response.ResponseHeader  = CreateResponseHeader(request.RequestHeader);
                    response.Results         = results;
                    response.DiagnosticInfos = diagnosticInfos;

                    return(response);
                }
            }
            catch (Exception e)
            {
                throw CreateSoapFault(request.RequestHeader, e);
            }
        }
예제 #5
0
        /// <summary>
        /// Checks if the subscription is ready to publish and returns a notification message.
        /// </summary>
        public NotificationMessage Publish()
        {
            lock (m_lock)
            {
                long currentTime = DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond;

                // check of it is time for a publish.
                if (m_lastPublishTime + m_publishingInterval < currentTime)
                {
                    ListOfMonitoredItemNotification notifications = new ListOfMonitoredItemNotification();
                    ListOfDiagnosticInfo diagnosticInfos = new ListOfDiagnosticInfo();

                    // check each monitored item for data changes to send.
                    foreach (MonitoredItem monitoredItem in m_monitoredItems.Values)
                    {
                        while (monitoredItem.Values.Count > 0)
                        {
                            MonitoredItemNotification notification = new MonitoredItemNotification();

                            notification.ClientHandle = monitoredItem.Parameters.ClientHandle;
                            notification.Value = monitoredItem.Values.Dequeue();

                            notifications.Add(notification);
                            diagnosticInfos.Add(monitoredItem.DiagnosticInfos.Dequeue());
                        }
                    }

                    // check if any notifications were found.
                    if (notifications.Count > 0)
                    {
                        // subscriptions can produce different types of notifications so the notification parameter 
                        // is an extensible parameter. This means the object must be manually serialized and wrapped in
                        // an ExtensionObject which specifies the type of data contained in the Body. The complete
                        // UA SDK takes care this housekeeping and will serialize extensible parameters automatically.

                        DataChangeNotification body = new DataChangeNotification();

                        body.MonitoredItems = notifications;
                        body.DiagnosticInfos = diagnosticInfos;
                        
                        ExtensionObject extension = new ExtensionObject(
                            new ExpandedNodeId(Objects.DataChangeNotification_Encoding_DefaultXml),
                            body);

                        // construct the message and assign a new sequence number.
                        NotificationMessage message = new NotificationMessage();

                        message.SequenceNumber = ++m_nextSequenceNumber;
                        message.PublishTime = DateTime.UtcNow;
                        message.NotificationData = new ListOfExtensionObject();

                        message.NotificationData.Add(extension);

                        m_lastPublishTime = currentTime;
                        m_nextKeepAliveTime = (long)(currentTime + m_publishingInterval * m_keepAliveCount);

                        return message;
                    }
                }

                // check if it is time for a keep alive.
                if (m_nextKeepAliveTime < currentTime)
                {
                    NotificationMessage message = new NotificationMessage();

                    message.SequenceNumber = m_nextSequenceNumber;
                    message.PublishTime = DateTime.UtcNow;
                    message.NotificationData = new ListOfExtensionObject();

                    m_nextKeepAliveTime = (long)(currentTime + m_publishingInterval * m_keepAliveCount);

                    return message;
                }

                return null;
            }
        }
예제 #6
0
        /// <summary>
        /// Specifies one or more nodes to monitor for data changes or events. 
        /// </summary>
        public CreateMonitoredItemsResponseMessage CreateMonitoredItems(CreateMonitoredItemsMessage request)
        {
            try
            {
                lock (m_lock)
                {
                    // verify session.
                    VerifySession(request.RequestHeader, false);

                    // look up subscription.
                    Subscription subscription = null;

                    if (!m_subscriptions.TryGetValue(request.SubscriptionId, out subscription))
                    {
                        throw new StatusCodeException(StatusCodes.BadSubscriptionIdInvalid, "Could not find subscription");
                    }

                    // process each item.
                    ListOfMonitoredItemCreateResult results = new ListOfMonitoredItemCreateResult();
                    ListOfDiagnosticInfo diagnosticInfos = new ListOfDiagnosticInfo();

                    for (int ii = 0; ii < request.ItemsToCreate.Count; ii++)
                    {
                        MonitoredItemCreateResult result = new MonitoredItemCreateResult();
                        DiagnosticInfo diagnosticInfo = new DiagnosticInfo();

                        subscription.CreateMonitoredItem(
                            request.TimestampsToReturn,
                            request.ItemsToCreate[ii],
                            result,
                            diagnosticInfo);

                        results.Add(result);
                        diagnosticInfos.Add(diagnosticInfo);
                    }
                    
                    // return the response.
                    CreateMonitoredItemsResponseMessage response = new CreateMonitoredItemsResponseMessage();

                    response.ResponseHeader = CreateResponseHeader(request.RequestHeader);
                    response.Results = results;
                    response.DiagnosticInfos = diagnosticInfos;

                    return response;
                }
            }
            catch (Exception e)
            {
                throw CreateSoapFault(request.RequestHeader, e);
            }
        }
예제 #7
0
        /// <summary>
        /// Reads the values for one or more attributes.
        /// </summary>
        public ReadResponseMessage Read(ReadMessage request)
        {
            try
            {
                lock (m_lock)
                {
                    // verify that the session is still valid. 
                    VerifySession(request.RequestHeader, false);

                    // process each attribute.
                    ListOfDataValue results = new ListOfDataValue();
                    ListOfDiagnosticInfo diagnosticInfos = new ListOfDiagnosticInfo();

                    for (int ii = 0; ii < request.NodesToRead.Count; ii++)
                    {
                        DataValue result = new DataValue();
                        DiagnosticInfo diagnosticInfo = new DiagnosticInfo();

                        m_nodeManager.Read(
                            request.NodesToRead[ii],
                            result,
                            diagnosticInfo);

                        results.Add(result);
                        diagnosticInfos.Add(diagnosticInfo);
                    }

                    // return the response.
                    ReadResponseMessage response = new ReadResponseMessage();

                    response.ResponseHeader = CreateResponseHeader(request.RequestHeader);
                    response.Results = results;
                    response.DiagnosticInfos = diagnosticInfos;

                    return response;
                }
            }
            catch (Exception e)
            {
                throw CreateSoapFault(request.RequestHeader, e);
            }
        }
예제 #8
0
        /// <summary>
        /// Returns the target nodes found by following a browse path from a starting node.
        /// </summary>
        public TranslateBrowsePathsToNodeIdsResponseMessage TranslateBrowsePathsToNodeIds(TranslateBrowsePathsToNodeIdsMessage request)
        {
            try
            {
                lock (m_lock)
                {
                    // verify that the session is still valid. 
                    VerifySession(request.RequestHeader, false);

                    // process each path being followed.
                    ListOfBrowsePathResult results = new ListOfBrowsePathResult();
                    ListOfDiagnosticInfo diagnosticInfos = new ListOfDiagnosticInfo();

                    for (int ii = 0; ii < request.BrowsePaths.Count; ii++)
                    {
                        BrowsePathResult result = new BrowsePathResult();
                        DiagnosticInfo diagnosticInfo = new DiagnosticInfo();

                        m_nodeManager.TranslateBrowsePath(
                            request.BrowsePaths[ii],
                            result,
                            diagnosticInfo);

                        results.Add(result);
                        diagnosticInfos.Add(diagnosticInfo);
                    }

                    // return the response.
                    TranslateBrowsePathsToNodeIdsResponseMessage response = new TranslateBrowsePathsToNodeIdsResponseMessage();

                    response.ResponseHeader = CreateResponseHeader(request.RequestHeader);
                    response.Results = results;
                    response.DiagnosticInfos = diagnosticInfos;

                    return response;
                }
            }
            catch (Exception e)
            {
                throw CreateSoapFault(request.RequestHeader, e);
            }
        }
예제 #9
0
        /// <summary>
        /// Returns the references that meet the filter criteria for one or more nodes.
        /// </summary>
        public BrowseResponseMessage Browse(BrowseMessage request)
        {
            try
            {
                lock (m_lock)
                {
                    // verify the session.
                    VerifySession(request.RequestHeader, false);

                    // process each node being browsed.
                    ListOfBrowseResult results = new ListOfBrowseResult();
                    ListOfDiagnosticInfo diagnosticInfos = new ListOfDiagnosticInfo();

                    for (int ii = 0; ii < request.NodesToBrowse.Count; ii++)
                    {
                        BrowseResult result = new BrowseResult();
                        DiagnosticInfo diagnosticInfo = new DiagnosticInfo();

                        m_nodeManager.Browse(
                            request.NodesToBrowse[ii],
                            result,
                            diagnosticInfo);

                        results.Add(result);
                        diagnosticInfos.Add(diagnosticInfo);
                    }

                    // return the response.
                    BrowseResponseMessage response = new BrowseResponseMessage();

                    response.ResponseHeader = CreateResponseHeader(request.RequestHeader);
                    response.Results = results;
                    response.DiagnosticInfos = diagnosticInfos;

                    return response;
                }
            }
            catch (Exception e)
            {
                throw CreateSoapFault(request.RequestHeader, e);
            }
        }
예제 #10
0
        /// <summary>
        /// Checks if the subscription is ready to publish and returns a notification message.
        /// </summary>
        public NotificationMessage Publish()
        {
            lock (m_lock)
            {
                long currentTime = DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond;

                // check of it is time for a publish.
                if (m_lastPublishTime + m_publishingInterval < currentTime)
                {
                    ListOfMonitoredItemNotification notifications   = new ListOfMonitoredItemNotification();
                    ListOfDiagnosticInfo            diagnosticInfos = new ListOfDiagnosticInfo();

                    // check each monitored item for data changes to send.
                    foreach (MonitoredItem monitoredItem in m_monitoredItems.Values)
                    {
                        while (monitoredItem.Values.Count > 0)
                        {
                            MonitoredItemNotification notification = new MonitoredItemNotification();

                            notification.ClientHandle = monitoredItem.Parameters.ClientHandle;
                            notification.Value        = monitoredItem.Values.Dequeue();

                            notifications.Add(notification);
                            diagnosticInfos.Add(monitoredItem.DiagnosticInfos.Dequeue());
                        }
                    }

                    // check if any notifications were found.
                    if (notifications.Count > 0)
                    {
                        // subscriptions can produce different types of notifications so the notification parameter
                        // is an extensible parameter. This means the object must be manually serialized and wrapped in
                        // an ExtensionObject which specifies the type of data contained in the Body. The complete
                        // UA SDK takes care this housekeeping and will serialize extensible parameters automatically.

                        DataChangeNotification body = new DataChangeNotification();

                        body.MonitoredItems  = notifications;
                        body.DiagnosticInfos = diagnosticInfos;

                        ExtensionObject extension = new ExtensionObject(
                            new ExpandedNodeId(Objects.DataChangeNotification_Encoding_DefaultXml),
                            body);

                        // construct the message and assign a new sequence number.
                        NotificationMessage message = new NotificationMessage();

                        message.SequenceNumber   = ++m_nextSequenceNumber;
                        message.PublishTime      = DateTime.UtcNow;
                        message.NotificationData = new ListOfExtensionObject();

                        message.NotificationData.Add(extension);

                        m_lastPublishTime   = currentTime;
                        m_nextKeepAliveTime = (long)(currentTime + m_publishingInterval * m_keepAliveCount);

                        return(message);
                    }
                }

                // check if it is time for a keep alive.
                if (m_nextKeepAliveTime < currentTime)
                {
                    NotificationMessage message = new NotificationMessage();

                    message.SequenceNumber   = m_nextSequenceNumber;
                    message.PublishTime      = DateTime.UtcNow;
                    message.NotificationData = new ListOfExtensionObject();

                    m_nextKeepAliveTime = (long)(currentTime + m_publishingInterval * m_keepAliveCount);

                    return(message);
                }

                return(null);
            }
        }