Makes some massive headway with the real config section, have got all code re-delegated to using it and have migrated the baserest config to the core project, all configs will be shared out of the UmbracoConfiguration singleton, now to get the unit tests all wired up and using mocks for the most part.

This commit is contained in:
Shannon
2013-09-13 18:11:20 +10:00
parent 36d82dc43b
commit f38a6e1561
84 changed files with 841 additions and 2099 deletions

View File

@@ -0,0 +1,45 @@
using System.Collections.Generic;
using System.Configuration;
namespace Umbraco.Core.Configuration.BaseRest
{
[ConfigurationKey("BaseRestExtensions")]
internal class BaseRestSection : UmbracoConfigurationSection, IBaseRest
{
private const string KeyEnabled = "enabled";
private bool? _enabled;
internal protected override void ResetSection()
{
base.ResetSection();
_enabled = null;
}
[ConfigurationProperty("", IsKey = false, IsRequired = false, IsDefaultCollection = true)]
public ExtensionElementCollection Items
{
get { return (ExtensionElementCollection)base[""]; }
}
/// <summary>
/// Gets or sets a value indicating whether base rest extensions are enabled.
/// </summary>
[ConfigurationProperty(KeyEnabled, DefaultValue = true, IsRequired = false)]
public bool Enabled
{
get
{
return _enabled ?? (IsPresent == false || (bool)this[KeyEnabled]);
}
internal set { _enabled = value; }
}
IExtensionsCollection IBaseRest.Items
{
get { return Items; }
}
}
}

View File

@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Configuration;
namespace Umbraco.Core.Configuration.BaseRest
{
[ConfigurationCollection(typeof(ExtensionElement), CollectionType = ConfigurationElementCollectionType.BasicMapAlternate)]
internal class ExtensionElement : ConfigurationElementCollection, IEnumerable<IMethod>, IExtension
{
const string KeyAlias = "alias";
const string KeyType = "type";
const string KeyMethod = "method";
[ConfigurationProperty(KeyAlias, IsKey = true, IsRequired = true)]
public string Alias
{
get { return (string)base[KeyAlias]; }
}
[ConfigurationProperty(KeyType, IsKey = false, IsRequired = true)]
public string Type
{
get { return (string)base[KeyType]; }
}
public override ConfigurationElementCollectionType CollectionType
{
get { return ConfigurationElementCollectionType.BasicMapAlternate; }
}
protected override string ElementName
{
get { return KeyMethod; }
}
protected override bool IsElementName(string elementName)
{
return elementName.Equals(KeyMethod, StringComparison.InvariantCultureIgnoreCase);
}
protected override ConfigurationElement CreateNewElement()
{
return new MethodElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((MethodElement)element).Name;
}
public override bool IsReadOnly()
{
return false;
}
new public MethodElement this[string index]
{
get { return (MethodElement)BaseGet(index); }
}
IEnumerator<IMethod> IEnumerable<IMethod>.GetEnumerator()
{
for (var i = 0; i < Count; i++)
{
yield return BaseGet(i) as IMethod;
}
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
IMethod IExtension.this[string index]
{
get { return this[index]; }
}
}
}

View File

@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Configuration;
namespace Umbraco.Core.Configuration.BaseRest
{
public interface IExtensionsCollection : IEnumerable<IExtension>
{
IExtension this[string index] { get; }
}
[ConfigurationCollection(typeof(ExtensionElement), CollectionType = ConfigurationElementCollectionType.BasicMapAlternate)]
internal class ExtensionElementCollection : ConfigurationElementCollection, IExtensionsCollection
{
const string KeyExtension = "extension";
public override ConfigurationElementCollectionType CollectionType
{
get { return ConfigurationElementCollectionType.BasicMapAlternate; }
}
protected override string ElementName
{
get { return KeyExtension; }
}
protected override bool IsElementName(string elementName)
{
return elementName.Equals(KeyExtension, StringComparison.InvariantCultureIgnoreCase);
}
protected override ConfigurationElement CreateNewElement()
{
return new ExtensionElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((ExtensionElement)element).Alias;
}
public override bool IsReadOnly()
{
return false;
}
new public ExtensionElement this[string index]
{
get { return (ExtensionElement)BaseGet(index); }
}
IEnumerator<IExtension> IEnumerable<IExtension>.GetEnumerator()
{
for (var i = 0; i < Count; i++)
{
yield return BaseGet(i) as IExtension;
}
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
IExtension IExtensionsCollection.this[string index]
{
get { return this[index]; }
}
}
}

View File

@@ -0,0 +1,14 @@
using System.Collections.Generic;
namespace Umbraco.Core.Configuration.BaseRest
{
public interface IBaseRest
{
IExtensionsCollection Items { get; }
/// <summary>
/// Gets a value indicating whether base rest extensions are enabled.
/// </summary>
bool Enabled { get; }
}
}

View File

@@ -0,0 +1,11 @@
namespace Umbraco.Core.Configuration.BaseRest
{
public interface IExtension
{
string Alias { get; }
string Type { get; }
IMethod this[string index] { get; }
}
}

View File

@@ -0,0 +1,17 @@
namespace Umbraco.Core.Configuration.BaseRest
{
public interface IMethod
{
string Name { get; }
bool AllowAll { get; }
string AllowGroup { get; }
string AllowType { get; }
string AllowMember { get; }
bool ReturnXml { get; }
}
}

View File

@@ -0,0 +1,50 @@
using System.Configuration;
namespace Umbraco.Core.Configuration.BaseRest
{
internal class MethodElement : ConfigurationElement, IMethod
{
const string KeyName = "name";
const string KeyAllowAll = "allowAll";
const string KeyAllowGroup = "allowGroup";
const string KeyAllowType = "allowType";
const string KeyAllowMember = "allowMember";
const string KeyReturnXml = "returnXml";
[ConfigurationProperty(KeyName, IsKey = true, IsRequired = true)]
public string Name
{
get { return (string)base[KeyName]; }
}
[ConfigurationProperty(KeyAllowAll, IsKey = false, IsRequired = false, DefaultValue = false)]
public bool AllowAll
{
get { return (bool)base[KeyAllowAll]; }
}
[ConfigurationProperty(KeyAllowGroup, IsKey = false, IsRequired = false, DefaultValue = null)]
public string AllowGroup
{
get { return (string)base[KeyAllowGroup]; }
}
[ConfigurationProperty(KeyAllowType, IsKey = false, IsRequired = false, DefaultValue = null)]
public string AllowType
{
get { return (string)base[KeyAllowType]; }
}
[ConfigurationProperty(KeyAllowMember, IsKey = false, IsRequired = false, DefaultValue = null)]
public string AllowMember
{
get { return (string)base[KeyAllowMember]; }
}
[ConfigurationProperty(KeyReturnXml, IsKey = false, IsRequired = false, DefaultValue = true)]
public bool ReturnXml
{
get { return (bool)base[KeyReturnXml]; }
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -10,6 +10,7 @@ namespace Umbraco.Core.Configuration
internal class RazorDataTypeModelStaticMappingItem
{
[Obsolete("This is not used whatsoever")]
public string Raw { get; set; }
//if all of the set (non null) properties match the property data currently being evaluated
public string PropertyTypeAlias { get; set; }

View File

@@ -1,4 +1,7 @@
using Umbraco.Core.Configuration.UmbracoSettings;
using System;
using System.Configuration;
using Umbraco.Core.Configuration.BaseRest;
using Umbraco.Core.Configuration.UmbracoSettings;
namespace Umbraco.Core.Configuration
{
@@ -7,13 +10,45 @@ namespace Umbraco.Core.Configuration
/// </summary>
public class UmbracoConfiguration
{
//TODO: Add other configurations here !
#region Singleton
public IUmbracoSettings UmbracoSettings { get; private set; }
private static readonly Lazy<UmbracoConfiguration> Lazy = new Lazy<UmbracoConfiguration>(() => new UmbracoConfiguration());
public UmbracoConfiguration(IUmbracoSettings umbracoSettings)
public static UmbracoConfiguration Current { get { return Lazy.Value; } }
#endregion
/// <summary>
/// Default constructor
/// </summary>
private UmbracoConfiguration()
{
if (UmbracoSettings == null)
{
var umbracoSettings = ConfigurationManager.GetSection("umbracoConfiguration/settings") as IUmbracoSettings;
if (umbracoSettings == null)
{
throw new InvalidOperationException("Could not find configuration section 'umbracoConfiguration/settings' or it does not cast to " + typeof(IUmbracoSettings));
}
UmbracoSettings = umbracoSettings;
}
}
/// <summary>
/// Constructor - can be used for testing
/// </summary>
/// <param name="umbracoSettings"></param>
/// <param name="baseRestSettings"></param>
public UmbracoConfiguration(IUmbracoSettings umbracoSettings, IBaseRest baseRestSettings)
{
UmbracoSettings = umbracoSettings;
BaseRestExtensions = baseRestSettings;
}
public IUmbracoSettings UmbracoSettings { get; private set; }
public IBaseRest BaseRestExtensions { get; private set; }
//TODO: Add other configurations here !
}
}

View File

@@ -3,7 +3,7 @@ using System.Configuration;
namespace Umbraco.Core.Configuration.UmbracoSettings
{
internal class AppCodeFileExtensionsElement : ConfigurationElement, IAppCodeFileExtensions
internal class AppCodeFileExtensionsElement : ConfigurationElement
{
[ConfigurationCollection(typeof(AppCodeFileExtensionsCollection), AddItemName = "ext")]
[ConfigurationProperty("", IsDefaultCollection = true)]
@@ -13,9 +13,5 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
set { base[""] = value; }
}
IEnumerable<IFileExtension> IAppCodeFileExtensions.AppCodeFileExtensions
{
get { return AppCodeFileExtensionsCollection; }
}
}
}

View File

@@ -379,12 +379,12 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
get { return UmbracoLibraryCacheDuration; }
}
MacroErrorBehaviour IContent.MacroErrors
MacroErrorBehaviour IContent.MacroErrorBehaviour
{
get { return MacroErrors; }
}
IconPickerBehaviour IContent.DocumentTypeIconList
IconPickerBehaviour IContent.IconPickerBehaviour
{
get { return DocumentTypeIconList; }
}

View File

@@ -1,4 +1,5 @@
using System.Configuration;
using System.Collections.Generic;
using System.Configuration;
namespace Umbraco.Core.Configuration.UmbracoSettings
{
@@ -38,9 +39,9 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
}
}
IAppCodeFileExtensions IDeveloper.AppCodeFileExtensions
IEnumerable<IFileExtension> IDeveloper.AppCodeFileExtensions
{
get { return AppCodeFileExtensions; }
get { return AppCodeFileExtensions.AppCodeFileExtensionsCollection; }
}
}
}

View File

@@ -40,7 +40,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
get { return UserId; }
}
IEnumerable<IServerElement> IDistributedCall.Servers
IEnumerable<IServer> IDistributedCall.Servers
{
get { return Servers; }
}

View File

@@ -27,7 +27,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
get { return Assembly; }
}
string IExternalLogger.Type
string IExternalLogger.ExternalLoggerType
{
get { return Type; }
}

View File

@@ -1,9 +0,0 @@
using System.Collections.Generic;
namespace Umbraco.Core.Configuration.UmbracoSettings
{
public interface IAppCodeFileExtensions
{
IEnumerable<IFileExtension> AppCodeFileExtensions { get; }
}
}

View File

@@ -42,9 +42,9 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
int UmbracoLibraryCacheDuration { get; }
MacroErrorBehaviour MacroErrors { get; }
MacroErrorBehaviour MacroErrorBehaviour { get; }
IconPickerBehaviour DocumentTypeIconList { get; }
IconPickerBehaviour IconPickerBehaviour { get; }
IEnumerable<string> DisallowedUploadFiles { get; }

View File

@@ -1,7 +1,9 @@
namespace Umbraco.Core.Configuration.UmbracoSettings
using System.Collections.Generic;
namespace Umbraco.Core.Configuration.UmbracoSettings
{
public interface IDeveloper
{
IAppCodeFileExtensions AppCodeFileExtensions { get; }
IEnumerable<IFileExtension> AppCodeFileExtensions { get; }
}
}

View File

@@ -8,6 +8,6 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
int UserId { get; }
IEnumerable<IServerElement> Servers { get; }
IEnumerable<IServer> Servers { get; }
}
}

View File

@@ -6,7 +6,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
{
string Assembly { get; }
string Type { get; }
string ExternalLoggerType { get; }
bool LogAuditTrail { get; }
}

View File

@@ -6,7 +6,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
{
Guid DataTypeGuid { get; }
string NodeTypeAlias { get; }
string DocumentTypeAlias { get; }
string PropertyTypeAlias { get; }
string MappingName { get; }
}
}

View File

@@ -2,6 +2,8 @@
namespace Umbraco.Core.Configuration.UmbracoSettings
{
//TODO: Where do we put the 'package server' setting?
public interface IRepositories
{
IEnumerable<IRepository> Repositories { get; }

View File

@@ -1,6 +1,6 @@
namespace Umbraco.Core.Configuration.UmbracoSettings
{
public interface IServerElement
public interface IServer
{
string ForcePortnumber { get; }
string ForceProtocol { get; }

View File

@@ -5,5 +5,8 @@
bool TrySkipIisCustomErrors { get; }
bool InternalRedirectPreservesTemplate { get; }
string UrlProviderMode { get; }
}
}

View File

@@ -14,7 +14,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
{
return ((RazorStaticMappingElement) element).DataTypeGuid
+ ((RazorStaticMappingElement) element).NodeTypeAlias
+ ((RazorStaticMappingElement) element).DocumentTypeAlias;
+ ((RazorStaticMappingElement) element).PropertyTypeAlias;
}

View File

@@ -24,13 +24,13 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
}
}
public string DocumentTypeAlias
public string PropertyTypeAlias
{
get
{
return RawXml.Attribute("documentTypeAlias") == null
return RawXml.Attribute("propertyTypeAlias") == null
? null
: RawXml.Attribute("documentTypeAlias").Value;
: RawXml.Attribute("propertyTypeAlias").Value;
}
}

View File

@@ -3,7 +3,7 @@ using System.Configuration;
namespace Umbraco.Core.Configuration.UmbracoSettings
{
internal class ServerCollection : ConfigurationElementCollection, IEnumerable<IServerElement>
internal class ServerCollection : ConfigurationElementCollection, IEnumerable<IServer>
{
protected override ConfigurationElement CreateNewElement()
{
@@ -15,11 +15,11 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
return ((ServerElement)element).Value;
}
IEnumerator<IServerElement> IEnumerable<IServerElement>.GetEnumerator()
IEnumerator<IServer> IEnumerable<IServer>.GetEnumerator()
{
for (var i = 0; i < Count; i++)
{
yield return BaseGet(i) as IServerElement;
yield return BaseGet(i) as IServer;
}
}

View File

@@ -1,6 +1,6 @@
namespace Umbraco.Core.Configuration.UmbracoSettings
{
internal class ServerElement : InnerTextConfigurationElement<string>, IServerElement
internal class ServerElement : InnerTextConfigurationElement<string>, IServer
{
public string ForcePortnumber
{
@@ -22,7 +22,7 @@
}
}
string IServerElement.ServerAddress
string IServer.ServerAddress
{
get { return Value; }
}

View File

@@ -16,5 +16,11 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
get { return (bool) base["internalRedirectPreservesTemplate"]; }
}
[ConfigurationProperty("urlProviderMode", DefaultValue = "Auto")]
public string UrlProviderMode
{
get { return (string)base["urlProviderMode"]; }
}
}
}