// ----------------------------------------------------------------------- // // Copyright (c) James South. // Licensed under the Apache License, Version 2.0. // // ----------------------------------------------------------------------- namespace ImageProcessor.Web.Config { #region Using using System.Configuration; using ImageProcessor.Helpers.Extensions; #endregion /// /// Represents an image cache section within a configuration file. /// public sealed class ImageCacheSection : ConfigurationSection { /// /// Gets or sets the virtual path of the cache folder. /// /// The name of the cache folder. [ConfigurationProperty("virtualPath", DefaultValue = "~/cache", IsRequired = true)] [StringValidator(MinLength = 3, MaxLength = 200)] public string VirtualPath { get { string virtualPath = (string)this["virtualPath"]; return virtualPath.IsValidVirtualPathName() ? virtualPath : "~/cache"; } set { this["virtualPath"] = value; } } /// /// Gets or sets the maximum number of days to store an image in the cache. /// /// The maximum number of days to store an image in the cache. /// Defaults to 28 if not set. [ConfigurationProperty("maxDays", DefaultValue = "28", IsRequired = false)] [IntegerValidator(ExcludeRange = false, MinValue = 0)] public int MaxDays { get { return (int)this["maxDays"]; } set { this["maxDays"] = value; } } /// /// Retrieves the cache configuration section from the current application configuration. /// /// The cache configuration section from the current application configuration. public static ImageCacheSection GetConfiguration() { ImageCacheSection imageCacheSection = ConfigurationManager.GetSection("imageProcessor/cache") as ImageCacheSection; if (imageCacheSection != null) { return imageCacheSection; } return new ImageCacheSection(); } } }