Пример #1
0
        public void AddToCache(PictureCacheItem image)
        {
            Cache.Add(image.PictureId.ToString(), image, CacheItemPriority.Low, null, new SlidingTime(TimeSpan.FromDays(10)));
            PictureInfoDTO info;

            downloadingPictures.TryRemove(image.PictureId, out info);
        }
Пример #2
0
        public PictureCacheItem GetImage(PictureInfoDTO pictureInfo)
        {
            PictureCacheItem picture = (PictureCacheItem)Cache.GetData(pictureInfo.PictureId.ToString());

            if (picture == null || (picture.Image != null && picture.Hash != pictureInfo.Hash))
            {
                loadImage(pictureInfo);
            }
            return(picture);
        }
Пример #3
0
        public static PictureCacheItem ToPictureCacheItem(this PictureDTO pictureDto)
        {
            if (pictureDto.ImageStream.CanSeek)
            {
                pictureDto.ImageStream.Seek(0, SeekOrigin.Begin);
            }
            MemoryStream stream = new MemoryStream();

            pictureDto.ImageStream.CopyTo(stream);
            stream.Seek(0, SeekOrigin.Begin);
            var image             = Image.FromStream(stream);
            PictureCacheItem item = new PictureCacheItem(image, pictureDto.PictureId, pictureDto.Hash);

            return(item);
        }
Пример #4
0
 public void Execute()
 {
     try
     {
         var image = ServiceManager.GetImage(picture);
         cache.AddToCache(image.ToPictureCacheItem());
         cache.Notify(image.GetPictureInfo());
     }
     catch (FileNotFoundException ex)
     {
         ExceptionHandler.Default.Process(ex);
         PictureCacheItem item = new PictureCacheItem(null, picture.PictureId, picture.Hash);
         cache.AddToCache(item);
         cache.Notify(new PictureInfoDTO(picture.PictureId, picture.Hash));
     }
 }