Ejemplo n.º 1
0
        public void UpdateItem(int p_ClientHandle, Dictionary <string, string> p_Properties)
        {
            if (!p_Properties.ContainsKey(ITEM_PROP_VALUE_KEY) ||
                !p_Properties.ContainsKey(ITEM_PROP_QUALITY_KEY) ||
                !p_Properties.ContainsKey(ITEM_PROP_TIMESTAMP_KEY))
            {
                throw new OPCItemException("The item can't be updated.", p_ClientHandle.ToString());
            }
            else
            {
                IOPCItem l_Item;

                if (m_ClientHandleToItemDictionary.TryGetValue(p_ClientHandle, out l_Item))
                {
                    string l_Value, l_Quality, l_Timestamp;
                    p_Properties.TryGetValue(ITEM_PROP_VALUE_KEY, out l_Value);
                    p_Properties.TryGetValue(ITEM_PROP_QUALITY_KEY, out l_Quality);
                    p_Properties.TryGetValue(ITEM_PROP_TIMESTAMP_KEY, out l_Timestamp);

                    l_Item.Value     = l_Value;
                    l_Item.Quality   = l_Quality;
                    l_Item.Timestamp = l_Timestamp;

                    ModelChangeEventArgs l_Event = new ModelChangeEventArgs(ModelChangeEventType.UPDATE,
                                                                            l_Item.ID, l_Item.Type, l_Value, l_Quality, l_Timestamp);

                    if (ModelChanged != null)
                    {
                        ModelChanged(this, l_Event);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void UpdateItem(int clientHandle, Dictionary <string, string> properties)
        {
            if (!properties.ContainsKey(ItemPropValueKey) ||
                !properties.ContainsKey(ItemPropQualityKey) ||
                !properties.ContainsKey(ItemPropTimestampKey))
            {
                throw new OpcItemException("The item can't be updated.", clientHandle.ToString());
            }

            if (!m_ClientHandleToItemDictionary.TryGetValue(clientHandle, out var item))
            {
                return;
            }

            properties.TryGetValue(ItemPropValueKey, out var value);
            properties.TryGetValue(ItemPropQualityKey, out var quality);
            properties.TryGetValue(ItemPropTimestampKey, out var timestamp);

            item.Value     = value;
            item.Quality   = quality;
            item.Timestamp = timestamp;

            var eventArgs = new ModelChangeEventArgs(ModelChangeEventType.Update,
                                                     item.ID, item.Type, value, quality, timestamp);

            ModelChanged?.Invoke(this, eventArgs);
        }
Ejemplo n.º 3
0
        public void AddItem(int p_ClientHandle, int p_ServerHandle, Dictionary <string, string> p_Properties)
        {
            if (!p_Properties.ContainsKey(ITEM_PROP_ID_KEY) || !p_Properties.ContainsKey(ITEM_PROP_TYPE_KEY))
            {
                throw new OPCItemException("The item can't be added to the model.", p_ClientHandle.ToString());
            }
            else
            {
                string l_ID, l_Type, l_Value, l_Quality, l_Timestamp;
                p_Properties.TryGetValue(ITEM_PROP_ID_KEY, out l_ID);
                p_Properties.TryGetValue(ITEM_PROP_TYPE_KEY, out l_Type);

                if (!p_Properties.ContainsKey(ITEM_PROP_VALUE_KEY))
                {
                    l_Value = OPCUtility.ITEM_UNKNOWN;
                }
                else
                {
                    p_Properties.TryGetValue(ITEM_PROP_VALUE_KEY, out l_Value);
                }

                if (!p_Properties.ContainsKey(ITEM_PROP_QUALITY_KEY))
                {
                    l_Quality = OPCUtility.ITEM_UNKNOWN;
                }
                else
                {
                    p_Properties.TryGetValue(ITEM_PROP_QUALITY_KEY, out l_Quality);
                }

                if (!p_Properties.ContainsKey(ITEM_PROP_TIMESTAMP_KEY))
                {
                    l_Timestamp = OPCUtility.ITEM_UNKNOWN;
                }
                else
                {
                    p_Properties.TryGetValue(ITEM_PROP_TIMESTAMP_KEY, out l_Timestamp);
                }

                IOPCItem l_Item = new OPCItem(l_ID, l_Type);
                l_Item.Value     = l_Value;
                l_Item.Quality   = l_Quality;
                l_Item.Timestamp = l_Timestamp;

                m_ItemIdToServerHandleDictionary.Add(l_Item.ID, p_ServerHandle);
                m_ClientHandleToItemDictionary.Add(p_ClientHandle, l_Item);
                m_ServerHandleToClientHandleDictionary.Add(p_ServerHandle, p_ClientHandle);

                ModelChangeEventArgs l_Event = new ModelChangeEventArgs(ModelChangeEventType.ADD, l_ID, l_Type,
                                                                        l_Value, l_Quality, l_Timestamp);
                if (ModelChanged != null)
                {
                    ModelChanged(this, l_Event);
                }
            }
        }
Ejemplo n.º 4
0
        public void AddItem(int clientHandle, int serverHandle, Dictionary <string, string> properties)
        {
            if (!properties.ContainsKey(ItemPropIdKey) || !properties.ContainsKey(ItemPropTypeKey))
            {
                throw new OpcItemException("The item can't be added to the model.", clientHandle.ToString());
            }

            string value, quality, timestamp;

            properties.TryGetValue(ItemPropIdKey, out var id);
            properties.TryGetValue(ItemPropTypeKey, out var type);

            if (!properties.ContainsKey(ItemPropValueKey))
            {
                value = OpcUtility.ITEM_UNKNOWN;
            }
            else
            {
                properties.TryGetValue(ItemPropValueKey, out value);
            }

            if (!properties.ContainsKey(ItemPropQualityKey))
            {
                quality = OpcUtility.ITEM_UNKNOWN;
            }
            else
            {
                properties.TryGetValue(ItemPropQualityKey, out quality);
            }

            if (!properties.ContainsKey(ItemPropTimestampKey))
            {
                timestamp = OpcUtility.ITEM_UNKNOWN;
            }
            else
            {
                properties.TryGetValue(ItemPropTimestampKey, out timestamp);
            }

            IOPCItem item = new OPCItem(id, type)
            {
                Value     = value,
                Quality   = quality,
                Timestamp = timestamp
            };

            m_ItemIdToServerHandleDictionary.Add(item.ID, serverHandle);
            m_ClientHandleToItemDictionary.Add(clientHandle, item);
            m_ServerHandleToClientHandleDictionary.Add(serverHandle, clientHandle);

            var args = new ModelChangeEventArgs(ModelChangeEventType.Add, id, type, value, quality, timestamp);

            ModelChanged?.Invoke(this, args);
        }