Пример #1
0
        private static IAsyncAction LoadAsync()
        {
            return(AsyncInfo.Run(async(cancellationToken) =>
            {
                if (rootObject != null && readList != null)
                {
                    // File already loaded, there is nothing to do.
                    return;
                }

                string jsonString = await FilesManager.LoadAsync(storageFolder, FileName);

                if (!JsonObject.TryParse(jsonString, out rootObject))
                {
                    Debug.WriteLine("Invalid JSON object in {0}", FileName);
                    CreateFromScratch();
                    return;
                }

                if (!rootObject.ContainsKey(ReadListKey))
                {
                    CreateFromScratch();
                    return;
                }

                readList = rootObject.GetNamedArray(ReadListKey);
            }));
        }
Пример #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);
                }
            }));
        }
Пример #3
0
        public static IAsyncAction LoadAndDisplayWebsitesAsync(ListView listView)
        {
            return(AsyncInfo.Run(async(cancellationToken) =>
            {
                string content = await FilesManager.LoadAsync(storageFolder, websitesFileName);

                if (String.IsNullOrEmpty(content))
                {
                    // Get content from the web.
                    content = await LoadFromWeb(websitesUriString);

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

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

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

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

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

                foreach (IJsonValue jsonValue in websitesArray)
                {
                    var option = new BindableWebsiteOption(jsonValue.GetObject());
                    if (option.IsListable)
                    {
                        listView.Items.Add(option);
                    }
                }
            }));
        }
Пример #4
0
        public static IAsyncAction SaveAsync()
        {
            Task saveTask = FilesManager.SaveAsync(storageFolder, FileName, rootObject.Stringify());

            return(saveTask.AsAsyncAction());
        }