상속: DaSubscription
예제 #1
0
        //-
        #endregion

        #region Private Methods
        //---------------------

        private void AddItemsInListView(ControlDaSubscription controlSubscription)
        {
            if (IsAddingSubscription)
            {
                ListViewItem newItem = new ListViewItem(controlSubscription.StoredName);
                newItem.Tag = controlSubscription;
                m_listView.Items.Add(newItem);
                if (controlSubscription.IsActivated)
                {
                    newItem.SubItems.Add("true");
                }
                else
                {
                    newItem.SubItems.Add("false");
                }
                newItem.SubItems.Add(controlSubscription.StoredUpdateRate.ToString());
                newItem.SubItems.Add(controlSubscription.ItemList.Length.ToString());
            }
            if (IsEditingSubscription)
            {
                ListViewItem item = m_listView.Items[m_position];
                item.SubItems[0].Text = controlSubscription.Name;
                bool active = controlSubscription.IsActivated;
                if (active)
                {
                    item.SubItems[1].Text = "true";
                }
                else
                {
                    item.SubItems[1].Text = "false";
                }

                item.SubItems[2].Text = controlSubscription.StoredUpdateRate.ToString();
            }
        }
		//----------------------------

		/// <summary>
		/// Initializes a new instance of <see cref="ControlDaItem"/> class with
		/// the value indicated by an item identifier and a <see cref="ControlDaSubscription"/> object to whom to be added.
		/// </summary>
		/// <param name="itemId">An unique identifier for the item in the server's address space.</param>
		/// <param name="parentSubscription">The subscription to whom the item is to be added.</param>
		/// <include
		///  file='TBNC.doc.xml'
		///  path='//class[@name="ControlDaItem"]/constructor[@name="ControlDaItem"]/doc/*'
		/// />
		public ControlDaItem(
			string itemId,
			ControlDaSubscription parentSubscription)
			:
				base(
				itemId,
				parentSubscription)
		{
			m_ID = itemId;
		} //	end ctr
        //-
        #endregion

        #region Internal Methods
        //----------------------

        /// <summary>
        /// Called when the active <see cref="ControlDaItem">items</see> of a <see cref="ControlDaSubscription">subscription</see> change their values.
        /// </summary>
        /// <param name="aDaSubscription"></param>
        /// <param name="items">A list of items bellonging to the subscription.</param>
        /// <param name="values">A list with the new item values.</param>
        /// <param name="results">A list with the result of value change for each item.</param>
        internal void OnDataChange(ControlDaSubscription aDaSubscription, ControlDaItem[] items, ValueQT[] values,
                                   int[] results)
        {
            try
            {
                if (DataChanged != null)
                {
                    DataChanged(aDaSubscription, items, values, results);
                }
            }
            catch (Exception exc)
            {
                m_instance.Trace(
                    EnumTraceLevel.ERR,
                    EnumTraceGroup.CLIENT,
                    "DataControl.OnDataChange",
                    exc.ToString());
            }
        }
        //-
        #endregion

        #region Public Methods
        //----------------------

        /// <summary>
        /// Starts the <see cref="DataControl">DataControl.</see>
        /// </summary>
        /// <remarks>
        /// After starting the <B>DataControl</B> the client will be notified about the <see cref="ValueQT">value</see> changes for all the
        /// <see cref="ControlDaItem">items</see> selected in the configuration phase. If an item is bound to a
        ///	Windows Forms Control then the new values will be displayed in this one.
        /// </remarks>
        /// <include
        ///  file='TBNC.doc.xml'
        ///  path='//class[@name="DataControl"]/method[@name="Start"]/doc/*'
        /// />
        public void Start()
        {
            try
            {
                if (m_session == null)
                {
                    return;
                }
                this.Clear();

                if (this.BinaryLicenseDa != string.Empty)
                {
                    m_instance.Activate(EnumFeature.DA_CLIENT, this.BinaryLicenseDa);
                }

                if (this.BinaryLicenseXmlDa != string.Empty)
                {
                    m_instance.Activate(EnumFeature.DA_CLIENT, this.BinaryLicenseXmlDa);
                }

                m_instance.Initialize();

                m_newSession = new ControlDaSession(m_session.StoredUrl);
                m_newSession.Connect(false, true, new ExecutionOptions());

                m_newSession.ShutdownRequest += new ShutdownEventHandler(HandleSessionShutdownWithReconnection);

                if (m_session.SubscriptionList.Length == 0)
                {
                    return;
                }

                foreach (ControlDaSubscription currentSubscription in m_session.SubscriptionList)
                {
                    ControlDaSubscription controlSubscription = new ControlDaSubscription(
                        currentSubscription.StoredUpdateRate,
                        m_newSession);

                    if (controlSubscription.Valid)
                    {
                        controlSubscription.Name             = currentSubscription.StoredName;
                        controlSubscription.StoredName       = controlSubscription.Name;
                        controlSubscription.StoredUpdateRate = controlSubscription.RequestedUpdateRate;
                        controlSubscription.IsActivated      = currentSubscription.IsActivated;

                        controlSubscription.DataChanged += new DataChangedEventHandler(ControlSubscription_DataChange);
                        DaItem[] items = currentSubscription.ItemList;
                        for (int i = 0; i < items.Length; i++)
                        {
                            ControlDaItem controlItem = new ControlDaItem(
                                ((ControlDaItem)items[i]).StoredId,
                                controlSubscription);

                            this.Add(controlItem);
                        }                         //	end for

                        if (controlSubscription.IsActivated)
                        {
                            controlSubscription.Connect(true, true, new ExecutionOptions());
                        }         //	end if
                    }             //	end if
                }                 //	end foreach

                m_session.Handle = m_newSession.Handle;
            }
            catch (Exception exc)
            {
                m_instance.Trace(
                    EnumTraceLevel.ERR,
                    EnumTraceGroup.CLIENT,
                    "DataControl.Start",
                    exc.ToString());
            }
        }         //	end Start
예제 #5
0
        //-------------

        private void okButton_Click(object sender, System.EventArgs e)
        {
            try
            {
                //when editing if I don't change yhe name of the current subscription it shouldn't be a problem
                ControlDaSubscription currentSelectedSubscription = (ControlDaSubscription)m_listView.Items[m_position].Tag;
                bool found = false;
                if (subscriptionNameTextBox.Text != string.Empty)
                {
                    //a subscription with the same name with another one cannot exist
                    foreach (ControlDaSubscription subscription in m_session.SubscriptionList)
                    {
                        if ((subscription.StoredName == subscriptionNameTextBox.Text) &&
                            (subscription.GetHashCode() != currentSelectedSubscription.GetHashCode()))
                        {
                            found = true;
                        }                 //	end if
                    }                     //	end foreach
                    if (found)
                    {
                        MessageBox.Show(
                            "The server already has a subscription named " + subscriptionNameTextBox.Text +
                            "!Please introduce a different subscription name.",
                            "Warning");
                        return;
                    }             //	end if
                }                 //	end if
                else
                {
                    if (IsAddingSubscription)
                    {
                        MessageBox.Show("Please introduce a subscription name.",
                                        "Warning");
                        return;
                    }
                }
                if (!found)
                {
                    if (IsAddingSubscription)
                    {
                        if (subscriptionUpdateRateTextBox.Text != string.Empty)
                        {
                            ControlDaSubscription controlSubscription = new ControlDaSubscription(
                                Convert.ToUInt32(subscriptionUpdateRateTextBox.Text),
                                m_session);
                            if (controlSubscription.Valid)
                            {
                                controlSubscription.Name             = subscriptionNameTextBox.Text;
                                controlSubscription.StoredName       = controlSubscription.Name;
                                controlSubscription.StoredUpdateRate = controlSubscription.RequestedUpdateRate;

                                controlSubscription.Connect(true, false, m_executionOptions);

                                if (activeCheckBox.Checked)
                                {
                                    controlSubscription.IsActivated = true;
                                }                                 //	end if
                                else
                                {
                                    controlSubscription.IsActivated = false;
                                }                                 //	end else

                                if (m_listView.InvokeRequired)
                                {
                                    AddItemsToSubscriptionListView aislv = new AddItemsToSubscriptionListView(AddItemsInListView);
                                    m_listView.BeginInvoke(aislv, new object[] { controlSubscription });
                                }                                 //	end if
                                else
                                {
                                    ListViewItem newItem = new ListViewItem(controlSubscription.StoredName);
                                    newItem.Tag = controlSubscription;
                                    m_listView.Items.Add(newItem);
                                    if (controlSubscription.IsActivated)
                                    {
                                        newItem.SubItems.Add("true");
                                    }
                                    else
                                    {
                                        newItem.SubItems.Add("false");
                                    }

                                    newItem.SubItems.Add(controlSubscription.StoredUpdateRate.ToString());
                                    newItem.SubItems.Add(controlSubscription.ItemList.Length.ToString());
                                }                         //	end else
                            }                             //	end if
                            //reset the indicator
                            IsAddingSubscription = false;

                            this.Close();
                        }                         //	end if
                        else
                        {
                            MessageBox.Show("Please introduce an update rate.",
                                            "Warning");
                        }                 //	end else
                    }                     //	end if adding a subscription

                    if (IsEditingSubscription)
                    {
                        //get the subscription currently selected
                        ControlDaSubscription currentSubscription = (ControlDaSubscription)m_listView.Items[m_position].Tag;

                        //modify the subscription's data
                        currentSubscription.Name = subscriptionNameTextBox.Text;
                        if (subscriptionUpdateRateTextBox.Text != string.Empty)
                        {
                            currentSubscription.RequestedUpdateRate = Convert.ToUInt32(subscriptionUpdateRateTextBox.Text);
                        }
                        currentSubscription.StoredName       = currentSubscription.Name;
                        currentSubscription.StoredUpdateRate = currentSubscription.RequestedUpdateRate;

                        currentSubscription.Connect(false, false, m_executionOptions);

                        if (activeCheckBox.Checked)
                        {
                            currentSubscription.IsActivated = true;
                        }
                        else
                        {
                            currentSubscription.IsActivated = false;
                        }

                        if (m_listView.InvokeRequired)
                        {
                            AddItemsToSubscriptionListView aislv = new AddItemsToSubscriptionListView(AddItemsInListView);
                            m_listView.BeginInvoke(aislv, new object[] { currentSubscription });
                        }
                        else
                        {
                            ListViewItem item = m_listView.Items[m_position];
                            item.SubItems[0].Text = currentSubscription.Name;
                            bool active = currentSubscription.IsActivated;
                            item.SubItems[1].Text = active.ToString().ToLower();
                            item.SubItems[2].Text = currentSubscription.StoredUpdateRate.ToString();
                        }
                        //set the new subscription in the list
                        m_listView.Items[m_position].Tag = currentSubscription;

                        //reset the indicator
                        IsEditingSubscription = false;

                        this.Close();
                    }             //	end if editing a subscription
                }                 //	end if
            }

            catch (System.FormatException exc)
            {
                Application.Instance.Trace(
                    EnumTraceLevel.ERR,
                    EnumTraceGroup.CLIENT,
                    "SubscriptionProperties.ok_button.Click",
                    exc.ToString());
                MessageBox.Show(" The update rate must have numeric format!");
                this.subscriptionUpdateRateTextBox.Text = String.Empty;
            }
            catch (Exception ex)
            {
                Application.Instance.Trace(
                    EnumTraceLevel.ERR,
                    EnumTraceGroup.CLIENT,
                    "SubscriptionProperties.ok_button.Click",
                    ex.ToString());
            }
        }