Ejemplo n.º 1
0
        // This method should be called when the StackExchange API refuses to pprovide data.
        public static void LoadAndDisplayEmergencyWebsites(ListView listView)
        {
            JsonObject jsonObject = JsonObject.Parse(emergencyJsonString);
            var        option     = new BindableWebsiteOption(jsonObject);

            if (option.IsListable)
            {
                listView.Items.Add(option);
            }
        }
Ejemplo n.º 2
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);
                    }
                }
            }));
        }
Ejemplo n.º 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);
                    }
                }
            });
        }
Ejemplo n.º 4
0
        public static IAsyncOperation <BindableWebsite> AddWebsiteAndSave(BindableWebsiteOption websiteOption)
        {
            return(AsyncInfo.Run(async(cancellationToken) =>
            {
                const int websitesLimit = 10;

                CheckSettingsAreLoaded();

                string websiteSiteUrl = websiteOption.SiteUrl;

                JsonObject roamingWebsiteObject = null;
                if (roamingWebsites.ContainsKey(websiteSiteUrl))
                {
                    // We already have this website. Nothing to do.
                    roamingWebsiteObject = roamingWebsites.GetNamedObject(websiteSiteUrl);
                }
                else if (roamingWebsites.Count < websitesLimit)
                {
                    roamingWebsiteObject = new JsonObject();
                    roamingWebsiteObject.SetNamedValue("Tags", new JsonObject());
                    roamingWebsiteObject.SetNamedValue("Name", JsonValue.CreateStringValue(websiteOption.ToString()));
                    roamingWebsiteObject.SetNamedValue("ApiSiteParameter", JsonValue.CreateStringValue(websiteOption.ApiSiteParameter));
                    roamingWebsiteObject.SetNamedValue("IconUrl", JsonValue.CreateStringValue(websiteOption.IconUrl));
                    roamingWebsiteObject.SetNamedValue(FaviconUrlKey, JsonValue.CreateStringValue(websiteOption.FaviconUrl));
                    roamingWebsites.SetNamedValue(websiteSiteUrl, roamingWebsiteObject);

                    JsonObject localWebsiteObject = new JsonObject();
                    localWebsites.SetNamedValue(websiteSiteUrl, localWebsiteObject);

                    SaveRoaming();
                    SaveLocal();
                }
                else
                {
                    MessageDialog dialog = new MessageDialog(
                        String.Format("Only {0} websites allowed.", websitesLimit),
                        "Oops.");
                    await dialog.ShowAsync();

                    // Make sure to return null.
                    return null;
                }

                return new BindableWebsite(websiteSiteUrl, roamingWebsiteObject);
            }));
        }
Ejemplo n.º 5
0
        public static IAsyncOperation<BindableWebsite> AddWebsiteAndSave(BindableWebsiteOption websiteOption)
        {
            return AsyncInfo.Run(async (cancellationToken) =>
            {
                const int websitesLimit = 10;

                CheckSettingsAreLoaded();

                string websiteSiteUrl = websiteOption.SiteUrl;

                JsonObject roamingWebsiteObject = null;
                if (roamingWebsites.ContainsKey(websiteSiteUrl))
                {
                    // We already have this website. Nothing to do.
                    roamingWebsiteObject = roamingWebsites.GetNamedObject(websiteSiteUrl);
                }
                else if (roamingWebsites.Count < websitesLimit)
                {
                    roamingWebsiteObject = new JsonObject();
                    roamingWebsiteObject.SetNamedValue("Tags", new JsonObject());
                    roamingWebsiteObject.SetNamedValue("Name", JsonValue.CreateStringValue(websiteOption.ToString()));
                    roamingWebsiteObject.SetNamedValue("ApiSiteParameter", JsonValue.CreateStringValue(websiteOption.ApiSiteParameter));
                    roamingWebsiteObject.SetNamedValue("IconUrl", JsonValue.CreateStringValue(websiteOption.IconUrl));
                    roamingWebsiteObject.SetNamedValue(FaviconUrlKey, JsonValue.CreateStringValue(websiteOption.FaviconUrl));
                    roamingWebsites.SetNamedValue(websiteSiteUrl, roamingWebsiteObject);

                    JsonObject localWebsiteObject = new JsonObject();
                    localWebsites.SetNamedValue(websiteSiteUrl, localWebsiteObject);

                    SaveRoaming();
                    SaveLocal();
                }
                else
                {
                    MessageDialog dialog = new MessageDialog(
                        String.Format("Only {0} websites allowed.", websitesLimit),
                        "Oops.");
                    await dialog.ShowAsync();

                    // Make sure to return null.
                    return null;
                }

                return new BindableWebsite(websiteSiteUrl, roamingWebsiteObject);
            });
        }
Ejemplo n.º 6
0
 // This method should be called when the StackExchange API refuses to pprovide data.
 public static void LoadAndDisplayEmergencyWebsites(ListView listView)
 {
     JsonObject jsonObject = JsonObject.Parse(emergencyJsonString);
     var option = new BindableWebsiteOption(jsonObject);
     if (option.IsListable)
     {
         listView.Items.Add(option);
     }
 }