Ejemplo n.º 1
0
 /// <summary>
 ///     return true cache is needed, otherwise false
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 private bool CacheData(PictureData data)
 {
     lock (_cacheLock)
     {
         bool isCached = _cachedData.ToList().Exists(c => c.PageUrl == data.PageUrl);
         if (!isCached)
         {
             _cachedData.Enqueue(data);
         }
         if (_cachedData.Count > CacheLimit)
         {
             _cachedData.Dequeue();
         }
         return(!isCached);
     }
 }
Ejemplo n.º 2
0
        //download and display cell
        private async Task DisplayAnImage(PictureData pictureData, Queue <ImageCell> queue, IPictureDataProvider provider)
        {
            var bitmap = pictureData.ThumbBitmap ?? await pictureData.GetThumbBitmap().ConfigureAwait(false);

            if (bitmap == null)
            {
                Debug.WriteLine("Thumb download failed, scraper: " + pictureData.Scraper.SiteName);
                if (provider.CanSupplyWhenFail)
                //replace with another image
                {
                    Debug.WriteLine("Replace fail thumb...");
                    await FillImages(1, queue, provider).ConfigureAwait(false);
                }
                else
                {
                    //fixed set, cant replace, displays default error image
                    UiInvoke(() => { throw new NotImplementedException(); });
                }
                return;
            }
            bool needCached = CacheData(pictureData);

            if (queue.Count == 0)
            {
                Debug.WriteLine("Queue is empty, can not display image.");
                return;
            }
            var cell = queue.Dequeue();

            //when a favorited data is randomly loaded marks it as so
            pictureData.IsFavorite = _favoriteSaver.CheckFavorite(pictureData);
            UiInvoke(() =>
            {
                //cell.SetValue(ImageCell.IsImageDownloaded, true);
                cell.SetData(pictureData);
                //no effect when data is taken from cached
                if (needCached)
                {
                    cell.BeginStoryboard((Storyboard)TryFindResource("fadeInEffect"));
                }
            });

            RaiseThumbDowloaded();
        }
Ejemplo n.º 3
0
 private PictureData GetCachedData(PictureData data)
 {
     lock (_cacheLock)
     {
         var cachedData = _cachedData.ToList().FirstOrDefault(d => d.PageUrl == data.PageUrl);
         if (cachedData == null)
         {
             //download new bitmap, delays throttle rq
             _thumbDownloadDelay = DefaultThumbDownloadDelay;
             cachedData          = data;
         }
         else
         {
             //load from cache
             _thumbDownloadDelay = 0;
         }
         return(cachedData);
     }
 }