Esempio n. 1
0
        //Download Bing wallpaper
        async Task DownloadBingWallpaper()
        {
            try
            {
                Debug.WriteLine("Downloading Bing update.");

                //Check for internet connection
                if (!DownloadInternetCheck())
                {
                    BackgroundStatusUpdateSettings(null, null, "Never", null, "NoWifiEthernet"); return;
                }

                //Load and set Download Information
                string DownloadBingRegion = "en-US";
                switch (setDownloadBingRegion)
                {
                case 0: { DownloadBingRegion = vCultureInfoReg.Name; break; }

                case 2: { DownloadBingRegion = "en-GB"; break; }

                case 3: { DownloadBingRegion = "en-AU"; break; }

                case 4: { DownloadBingRegion = "de-DE"; break; }

                case 5: { DownloadBingRegion = "en-CA"; break; }

                case 6: { DownloadBingRegion = "ja-JP"; break; }

                case 7: { DownloadBingRegion = "zh-CN"; break; }

                case 8: { DownloadBingRegion = "fr-FR"; break; }

                case 9: { DownloadBingRegion = "pt-BR"; break; }

                case 10: { DownloadBingRegion = "nz-NZ"; break; }
                }
                string DownloadBingResolution = "1920x1080";
                switch (setDownloadBingResolution)
                {
                case 1: { DownloadBingResolution = "1280x720"; break; }

                case 2: { DownloadBingResolution = "1080x1920"; break; }

                case 3: { DownloadBingResolution = "720x1280"; break; }

                case 4: { DownloadBingResolution = "1024x768"; break; }
                }

                //Download and read Bing Wallpaper XML
                XDocument XDocumentBing = XDocument.Parse(await AVDownloader.DownloadStringAsync(5000, "TimeMe", null, new Uri("https://www.bing.com/HPImageArchive.aspx?format=xml&n=1&mkt=" + DownloadBingRegion)));

                //Read and check current Bing wallpaper
                XElement XElement        = XDocumentBing.Descendants("image").First();
                string   BingUrlName     = XElement.Element("urlBase").Value + "_" + DownloadBingResolution + ".jpg";
                string   BingDescription = XElement.Element("copyright").Value;
                if (BgStatusBingDescription != BingDescription)
                {
                    //Download and Save Bing Wallpaper image
                    IBuffer BingWallpaperFile = await AVDownloader.DownloadBufferAsync(5000, "TimeMe", new Uri("https://www.bing.com" + BingUrlName));

                    if (BingWallpaperFile != null)
                    {
                        //Save the Bing wallpaper image
                        StorageFile BingSaveFile = await AVFile.SaveBuffer("TimeMeTilePhoto.png" + new String(' ', new Random().Next(1, 50)), BingWallpaperFile);

                        //Set background photo as device wallpaper
                        try
                        {
                            if (setDeviceWallpaper)
                            {
                                await UserProfilePersonalizationSettings.Current.TrySetWallpaperImageAsync(BingSaveFile);
                            }
                        }
                        catch { Debug.WriteLine("Failed to update Device wallpaper."); }

                        //Set background photo as lockscreen wallpaper
                        try
                        {
                            if (setLockWallpaper)
                            {
                                if (setDevStatusMobile)
                                {
                                    await UserProfilePersonalizationSettings.Current.TrySetLockScreenImageAsync(await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Tiles/TimeMeTileColor.png")));
                                }
                                await UserProfilePersonalizationSettings.Current.TrySetLockScreenImageAsync(BingSaveFile);
                            }
                        }
                        catch { Debug.WriteLine("Failed to update Lock screen wallpaper."); }

                        //Save Bing photo name
                        BgStatusPhotoName = BingUrlName;
                        vApplicationSettings["BgStatusPhotoName"] = BgStatusPhotoName;

                        //Save Bing description status
                        BgStatusBingDescription = BingDescription;
                        vApplicationSettings["BgStatusBingDescription"] = BgStatusBingDescription;

                        //Notification - Bing description
                        ShowNotiBingDescription();

                        //Force live tile update
                        TileLive_ForceUpdate = true;
                    }
                    else
                    {
                        Debug.WriteLine("Failed downloading the Bing wallpaper.");
                        BackgroundStatusUpdateSettings(null, null, "Never", null, "FailedDownloadBingWallpaper");
                        return;
                    }
                }

                //Save Bing update status
                BgStatusDownloadBing = DateTimeNow.ToString(vCultureInfoEng);
                vApplicationSettings["BgStatusDownloadBing"] = BgStatusDownloadBing;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed updating the Bing wallpaper.");
                BackgroundStatusUpdateSettings(null, null, "Never", null, "CatchDownloadBingWallpaper" + ex.Message);
            }
        }
Esempio n. 2
0
        static public async Task <bool> Feeds(bool Silent, bool EnableUI)
        {
            try
            {
                if (!Silent)
                {
                    await EventProgressDisableUI("Downloading latest feeds...", true);
                }
                Debug.WriteLine("Downloading latest feeds...");

                string[][] RequestHeader  = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppVariables.ApplicationSettings["ConnectApiAuth"].ToString() } };
                string     DownloadString = await AVDownloader.DownloadStringAsync(10000, "News Scroll", RequestHeader, new Uri(ApiConnectionUrl + "subscription/list?output=json"));

                JObject WebJObject = JObject.Parse(DownloadString);
                if (WebJObject["subscriptions"] != null && WebJObject["subscriptions"].HasValues)
                {
                    if (!Silent)
                    {
                        await EventProgressDisableUI("Processing " + WebJObject["subscriptions"].Count() + " feeds...", true);
                    }
                    Debug.WriteLine("Processing " + WebJObject["subscriptions"].Count() + " feeds...");

                    List <String> ApiFeedIdList = new List <String>();
                    IReadOnlyList <IStorageItem> LocalFileList = await ApplicationData.Current.LocalFolder.GetItemsAsync();

                    //Wait for busy database
                    await ApiUpdate.WaitForBusyDatabase();

                    List <TableFeeds> TableUpdatedFeeds = new List <TableFeeds>();
                    List <TableFeeds> TableCurrentFeeds = await SQLConnection.Table <TableFeeds>().ToListAsync();

                    foreach (JToken JTokenRoot in WebJObject["subscriptions"])
                    {
                        string FeedId    = JTokenRoot["sortid"].ToString();
                        string FeedTitle = JTokenRoot["title"].ToString();

                        string HtmlUrl = WebUtility.HtmlDecode(JTokenRoot["htmlUrl"].ToString());
                        HtmlUrl = WebUtility.UrlDecode(HtmlUrl);

                        Uri FullUrl = new Uri(HtmlUrl);
                        ApiFeedIdList.Add(FeedId);

                        TableFeeds TableResult = TableCurrentFeeds.Where(x => x.feed_id == FeedId).FirstOrDefault();
                        if (TableResult == null)
                        {
                            //Debug.WriteLine("Adding feed: " + FeedTitle);

                            TableFeeds AddFeed = new TableFeeds();
                            AddFeed.feed_id    = FeedId;
                            AddFeed.feed_title = FeedTitle;
                            AddFeed.feed_link  = FullUrl.Scheme + "://" + FullUrl.Host;

                            AddFeed.feed_ignore_status = false;
                            if (JTokenRoot["categories"] != null && JTokenRoot["categories"].HasValues)
                            {
                                AddFeed.feed_folder = JTokenRoot["categories"][0]["label"].ToString();
                            }

                            TableUpdatedFeeds.Add(AddFeed);
                        }
                        else
                        {
                            //Debug.WriteLine("Updating feed: " + FeedTitle);

                            TableResult.feed_title = FeedTitle;
                            TableResult.feed_link  = FullUrl.Scheme + "://" + FullUrl.Host;

                            if (JTokenRoot["categories"] != null && JTokenRoot["categories"].HasValues)
                            {
                                TableResult.feed_folder = JTokenRoot["categories"][0]["label"].ToString();
                            }

                            TableUpdatedFeeds.Add(TableResult);
                        }

                        //Check and download feed logo
                        if (!LocalFileList.Any(x => x.Name == FeedId + ".png"))
                        {
                            try
                            {
                                if (!Silent)
                                {
                                    await EventProgressDisableUI("Downloading " + FeedTitle + " icon...", true);
                                }

                                Uri     IconUrl      = new Uri("https://s2.googleusercontent.com/s2/favicons?domain=" + FullUrl.Host);
                                IBuffer HttpFeedIcon = await AVDownloader.DownloadBufferAsync(3000, "News Scroll", IconUrl);

                                if (HttpFeedIcon != null && HttpFeedIcon.Length > 75)
                                {
                                    await AVFile.SaveBuffer(FeedId + ".png", HttpFeedIcon);

                                    Debug.WriteLine("Downloaded transparent logo: " + HttpFeedIcon.Length + "bytes/" + IconUrl);
                                }
                                else
                                {
                                    Debug.WriteLine("No logo found for: " + IconUrl);
                                }
                            }
                            catch { }
                        }
                    }

                    //Update the feeds in database
                    if (TableUpdatedFeeds.Any())
                    {
                        await SQLConnection.InsertOrReplaceAllAsync(TableUpdatedFeeds);
                    }

                    //Delete removed feeds from the database
                    List <String> DeletedFeeds = TableCurrentFeeds.Select(x => x.feed_id).Except(ApiFeedIdList).ToList();
                    Debug.WriteLine("Found deleted feeds: " + DeletedFeeds.Count());
                    foreach (String DeleteFeedId in DeletedFeeds)
                    {
                        await DeleteFeed(DeleteFeedId);
                    }
                }

                if (EnableUI)
                {
                    await EventProgressEnableUI();
                }
                return(true);
            }
            catch
            {
                await EventProgressEnableUI();

                return(false);
            }
        }