Beispiel #1
0
        /// <summary>
        /// Updates the event types in cache with the most recent info fetched from the AE server.
        /// </summary>
        public void UpdateCache(ServerSystemContext context, ushort namespaceIndex)
        {
            // clear the existing nodes.
            EventTypeNodes = new NodeIdDictionary <BaseObjectTypeState>();
            Attributes     = new Dictionary <int, int[]>();
            TypeTable typeTable = context.TypeTable as TypeTable;

            // rebuild from the recently fetched list.
            for (int ii = 0; ii < EventTypes.Count; ii++)
            {
                // save the attributes for use when creating filters.
                if (EventTypes[ii].EventTypeMapping != EventTypeMapping.ConditionClassType && !Attributes.ContainsKey(EventTypes[ii].CategoryId))
                {
                    EventType eventType = EventTypes[ii];

                    int[] attributeIds = new int[eventType.Attributes.Count];

                    for (int jj = 0; jj < attributeIds.Length; jj++)
                    {
                        attributeIds[jj] = eventType.Attributes[jj].Id;
                    }

                    Attributes.Add(EventTypes[ii].CategoryId, attributeIds);
                }

                AeEventTypeState node = new AeEventTypeState(EventTypes[ii], namespaceIndex);

                BaseObjectTypeState mappingNode = null;

                if (!EventTypeNodes.TryGetValue(node.SuperTypeId, out mappingNode))
                {
                    mappingNode = new AeEventTypeMappingState(node.EventType.EventTypeMapping, namespaceIndex);
                    EventTypeNodes.Add(mappingNode.NodeId, mappingNode);

                    // ensure the mapping node is in the type table.
                    if (typeTable != null)
                    {
                        if (!typeTable.IsKnown(mappingNode.NodeId))
                        {
                            typeTable.AddSubtype(mappingNode.NodeId, mappingNode.SuperTypeId);
                        }
                    }
                }

                EventTypeNodes.Add(node.NodeId, node);

                // ensure the type node is in the type table.
                if (typeTable != null)
                {
                    if (!typeTable.IsKnown(node.NodeId))
                    {
                        typeTable.AddSubtype(node.NodeId, mappingNode.NodeId);
                    }
                }
            }
        }
        /// <summary>
        /// Returns a unique handle for the node.
        /// </summary>
        protected override NodeHandle GetManagerHandle(ServerSystemContext context, NodeId nodeId, IDictionary <NodeId, NodeState> cache)
        {
            lock (Lock)
            {
                // quickly exclude nodes that are not in the namespace.
                if (!IsNodeIdInNamespace(nodeId))
                {
                    return(null);
                }

                NodeHandle handle = new NodeHandle();
                handle.NodeId    = nodeId;
                handle.Validated = true;

                uint id = (uint)nodeId.Identifier;

                // find register
                int registerId = (int)((id & 0xFF000000) >> 24);
                int index      = (int)(id & 0x00FFFFFF);

                if (registerId == 0)
                {
                    MemoryRegister register = m_system.GetRegister(index);

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

                    handle.Node = ModelUtils.GetRegister(register, NamespaceIndex);
                }

                // find register variable.
                else
                {
                    MemoryRegister register = m_system.GetRegister(registerId);

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

                    // find register variable.
                    BaseDataVariableState variable = ModelUtils.GetRegisterVariable(register, index, NamespaceIndex);

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

                    handle.Node = variable;
                }

                return(handle);
            }
        }
        /// <summary>
        /// Called after creating a MonitoredItem.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="handle">The handle for the node.</param>
        /// <param name="monitoredItem">The monitored item.</param>
        protected override void OnMonitoredItemCreated(ServerSystemContext context, NodeHandle handle, MonitoredItem monitoredItem)
        {
            if (handle.Node.GetHierarchyRoot() is BlockState block)
            {
                block.StartMonitoring(context);

                // need to save the block to ensure that multiple monitored items use the same instance.
                _blocks[block.NodeId] = block;
            }
        }
Beispiel #4
0
 /// <summary>
 /// Verifies that the specified node exists.
 /// </summary>
 protected override NodeState ValidateNode(ServerSystemContext context, NodeHandle handle, IDictionary <NodeId, NodeState> cache)
 {
     // not valid if no root.
     if (handle == null)
     {
         return(null);
     }
     // check if previously validated.
     return(handle.Validated ? handle.Node : null);
 }
 /// <summary>
 /// Creates a refrigerator factory
 /// </summary>
 /// <param name="parentNode">The node that should old the refrigerators</param>
 /// <param name="refrigeratorName">The name for the new refrigerator</param>
 /// <param name="customManager">The node manager for the nodes created.</param>
 public RefrigeratorFactory(NodeState parentNode, string refrigeratorName, CustomNodeManager2 customManager)
 {
     m_refrigeratorName = refrigeratorName;
     m_namespaceindex   = customManager.NamespaceIndex;
     m_systemContext    = customManager.SystemContext;
     m_nodeFactory      = new NodeFactory(customManager);
     m_parentNode       = parentNode;
     _numGenerator      = new Random();
     CreateRefrigerator();
 }
 /// <summary>
 /// Called after deleting a MonitoredItem.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="handle">The handle for the node.</param>
 /// <param name="monitoredItem">The monitored item.</param>
 protected override void OnMonitoredItemDeleted(ServerSystemContext context, NodeHandle handle, MonitoredItem monitoredItem)
 {
     if (handle.Node.GetHierarchyRoot() is BlockState block)
     {
         if (!block.StopMonitoring(context))
         {
             // can remove the block since all monitored items for the block are gone.
             _blocks.Remove(block.NodeId);
         }
     }
 }
        /// <summary>
        /// Returns a unique handle for the node.
        /// </summary>
        protected override NodeHandle GetManagerHandle(ServerSystemContext context, NodeId nodeId, IDictionary <NodeId, NodeState> cache)
        {
            lock (Lock) {
                // quickly exclude nodes that are not in the namespace.
                if (!IsNodeIdInNamespace(nodeId))
                {
                    return(null);
                }

                // check for check for nodes that are being currently monitored.

                if (MonitoredNodes.TryGetValue(nodeId, out var monitoredNode))
                {
                    var handle = new NodeHandle {
                        NodeId    = nodeId,
                        Validated = true,
                        Node      = monitoredNode.Node
                    };

                    return(handle);
                }

                if (nodeId.IdType != IdType.String)
                {
                    if (PredefinedNodes.TryGetValue(nodeId, out var node))
                    {
                        var handle = new NodeHandle {
                            NodeId    = nodeId,
                            Node      = node,
                            Validated = true
                        };

                        return(handle);
                    }
                }

                // parse the identifier.
                var parsedNodeId = ParsedNodeId.Parse(nodeId);

                if (parsedNodeId != null)
                {
                    var handle = new NodeHandle {
                        NodeId       = nodeId,
                        Validated    = false,
                        Node         = null,
                        ParsedNodeId = parsedNodeId
                    };

                    return(handle);
                }

                return(null);
            }
        }
 /// <summary>
 /// Called after deleting a MonitoredItem.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="handle">The handle for the node.</param>
 /// <param name="monitoredItem">The monitored item.</param>
 protected override void OnMonitoredItemDeleted(
     ServerSystemContext context,
     NodeHandle handle,
     MonitoredItem monitoredItem)
 {
     // check for variables that need to be scanned.
     if (SystemScanRequired(handle.MonitoredNode, monitoredItem))
     {
         m_system.StopMonitoringValue(monitoredItem.Id);
     }
 }
        protected override void OnSetMonitoringModeComplete(ServerSystemContext context, IList <IMonitoredItem> monitoredItems)
        {
            List <DataSourceClient.MonitoringRequest> requests = null;

            lock (Lock)
            {
                requests = CollectRequests(context, monitoredItems);
            }

            m_source.SetMonitoringMode(requests);
        }
        private ServiceResult OnRequestLock(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            IList <object> inputArguments,
            IList <object> outputArguments)
        {
            DsatsDemo.LockConditionState node = (DsatsDemo.LockConditionState)FindPredefinedNode(objectId, typeof(DsatsDemo.LockConditionState));

            if (!node.EnabledState.Id.Value)
            {
                return(StatusCodes.BadConditionDisabled);
            }

            if (node.LockState.CurrentState.Id.Value != new NodeId(DsatsDemo.Objects.LockStateMachineType_Unlocked, NamespaceIndex))
            {
                return(StatusCodes.BadConditionAlreadyShelved);
            }

            node.SessionId.Value    = context.SessionId;
            node.ClientUserId.Value = null;
            node.SubjectName.Value  = null;

            // get the current user name.
            if (context.UserIdentity != null)
            {
                node.ClientUserId.Value = context.UserIdentity.DisplayName;
            }

            X509Certificate2 certificate = null;

            // get the client certificate subject name.
            ServerSystemContext systemContext = context as ServerSystemContext;

            if (systemContext != null && systemContext.OperationContext != null && systemContext.OperationContext.Session != null && systemContext.OperationContext.Session.ClientCertificate != null)
            {
                certificate            = systemContext.OperationContext.Session.ClientCertificate;
                node.SubjectName.Value = certificate.Subject;
            }

            node.RequestLock(context);

            // admins get locks immediately.
            if (CheckAdminAccess(context) || (certificate != null && node.HasPermission(certificate)))
            {
                GrantLockToSession(context, node.SessionId.Value, objectId);
                node.SetLock(context);
            }

            node.ReportEvent(context, node);
            node.ClearChangeMasks(context, true);

            return(ServiceResult.Good);
        }
        /// <summary>
        /// Called when a monitored item is deleted
        /// </summary>
        protected override void OnMonitoredItemDeleted(ServerSystemContext context, NodeHandle handle, MonitoredItem monitoredItem)
        {
            // check if monitored item requires scaning.
            if (!IsScanRequired(handle, monitoredItem))
            {
                return;
            }

            // delete monitored item.
            StopScan(handle, monitoredItem);
        }
Beispiel #12
0
 /// <summary>
 /// Called after modifying a MonitoredItem.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="handle">The handle for the node.</param>
 /// <param name="monitoredItem">The monitored item.</param>
 protected override void OnMonitoredItemModified(
     ServerSystemContext context,
     NodeHandle handle,
     MonitoredItem monitoredItem) {
     if (SystemScanRequired(handle.MonitoredNode, monitoredItem)) {
         if (monitoredItem.MonitoringMode != MonitoringMode.Disabled) {
             BaseVariableState source = handle.Node as BaseVariableState;
             m_system.StopMonitoringValue(monitoredItem.Id);
             m_system.StartMonitoringValue(monitoredItem.Id, monitoredItem.SamplingInterval, source);
         }
     }
 }
Beispiel #13
0
        /// <summary>
        /// Queues the value to the monitored item.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="request">The request.</param>
        /// <param name="initialUpdate">if set to <c>true</c> [initial update].</param>
        public void QueueValues(ServerSystemContext context, HdaReadRequest request, bool initialUpdate)
        {
            for (int ii = 0; ii < m_monitoredItems.Count; ii++)
            {
                QueueValue(context, request, m_monitoredItems[ii]);
            }

            if (!initialUpdate)
            {
                IncrementSampleTime();
            }
        }
Beispiel #14
0
        /// <summary>
        /// Tells the node manager to refresh any conditions associated with the specified monitored items.
        /// </summary>
        /// <remarks>
        /// This method is called when the condition refresh method is called for a subscription.
        /// The node manager must create a refresh event for each condition monitored by the subscription.
        /// </remarks>
        public override ServiceResult ConditionRefresh(
            OperationContext context,
            IList <IEventMonitoredItem> monitoredItems)
        {
            ServerSystemContext serverSystemContext = SystemContext.Copy(context);

            foreach (MonitoredItem monitoredItem in monitoredItems)
            {
                if (monitoredItem == null)
                {
                    continue;
                }

                List <IFilterTarget> events         = new List <IFilterTarget>();
                List <NodeState>     nodesToRefresh = new List <NodeState>();

                lock (Lock)
                {
                    // check for server subscription.
                    if (monitoredItem.NodeId == ObjectIds.Server)
                    {
                        if (_rootNotifiers != null)
                        {
                            nodesToRefresh.AddRange(_rootNotifiers);
                        }
                    }
                    else
                    {
                        if (!MonitoredNodes.TryGetValue(monitoredItem.NodeId, out MonitoredNode2 monitoredNode))
                        {
                            continue;
                        }

                        // get the refresh events.
                        nodesToRefresh.Add(monitoredNode.Node);
                    }
                }

                foreach (var node in nodesToRefresh)
                {
                    node.ConditionRefresh(SystemContext, events, true);
                }

                foreach (var @event in events)
                {
                    monitoredItem.QueueEvent(@event);
                }
            }

            return(ServiceResult.Good);
        }
        /// <summary>
        /// Returns a unique handle for the node.
        /// </summary>
        protected override NodeHandle GetManagerHandle(ServerSystemContext context, NodeId nodeId, IDictionary <NodeId, NodeState> cache)
        {
            lock (Lock)
            {
                // quickly exclude nodes that are not in the namespace.
                if (!IsNodeIdInNamespace(nodeId))
                {
                    return(null);
                }

                NodeState node = null;

                // check cache (the cache is used because the same node id can appear many times in a single request).
                if (cache != null)
                {
                    if (cache.TryGetValue(nodeId, out node))
                    {
                        return(new NodeHandle(nodeId, node));
                    }
                }

                // look up predefined node.
                if (PredefinedNodes.TryGetValue(nodeId, out node))
                {
                    NodeHandle handle = new NodeHandle(nodeId, node);

                    if (cache != null)
                    {
                        cache.Add(nodeId, node);
                    }

                    return(handle);
                }


                #region Task #A5 - Add Support for External Nodes
                // parse the node id and return an unvalidated handle.
                if (nodeId.IdType == IdType.String)
                {
                    NodeHandle handle = new NodeHandle();
                    handle.NodeId       = nodeId;
                    handle.Validated    = false;
                    handle.ParsedNodeId = ParsedNodeId.Parse(nodeId);
                    return(handle);
                }
                #endregion

                // node not found.
                return(null);
            }
        }
Beispiel #16
0
        /// <summary>
        /// Returns the history data source for a node.
        /// </summary>
        protected virtual ServiceResult GetHistoryDataSource(
            ServerSystemContext context,
            BaseVariableState variable,
            out IHistoryDataSource datasource)
        {
            datasource = _system.GetHistoryFile(variable);

            if (datasource == null)
            {
                return(StatusCodes.BadNotReadable);
            }

            return(ServiceResult.Good);
        }
Beispiel #17
0
        /// <summary>
        /// Starts the monitoring the block.
        /// </summary>
        /// <param name="context">The context.</param>
        public void StartMonitoring(ServerSystemContext context)
        {
            if (_monitoringCount == 0)
            {
                if (context.SystemHandle is UnderlyingSystem system)
                {
                    var block = system.FindBlock(_blockId);

                    block?.StartMonitoring(OnTagsChanged);
                }
            }

            _monitoringCount++;
        }
        /// <summary>
        /// Called when a monitored item is created.
        /// </summary>
        protected override void OnMonitoredItemCreated(ServerSystemContext context, NodeHandle handle, MonitoredItem monitoredItem)
        {
            // check if monitored item requires scaning.
            if (!IsScanRequired(handle, monitoredItem))
            {
                return;
            }

            // only scan enabled items.
            if (monitoredItem.MonitoringMode != MonitoringMode.Disabled)
            {
                StartScan(handle, monitoredItem);
            }
        }
        /// <summary>
        /// Verifies that the specified node exists.
        /// </summary>
        protected override NodeState ValidateNode(
            ServerSystemContext context,
            NodeHandle handle,
            IDictionary <NodeId, NodeState> cache)
        {
            // not valid if no root.
            if (handle == null)
            {
                return(null);
            }

            // check if previously validated.
            if (handle.Validated)
            {
                return(handle.Node);
            }

            // lookup in operation cache.
            NodeState target = FindNodeInCache(context, handle, cache);

            if (target != null)
            {
                handle.Node      = target;
                handle.Validated = true;
                return(handle.Node);
            }

            #region Task #A5 - Add Support for External Nodes
            ParsedNodeId    nodeId = (ParsedNodeId)handle.ParsedNodeId;
            BaseObjectState node   = CreateFolderNode(nodeId.RootId);

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

            target = node;
            #endregion

            // put root into operation cache.
            if (cache != null)
            {
                cache[handle.NodeId] = target;
            }

            handle.Node      = target;
            handle.Validated = true;
            return(handle.Node);
        }
 protected override NodeState ValidateNode(
     ServerSystemContext context,
     NodeHandle handle,
     IDictionary<NodeId, NodeState> cache)
 {
     if (handle == null)
     {
         return null;
     }
     if (handle.Validated)
     {
         return handle.Node;
     }
     return null;
 }
Beispiel #21
0
        /// <summary>
        /// Restores a previously cached history reader.
        /// </summary>
        protected virtual HistoryDataReader RestoreDataReader(ServerSystemContext context, byte[] continuationPoint)
        {
            if (context == null || context.OperationContext == null || context.OperationContext.Session == null)
            {
                return(null);
            }


            if (!(context.OperationContext.Session.RestoreHistoryContinuationPoint(continuationPoint) is HistoryDataReader reader))
            {
                return(null);
            }

            return(reader);
        }
Beispiel #22
0
 /// <summary>
 /// Removes the specified monitored item.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="monitoredItem">The monitored item.</param>
 public void Remove(ServerSystemContext context, MonitoredItem monitoredItem)
 {
     // remove the monitored item.
     if (monitoredItem != null && m_monitoredItems != null)
     {
         for (int ii = 0; ii < m_monitoredItems.Count; ii++)
         {
             if (Object.ReferenceEquals(m_monitoredItems[ii], monitoredItem))
             {
                 m_monitoredItems.RemoveAt(ii);
                 break;
             }
         }
     }
 }
Beispiel #23
0
        /// <summary>
        /// Adds the specified monitored item.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="monitoredItem">The monitored item.</param>
        public void Add(ServerSystemContext context, MonitoredItem monitoredItem)
        {
            if (monitoredItem == null)
            {
                return;
            }

            // save the monitored item.
            if (m_monitoredItems == null)
            {
                m_monitoredItems = new List <MonitoredItem>();
            }

            m_monitoredItems.Add(monitoredItem);
        }
Beispiel #24
0
 /// <summary>
 /// 重写节点验证 方式
 /// </summary>
 /// <param name="context"></param>
 /// <param name="handle"></param>
 /// <param name="cache"></param>
 /// <returns></returns>
 protected override NodeState ValidateNode(ServerSystemContext context, NodeHandle handle,
                                           IDictionary <NodeId, NodeState> cache)
 {
     //如果handle没有root节点 not valid
     if (handle == null)
     {
         return(null);
     }
     //检查是否已验证过
     if (handle.Validated)
     {
         return(handle.Node);
     }
     return(null);
 }
        /// <summary>
        /// Returns the type identified by the category id and condition name.
        /// </summary>
        public AeEventTypeState FindType(ServerSystemContext context, NodeId nodeId)
        {
            if (NodeId.IsNull(nodeId))
            {
                return(null);
            }

            BaseObjectTypeState eventType = null;

            if (!EventTypeNodes.TryGetValue(nodeId, out eventType))
            {
                return(null);
            }

            return(eventType as AeEventTypeState);
        }
Beispiel #26
0
        /// <summary>
        /// Stop the monitoring the block.
        /// </summary>
        /// <param name="context">The context.</param>
        public bool StopMonitoring(ServerSystemContext context)
        {
            _monitoringCount--;

            if (_monitoringCount == 0)
            {
                if (context.SystemHandle is UnderlyingSystem system)
                {
                    var block = system.FindBlock(_blockId);

                    block?.StopMonitoring();
                }
            }

            return(_monitoringCount != 0);
        }
        /// <summary>
        /// Verifies that the specified node exists.
        /// </summary>
        protected override NodeState ValidateNode(
            ServerSystemContext context,
            NodeHandle handle,
            IDictionary <NodeId, NodeState> cache)
        {
            // not valid if no root.
            if (handle == null)
            {
                return(null);
            }

            // check if previously validated.
            if (handle.Validated)
            {
                return(handle.Node);
            }

            // lookup in operation cache.
            NodeState target = FindNodeInCache(context, handle, cache);

            if (target != null)
            {
                handle.Node      = target;
                handle.Validated = true;
                return(handle.Node);
            }

            #region Task #A5 - Add Support for External Nodes
            // checkf if the id actually referes to a valid node id.
            target = ValidateExternalNode(context, handle);

            if (target == null)
            {
                return(null);
            }
            #endregion

            // put root into operation cache.
            if (cache != null)
            {
                cache[handle.NodeId] = target;
            }

            handle.Node      = target;
            handle.Validated = true;
            return(handle.Node);
        }
        /// <summary>
        /// Saves a history continuation point.
        /// </summary>
        private byte[] SaveContinuationPoint(
            ServerSystemContext context,
            HistoryReadRequest request)
        {
            Session session = context.OperationContext.Session;

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

            Guid id = Guid.NewGuid();

            session.SaveHistoryContinuationPoint(id, request);
            request.ContinuationPoint = id.ToByteArray();
            return(request.ContinuationPoint);
        }
Beispiel #29
0
        public static void RegistPublishers(this
                                            MachineState machineState,
                                            ServerSystemContext systemContext)
        {
            //regist machine log publisher push.
            var machineLogPublisher = new MachineLogPublisher();

            machineLogPublisher.Regist(machineState, systemContext);
            Publishers.Add(machineLogPublisher);
            Logstash.Service.Logstash.Startup();

            //regist machine performance publisher push.
            var machinePerformancePublisher = new MachinePerformancePublisher();

            machinePerformancePublisher.Regist(machineState, systemContext);
            Publishers.Add(machinePerformancePublisher);
        }
Beispiel #30
0
        /// <summary>
        /// Returns a unique handle for the node.
        /// </summary>
        protected override NodeHandle GetManagerHandle(ServerSystemContext context, NodeId nodeId, IDictionary <NodeId, NodeState> cache)
        {
            lock (Lock)
            {
                // quickly exclude nodes that are not in the namespace.
                if (!IsNodeIdInNamespace(nodeId))
                {
                    return(null);
                }

                // check for predefined nodes.
                if (PredefinedNodes != null)
                {
                    NodeState node = null;

                    if (PredefinedNodes.TryGetValue(nodeId, out node))
                    {
                        NodeHandle handle = new NodeHandle();

                        handle.NodeId    = nodeId;
                        handle.Validated = true;
                        handle.Node      = node;

                        return(handle);
                    }
                }

                // parse the identifier.
                DaParsedNodeId parsedNodeId = DaParsedNodeId.Parse(nodeId);

                if (parsedNodeId != null)
                {
                    NodeHandle handle = new NodeHandle();

                    handle.NodeId       = nodeId;
                    handle.Validated    = false;
                    handle.Node         = null;
                    handle.ParsedNodeId = parsedNodeId;

                    return(handle);
                }

                return(null);
            }
        }