Example #1
0
        /// <summary>
        ///     Fill n images to queue
        /// </summary>
        /// <param name="count">number of images to load</param>
        /// <param name="queue">queue of ImageCell to fill</param>
        /// <param name="provider">data provider</param>
        /// <returns></returns>
        private async Task FillImages(int count, Queue <ImageCell> queue, IPictureDataProvider provider)
        {
            if (count < 1)
            {
                ExManager.Ex(new InvalidOperationException("FillImageQueue is passed with 0"));
            }
            var tasks = new List <Task>();

            for (int i = count; i > 0; i--)
            {
                tasks.Add(
                    DisplayAnImage(
                        GetCachedData(await provider.GetData().ConfigureAwait(false)), queue, provider));
                await Task.Delay(_thumbDownloadDelay);
            }
            await Task.WhenAll(tasks);
        }
Example #2
0
        public async Task <Bitmap> GetThumbBitmap()
        {
            try
            {
                //if (Scraper is Scrap1)
                //    throw new Exception();
                var stream = await _downloader.OpenReadAsync(ThumbUrl).ConfigureAwait(false);

                ThumbBitmap = stream.ConvertToBitmap();
                return(ThumbBitmap);
            }
            catch (Exception ex)
            {
                ExManager.Ex(ex);
                return(null);
            }
        }
Example #3
0
 private async Task <List <PictureData> > FetchDataAsync(Scraper scraper)
 {
     try
     {
         //if (scraper is Scrap14) throw new Exception();
         string html = (await _downloader.OpenReadAsync(scraper.GetRandomPageUrl()).ConfigureAwait(false)).
                       ConvertToString();
         scraper.UpdateMaxRnd(html); //try updating Max Rnd value
         var list = scraper.ExtractImages(html).ToList();
         if (list.Count < 1)
         {
             ExManager.Ex(new InvalidOperationException("Parsed list is 0 in length."));
         }
         return(list);
     }
     catch (Exception ex)
     {
         ExManager.Ex(ex);
         return(null);
     }
 }
Example #4
0
 //res label clicked
 private async void Curtain_LabelClicked(string jpgLink)
 {
     if (IsSettingWallpaper)
     {
         return;
     }
     IsSettingWallpaper = true;
     Curtain.StartLoadingAnimation();
     RaiseResClicked();
     try
     {
         if (_clickedPictureCell.Data.Scraper.IsJpgUrlNeedParsed)
         {
             string html =
                 (await _downloader.DownloadDataAsync(jpgLink).ConfigureAwait(false)).ConvertToString();
             jpgLink = _clickedPictureCell.Data.Scraper.JpgLink(html);
         }
         var    bitmap = new Bitmap(await _downloader.DownloadDataAsync(jpgLink).ConfigureAwait(false));
         string name   = _clickedPictureCell.Data.WallpaperName;
         if (string.IsNullOrEmpty(name))
         {
             var split = jpgLink.Split('/');
             name = split[split.Length - 1];
         }
         RaiseDownloadWallpaperCompleted(new DownloadWallpaperCompletedEventArgs(bitmap, name));
         DesktopWallpaperHelper.SetWallpaper(bitmap, StretchTo);
     }
     catch (Exception ex)
     {
         ExManager.Ex(ex);
         //MessageBox.Show("Failed to set new wallpaper.");
         UiInvoke(Curtain.ShowError);
     }
     finally
     {
         UiInvoke(Curtain.StopLoadingAnimation);
         IsSettingWallpaper = false;
     }
 }
Example #5
0
 public async Task <IEnumerable <ResolutionCapsule> > GetResolutions()
 {
     try
     {
         if (Resolutions == null)
         {
             string html = (await _downloader.DownloadDataAsync(PageUrl).
                            ConfigureAwait(false)).ConvertToString();
             Resolutions = SortAndTrim(Scraper.ExtractResolutions(html));
         }
         if (Resolutions.ToList().Count < 1)
         {
             throw new Exception("Parse res list is 0 in length");
         }
         return(Resolutions);
     }
     catch (Exception ex)
     {
         ExManager.Ex(ex);
         return(null);
     }
 }