/// <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); }
/// <summary> /// Creates the client. /// </summary> /// <param name="onlineLocator">The online locator.</param> /// <returns></returns> public static LocatorHub.LocatorHub CreateClient(OnlineLocator onlineLocator) { return(LocatorManager.CreateClient(onlineLocator.Url, onlineLocator.Username, onlineLocator.Password, onlineLocator.Authentication, onlineLocator.TokenUrl)); }
/// <summary> /// Creates the client. /// </summary> /// <param name="url">The URL.</param> /// <returns></returns> public static LocatorHub.LocatorHub CreateClient(string url) { return(LocatorManager.CreateClient(url, null, null, AuthenticationMode.None, null)); }
/// <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); } }