/// <summary>
        /// Populates the tree with the event attributes supported by the category.
        /// </summary>
        private void ShowEventAttributes(TreeNodeCollection nodes, OpcClientSdk.Ae.TsCAeCategory category)
        {
            OpcClientSdk.Ae.TsCAeAttribute[] attributes = null;

            // fetch attributes.
            try
            {
                attributes = m_server.QueryEventAttributes(category.ID);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return;
            }

            // add attributes to tree.
            foreach (OpcClientSdk.Ae.TsCAeAttribute attribute in attributes)
            {
                // create node.
                TreeNode node = new TreeNode(attribute.Name);

                node.ImageIndex         = Resources.IMAGE_EXPLODING_BOX;
                node.SelectedImageIndex = Resources.IMAGE_EXPLODING_BOX;
                node.Tag = attribute;

                // add to tree.
                nodes.Add(node);
            }
        }
        /// <summary>
        /// Updates categories with selected attributes to dictionary.
        /// </summary>
        private void SetSelectedCategories(TreeNode parent, OpcClientSdk.Ae.TsCAeAttributeDictionary attributes)
        {
            foreach (TreeNode child in parent.Nodes)
            {
                if (!typeof(OpcClientSdk.Ae.TsCAeCategory).IsInstanceOfType(child.Tag))
                {
                    continue;
                }

                // check if category exists.
                OpcClientSdk.Ae.TsCAeCategory category = (OpcClientSdk.Ae.TsCAeCategory)child.Tag;

                if (!attributes.Contains(category.ID))
                {
                    child.Checked = false;
                    continue;
                }

                // check if attributes need to be fetched.
                if (child.Nodes.Count == 1 && child.Nodes[0].Text.Length == 0)
                {
                    child.Nodes.Clear();
                    ShowEventAttributes(child.Nodes, category);
                }

                // update individual attributes.
                SetSelectedAttributes(child, category, attributes);
            }
        }
Example #3
0
        /// <summary>
        /// Sets the currently selected categories.
        /// </summary>
        public void SetSelectedCategories(int[] categoryIDs)
        {
            foreach (ListViewItem item in CategoriesLV.Items)
            {
                item.Checked = false;

                OpcClientSdk.Ae.TsCAeCategory category = (OpcClientSdk.Ae.TsCAeCategory)item.Tag;

                for (int ii = 0; ii < categoryIDs.Length; ii++)
                {
                    if (categoryIDs[ii] == category.ID)
                    {
                        item.Checked = true;
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Updates the selected attributes to the dictionary.
        /// </summary>
        private void SetSelectedAttributes(TreeNode parent, OpcClientSdk.Ae.TsCAeCategory category, OpcClientSdk.Ae.TsCAeAttributeDictionary attributes)
        {
            foreach (TreeNode child in parent.Nodes)
            {
                if (!typeof(TsCAeAttribute).IsInstanceOfType(child.Tag))
                {
                    continue;
                }

                OpcClientSdk.Ae.TsCAeAttribute attribute = (OpcClientSdk.Ae.TsCAeAttribute)child.Tag;

                if (attributes[category.ID].Contains(attribute.ID))
                {
                    child.Checked = true;
                }
                else
                {
                    child.Checked = false;
                }
            }
        }
        /// <summary>
        /// Checks or unchecks all attributes for the specified category id.
        /// </summary>
        public void SelectCategory(TreeNode parent, int categoryID, bool picked)
        {
            foreach (TreeNode child in parent.Nodes)
            {
                if (!typeof(OpcClientSdk.Ae.TsCAeCategory).IsInstanceOfType(child.Tag))
                {
                    continue;
                }

                // find the matching category id.
                OpcClientSdk.Ae.TsCAeCategory category = (OpcClientSdk.Ae.TsCAeCategory)child.Tag;

                if (categoryID == category.ID)
                {
                    // ensure node is visible if state changes.
                    if (child.Checked != picked)
                    {
                        // fetch attributes if a dummy mode exists.
                        if (child.Nodes.Count == 1 && child.Nodes[0].Text.Length == 0)
                        {
                            child.Nodes.Clear();
                            ShowEventAttributes(child.Nodes, category);
                        }

                        child.EnsureVisible();
                    }

                    if (picked)
                    {
                        child.Checked = true;
                    }
                    else
                    {
                        child.Checked = false;
                    }
                }
            }
        }
        /// <summary>
        /// Adds selected attributes to the dictionary.
        /// </summary>
        private void GetSelectedAttributes(TreeNode parent, OpcClientSdk.Ae.TsCAeCategory category, OpcClientSdk.Ae.TsCAeAttributeDictionary attributes)
        {
            foreach (TreeNode child in parent.Nodes)
            {
                if (!typeof(OpcClientSdk.Ae.TsCAeAttribute).IsInstanceOfType(child.Tag))
                {
                    continue;
                }

                if (child.Checked)
                {
                    OpcClientSdk.Ae.TsCAeAttributeCollection collection = attributes[category.ID];

                    if (collection == null)
                    {
                        attributes.Add(category.ID, null);
                        collection = attributes[category.ID];
                    }

                    collection.Add(((OpcClientSdk.Ae.TsCAeAttribute)child.Tag).ID);
                }
            }
        }
        /// <summary>
        /// Displays the notification in the control.
        /// </summary>
        public void ShowNotification(Ae.TsCAeSubscription subscription, TsCAeEventNotification notification)
        {
            // check for null value.
            if (notification == null)
            {
                SourceTB.Text           = "";
                TimeTB.Text             = "";
                MessageTB.Text          = "";
                EventTypeTB.Text        = "";
                EventCategoryTB.Text    = "";
                ConditionNameTB.Text    = "";
                SubConditionNameTB.Text = "";
                NewStateTB.Text         = "";
                AckRequiredTB.Text      = "";
                QualityTB.Text          = "";
                ActiveTimeTB.Text       = "";
                ActorTB.Text            = "";

                AttributesLV.Items.Clear();
                return;
            }

            // find category.
            OpcClientSdk.Ae.TsCAeCategory category = null;

            try
            {
                OpcClientSdk.Ae.TsCAeCategory[] categories = subscription.Server.QueryEventCategories((int)notification.EventType);

                for (int ii = 0; ii < categories.Length; ii++)
                {
                    if (categories[ii].ID == notification.EventCategory)
                    {
                        category = categories[ii];
                        break;
                    }
                }
            }
            catch
            {
                category = null;
            }

            // find attributes.
            ArrayList attributes = new ArrayList();

            try
            {
                // get attribute descriptions.
                OpcClientSdk.Ae.TsCAeAttribute[] descriptions = subscription.Server.QueryEventAttributes(notification.EventCategory);

                // get selected attributes.
                int[] attributeIDs = null;

                if (subscription.Attributes.Contains(notification.EventCategory))
                {
                    attributeIDs = subscription.Attributes[notification.EventCategory].ToArray();
                }

                // find decriptions for selected attributes.
                if (attributeIDs != null)
                {
                    for (int ii = 0; ii < attributeIDs.Length; ii++)
                    {
                        for (int jj = 0; jj < descriptions.Length; jj++)
                        {
                            if (descriptions[jj].ID == attributeIDs[ii])
                            {
                                attributes.Add(descriptions[jj]);
                                break;
                            }
                        }
                    }
                }
            }
            catch
            {
                // ignore errors.
            }

            SourceTB.Text           = notification.SourceID;
            TimeTB.Text             = OpcClientSdk.OpcConvert.ToString(notification.Time);
            MessageTB.Text          = notification.Message;
            EventTypeTB.Text        = OpcClientSdk.OpcConvert.ToString(notification.EventType);
            EventCategoryTB.Text    = (category != null)?category.Name:"";
            ConditionNameTB.Text    = notification.ConditionName;
            SubConditionNameTB.Text = notification.SubConditionName;
            NewStateTB.Text         = "";
            AckRequiredTB.Text      = OpcClientSdk.OpcConvert.ToString(notification.AckRequired);
            QualityTB.Text          = OpcClientSdk.OpcConvert.ToString(notification.Quality);
            ActiveTimeTB.Text       = OpcClientSdk.OpcConvert.ToString(notification.ActiveTime);
            ActorTB.Text            = notification.ActorID;

            // convert state to a string.
            if ((notification.NewState & (int)Ae.TsCAeConditionState.Active) != 0)
            {
                NewStateTB.Text += Ae.TsCAeConditionState.Active.ToString();
            }

            if ((notification.NewState & (int)Ae.TsCAeConditionState.Enabled) != 0)
            {
                if (NewStateTB.Text != "")
                {
                    NewStateTB.Text += " AND ";
                }
                NewStateTB.Text += Ae.TsCAeConditionState.Enabled.ToString();
            }

            if ((notification.NewState & (int)Ae.TsCAeConditionState.Acknowledged) != 0)
            {
                if (NewStateTB.Text != "")
                {
                    NewStateTB.Text += " AND ";
                }
                NewStateTB.Text += Ae.TsCAeConditionState.Acknowledged.ToString();
            }

            // fill attributes list.
            AttributesLV.Items.Clear();

            for (int ii = 0; ii < notification.Attributes.Count; ii++)
            {
                OpcClientSdk.Ae.TsCAeAttribute attribute = (ii < attributes.Count)?(OpcClientSdk.Ae.TsCAeAttribute)attributes[ii]:null;

                ListViewItem item = new ListViewItem((attribute != null)?attribute.Name:"Unknown");

                item.SubItems.Add(OpcClientSdk.OpcConvert.ToString(notification.Attributes[ii]));

                AttributesLV.Items.Add(item);
            }

            AdjustColumns(AttributesLV);
        }