More clean up of old configs

This commit is contained in:
Bjarke Berg
2020-09-14 12:58:41 +02:00
parent acb46119be
commit 4173a2fb20
20 changed files with 0 additions and 711 deletions

View File

@@ -1,70 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
namespace Umbraco.Core.Configuration
{
/// <summary>
/// Defines a configuration section that contains inner text that is comma delimited
/// </summary>
internal class CommaDelimitedConfigurationElement : InnerTextConfigurationElement<CommaDelimitedStringCollection>, IEnumerable<string>
{
public override CommaDelimitedStringCollection Value
{
get
{
var converter = new CommaDelimitedStringCollectionConverter();
return (CommaDelimitedStringCollection) converter.ConvertFrom(RawValue);
}
}
IEnumerator<string> IEnumerable<string>.GetEnumerator()
{
return new InnerEnumerator(Value.GetEnumerator());
}
IEnumerator IEnumerable.GetEnumerator()
{
return new InnerEnumerator(Value.GetEnumerator());
}
/// <summary>
/// A wrapper for StringEnumerator since it doesn't explicitly implement IEnumerable
/// </summary>
private class InnerEnumerator : IEnumerator<string>
{
private readonly StringEnumerator _stringEnumerator;
public InnerEnumerator(StringEnumerator stringEnumerator)
{
_stringEnumerator = stringEnumerator;
}
public bool MoveNext()
{
return _stringEnumerator.MoveNext();
}
public void Reset()
{
_stringEnumerator.Reset();
}
string IEnumerator<string>.Current
{
get { return _stringEnumerator.Current; }
}
public object Current
{
get { return _stringEnumerator.Current; }
}
public void Dispose()
{
_stringEnumerator.DisposeIfDisposable();
}
}
}
}

View File

@@ -1,69 +0,0 @@
using System;
using System.Xml;
using System.Xml.Linq;
namespace Umbraco.Core.Configuration
{
/// <summary>
/// A full config section is required for any full element and we have some elements that are defined like this:
/// {element}MyValue{/element} instead of as attribute values.
/// </summary>
/// <typeparam name="T"></typeparam>
internal class InnerTextConfigurationElement<T> : RawXmlConfigurationElement
{
public InnerTextConfigurationElement()
{
}
public InnerTextConfigurationElement(XElement rawXml) : base(rawXml)
{
}
protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
{
base.DeserializeElement(reader, serializeCollectionKey);
//now validate and set the raw value
if (RawXml.HasElements)
throw new InvalidOperationException("An InnerTextConfigurationElement cannot contain any child elements, only attributes and a value");
RawValue = RawXml.Value.Trim();
//RawValue = reader.ReadElementContentAsString();
}
public virtual T Value
{
get
{
var converted = RawValue.TryConvertTo<T>();
if (converted.Success == false)
throw new InvalidCastException("Could not convert value " + RawValue + " to type " + typeof(T));
return converted.Result;
}
}
/// <summary>
/// Exposes the raw string value
/// </summary>
internal string RawValue { get; set; }
/// <summary>
/// Implicit operator so we don't need to use the 'Value' property explicitly
/// </summary>
/// <param name="m"></param>
/// <returns></returns>
public static implicit operator T(InnerTextConfigurationElement<T> m)
{
return m.Value;
}
/// <summary>
/// Return the string value of Value
/// </summary>
/// <returns></returns>
public override string ToString()
{
return string.Format("{0}", Value);
}
}
}

View File

@@ -1,43 +0,0 @@
using System.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
namespace Umbraco.Core.Configuration
{
/// <summary>
/// Used for specifying default values for comma delimited config
/// </summary>
internal class OptionalCommaDelimitedConfigurationElement : CommaDelimitedConfigurationElement
{
private readonly CommaDelimitedConfigurationElement _wrapped;
private readonly string[] _defaultValue;
public OptionalCommaDelimitedConfigurationElement()
{
}
public OptionalCommaDelimitedConfigurationElement(CommaDelimitedConfigurationElement wrapped, string[] defaultValue)
{
_wrapped = wrapped;
_defaultValue = defaultValue;
}
public override CommaDelimitedStringCollection Value
{
get
{
if (_wrapped == null)
{
return base.Value;
}
if (string.IsNullOrEmpty(_wrapped.RawValue))
{
var val = new CommaDelimitedStringCollection();
val.AddRange(_defaultValue);
return val;
}
return _wrapped.Value;
}
}
}
}

View File

@@ -1,23 +0,0 @@
namespace Umbraco.Core.Configuration
{
/// <summary>
/// This is used to supply optional/default values when using InnerTextConfigurationElement
/// </summary>
/// <typeparam name="T"></typeparam>
internal class OptionalInnerTextConfigurationElement<T> : InnerTextConfigurationElement<T>
{
private readonly InnerTextConfigurationElement<T> _wrapped;
private readonly T _defaultValue;
public OptionalInnerTextConfigurationElement(InnerTextConfigurationElement<T> wrapped, T defaultValue)
{
_wrapped = wrapped;
_defaultValue = defaultValue;
}
public override T Value
{
get { return string.IsNullOrEmpty(_wrapped.RawValue) ? _defaultValue : _wrapped.Value; }
}
}
}

View File

@@ -1,30 +0,0 @@
using System.Configuration;
using System.Xml;
using System.Xml.Linq;
namespace Umbraco.Core.Configuration
{
/// <summary>
/// A configuration section that simply exposes the entire raw xml of the section itself which inheritors can use
/// to do with as they please.
/// </summary>
internal abstract class RawXmlConfigurationElement : ConfigurationElement
{
protected RawXmlConfigurationElement()
{
}
protected RawXmlConfigurationElement(XElement rawXml)
{
RawXml = rawXml;
}
protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
{
RawXml = (XElement)XNode.ReadFrom(reader);
}
protected XElement RawXml { get; private set; }
}
}

View File

@@ -1,24 +0,0 @@
using System.Configuration;
namespace Umbraco.Core.Configuration
{
/// <summary>
/// Represents an Umbraco section within the configuration file.
/// </summary>
/// <remarks>
/// <para>The requirement for these sections is to be read-only.</para>
/// <para>However for unit tests purposes it is internally possible to override some values, and
/// then calling <c>>ResetSection</c> should cancel these changes and bring the section back to
/// what it was originally.</para>
/// <para>The <c>UmbracoSettings.For{T}</c> method will return a section, either one that
/// is in the configuration file, or a section that was created with default values.</para>
/// </remarks>
public abstract class UmbracoConfigurationSection : ConfigurationSection, IUmbracoConfigurationSection
{
/// <summary>
/// Gets a value indicating whether the section actually is in the configuration file.
/// </summary>
protected bool IsPresent { get { return ElementInformation.IsPresent; } }
}
}

View File

@@ -1,36 +0,0 @@
using System.Collections.Generic;
using System.Configuration;
namespace Umbraco.Core.Configuration.UmbracoSettings
{
internal class CharCollection : ConfigurationElementCollection, IEnumerable<IChar>
{
internal void Add(CharElement c)
{
BaseAdd(c);
}
protected override ConfigurationElement CreateNewElement()
{
return new CharElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((CharElement)element).Char;
}
IEnumerator<IChar> IEnumerable<IChar>.GetEnumerator()
{
for (var i = 0; i < Count; i++)
{
yield return BaseGet(i) as IChar;
}
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}

View File

@@ -1,24 +0,0 @@
namespace Umbraco.Core.Configuration.UmbracoSettings
{
internal class CharElement : InnerTextConfigurationElement<string>, IChar
{
private string _char;
private string _replacement;
internal string Char
{
get => _char ?? (_char = (string)RawXml.Attribute("org"));
set => _char = value;
}
internal string Replacement
{
get => _replacement ?? (_replacement = Value);
set => _replacement = value;
}
string IChar.Char => Char;
string IChar.Replacement => Replacement;
}
}

View File

@@ -1,37 +0,0 @@
using System.Collections.Generic;
using System.Configuration;
namespace Umbraco.Core.Configuration.UmbracoSettings
{
internal class ContentError404Collection : ConfigurationElementCollection, IEnumerable<ContentErrorPageElement>
{
internal void Add(ContentErrorPageElement element)
{
BaseAdd(element);
}
protected override ConfigurationElement CreateNewElement()
{
return new ContentErrorPageElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((ContentErrorPageElement)element).Culture
+ ((ContentErrorPageElement)element).Value;
}
IEnumerator<ContentErrorPageElement> IEnumerable<ContentErrorPageElement>.GetEnumerator()
{
for (var i = 0; i < Count; i++)
{
yield return BaseGet(i) as ContentErrorPageElement;
}
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}

View File

@@ -1,56 +0,0 @@
using System;
using System.Xml.Linq;
namespace Umbraco.Core.Configuration.UmbracoSettings
{
internal class ContentErrorPageElement : InnerTextConfigurationElement<string>, IContentErrorPage
{
public ContentErrorPageElement(XElement rawXml)
: base(rawXml)
{
}
public ContentErrorPageElement()
{
}
public bool HasContentId => ContentId != int.MinValue;
public bool HasContentKey => ContentKey != Guid.Empty;
public int ContentId
{
get
{
int parsed;
if (int.TryParse(Value, out parsed))
{
return parsed;
}
return int.MinValue;
}
}
public Guid ContentKey
{
get
{
Guid parsed;
if (Guid.TryParse(Value, out parsed))
{
return parsed;
}
return Guid.Empty;
}
}
public string ContentXPath => Value;
public string Culture
{
get => (string) RawXml.Attribute("culture");
set => RawXml.Attribute("culture").Value = value;
}
}
}

View File

@@ -1,44 +0,0 @@
using System.Collections.Generic;
using System.Linq;
namespace Umbraco.Core.Configuration.UmbracoSettings
{
internal class ContentErrorsElement : RawXmlConfigurationElement
{
public IEnumerable<IContentErrorPage> Error404Collection
{
get
{
var result = new ContentError404Collection();
if (RawXml != null)
{
var e404 = RawXml.Elements("error404").First();
var ePages = e404.Elements("errorPage").ToArray();
if (ePages.Any())
{
//there are multiple
foreach (var e in ePages)
{
result.Add(new ContentErrorPageElement(e)
{
Culture = (string)e.Attribute("culture"),
RawValue = e.Value
});
}
}
else
{
//there's only one defined
result.Add(new ContentErrorPageElement(e404)
{
RawValue = e404.Value
});
}
}
return result;
}
}
}
}

View File

@@ -1,64 +0,0 @@
using System.Configuration;
namespace Umbraco.Core.Configuration.UmbracoSettings
{
internal class ContentImagingElement : ConfigurationElement
{
[ConfigurationProperty("imageFileTypes")]
internal CommaDelimitedConfigurationElement ImageFileTypes =>
new OptionalCommaDelimitedConfigurationElement(
(CommaDelimitedConfigurationElement)this["imageFileTypes"],
//set the default
GetDefaultImageFileTypes());
public static string[] GetDefaultImageFileTypes()
{
return new[] {"jpeg", "jpg", "gif", "bmp", "png", "tiff", "tif"};
}
private ImagingAutoFillPropertiesCollection _defaultImageAutoFill;
[ConfigurationCollection(typeof(ImagingAutoFillPropertiesCollection), AddItemName = "uploadField")]
[ConfigurationProperty("autoFillImageProperties", IsDefaultCollection = true)]
internal ImagingAutoFillPropertiesCollection ImageAutoFillProperties
{
get
{
if (_defaultImageAutoFill != null)
{
return _defaultImageAutoFill;
}
//here we need to check if this element is defined, if it is not then we'll setup the defaults
var prop = Properties["autoFillImageProperties"];
var autoFill = this[prop] as ConfigurationElement;
if (autoFill != null && autoFill.ElementInformation.IsPresent == false)
{
_defaultImageAutoFill = new ImagingAutoFillPropertiesCollection
{
new ImagingAutoFillUploadFieldElement
{
Alias = "umbracoFile"
}
};
return _defaultImageAutoFill;
}
return (ImagingAutoFillPropertiesCollection) base["autoFillImageProperties"];
}
}
public static ImagingAutoFillPropertiesCollection GetDefaultImageAutoFillProperties()
{
return new ImagingAutoFillPropertiesCollection
{
new ImagingAutoFillUploadFieldElement
{
Alias = "umbracoFile"
}
};
}
}
}

View File

@@ -1,37 +0,0 @@
using System.Collections.Generic;
using System.Configuration;
namespace Umbraco.Core.Configuration.UmbracoSettings
{
internal class ImagingAutoFillPropertiesCollection : ConfigurationElementCollection, IEnumerable<IImagingAutoFillUploadField>
{
protected override ConfigurationElement CreateNewElement()
{
return new ImagingAutoFillUploadFieldElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((ImagingAutoFillUploadFieldElement)element).Alias;
}
internal void Add(ImagingAutoFillUploadFieldElement item)
{
BaseAdd(item);
}
IEnumerator<IImagingAutoFillUploadField> IEnumerable<IImagingAutoFillUploadField>.GetEnumerator()
{
for (var i = 0; i < Count; i++)
{
yield return BaseGet(i) as IImagingAutoFillUploadField;
}
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}

View File

@@ -1,39 +0,0 @@
using System.Configuration;
namespace Umbraco.Core.Configuration.UmbracoSettings
{
internal class ImagingAutoFillUploadFieldElement : UmbracoConfigurationElement, IImagingAutoFillUploadField
{
/// <summary>
/// Allow setting internally so we can create a default
/// </summary>
[ConfigurationProperty("alias", IsKey = true, IsRequired = true)]
public string Alias
{
get => (string)this["alias"];
set => this["alias"] = value;
}
[ConfigurationProperty("widthFieldAlias")]
internal InnerTextConfigurationElement<string> WidthFieldAlias => GetOptionalTextElement("widthFieldAlias", "umbracoWidth");
[ConfigurationProperty("heightFieldAlias")]
internal InnerTextConfigurationElement<string> HeightFieldAlias => GetOptionalTextElement("heightFieldAlias", "umbracoHeight");
[ConfigurationProperty("lengthFieldAlias")]
internal InnerTextConfigurationElement<string> LengthFieldAlias => GetOptionalTextElement("lengthFieldAlias", "umbracoBytes");
[ConfigurationProperty("extensionFieldAlias")]
internal InnerTextConfigurationElement<string> ExtensionFieldAlias => GetOptionalTextElement("extensionFieldAlias", "umbracoExtension");
string IImagingAutoFillUploadField.Alias => Alias;
string IImagingAutoFillUploadField.WidthFieldAlias => WidthFieldAlias;
string IImagingAutoFillUploadField.HeightFieldAlias => HeightFieldAlias;
string IImagingAutoFillUploadField.LengthFieldAlias => LengthFieldAlias;
string IImagingAutoFillUploadField.ExtensionFieldAlias => ExtensionFieldAlias;
}
}

View File

@@ -1,6 +0,0 @@
namespace Umbraco.Core.Configuration.UmbracoSettings
{
internal class MemberPasswordConfigurationElement : PasswordConfigurationElement, IMemberPasswordConfiguration
{
}
}

View File

@@ -1,13 +0,0 @@
using System.Configuration;
namespace Umbraco.Core.Configuration.UmbracoSettings
{
internal class NotificationsElement : UmbracoConfigurationElement
{
[ConfigurationProperty("email")]
internal InnerTextConfigurationElement<string> NotificationEmailAddress => (InnerTextConfigurationElement<string>)this["email"];
[ConfigurationProperty("disableHtmlEmail")]
internal InnerTextConfigurationElement<bool> DisableHtmlEmail => GetOptionalTextElement("disableHtmlEmail", false);
}
}

View File

@@ -1,31 +0,0 @@
using System.Configuration;
namespace Umbraco.Core.Configuration.UmbracoSettings
{
internal class PasswordConfigurationElement : UmbracoConfigurationElement
{
[ConfigurationProperty("requiredLength", DefaultValue = "12")]
public int RequiredLength => (int)base["requiredLength"];
[ConfigurationProperty("requireNonLetterOrDigit", DefaultValue = "false")]
public bool RequireNonLetterOrDigit => (bool)base["requireNonLetterOrDigit"];
[ConfigurationProperty("requireDigit", DefaultValue = "false")]
public bool RequireDigit => (bool)base["requireDigit"];
[ConfigurationProperty("requireLowercase", DefaultValue = "false")]
public bool RequireLowercase => (bool)base["requireLowercase"];
[ConfigurationProperty("requireUppercase", DefaultValue = "false")]
public bool RequireUppercase => (bool)base["requireUppercase"];
[ConfigurationProperty("useLegacyEncoding", DefaultValue = "false")]
public bool UseLegacyEncoding => (bool)base["useLegacyEncoding"];
[ConfigurationProperty("hashAlgorithmType", DefaultValue = Constants.Security.AspNetCoreV3PasswordHashAlgorithmName)]
public string HashAlgorithmType => (string)base["hashAlgorithmType"];
[ConfigurationProperty("maxFailedAccessAttemptsBeforeLockout", DefaultValue = "5")]
public int MaxFailedAccessAttemptsBeforeLockout => (int)base["maxFailedAccessAttemptsBeforeLockout"];
}
}

View File

@@ -1,36 +0,0 @@
using System.Collections.Concurrent;
using System.Configuration;
namespace Umbraco.Core.Configuration.UmbracoSettings
{
/// <summary>
/// Base class with shared helper methods
/// </summary>
internal class UmbracoConfigurationElement : ConfigurationElement
{
/// <summary>
/// Used so the RawElement types are not re-created every time they are accessed
/// </summary>
private readonly ConcurrentDictionary<string, RawXmlConfigurationElement> _rawElements = new ConcurrentDictionary<string, RawXmlConfigurationElement>();
protected OptionalInnerTextConfigurationElement<T> GetOptionalTextElement<T>(string name, T defaultVal)
{
return (OptionalInnerTextConfigurationElement<T>) _rawElements.GetOrAdd(
name,
s => new OptionalInnerTextConfigurationElement<T>(
(InnerTextConfigurationElement<T>) this[s],
//set the default
defaultVal));
}
protected OptionalCommaDelimitedConfigurationElement GetOptionalDelimitedElement(string name, string[] defaultVal)
{
return (OptionalCommaDelimitedConfigurationElement) _rawElements.GetOrAdd(
name,
s => new OptionalCommaDelimitedConfigurationElement(
(CommaDelimitedConfigurationElement) this[name],
//set the default
defaultVal));
}
}
}

View File

@@ -1,23 +0,0 @@
using System.Collections.Generic;
using System.Configuration;
namespace Umbraco.Core.Configuration.UmbracoSettings
{
internal class UrlReplacingElement : ConfigurationElement
{
[ConfigurationProperty("removeDoubleDashes", DefaultValue = true)]
internal bool RemoveDoubleDashes => (bool) base["removeDoubleDashes"];
[ConfigurationProperty("toAscii", DefaultValue = "false")]
internal string ConvertUrlsToAscii => (string) base["toAscii"];
[ConfigurationCollection(typeof(CharCollection), AddItemName = "char")]
[ConfigurationProperty("", IsDefaultCollection = true)]
internal CharCollection CharCollection
{
get => (CharCollection)base[""];
set => base[""] = value;
}
}
}

View File

@@ -1,6 +0,0 @@
namespace Umbraco.Core.Configuration.UmbracoSettings
{
internal class UserPasswordConfigurationElement : PasswordConfigurationElement, IUserPasswordConfiguration
{
}
}