Exemplo n.º 1
0
        /// <summary>
        /// Called when the close button is clicked.
        /// </summary>
        private void DoneBTN_Click(object sender, System.EventArgs e)
        {
            try
            {
                m_areas   = AreaSourcesListCTRL.GetAreas();
                m_sources = AreaSourcesListCTRL.GetSources();

                // don't activate until all the filters are applied.
                bool active = m_state.Active;
                bool update = m_subscription != null;

                // create new subscription.
                if (m_subscription == null)
                {
                    m_state.Active       = false;
                    m_state.ClientHandle = Guid.NewGuid().ToString();
                    m_subscription       = (Ae.TsCAeSubscription)m_server.CreateSubscription(m_state);
                }

                // update existing subscription.
                else
                {
                    m_subscription.ModifyState(((int)TsCAeStateMask.All & ~(int)TsCAeStateMask.Active), m_state);
                }

                // select filters.
                m_filters.Areas.Clear();
                m_filters.Areas.AddRange(m_areas);
                m_filters.Sources.Clear();
                m_filters.Sources.AddRange(m_sources);

                m_subscription.SetFilters(m_filters);

                // select attributes.
                IDictionaryEnumerator enumerator = m_attributes.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    int categoryID = (int)enumerator.Key;
                    OpcClientSdk.Ae.TsCAeAttributeCollection attributeIDs = (OpcClientSdk.Ae.TsCAeAttributeCollection)enumerator.Value;

                    m_subscription.SelectReturnedAttributes(categoryID, attributeIDs.ToArray());
                }

                // activate the subscription.
                if (active || update)
                {
                    m_state.Active = active;
                    m_subscription.ModifyState((int)TsCAeStateMask.Active, m_state);
                }

                // close the dialog.
                DialogResult = DialogResult.OK;
                Close();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
        /// <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);
                }
            }
        }