/// <summary> /// Loads image services from configuration. /// </summary> /// <exception cref="TypeLoadException"> /// Thrown when an <see cref="IImageService"/> cannot be loaded. /// </exception> private void LoadImageServices() { ImageSecuritySection.ServiceElementCollection services = this.GetImageSecuritySection().ImageServices; this.ImageServices = new List <IImageService>(); foreach (ImageSecuritySection.ServiceElement config in services) { var type = Type.GetType(config.Type); if (type == null) { string message = $"Couldn't load IImageService: {config.Type}"; ImageProcessorBootstrapper.Instance.Logger.Log <ImageProcessorConfiguration>(message); throw new TypeLoadException(message); } var imageService = Activator.CreateInstance(type) as IImageService; if (imageService != null) { string name = config.Name ?? imageService.GetType().Name; imageService.Prefix = config.Prefix; imageService.Settings = this.GetServiceSettings(name); imageService.WhiteList = this.GetServiceWhitelist(name); } this.ImageServices.Add(imageService); } }
/// <summary> /// Loads image services from configuration. /// </summary> /// <exception cref="TypeLoadException"> /// Thrown when an <see cref="IGraphicsProcessor"/> cannot be loaded. /// </exception> private void LoadImageServicesFromConfiguration() { ImageSecuritySection.ServiceElementCollection services = imageSecuritySection.ImageServices; this.ImageServices = new List <IImageService>(); foreach (ImageSecuritySection.ServiceElement config in services) { Type type = Type.GetType(config.Type); if (type == null) { throw new TypeLoadException("Couldn't load IImageService: " + config.Type); } IImageService imageService = Activator.CreateInstance(type) as IImageService; if (!string.IsNullOrWhiteSpace(config.Prefix)) { if (imageService != null) { imageService.Prefix = config.Prefix; } } this.ImageServices.Add(imageService); } // Add the available settings. foreach (IImageService service in this.ImageServices) { string name = service.GetType().Name; service.Settings = this.GetServiceSettings(name); service.WhiteList = this.GetServiceWhitelist(name); } }
/// <summary> /// Loads image services from configuration. /// </summary> /// <exception cref="TypeLoadException"> /// Thrown when an <see cref="IImageService"/> cannot be loaded. /// </exception> private void LoadImageServices() { ImageSecuritySection.ServiceElementCollection services = this.GetImageSecuritySection().ImageServices; this.ImageServices = new List <IImageService>(); foreach (ImageSecuritySection.ServiceElement config in services) { Type type = Type.GetType(config.Type); if (type == null) { string message = $"Couldn\'t load IImageService: {config.Type}"; ImageProcessorBootstrapper.Instance.Logger.Log <ImageProcessorConfiguration>(message); throw new TypeLoadException(message); } IImageService imageService = Activator.CreateInstance(type) as IImageService; if (!string.IsNullOrWhiteSpace(config.Prefix)) { if (imageService != null) { imageService.Prefix = config.Prefix; } } this.ImageServices.Add(imageService); } // Add the available settings. foreach (IImageService service in this.ImageServices) { string name = service.GetType().Name; Dictionary <string, string> settings = this.GetServiceSettings(name); if (settings.Any()) { service.Settings = settings; } else if (service.Settings == null) { // I've noticed some developers are not initializing // the settings in their implentations. service.Settings = new Dictionary <string, string>(); } Uri[] whitelist = this.GetServiceWhitelist(name); if (whitelist.Any()) { service.WhiteList = this.GetServiceWhitelist(name); } } }