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:
45
src/Umbraco.Core/Configuration/BaseRest/BaseRestSection.cs
Normal file
45
src/Umbraco.Core/Configuration/BaseRest/BaseRestSection.cs
Normal 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; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
81
src/Umbraco.Core/Configuration/BaseRest/ExtensionElement.cs
Normal file
81
src/Umbraco.Core/Configuration/BaseRest/ExtensionElement.cs
Normal 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]; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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]; }
|
||||
}
|
||||
}
|
||||
}
|
||||
14
src/Umbraco.Core/Configuration/BaseRest/IBaseRest.cs
Normal file
14
src/Umbraco.Core/Configuration/BaseRest/IBaseRest.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
11
src/Umbraco.Core/Configuration/BaseRest/IExtension.cs
Normal file
11
src/Umbraco.Core/Configuration/BaseRest/IExtension.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Umbraco.Core.Configuration.BaseRest
|
||||
{
|
||||
public interface IExtension
|
||||
{
|
||||
string Alias { get; }
|
||||
|
||||
string Type { get; }
|
||||
|
||||
IMethod this[string index] { get; }
|
||||
}
|
||||
}
|
||||
17
src/Umbraco.Core/Configuration/BaseRest/IMethod.cs
Normal file
17
src/Umbraco.Core/Configuration/BaseRest/IMethod.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
50
src/Umbraco.Core/Configuration/BaseRest/MethodElement.cs
Normal file
50
src/Umbraco.Core/Configuration/BaseRest/MethodElement.cs
Normal 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]; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user