Form used to configure locators
Inheritance: System.Windows.Forms.Form
 /// <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 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);
            }
        }
        /// <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);
            }
        }