Пример #1
0
        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);
            }
        }
Пример #2
0
        private async Task GetRulePackages()
        {
            try
            {
                await QueuedTask.Run(async() =>
                {
                    //building the URL to get the ruel packages.
                    UriBuilder searchURL =
                        new UriBuilder(_arcgisOnline)
                    {
                        Path = "sharing/rest/search"
                    };

                    EsriHttpClient httpClient = new EsriHttpClient();

                    //these are the 3 rule packages we will download for this sample
                    string rulePackage =
                        "(type:\"Rule Package\" AND (title:\"Paris Rule package 2014\" OR title:\"Venice Rule package 2014\" OR title:\"Extrude/Color/Rooftype Rule package 2014\"))&f=json";
                    searchURL.Query = string.Format("q={0}&f=json", rulePackage);

                    var searchResponse = httpClient.Get(searchURL.Uri.ToString());

                    //Parsing the JSON retrieved.
                    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);

                    //creating the collection of Rule packages from the parsed JSON.
                    foreach (dynamic item in resultItemList)
                    {
                        var id        = item.id.ToString();
                        var title     = item.title.ToString();
                        var name      = item.name.ToString();
                        var snippet   = item.snippet.ToString();
                        var thumbnail = item.thumbnail.ToString();
                        lock (_rpkLock)
                        {
                            RulePackageCollection.Add(new RulePackage(_arcgisOnline, id, title, name, thumbnail, snippet));
                        }
                    }
                });
            }

            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }