Exemplo n.º 1
0
        public byte[] GetImage(string id, FanArtThumb image, string folderPath)
        {
            string cacheFileName = CreateAndGetCacheName(id, image, folderPath);

            if (string.IsNullOrEmpty(cacheFileName))
            {
                return(null);
            }

            return(_downloader.ReadDownloadedFile(cacheFileName));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Downloads images in "original" size and saves them to cache.
        /// </summary>
        /// <param name="image">Image to download</param>
        /// <param name="folderPath">The folder to store the image</param>
        /// <returns><c>true</c> if successful</returns>
        public Task <bool> DownloadImageAsync(string id, FanArtThumb image, string folderPath)
        {
            string cacheFileName = CreateAndGetCacheName(id, image, folderPath);

            if (string.IsNullOrEmpty(cacheFileName))
            {
                return(Task.FromResult(false));
            }

            string sourceUri = image.Url;

            return(_downloader.DownloadFileAsync(sourceUri, cacheFileName));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Downloads images in "original" size and saves them to cache.
        /// </summary>
        /// <param name="image">Image to download</param>
        /// <param name="folderPath">The folder to store the image</param>
        /// <returns><c>true</c> if successful</returns>
        public bool DownloadImage(string id, FanArtThumb image, string folderPath)
        {
            string cacheFileName = CreateAndGetCacheName(id, image, folderPath);

            if (string.IsNullOrEmpty(cacheFileName))
            {
                return(false);
            }

            string sourceUri = image.Url;

            return(_downloader.DownloadFile(sourceUri, cacheFileName));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Creates a local file name for loading and saving <see cref="MovieImage"/>s.
 /// </summary>
 /// <param name="image"></param>
 /// <param name="folderPath"></param>
 /// <returns>Cache file name or <c>null</c> if directory could not be created</returns>
 protected string CreateAndGetCacheName(string id, FanArtThumb image, string folderPath)
 {
     try
     {
         string prefix = string.Format(@"FATV({0})_", id);
         if (!Directory.Exists(folderPath))
         {
             Directory.CreateDirectory(folderPath);
         }
         return(Path.Combine(folderPath, prefix + image.Url.Substring(image.Url.LastIndexOf('/') + 1)));
     }
     catch
     {
         // TODO: logging
         return(null);
     }
 }