private byte[] GetDefaultImages(MovieImageTypes imageType) { StringBuilder pathBuilder = new StringBuilder(); pathBuilder.Append(AppDomain.CurrentDomain.BaseDirectory); pathBuilder.Append(defaultImageFolder); switch (imageType) { case MovieImageTypes.Actor: pathBuilder.Append(defaultActorImageName); break; case MovieImageTypes.Director: pathBuilder.Append(defaultDirectorImageName); break; case MovieImageTypes.Poster: pathBuilder.Append(defaulPosterImageName); break; case MovieImageTypes.Backdrop: pathBuilder.Append(defaultBackdropImageName); break; default: pathBuilder = null; break; } return(File.ReadAllBytes(pathBuilder.ToString())); }
public byte[] FetchFromUrl(MovieImageTypes imageType, string imageName) { string url = string.Empty; byte[] imageBytes = null; switch (imageType) { case MovieImageTypes.Actor: url = imageBaseUrl + thumbnailImageUrlPath + imageName; imageBytes = GetDefaultImages(MovieImageTypes.Actor); break; case MovieImageTypes.Director: url = imageBaseUrl + thumbnailImageUrlPath + imageName; imageBytes = GetDefaultImages(MovieImageTypes.Director); break; case MovieImageTypes.Poster: url = imageBaseUrl + posterImageUrlPath + imageName; imageBytes = GetDefaultImages(MovieImageTypes.Poster); break; case MovieImageTypes.Backdrop: url = imageBaseUrl + backdropImageUrlPath + imageName; imageBytes = GetDefaultImages(MovieImageTypes.Backdrop); break; default: break; } if (url != string.Empty && imageName != null && imageName != string.Empty) { using (var webClient = new WebClient()) { imageBytes = webClient.DownloadData(url); } } return(imageBytes); }
/// <summary> /// A helper refirect a call to fetch image from end point. /// </summary> /// <param name="imageType">Type of the image represented by <see cref="MovieImageTypes"/></param> /// <param name="imageName">The name of the image in the service.</param> /// <returns></returns> private static byte[] GetImage(MovieImageTypes imageType, string imageName) { ImageFetchUtil imageFetch = new ImageFetchUtil(); return(imageFetch.FetchFromUrl(imageType, imageName)); }