Esempio n. 1
0
        public static IAsyncAction LoadAndDisplayTagOptionsAsync(ListView listView, string apiSiteParameter)
        {
            return(AsyncInfo.Run(async(cancellationToken) =>
            {
                // Create a unique file name per website.
                string tagsFileName = "tags." + apiSiteParameter + ".json";
                string content = await FilesManager.LoadAsync(storageFolder, tagsFileName);

                if (String.IsNullOrEmpty(content))
                {
                    // Get content from the web.
                    string customUriString = String.Format(tagsUriString, apiSiteParameter);
                    content = await LoadFromWeb(customUriString);

                    if (String.IsNullOrEmpty(content))
                    {
                        // No content found, there is nothing else to do.
                        return;
                    }

                    // Save it locally.
                    await FilesManager.SaveAsync(storageFolder, tagsFileName, content);
                }

                // Parse content.
                JsonObject jsonObject;
                if (!JsonObject.TryParse(content, out jsonObject))
                {
                    Debug.WriteLine("Invalid JSON oject: {0}", content);
                    return;
                }

                if (!jsonObject.ContainsKey("items"))
                {
                    Debug.WriteLine("No items value.");
                    return;
                }

                JsonArray tagsArray = jsonObject.GetNamedArray("items");

                foreach (IJsonValue jsonValue in tagsArray)
                {
                    var option = new BindableTagOption(jsonValue.GetObject());
                    listView.Items.Add(option);
                }
            }));
        }
Esempio n. 2
0
        public static IAsyncAction LoadAndDisplayTagOptionsAsync(ListView listView, string apiSiteParameter)
        {
            return AsyncInfo.Run(async (cancellationToken) =>
            {
                // Create a unique file name per website.
                string tagsFileName = "tags." + apiSiteParameter + ".json";
                string content = await FilesManager.LoadAsync(storageFolder, tagsFileName);

                if (String.IsNullOrEmpty(content))
                {
                    // Get content from the web.
                    string customUriString = String.Format(tagsUriString, apiSiteParameter);
                    content = await LoadFromWeb(customUriString);

                    if (String.IsNullOrEmpty(content))
                    {
                        // No content found, there is nothing else to do.
                        return;
                    }

                    // Save it locally.
                    await FilesManager.SaveAsync(storageFolder, tagsFileName, content);
                }

                // Parse content.
                JsonObject jsonObject;
                if (!JsonObject.TryParse(content, out jsonObject))
                {
                    Debug.WriteLine("Invalid JSON oject: {0}", content);
                    return;
                }

                if (!jsonObject.ContainsKey("items"))
                {
                    Debug.WriteLine("No items value.");
                    return;
                }

                JsonArray tagsArray = jsonObject.GetNamedArray("items");

                foreach (IJsonValue jsonValue in tagsArray)
                {
                    var option = new BindableTagOption(jsonValue.GetObject());
                    listView.Items.Add(option);
                }
            });
        }