Stores a request to subscribe to a COM DA item.
Exemplo n.º 1
0
        /// <summary>
        /// Assigns a request to a group.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="request">The request.</param>
        public void UpdateGroup(ComDaClient client, SubscribeItemRequest request)
        {
            lock (m_lock)
            {
                // check for empty request.
                if (request.MonitoredItems.Count == 0)
                {
                    return;
                }

                request.Update();

                // check if existing group can be used.
                if (request.Group != null)
                {
                    if (request.Group.ModifyItem(request.GroupItem, request.SamplingInterval, request.Deadband, request.Active))
                    {
                        if (request.GroupItem.Active != request.Active)
                        {
                            request.GroupItem.Active = request.Active;
                            request.GroupItem.ActiveChanged = true;
                        }

                        request.Group.SetMonitoredItems(request.GroupItem, request.MonitoredItems.ToArray());
                        return;
                    }
                }

                // clear link to existing group.
                request.Group = null;
                request.GroupItem = null;
                
                // assign to an existing group.
                for (int ii = 0; ii < m_groups.Count; ii++)
                {
                    ComDaGroup group = m_groups[ii];

                    request.GroupItem = group.CreateItem(request.ItemId, request.SamplingInterval, request.Deadband, request.Active);

                    if (request.GroupItem != null)
                    {
                        request.Group = group;
                        request.Group.SetMonitoredItems(request.GroupItem, request.MonitoredItems.ToArray());
                        return; 
                    }
                }

                // create a new group.
                request.Group = new ComDaGroup(client, true);
                request.GroupItem = request.Group.CreateItem(request.ItemId, request.SamplingInterval, request.Deadband, request.Active);
                request.Group.SetMonitoredItems(request.GroupItem, request.MonitoredItems.ToArray());
                m_groups.Add(request.Group);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Finds the item value request for the specifed item. 
        /// </summary>
        /// <param name="itemId">The item id.</param>
        /// <param name="create">if set to <c>true</c> a new request is created if it does not exist.</param>
        /// <returns>The subscribe item request.</returns>
        public SubscribeItemRequest FindItemRequest(string itemId, bool create)
        {
            lock (m_lock)
            {
                SubscribeItemRequest subscribedItem = null;

                if (!m_subscribedItems.TryGetValue(itemId, out subscribedItem))
                {
                    if (!create)
                    {
                        return null;
                    }

                    subscribedItem = new SubscribeItemRequest(itemId);
                    m_subscribedItems.Add(itemId, subscribedItem);
                }

                return subscribedItem;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Removes the specified item request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>True of the request was removed.</returns>
        public bool Remove(SubscribeItemRequest request)
        {
            lock (m_lock)
            {
                if (request != null && request.ItemId != null)
                {
                    return m_subscribedItems.Remove(request.ItemId);
                }

                return false;
            }
        }