Пример #1
0
        /// <summary>
        /// Adds a set of items to a subscription.
        /// </summary>
        private void DoAddItems()
        {
            try
            {
                // assign globally unique client handle.
                TsCDaItem[] items = ItemsCTRL.GetItems();

                foreach (TsCDaItem item in items)
                {
                    item.ClientHandle = Guid.NewGuid().ToString();
                }

                // add items to subscription.
                m_items = m_subscription.AddItems(items);

                // move to add items panel.
                BackBTN.Enabled          = true;
                NextBTN.Enabled          = false;
                CancelBTN.Visible        = false;
                DoneBTN.Visible          = true;
                OptionsBTN.Visible       = false;
                SubscriptionCTRL.Visible = true;
                BrowseCTRL.Visible       = false;
                ItemsCTRL.Visible        = false;
                ResultsCTRL.Visible      = true;

                // update controls with actual values.
                SubscriptionCTRL.Set(m_subscription.State);
                ResultsCTRL.Initialize(m_server, null, m_items);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
        /// <summary>
        /// Executes a  read request for the current set if items.
        /// </summary>
        public void DoRead()
        {
            try
            {
                // read from server.
                TsCDaItem[] items = ItemsCTRL.GetItems();

                TsCDaItemValueResult[] results = null;

                if (m_subscription != null)
                {
                    if (m_synchronous)
                    {
                        results = m_subscription.Read(items);
                    }
                    else
                    {
                        results = new AsyncRequestDlg().ShowDialog(m_subscription, items);

                        if (results == null)
                        {
                            return;
                        }
                    }
                }
                else
                {
                    // add dummy client handles to test that they get returned properly.
                    foreach (TsCDaItem item in items)
                    {
                        item.ClientHandle = item.ItemName;
                    }

                    results = m_server.Read(items);
                }

                // save results.
                m_values = results;

                BackBTN.Enabled     = true;
                NextBTN.Enabled     = false;
                CancelBTN.Visible   = false;
                DoneBTN.Visible     = true;
                OptionsBTN.Visible  = false;
                ItemsCTRL.Visible   = false;
                ResultsCTRL.Visible = true;

                // display results.
                ResultsCTRL.Initialize(m_server, (m_subscription != null)?m_subscription.Locale:m_server.Locale, results);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }