/// <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);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Gets the list of locators from hub.
        /// </summary>
        /// <returns></returns>
        private BindingList <RemoteLocator> GetListOfLocatorsFromHub()
        {
            string             url            = cboUrl.Text;
            string             username       = null;
            string             password       = null;
            AuthenticationMode authentication = AuthenticationMode.None;

            if (radAuthWindows.Checked)
            {
                if (chkUseCurrentCredntials.Checked)
                {
                    authentication = AuthenticationMode.CurrentWindows;
                }
                else
                {
                    authentication = AuthenticationMode.Windows;
                    username       = txtUsername.Text;
                    password       = txtPassword.Text;
                }
            }
            else if (radAuthToken.Checked)
            {
                authentication = AuthenticationMode.Token;
                username       = txtUsername.Text;
                password       = txtPassword.Text;
            }


            LocatorHub.LocatorHub locatorHubClient = LocatorManager.CreateClient(url, username, password, authentication, null);

            return(new BindingList <RemoteLocator>(locatorHubClient.ListLocators()));
        }
        /// <summary>
        /// Creates the client.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <param name="authenticationMode">The authentication mode.</param>
        /// <returns></returns>
        public static LocatorHub.LocatorHub CreateClient(string url, string username, string password, AuthenticationMode authenticationMode, string tokenUrl)
        {
            LocatorHub.LocatorHub client = new LocatorHub.LocatorHub();
            string locatorUrl            = url;

            if (locatorUrl.StartsWith("DATAHUB:"))
            {
                locatorUrl = locatorUrl.Replace("DATAHUB:", "");
                string token = LocatorManager.GetToken(LocatorManager.GetTokenUrlFromLocatorUrl(locatorUrl), DataHubConfiguration.Current.UserName, DataHubConfiguration.Current.Password);
                locatorUrl = String.Format("{0}?Token={1}", locatorUrl, token);
            }
            else
            {
                switch (authenticationMode)
                {
                case AuthenticationMode.Token:
                    string locatorTokenURl = tokenUrl;
                    if (String.IsNullOrEmpty(locatorTokenURl))
                    {
                        locatorTokenURl = LocatorManager.GetTokenUrlFromLocatorUrl(url);
                    }
                    string token = LocatorManager.GetToken(locatorTokenURl, username, password);
                    locatorUrl = String.Format("{0}?Token={1}", url, token);
                    break;

                case AuthenticationMode.Windows:
                    client.Credentials = new NetworkCredential(username, password);
                    break;

                case AuthenticationMode.CurrentWindows:
                    client.Credentials = CredentialCache.DefaultNetworkCredentials;
                    break;
                }
            }


            client.Url = locatorUrl;

            return(client);
        }
Esempio n. 5
0
        /// <summary>
        /// Run LocatorHub Search
        /// </summary>
        internal void RunSearch()
        {
            try
            {
                if (LocatorCombo.Current.SelectedIndex == -1)
                {
                    return;
                }
                //Get locator
                OnlineLocator onlineLocator = DataHubConfiguration.Current.Locators[LocatorCombo.Current.SelectedIndex];

                //Get Query String
                String Query = LocatorSearchQuery.Current.TextValue;

                //Get use Fuzzy
                bool UseFuzzy = DataHubConfiguration.Current.UseFuzzy;

                //create popup form
                LocatorHub.LocatorHub client           = LocatorManager.CreateClient(onlineLocator);
                LocatorPopupForm      locatorPopupForm = new LocatorPopupForm(client);

                int factcode = -1;
                try
                {
                    IMxDocument mxDocument = ArcMap.Application.Document as IMxDocument;
                    //get map
                    IMap map = mxDocument.FocusMap;
                    factcode = map.SpatialReference.FactoryCode;
                }
                catch (Exception)
                {
                    factcode = -1;
                }

                //Setup form
                locatorPopupForm.Setup(onlineLocator.Target, Query, onlineLocator.GazId, UseFuzzy, LocatorCombo.Current.TextValue, factcode);

                //Show popup if multiple records
                if (locatorPopupForm.FoundRecord == null && locatorPopupForm.FailReason == MatchResultCodes.PickList)
                {
                    //Show Dialog
                    locatorPopupForm.ShowDialog();
                }

                if (locatorPopupForm.DialogResult == DialogResult.OK)
                {
                    //get the matchresult from the popupform
                    MatchResult matchResult = locatorPopupForm.FoundRecord;
                    ClearGraphics();

                    string[] values = matchResult.MatchedRecord.R.V;
                    string[] point  = values[locatorPopupForm.ColumnLookup["LOCATOR_POINT"]].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    // string description = values[locatorPopupForm.ColumnLookup["LOCATOR_DESCRIPTION"]];
                    string[]      fieldNames = onlineLocator.FieldList();
                    StringBuilder sb         = new StringBuilder(values[locatorPopupForm.ColumnLookup[fieldNames[0]]]);
                    for (int i = 1; i < fieldNames.Length; i++)
                    {
                        sb.Append("|LOCATOR_SEPARATOR|");
                        sb.Append(values[locatorPopupForm.ColumnLookup[fieldNames[i]]]);
                    }
                    string   description = sb.ToString();
                    string[] extent      = values[locatorPopupForm.ColumnLookup["LOCATOR_ENVELOPE"]].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    AddPoint(point[0].ToDouble(), point[1].ToDouble(), matchResult.ReturnedCoordinateSystem, description, extent[0].ToDouble(), extent[1].ToDouble(), extent[2].ToDouble(), extent[3].ToDouble());
                }
                else if (locatorPopupForm.DialogResult == DialogResult.Abort)
                {
                    switch (locatorPopupForm.FailReason)
                    {
                    case MatchResultCodes.NoMatchNoResult:
                        MessageBox.Show("No Match. There were no matches for the specified query.", "Query");
                        break;

                    case MatchResultCodes.NoMatchTooVague:
                        MessageBox.Show("Query too vague. There were too many possible matches for the specified query.", "Query");
                        break;
                    }
                }

                locatorPopupForm = null;
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LocatorPopupForm"/> class.
 /// </summary>
 public LocatorPopupForm(LocatorHub.LocatorHub client)
 {
     InitializeComponent();
     this.Client = client;
 }
        /// <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);
            }
        }