diff --git a/src/Umbraco.Core/Configuration/ProviderFeatureSection.cs b/src/Umbraco.Core/Configuration/ProviderFeatureSection.cs deleted file mode 100644 index 59d50f664f..0000000000 --- a/src/Umbraco.Core/Configuration/ProviderFeatureSection.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Configuration; - -namespace Umbraco.Core.Configuration -{ - public class ProviderFeatureSection : ConfigurationSection - { - private readonly ConfigurationProperty _defaultProvider = new ConfigurationProperty("defaultProvider", typeof(string), null); - - private readonly ConfigurationProperty _providers = new ConfigurationProperty("providers", typeof(ProviderSettingsCollection), null); - - private readonly ConfigurationPropertyCollection _properties = new ConfigurationPropertyCollection(); - - public ProviderFeatureSection() - { - _properties.Add(_providers); - _properties.Add(_defaultProvider); - } - - [ConfigurationProperty("defaultProvider")] - public string DefaultProvider - { - get { return (string)base[_defaultProvider]; } - set { base[_defaultProvider] = value; } - } - - [ConfigurationProperty("providers")] - public ProviderSettingsCollection Providers - { - get { return (ProviderSettingsCollection)base[_providers]; } - } - - protected override ConfigurationPropertyCollection Properties - { - get { return _properties; } - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/GenericProviderCollection.cs b/src/Umbraco.Core/GenericProviderCollection.cs deleted file mode 100644 index 82bd6b47be..0000000000 --- a/src/Umbraco.Core/GenericProviderCollection.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Configuration.Provider; - -namespace Umbraco.Core -{ - public class GenericProviderCollection : ProviderCollection where TProvider : ProviderBase - { - public override void Add(ProviderBase provider) - { - // make sure the provider supplied is not null - if (provider == null) - throw new ArgumentNullException("provider"); - - if (provider as TProvider == null) - { - string providerTypeName = typeof(TProvider).ToString(); - throw new ArgumentException("Provider must implement provider type", providerTypeName); - } - - base.Add(provider); - } - - new public TProvider this[string name] - { - get - { - return (TProvider)base[name]; - } - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Media/IImageUrlProvider.cs b/src/Umbraco.Core/Media/IImageUrlProvider.cs new file mode 100644 index 0000000000..db51590b8a --- /dev/null +++ b/src/Umbraco.Core/Media/IImageUrlProvider.cs @@ -0,0 +1,11 @@ +using System.Collections.Specialized; + +namespace Umbraco.Core.Media +{ + public interface IImageUrlProvider + { + string Name { get; } + string GetImageUrlFromMedia(int mediaId, NameValueCollection parameters); + string GetImageUrlFromFileName(string specifiedSrc, NameValueCollection parameters); + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Media/ImageUrlProviderBase.cs b/src/Umbraco.Core/Media/ImageUrlProviderBase.cs deleted file mode 100644 index a7a0870da4..0000000000 --- a/src/Umbraco.Core/Media/ImageUrlProviderBase.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Collections.Specialized; -using System.Configuration.Provider; - -namespace Umbraco.Core.Media -{ - public abstract class ImageUrlProviderBase : ProviderBase - { - public abstract string GetImageUrlFromMedia(int mediaId, NameValueCollection parameters); - public abstract string GetImageUrlFromFileName(string specifiedSrc, NameValueCollection parameters); - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/ObjectResolution/IHttpContextFactory.cs b/src/Umbraco.Core/ObjectResolution/IHttpContextFactory.cs deleted file mode 100644 index 3095c78516..0000000000 --- a/src/Umbraco.Core/ObjectResolution/IHttpContextFactory.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Web; - -namespace Umbraco.Core.ObjectResolution -{ - public interface IHttpContextFactory - { - HttpContextBase Context { get; } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/ObjectResolution/WebHttpContextFactory.cs b/src/Umbraco.Core/ObjectResolution/WebHttpContextFactory.cs deleted file mode 100644 index d8f6d4131f..0000000000 --- a/src/Umbraco.Core/ObjectResolution/WebHttpContextFactory.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Web; - -namespace Umbraco.Core.ObjectResolution -{ - public class WebHttpContextFactory : IHttpContextFactory - { - public HttpContextBase Context - { - get { return new HttpContextWrapper(HttpContext.Current); } - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/ProviderFeature.cs b/src/Umbraco.Core/ProviderFeature.cs deleted file mode 100644 index 9fab0b7db6..0000000000 --- a/src/Umbraco.Core/ProviderFeature.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Configuration; -using System.Configuration.Provider; -using System.Web.Configuration; -using Umbraco.Core.Configuration; - -namespace Umbraco.Core -{ - public abstract class ProviderFeature where TProvider : ProviderBase - { - private static bool _initialized; - private static object _lock = new object(); - - public static TProvider Provider { get; private set; } - - public static GenericProviderCollection Providers { get; private set; } - - protected static void Initialize(string sectionName) - { - if (!_initialized) - { - lock (_lock) - { - if (_initialized) - return; - - var section = (ProviderFeatureSection) ConfigurationManager.GetSection(sectionName); - if (section == null) - throw new Exception(string.Format("{0} is not configured for this application", sectionName)); - - Providers = new GenericProviderCollection(); - - ProvidersHelper.InstantiateProviders(section.Providers, Providers, typeof (TProvider)); - - Provider = Providers[section.DefaultProvider]; - - _initialized = true; - } - } - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index f13206e9e7..7509049668 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -60,7 +60,6 @@ - diff --git a/src/Umbraco.Web.UI/config/ImageUrl.Release.config b/src/Umbraco.Web.UI/config/ImageUrl.Release.config deleted file mode 100644 index 288001b6aa..0000000000 --- a/src/Umbraco.Web.UI/config/ImageUrl.Release.config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/src/Umbraco.Web.UI/config/ImageUrl.config b/src/Umbraco.Web.UI/config/ImageUrl.config deleted file mode 100644 index 288001b6aa..0000000000 --- a/src/Umbraco.Web.UI/config/ImageUrl.config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/src/Umbraco.Web.UI/web.Template.Debug.config b/src/Umbraco.Web.UI/web.Template.Debug.config index d9ae7746f3..3318b0a4a6 100644 --- a/src/Umbraco.Web.UI/web.Template.Debug.config +++ b/src/Umbraco.Web.UI/web.Template.Debug.config @@ -14,6 +14,13 @@ xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> --> + + + + + diff --git a/src/Umbraco.Web/Media/ImageUrl.cs b/src/Umbraco.Web/Media/ImageUrl.cs index 2d99c79e84..cfdc037ac4 100644 --- a/src/Umbraco.Web/Media/ImageUrl.cs +++ b/src/Umbraco.Web/Media/ImageUrl.cs @@ -13,30 +13,23 @@ using umbraco; namespace Umbraco.Web.Media { - public class ImageUrl : ProviderFeature + public class ImageUrl { - private static IHttpContextFactory _contextFactory; - - static ImageUrl() - { - _contextFactory = new WebHttpContextFactory(); - Initialize("ImageUrl"); - } - - public static string GetImageUrl(string specifiedSrc, string field, string provider, string parameters, int? nodeId = null) + public static string GetImageUrl(string specifiedSrc, string field, string provider, string parameters, + int? nodeId = null) { string url; - ImageUrlProviderBase p = GetProvider(provider); + IImageUrlProvider p = GetProvider(provider); - NameValueCollection parsedParameters = string.IsNullOrEmpty(parameters)? - new NameValueCollection() : - HttpUtility.ParseQueryString(parameters); + NameValueCollection parsedParameters = string.IsNullOrEmpty(parameters) + ? new NameValueCollection() + : HttpUtility.ParseQueryString(parameters); - string fieldValue = string.Empty; if (!string.IsNullOrEmpty(field)) { - if(nodeId.HasValue) + string fieldValue = string.Empty; + if (nodeId.HasValue) { var contentFromCache = GetContentFromCache(nodeId.GetValueOrDefault(), field); if (contentFromCache != null) @@ -45,17 +38,23 @@ namespace Umbraco.Web.Media } else { - page itemPage =new page(content.Instance.XmlContent.GetElementById(nodeId.GetValueOrDefault().ToString(CultureInfo.InvariantCulture))); + var itemPage = new page(content.Instance.XmlContent.GetElementById(nodeId.GetValueOrDefault().ToString(CultureInfo.InvariantCulture))); var value = itemPage.Elements[field]; fieldValue = value != null ? value.ToString() : string.Empty; } } else { - var context = _contextFactory.Context; - Hashtable elements = context.Items["pageElements"] as Hashtable; - var value = elements[field]; - fieldValue = value != null ? value.ToString() : string.Empty; + var context = HttpContext.Current; + if (context != null) + { + var elements = context.Items["pageElements"] as Hashtable; + if (elements != null) + { + var value = elements[field]; + fieldValue = value != null ? value.ToString() : string.Empty; + } + } } int mediaId; if (int.TryParse(fieldValue, out mediaId)) @@ -66,7 +65,7 @@ namespace Umbraco.Web.Media else { //assume file path - url = p.GetImageUrlFromFileName(fieldValue, parsedParameters); + url = p.GetImageUrlFromFileName(fieldValue, parsedParameters); } } @@ -77,18 +76,17 @@ namespace Umbraco.Web.Media return url; } - private static ImageUrlProviderBase GetProvider(string provider) + private static IImageUrlProvider GetProvider(string provider) { - return string.IsNullOrEmpty(provider) ? - Provider : - Providers[provider]; + return ImageUrlProviderResolver.Current.Provider(provider); } private static object GetContentFromCache(int nodeIdInt, string field) { - object content = _contextFactory.Context.Cache[String.Format("contentItem{0}_{1}", nodeIdInt.ToString(CultureInfo.InvariantCulture), field)]; + object content = + ContextFactory.Context.Cache[ + String.Format("contentItem{0}_{1}", nodeIdInt.ToString(CultureInfo.InvariantCulture), field)]; return content; } - } } \ No newline at end of file diff --git a/src/Umbraco.Web/Media/ImageUrlProviderResolver.cs b/src/Umbraco.Web/Media/ImageUrlProviderResolver.cs new file mode 100644 index 0000000000..7f4a37613d --- /dev/null +++ b/src/Umbraco.Web/Media/ImageUrlProviderResolver.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Umbraco.Core.Media; +using Umbraco.Core.ObjectResolution; +using Umbraco.Web.Media.ImageUrlProviders; + +namespace Umbraco.Web.Media +{ + internal sealed class ImageUrlProviderResolver : ManyObjectsResolverBase + { + internal ImageUrlProviderResolver(IEnumerable value) : base(value) { } + + public IImageUrlProvider Provider(string provider) + { + return string.IsNullOrEmpty(provider) ? Values.First(v => v.Name == ImageUrlProvider.DefaultName) : Values.First(v => v.Name == provider); + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Media/ImageUrlProviders/ImageUrlProvider.cs b/src/Umbraco.Web/Media/ImageUrlProviders/ImageUrlProvider.cs index 06d11e221b..f86d569633 100644 --- a/src/Umbraco.Web/Media/ImageUrlProviders/ImageUrlProvider.cs +++ b/src/Umbraco.Web/Media/ImageUrlProviders/ImageUrlProvider.cs @@ -5,15 +5,15 @@ using umbraco; namespace Umbraco.Web.Media.ImageUrlProviders { - public class ImageUrlProvider : ImageUrlProviderBase + public class ImageUrlProvider : IImageUrlProvider { - public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config) + public const string DefaultName = "umbracoUpload"; + public string Name { - //Get default values from the provider config here? - base.Initialize(name, config); + get { return DefaultName; } } - public override string GetImageUrlFromMedia(int mediaId, NameValueCollection parameters) + public string GetImageUrlFromMedia(int mediaId, NameValueCollection parameters) { string url = string.Empty; var nodeIterator = library.GetMedia(mediaId, false); @@ -27,7 +27,7 @@ namespace Umbraco.Web.Media.ImageUrlProviders return url; } - public override string GetImageUrlFromFileName(string specifiedSrc, NameValueCollection parameters) + public string GetImageUrlFromFileName(string specifiedSrc, NameValueCollection parameters) { string withThumb = addThumbInfo(specifiedSrc, parameters); return addCropInfo(withThumb, parameters); diff --git a/src/Umbraco.Web/PluginManagerExtensions.cs b/src/Umbraco.Web/PluginManagerExtensions.cs index a477f33da8..45476d5153 100644 --- a/src/Umbraco.Web/PluginManagerExtensions.cs +++ b/src/Umbraco.Web/PluginManagerExtensions.cs @@ -69,5 +69,16 @@ namespace Umbraco.Web { return resolver.ResolveTypes(); } - } + + /// + /// Returns all IImageUrlProvider classes + /// + /// + /// + internal static IEnumerable ResolveImageUrlProviders(this PluginManager resolver) + { + return resolver.ResolveTypes(); + } + + } } \ No newline at end of file diff --git a/src/Umbraco.Web/WebBootManager.cs b/src/Umbraco.Web/WebBootManager.cs index 58d3c7fbab..fd0cbf6d59 100644 --- a/src/Umbraco.Web/WebBootManager.cs +++ b/src/Umbraco.Web/WebBootManager.cs @@ -9,6 +9,7 @@ using Umbraco.Core.Dictionary; using Umbraco.Core.Dynamics; using Umbraco.Core.PropertyEditors; using Umbraco.Web.Dictionary; +using Umbraco.Web.Media; using Umbraco.Web.Media.ThumbnailProviders; using Umbraco.Web.Models; using Umbraco.Web.Mvc; @@ -239,6 +240,9 @@ namespace Umbraco.Web ThumbnailProvidersResolver.Current = new ThumbnailProvidersResolver( PluginManager.Current.ResolveThumbnailProviders()); + ImageUrlProviderResolver.Current = new ImageUrlProviderResolver( + PluginManager.Current.ResolveImageUrlProviders()); + CultureDictionaryFactoryResolver.Current = new CultureDictionaryFactoryResolver( new DefaultCultureDictionaryFactory());