public string GetConfigurationCacheKey(IHasImages item, ImageType imageType) { Folder folder = item as Folder; BaseItem baseItem = item as BaseItem; string str1 = ""; string str2 = ""; if (baseItem != null) { str1 = baseItem.Id.ToString(); } if (folder != null) { str2 = folder.ExternalId; } string[] keys = new string[6]; keys[0] = item.DisplayMediaType ?? ""; keys[1] = item.GetType().Name; keys[2] = Version; keys[3] = imageType.ToString(); keys[4] = str1; keys[5] = str2; string keyString = string.Concat(keys); return(BaseExtensions.GetMD5(keyString).ToString()); }
public MetadataOptions GetMetadataOptions(IHasImages item) { var type = item.GetType().Name; return(ConfigurationManager.Configuration.MetadataOptions .FirstOrDefault(i => string.Equals(i.ItemType, type, StringComparison.OrdinalIgnoreCase)) ?? new MetadataOptions()); }
private async Task <object> GetImageResult(IHasImages item, ImageRequest request, ItemImageInfo image, bool cropwhitespace, List <ImageFormat> supportedFormats, List <IImageEnhancer> enhancers, TimeSpan?cacheDuration, IDictionary <string, string> headers, bool isHeadRequest) { var options = new ImageProcessingOptions { CropWhiteSpace = cropwhitespace, Enhancers = enhancers, Height = request.Height, ImageIndex = request.Index ?? 0, Image = image, Item = item, ItemId = item.Id.ToString("N"), ItemType = item.GetType().Name, MaxHeight = request.MaxHeight, MaxWidth = request.MaxWidth, Quality = request.Quality ?? 100, Width = request.Width, AddPlayedIndicator = request.AddPlayedIndicator, PercentPlayed = request.PercentPlayed ?? 0, UnplayedCount = request.UnplayedCount, Blur = request.Blur, BackgroundColor = request.BackgroundColor, ForegroundLayer = request.ForegroundLayer, SupportedOutputFormats = supportedFormats }; var imageResult = await _imageProcessor.ProcessImage(options).ConfigureAwait(false); headers["Vary"] = "Accept"; return(await ResultFactory.GetStaticFileResult(Request, new StaticFileResultOptions { CacheDuration = cacheDuration, ResponseHeaders = headers, ContentType = imageResult.Item2, DateLastModified = imageResult.Item3, IsHeadRequest = isHeadRequest, Path = imageResult.Item1, // Sometimes imagemagick keeps a hold on the file briefly even after it's done writing to it. // I'd rather do this than add a delay after saving the file FileShare = FileShareMode.ReadWrite }).ConfigureAwait(false)); }
private bool CanRefresh(IImageProvider provider, IHasImages item, MetadataOptions options, bool includeDisabled) { if (!includeDisabled) { // If locked only allow local providers if (item.IsLocked && !(provider is ILocalImageProvider)) { return(false); } if (provider is IRemoteImageProvider) { if (!ConfigurationManager.Configuration.EnableInternetProviders) { return(false); } if (Array.IndexOf(options.DisabledImageFetchers, provider.Name) != -1) { return(false); } } } if (!item.SupportsLocalMetadata && provider is ILocalImageProvider) { return(false); } try { return(provider.Supports(item)); } catch (Exception ex) { _logger.ErrorException("{0} failed in Supports for type {1}", ex, provider.GetType().Name, item.GetType().Name); return(false); } }
/// <summary> /// Gets the images. /// </summary> /// <param name="item">The item.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <param name="provider">The provider.</param> /// <param name="preferredLanguage">The preferred language.</param> /// <param name="type">The type.</param> /// <returns>Task{IEnumerable{RemoteImageInfo}}.</returns> private async Task <IEnumerable <RemoteImageInfo> > GetImages(IHasImages item, CancellationToken cancellationToken, IRemoteImageProvider provider, string preferredLanguage, ImageType?type = null) { try { var result = await provider.GetImages(item, cancellationToken).ConfigureAwait(false); if (type.HasValue) { result = result.Where(i => i.Type == type.Value); } if (string.Equals(preferredLanguage, "en", StringComparison.OrdinalIgnoreCase)) { result = result.Where(i => string.IsNullOrEmpty(i.Language) || string.Equals(i.Language, "en", StringComparison.OrdinalIgnoreCase)); } return(result); } catch (OperationCanceledException) { return(new List <RemoteImageInfo>()); } catch (Exception ex) { _logger.ErrorException("{0} failed in GetImageInfos for type {1}", ex, provider.GetType().Name, item.GetType().Name); return(new List <RemoteImageInfo>()); } }
private bool CanRefresh(IImageProvider provider, IHasImages item, MetadataOptions options, ImageRefreshOptions refreshOptions, bool includeDisabled) { if (!includeDisabled) { // If locked only allow local providers if (item.IsLocked && !(provider is ILocalImageProvider)) { if (refreshOptions.ImageRefreshMode != ImageRefreshMode.FullRefresh) { return(false); } } if (provider is IRemoteImageProvider || provider is IDynamicImageProvider) { if (Array.IndexOf(options.DisabledImageFetchers, provider.Name) != -1) { return(false); } if (provider is IRemoteImageProvider) { if (!item.IsInternetMetadataEnabled()) { return(false); } } } } try { return(provider.Supports(item)); } catch (Exception ex) { _logger.ErrorException("{0} failed in Supports for type {1}", ex, provider.GetType().Name, item.GetType().Name); return(false); } }
private MetadataOptions GetMetadataOptions(IHasImages item) { var type = item.GetType().Name; return _configurationManager.Configuration.MetadataOptions .FirstOrDefault(i => string.Equals(i.ItemType, type, StringComparison.OrdinalIgnoreCase)) ?? new MetadataOptions(); }