public virtual FileResult GetTrackImage(int id) { TrackImage image = trackPresentation.RedirecttrackImage(id); if (image != null) { return(File(image.ImageData, image.ImageMimeType)); } return(null); }
public virtual FileResult GetTrackImage(int id) { TrackImage image = adminTrack.RedirectTrackImage(id); if (image != null) { return(File(image.ImageData, image.ImageMimeType)); } return(null); }
public Task <byte[]> GetImageAsync(string albumId, TrackImage image, string folderPath) { if (string.IsNullOrEmpty(albumId)) { return(null); } string cacheFileName = CreateAndGetCacheName(albumId, image, folderPath); if (string.IsNullOrEmpty(cacheFileName)) { return(Task.FromResult <byte[]>(null)); } return(_downloader.ReadDownloadedFileAsync(cacheFileName)); }
/// <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 albumId, TrackImage image, string folderPath) { if (string.IsNullOrEmpty(albumId)) { return(Task.FromResult(false)); } string cacheFileName = CreateAndGetCacheName(albumId, image, folderPath); if (string.IsNullOrEmpty(cacheFileName)) { return(Task.FromResult(false)); } return(_downloader.DownloadFileAsync(image.ImageUrl, cacheFileName)); }
public byte[] GetImage(string albumId, TrackImage image, string folderPath) { if (string.IsNullOrEmpty(albumId)) { return(null); } string cacheFileName = CreateAndGetCacheName(albumId, image, folderPath); if (string.IsNullOrEmpty(cacheFileName)) { return(null); } return(_downloader.ReadDownloadedFile(cacheFileName)); }
/// <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 albumId, TrackImage image, string folderPath) { if (string.IsNullOrEmpty(albumId)) { return(false); } string cacheFileName = CreateAndGetCacheName(albumId, image, folderPath); if (string.IsNullOrEmpty(cacheFileName)) { return(false); } _downloader.DownloadFile(image.ImageUrl, cacheFileName); return(true); }
/// <summary> /// Creates a local file name for loading and saving <see cref="TrackImage"/>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, TrackImage image, string folderPath) { try { string prefix = string.Format(@"MB({0})_", id); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } return(Path.Combine(folderPath, prefix + image.ImageUrl.Substring(image.ImageUrl.LastIndexOf('/') + 1))); } catch { // TODO: logging return(null); } }