//- #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
//------------- 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()); } }