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]; }
}
}
}