/// <summary>
        /// Handles the SelectedIndexChanged event of the lstLocators control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void lstLocators_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (lstLocators.SelectedItem != null)
                {
                    OnlineLocator         current = lstLocators.SelectedItem as OnlineLocator;
                    LocatorHub.LocatorHub client  = LocatorManager.CreateClient(current);

                    LocatorCapabilities locatorCapabilities = client.Capabilities(current.GazId);

                    List <Target> targets = new List <Target>();
                    foreach (TargetElementDefinition targetElementDefinition in locatorCapabilities.TargetElements)
                    {
                        targets.Add(new Target(targetElementDefinition.TargetElementIdentity, targetElementDefinition.TargetElementName));
                    }

                    this._Targets = targets;

                    cboTarget.DisplayMember   = "Description";
                    cboTarget.ValueMember     = "Id";
                    this.cboTarget.DataSource = _Targets;
                    cboTarget.SelectedValue   = _Targets[0].Id;
                    cboTarget.Refresh();


                    ConfigureUI();
                }
            }
            catch (Exception)
            {
            }
        }
 /// <summary>
 /// Handles the Click event of the butAddLocator control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 private void butAddLocator_Click(object sender, EventArgs e)
 {
     try
     {
         ConfigureLocatorForm configureLocatorForm = new ConfigureLocatorForm();
         List <string>        names = new List <string>();
         foreach (OnlineLocator loc in _Locators)
         {
             names.Add(loc.Name);
         }
         configureLocatorForm.LocatorNamesAlreadyInUse = names;
         if (configureLocatorForm.ShowDialog() == DialogResult.OK)
         {
             try
             {
                 OnlineLocator         newloc = configureLocatorForm.ConfiguredLocator;
                 LocatorHub.LocatorHub client = LocatorManager.CreateClient(newloc);
                 LocatorCapabilities   locatorCapabilities = client.Capabilities(newloc.GazId);
                 newloc.Target = locatorCapabilities.TargetElements[0].TargetElementIdentity;
                 _Locators.Add(newloc);
                 lstLocators.Refresh();
                 lstLocators.SelectedItem = newloc;
                 lstLocators.Refresh();
                 this.lstLocators_SelectedIndexChanged(this, null);
             }
             catch (Exception)
             {
             }
         }
     }
     catch (Exception exv)
     {
         DataHubExtension.ShowError(exv);
     }
 }
        /// <summary>
        /// Handles the Click event of the butEditLocatorDefinition control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void butEditLocatorDefinition_Click(object sender, EventArgs e)
        {
            try
            {
                if (lstLocators.SelectedItem == null)
                {
                    return;
                }

                OnlineLocator currentItem = lstLocators.SelectedItem as OnlineLocator;
                if (currentItem == null)
                {
                    return;
                }

                ConfigureLocatorForm configureLocatorForm = new ConfigureLocatorForm(currentItem);
                List <string>        names = new List <string>();
                foreach (OnlineLocator loc in _Locators)
                {
                    names.Add(loc.Name);
                }

                names.Remove(currentItem.Name);
                configureLocatorForm.LocatorNamesAlreadyInUse = names;
                if (configureLocatorForm.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        //remove old item from the list
                        _Locators.Remove(lstLocators.SelectedItem as OnlineLocator);
                        //pickup the new item from the dialog and try to add to the list
                        OnlineLocator         newloc = configureLocatorForm.ConfiguredLocator;
                        LocatorHub.LocatorHub client = LocatorManager.CreateClient(newloc);
                        LocatorCapabilities   locatorCapabilities = client.Capabilities(newloc.GazId);
                        newloc.Target = locatorCapabilities.TargetElements[0].TargetElementIdentity;
                        _Locators.Add(newloc);
                        lstLocators.Refresh();
                        lstLocators.SelectedItem = newloc;
                        lstLocators.Refresh();
                        this.lstLocators_SelectedIndexChanged(this, null);
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            catch (Exception exv)
            {
                DataHubExtension.ShowError(exv);
            }

            try
            {
                //using (ConfigureLocatorDialog cd = new ConfigureLocatorDialog())
                //{
                //    LocatorConfig loc = (LocatorConfig)lstLocators.SelectedItem;
                //    List<string> names = new List<string>();
                //    foreach (LocatorConfig tloc in _Locators)
                //    {
                //        names.Add(tloc.Name);
                //    }
                //    names.Remove(loc.Name);
                //    cd.ConfiguredLocator = loc;
                //    cd.LocatorNamesAlreadyInUse = names;
                //    if (cd.ShowDialog() == DialogResult.OK)
                //    {
                //        try
                //        {
                //            _Locators.ResetBindings();
                //            lstLocators.Refresh();
                //        }
                //        finally
                //        {

                //        }

                //    }
                //}
            }
            catch (Exception ex)
            {
                DataHubExtension.ShowError(ex);
            }
        }