protected async override void OnClick() { //TODO - Get the URL of the Active Portal //HINT: Use PortalManager string portalUrl = PortalManager.GetActivePortal().ToString(); UriBuilder searchURL = new UriBuilder(portalUrl); searchURL.Path = "sharing/rest/search"; string layers = "(type:\"Map Service\" OR type:\"Image Service\" OR type:\"Feature Service\" OR type:\"WMS\" OR type:\"KML\")"; //any public layer content searchURL.Query = string.Format("q={0}&f=json", layers); EsriHttpClient httpClient = new EsriHttpClient(); var searchResponse = httpClient.Get(searchURL.Uri.ToString()); dynamic resultItems = JObject.Parse(await searchResponse.Content.ReadAsStringAsync()); //Use EsriHttpClient to call Online - Use the GET method //TODO get the JSON result from the searchResponse //HINT - examine methoods of searchResponse.Content //TODO Parse the returned JSON - here you will use the Newtonsoft library's JObject //examine JObject.Parse. Use a dynamic type to get the results of the Parse long numberOfTotalItems = resultItems.total.Value; if (numberOfTotalItems == 0) { return; } List <dynamic> resultItemList = new List <dynamic>(); resultItemList.AddRange(resultItems.results); //TODO add the ".results" of the returned JSON. //eg: resultItemList.AddRange(resultItems.results); //get the first result from resultItemList (or an index of your choice) //dynamic item = .... dynamic item = resultItemList[0]; //TODO create an Item via the ItemFactory. Use the ItemFactory.ItemType.PortalItem item type. string itemID = item.id; Item currentItem = ItemFactory.Create(itemID, ItemFactory.ItemType.PortalItem); await QueuedTask.Run(() => { // if we have an item that can be turned into a layer // add it to the map //TODO use the LayerFactory.CreateLayer and the MapView.Active.Map if (LayerFactory.CanCreateLayerFrom(currentItem)) { LayerFactory.CreateLayer(currentItem, MapView.Active.Map); } }); }
/// <summary> /// Execute the query command /// </summary> private void CmdDoQuery() { try { var httpEsri = new EsriHttpClient() { BaseAddress = PortalManager.GetActivePortal() }; // value has the following format: url with {};Redlands,...,...;Search Query,...,... // where Redlands ... are values and search query are keys var parts = AgolQuery.Value.Split(";".ToCharArray()); var getUrl = parts[0]; // get parameters if (CallParams.Count > 0) { var lstParams = new List <object>() as IList <object>; foreach (var kv in CallParams) { lstParams.Add(kv.Param); } getUrl = string.Format(parts[0], lstParams.ToArray()); } System.Diagnostics.Debug.WriteLine(getUrl); var httpResponse = httpEsri.Get(getUrl); if (httpResponse.StatusCode == HttpStatusCode.OK && httpResponse.Content != null) { var content = httpResponse.Content.ReadAsStringAsync().Result; QueryResult = string.Format(@"{0}{1}", getUrl, System.Environment.NewLine); QueryResult += string.Format(@"IsSuccessStatusCode: {0}{1}", httpResponse.IsSuccessStatusCode, System.Environment.NewLine); QueryResult += string.Format(@"StatusCode: {0}{1}", httpResponse.StatusCode, System.Environment.NewLine); QueryResult += content; if (AgolQuery.Key == ArcGISOnlineQueries.AGSQueryType.GetSelf) { _AgolUser = AgolUser.LoadAgolUser(content); } else if (AgolQuery.Key == ArcGISOnlineQueries.AGSQueryType.GetSearch) { _AgolSearchResult = AgolSearchResult.LoadAgolSearchResult(content); } else if (AgolQuery.Key == ArcGISOnlineQueries.AGSQueryType.GetUserContent) { _AgolUserContent = AgolUserContent.LoadAgolUserContent(content); _AgolFolderContent = null; } else if (AgolQuery.Key == ArcGISOnlineQueries.AGSQueryType.GetUserContentForFolder) { _AgolFolderContent = AgolFolderContent.LoadAgolFolderContent(content); } System.Diagnostics.Debug.WriteLine(QueryResult); } } catch (Exception ex) { QueryResult = ex.ToString(); } }
private string GetLoggedInUser() { UriBuilder selfURL = new UriBuilder(PortalManager.GetActivePortal()); selfURL.Path = "sharing/rest/portals/self"; selfURL.Query = "f=json"; EsriHttpClient client = new EsriHttpClient(); EsriHttpResponseMessage response = client.Get(selfURL.Uri.ToString()); dynamic portalSelf = JObject.Parse(response.Content.ReadAsStringAsync().Result); // if the response doesn't contain the user information then it is essentially // an anonymous request against the portal if (portalSelf.user == null) { return(null); } string userName = portalSelf.user.username; return(userName); }
protected override async void OnClick() { UriBuilder searchURL = new UriBuilder(PortalManager.GetActivePortal()); searchURL.Path = "sharing/rest/search"; string layers = "(type:\"Map Service\" OR type:\"Image Service\" OR type:\"Feature Service\" OR type:\"WMS\" OR type:\"KML\")"; //any public layer content searchURL.Query = string.Format("q={0}&f=json", layers); EsriHttpClient httpClient = new EsriHttpClient(); var searchResponse = httpClient.Get(searchURL.Uri.ToString()); dynamic resultItems = JObject.Parse(await searchResponse.Content.ReadAsStringAsync()); long numberOfTotalItems = resultItems.total.Value; if (numberOfTotalItems == 0) { return; } List <dynamic> resultItemList = new List <dynamic>(); resultItemList.AddRange(resultItems.results); //get the first result dynamic item = resultItemList[0]; string itemID = item.id; Item currentItem = ItemFactory.Create(itemID, ItemFactory.ItemType.PortalItem); await QueuedTask.Run(() => { // if we have an item that can be turned into a layer // add it to the map if (LayerFactory.CanCreateLayerFrom(currentItem)) { LayerFactory.CreateLayer(currentItem, MapView.Active.Map); } }); }
private async Task <object> PublishService(string id, string title) { string userName = GetLoggedInUser(); string publishURL = String.Format("{0}/sharing/rest/content/users/{1}/publish", PortalManager.GetActivePortal(), userName); EsriHttpClient myClient = new EsriHttpClient(); string publishParameters = string.Format("{{\"name\":\"{0}\"}}", title); var postData = new List <KeyValuePair <string, string> >(); postData.Add(new KeyValuePair <string, string>("f", "json")); postData.Add(new KeyValuePair <string, string>("itemId", id)); postData.Add(new KeyValuePair <string, string>("filetype", "vectortilepackage")); postData.Add(new KeyValuePair <string, string>("outputType", "VectorTiles")); postData.Add(new KeyValuePair <string, string>("publishParameters", publishParameters)); HttpContent content = new FormUrlEncodedContent(postData); EsriHttpResponseMessage respMsg = myClient.Post(publishURL, content); PublishResult publishResult = JsonConvert.DeserializeObject <PublishResult>(await respMsg.Content.ReadAsStringAsync()); if (publishResult.services.Count() == 1) { ShowProgress("Publish started", string.Format("Job id: {0}", publishResult.services[0].jobId), 3); string jobid = publishResult.services[0].jobId; string jobStatus = "processing"; int i = 0; while (jobStatus == "processing") { i += 1; Task.Delay(5000).Wait(); jobStatus = GetJobStatus(jobid, "publish", userName, publishResult.services[0].serviceItemId); ShowProgress("Publish in progress", string.Format("Job status: {0} - {1}", jobStatus, i), 3); } ShowProgress("Publish in progress", string.Format("Job status: {0} - {1}", jobStatus, i), 3); } return(null); }
public Tuple <bool, SDCItem> SearchPortalForItem(string itemName, string itemType) { string queryURL = String.Format(@"{0}/sharing/rest/search?q={1} AND type: {2}&f=json", PortalManager.GetActivePortal().ToString(), itemName, itemType); EsriHttpClient myClient = new EsriHttpClient(); var response = myClient.Get(queryURL); if (response == null) { return(new Tuple <bool, SDCItem>(false, null)); } string outStr = response.Content.ReadAsStringAsync().Result; SearchResult searchResults = JsonConvert.DeserializeObject <SearchResult>(outStr); if (searchResults.results.Count() > 0) { for (int i = 0; i < searchResults.results.Count; i++) { if ((searchResults.results[i].name == itemName) && (searchResults.results[i].type.Contains(itemType))) { return(new Tuple <bool, SDCItem>(true, searchResults.results[i])); } } } return(null); }
/// <summary> /// call back method to be triggered when "Get active portal" button is pressed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void GetActivePortal_Click(object sender, RoutedEventArgs e) { BaseUrl.Text = PortalManager.GetActivePortal().ToString(); }
private async Task <string> QueryImpl() { // Create EsriHttpClient object var httpClient = new EsriHttpClient(); // Make a self call to extract the signed on username for now. // Coming soon - An API which will give you the the signed on username for a portal var selfUrl = new UriBuilder(PortalManager.GetActivePortal()) { Path = "sharing/rest/portals/self", Query = "f=json" }; EsriHttpResponseMessage response = httpClient.Get(selfUrl.Uri.ToString()); dynamic portalSelf = JObject.Parse(await response.Content.ReadAsStringAsync()); // if the response doesn't contain the user information then it is essentially // an anonymous request against the portal if (portalSelf.user == null) { return("Unable to get current user from portal"); } string userName = portalSelf.user.username; string query = $@"q=owner:{userName} tags:""UploadVtpkToAgol Demo"" type:""Vector Tile Service"" "; // Once uploaded make another REST call to search for the uploaded data var searchUrl = new UriBuilder(PortalManager.GetActivePortal()) { Path = "sharing/rest/search", Query = $@"{query}&f=json" }; var searchResults = httpClient.Get(searchUrl.Uri.ToString()); dynamic resultItems = JObject.Parse(await searchResults.Content.ReadAsStringAsync()); long numberOfTotalItems = resultItems.total.Value; if (numberOfTotalItems == 0) { return($@"Unable to find uploaded item with query: {query}"); } var resultItemList = new List <dynamic>(); resultItemList.AddRange(resultItems.results); //get the first result dynamic item = resultItemList[0]; // Create an item from the search results string itemId = item.id; var currentItem = ItemFactory.Create(itemId, ItemFactory.ItemType.PortalItem); // Finally add the feature service to the map // if we have an item that can be turned into a layer // add it to the map if (LayerFactory.CanCreateLayerFrom(currentItem)) { LayerFactory.CreateLayer(currentItem, MapView.Active.Map); } return($@"Downloaded this item: {item.name} [Type: {item.type}] to ArcGIS Online and added the item to the Map"); }