private async Task GetRulePackages() { try { await QueuedTask.Run(async() => { ArcGISPortal portal = ArcGISPortalManager.Current.GetPortal(new Uri(_arcgisOnline)); var query = PortalQueryParameters.CreateForItemsOfType(PortalItemType.RulePackage, "title:\"Paris Rule package 2014\" OR title:\"Venice Rule package 2014\" OR title:\"Extrude/Color/Rooftype Rule package 2014\""); //Execute to return a result set PortalQueryResultSet <PortalItem> results = await ArcGISPortalExtensions.SearchForContentAsync(portal, query); foreach (var item in results.Results.OfType <PortalItem>()) { lock (_rpkLock) { RulePackageCollection.Add(new RulePackage(item)); } } }); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
private async Task <string> QueryImpl() { var portal = ArcGISPortalManager.Current.GetActivePortal(); string userName = ArcGISPortalManager.Current.GetActivePortal().GetSignOnUsername(); //Searching for Vector tile packages in the current user's content var pqp = PortalQueryParameters.CreateForItemsOfTypeWithOwner(PortalItemType.VectorTilePackage, userName, "tags: UploadVtpkToAgol Demo"); //Execute to return a result set PortalQueryResultSet <PortalItem> results = await ArcGISPortalExtensions.SearchForContentAsync(portal, pqp); if (results.Results.Count == 0) { return($@"Unable to find uploaded item with query: {pqp.Query}"); } // Create an item from the search results string itemId = results.Results[0].ID; var currentItem = ItemFactory.Instance.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.Instance.CanCreateLayerFrom(currentItem)) { LayerFactory.Instance.CreateLayer(currentItem, MapView.Active.Map); } return($@"Downloaded this item: {results.Results[0].Name} [Type: {results.Results[0].Type}] to ArcGIS Online and added the item to the Map"); }
/// <summary> /// This is an alternate method of implementing a Query. /// It uses the GetUserContentAsync method to return the items in the current user's content. /// </summary> /// <returns></returns> private async Task <string> QueryUserContentImpl() { var portal = ArcGISPortalManager.Current.GetActivePortal(); string userName = ArcGISPortalManager.Current.GetActivePortal().GetSignOnUsername(); //Get the content for the signed on user. //Users executing this query must be signed on or an exception will be thrown. var results = await ArcGISPortalExtensions.GetUserContentAsync(portal, userName); //Check if a specific item exits var itemExists = results.PortalItems.Any(p => p.Tags.Contains("UploadVtpkToAgol Demo")); if (!itemExists) { return($@"Unable to find uploaded item with query: {portal.ToString()}sharing/rest/content/users/{userName}"); } // Create an item from the search results var myItem = results.PortalItems.FirstOrDefault(i => i.Tags.Contains("UploadVtpkToAgol Demo")); var currentItem = ItemFactory.Instance.Create(myItem.ID, ItemFactory.ItemType.PortalItem); // Finally add the Vextor tile package to the map // if we have an item that can be turned into a layer // add it to the map if (LayerFactory.Instance.CanCreateLayerFrom(currentItem)) { LayerFactory.Instance.CreateLayer(currentItem, MapView.Active.Map); } return($@"Downloaded this item: {myItem.Name} [Type: {myItem.Type}] to ArcGIS Online and added the item to the Map"); }
private async void SubmitQuery() { if (this.SelectedOnlineQuery == null) { return; } if (_executeQuery) { return; } _executeQuery = true; _addFailed = false; _results.Clear(); _timer.Start(); OnPropertyChanged("IsExecutingQuery"); OnPropertyChanged("AddStatus"); int maxResults = 0; if (maxResults == 0) { maxResults = OnlineQuery.DefaultMaxResults; } try { this.SelectedOnlineQuery.Keywords = this.Keywords; this.SelectedOnlineQuery.Content = SelectedResultOption; int startIndex = 0; ArcGISPortal portal = ArcGISPortalManager.Current.GetPortal(new Uri(@"http://www.arcgis.com:80/")); do //Query ArcGIS Online for 25 items at a time for a max limit of 100 items. { this.SelectedOnlineQuery.Start = startIndex; PortalQueryResultSet <PortalItem> portalResults = await ArcGISPortalExtensions.SearchForContentAsync(portal, this.SelectedOnlineQuery.PortalQuery); if (portalResults.Results.OfType <PortalItem>().Count() == 0) { return; } foreach (var item in portalResults.Results.OfType <PortalItem>()) { _results.Add(item); } startIndex = portalResults.Results.Count + startIndex; } while (startIndex < maxResults); } finally { _timer.Stop(); _executeQuery = false; OnPropertyChanged("IsExecutingQuery"); } }
private async Task <string> UploadImpl() { // Create EsriHttpClient object var httpClient = new EsriHttpClient(); // Upload vtpk file to the currently active portal var itemToUpload = ItemFactory.Instance.Create(FilePath); var tags = new string[] { "ArcGIS Pro", "SDK", "UploadVtpkToAgol Demo" }; var portalUrl = ArcGISPortalManager.Current.GetActivePortal().PortalUri.ToString(); var uploadDefn = new UploadDefinition(portalUrl, itemToUpload, tags); var result = httpClient.Upload(uploadDefn); if (result.Item1 == false) { return($@"Unable to upload this item: {FilePath} to ArcGIS Online"); } // Once uploaded make another REST call to search for the uploaded data var portal = ArcGISPortalManager.Current.GetActivePortal(); string userName = ArcGISPortalManager.Current.GetActivePortal().GetSignOnUsername(); //Searching for Vector tile packages in the current user's content var pqp = PortalQueryParameters.CreateForItemsOfTypeWithOwner(PortalItemType.VectorTilePackage, userName, "tags: UploadVtpkToAgol Demo"); //Execute to return a result set PortalQueryResultSet <PortalItem> results = await ArcGISPortalExtensions.SearchForContentAsync(portal, pqp); if (results.Results.Count == 0) { return($@"Unable to find uploaded item with query: {pqp.Query}"); } // Create an item from the search results string itemId = results.Results[0].ID; var currentItem = ItemFactory.Instance.Create(itemId, ItemFactory.ItemType.PortalItem); var lyrParams = new LayerCreationParams(currentItem); // 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.Instance.CanCreateLayerFrom(currentItem)) { LayerFactory.Instance.CreateLayer <FeatureLayer>(lyrParams, MapView.Active.Map); } return($@"Uploaded this item: {results.Results[0].Name} [Type: {results.Results[0].Type}] to ArcGIS Online and added the item to the Map"); }
/// <summary> /// Searches the active portal for the item that has been uploaded. /// </summary> /// <param name="portalUrl"></param> /// <param name="item"></param> /// <returns></returns> private async Task <Tuple <bool, PortalItem> > SearchPortalForItemsAsync(string portalUrl, Item item) { var portal = ArcGISPortalManager.Current.GetPortal(new Uri(portalUrl)); //Get the PortalItemType of the item var portalItemType = GetProtalItemTypeFromItem(item); //Get the item name without the extension var portalItemName = System.IO.Path.GetFileNameWithoutExtension(item.Name); //Create the Query and the params var pqp = PortalQueryParameters.CreateForItemsOfType(portalItemType, $@"""{portalItemName}"" tags:""{ItemTags}"""); //Search active portal PortalQueryResultSet <PortalItem> results = await ArcGISPortalExtensions.SearchForContentAsync(portal, pqp); //Iterate through the returned items for THE item. var myPortalItem = results.Results?.OfType <PortalItem>().FirstOrDefault(); if (myPortalItem == null) { return(null); } return(new Tuple <bool, PortalItem>(true, myPortalItem)); }
/// <summary> /// Execute the given query and return the result /// </summary> /// <param name="query"></param> /// <param name="results"></param> /// <param name="portalUrl"></param> /// <param name="maxResults"></param> /// <returns></returns> //public string Exec(OnlineQuery query, ObservableCollection<OnlineResultItem> results, // int maxResults = 0) { // if (maxResults == 0) // maxResults = DefaultMaxResults; // if (MaxResponseLength == 0) // MaxResponseLength = DefaultMaxResponseLength; // _response = new StringBuilder(); // _errorResponse = ""; // //slap in the initial request // _response.AppendLine(query.FinalUrl); // _response.AppendLine(""); // results.Clear(); // try { // Tuple<long, long> stats = new Tuple<long, long>(-1, -1); // do { // query.Start = stats.Item2; // System.Diagnostics.Debug.WriteLine(""); // System.Diagnostics.Debug.WriteLine(query.FinalUrl); // System.Diagnostics.Debug.WriteLine(""); // EsriHttpClient httpClient = new EsriHttpClient(); // var response = httpClient.Get(query.FinalUri.ToString()); // var raw = response.Content.ReadAsStringAsync().Result;//block // stats = ProcessResults(results, raw, query); // } while (stats.Item2 < maxResults && stats.Item2 > 0); // } // catch (WebException we) { // //bad request // _response.AppendLine(""); // _response.AppendLine("WebException: " + we.Message); // _response.AppendLine(query.FinalUrl); // _response.AppendLine(""); // _response.AppendLine(new Uri(query.FinalUrl).Scheme.ToUpper() + " " + // ((int)we.Status).ToString()); // try { // _errorResponse = new StreamReader(we.Response.GetResponseStream()).ReadToEnd(); // _response.AppendLine(_errorResponse); // } // catch { // } // } // finally { // //content = _response.ToString() // // .Replace("{", "{\r\n") // // .Replace("}", "\r\n}") // // .Replace(",\"", ",\r\n\""); // } // return _response.ToString(); //} public async void Exec2Async(OnlineQuery query, ObservableCollection <OnlinePortalItem> results, string portalUrl, int maxResults = 0) { if (maxResults == 0) { maxResults = DefaultMaxResults; } if (MaxResponseLength == 0) { MaxResponseLength = DefaultMaxResponseLength; } _response = new StringBuilder(); _errorResponse = ""; //slap in the initial request _response.AppendLine(query.FinalUrl); _response.AppendLine(""); results.Clear(); try { Tuple <long, int> stats = new Tuple <long, int>(-1, -1); var portal = ArcGISPortalManager.Current.GetPortal(new Uri(portalUrl)); int startIndex = 0; var totalCount = 0; do { query.Start = startIndex; System.Diagnostics.Debug.WriteLine(""); System.Diagnostics.Debug.WriteLine(query.FinalUrl); System.Diagnostics.Debug.WriteLine(""); PortalQueryResultSet <PortalItem> portalResults = await ArcGISPortalExtensions.SearchForContentAsync(portal, query.PortalQueryParams); if (portalResults.Results.Count <= 0) { break; } foreach (var item in portalResults.Results.OfType <PortalItem>()) { OnlinePortalItem ri = new OnlinePortalItem { Id = item.ID, Title = item.Title ?? String.Format("Item {0}", startIndex + ++totalCount), Name = item.Name, Snippet = item.Description ?? "no snippet", Url = item.Url ?? "", ThumbnailUrl = item.ThumbnailPath, PortalItemType = item.PortalItemType }; string thumb = item.ThumbnailUri?.ToString() ?? ""; string s = item.Description; string a = item.Access.ToString(); ri.Configure(query.URL, ri.Id, thumb, s, item.PortalItemType, a); results.Add(ri); totalCount++; } startIndex += results.Count; } while (totalCount < maxResults); } catch (WebException we) { //bad request _response.AppendLine(""); _response.AppendLine("WebException: " + we.Message); _response.AppendLine(query.FinalUrl); _response.AppendLine(""); _response.AppendLine(new Uri(query.FinalUrl).Scheme.ToUpper() + " " + ((int)we.Status).ToString()); try { _errorResponse = new StreamReader(we.Response.GetResponseStream()).ReadToEnd(); _response.AppendLine(_errorResponse); } catch { } } finally { } //return _response.ToString(); }
/// <summary> /// Execute the given query and return the result /// </summary> /// <param name="query"></param> /// <param name="results"></param> /// <param name="portalUrl"></param> /// <param name="maxResults"></param> /// <returns></returns> //public string Exec(OnlineQuery query, ObservableCollection<OnlineResultItem> results, // int maxResults = 0) { // if (maxResults == 0) // maxResults = DefaultMaxResults; // if (MaxResponseLength == 0) // MaxResponseLength = DefaultMaxResponseLength; // _response = new StringBuilder(); // _errorResponse = ""; // //slap in the initial request // _response.AppendLine(query.FinalUrl); // _response.AppendLine(""); // results.Clear(); // try { // Tuple<long, long> stats = new Tuple<long, long>(-1, -1); // do { // query.Start = stats.Item2; // System.Diagnostics.Debug.WriteLine(""); // System.Diagnostics.Debug.WriteLine(query.FinalUrl); // System.Diagnostics.Debug.WriteLine(""); // EsriHttpClient httpClient = new EsriHttpClient(); // var response = httpClient.Get(query.FinalUri.ToString()); // var raw = response.Content.ReadAsStringAsync().Result;//block // stats = ProcessResults(results, raw, query); // } while (stats.Item2 < maxResults && stats.Item2 > 0); // } // catch (WebException we) { // //bad request // _response.AppendLine(""); // _response.AppendLine("WebException: " + we.Message); // _response.AppendLine(query.FinalUrl); // _response.AppendLine(""); // _response.AppendLine(new Uri(query.FinalUrl).Scheme.ToUpper() + " " + // ((int)we.Status).ToString()); // try { // _errorResponse = new StreamReader(we.Response.GetResponseStream()).ReadToEnd(); // _response.AppendLine(_errorResponse); // } // catch { // } // } // finally { // //content = _response.ToString() // // .Replace("{", "{\r\n") // // .Replace("}", "\r\n}") // // .Replace(",\"", ",\r\n\""); // } // return _response.ToString(); //} public async void Exec2Async(OnlineQuery query, ObservableCollection <PortalItem> results, string portalUrl, int maxResults = 0) { if (maxResults == 0) { maxResults = DefaultMaxResults; } if (MaxResponseLength == 0) { MaxResponseLength = DefaultMaxResponseLength; } _response = new StringBuilder(); _errorResponse = ""; //slap in the initial request _response.AppendLine(query.FinalUrl); _response.AppendLine(""); results.Clear(); try { Tuple <long, int> stats = new Tuple <long, int>(-1, -1); var portal = ArcGISPortalManager.Current.GetPortal(new Uri(portalUrl)); int startIndex = 0; do { query.Start = startIndex; System.Diagnostics.Debug.WriteLine(""); System.Diagnostics.Debug.WriteLine(query.FinalUrl); System.Diagnostics.Debug.WriteLine(""); PortalQueryResultSet <PortalItem> portalResults = await ArcGISPortalExtensions.SearchForContentAsync(portal, query.PortalQueryParams); foreach (var item in portalResults.Results.OfType <PortalItem>()) { results.Add(item); } startIndex = results.Count + startIndex; } while (startIndex < maxResults); } catch (WebException we) { //bad request _response.AppendLine(""); _response.AppendLine("WebException: " + we.Message); _response.AppendLine(query.FinalUrl); _response.AppendLine(""); _response.AppendLine(new Uri(query.FinalUrl).Scheme.ToUpper() + " " + ((int)we.Status).ToString()); try { _errorResponse = new StreamReader(we.Response.GetResponseStream()).ReadToEnd(); _response.AppendLine(_errorResponse); } catch { } } finally { } //return _response.ToString(); }