refactoring
This commit is contained in:
parent
8cec6d44e2
commit
7fc21f1056
25 changed files with 179 additions and 335 deletions
|
|
@ -2,7 +2,6 @@ using System;
|
|||
using System.Configuration;
|
||||
using System.Reflection;
|
||||
using System.Collections.Specialized;
|
||||
using Yavsc.Model.Blogs.Configuration;
|
||||
|
||||
namespace Yavsc.Model.Blogs
|
||||
{
|
||||
|
|
@ -17,22 +16,17 @@ namespace Yavsc.Model.Blogs
|
|||
/// <returns>The provider.</returns>
|
||||
public static BlogProvider GetProvider ()
|
||||
{
|
||||
BlogProvidersConfigurationSection config = ConfigurationManager.GetSection ("system.web/blog") as BlogProvidersConfigurationSection;
|
||||
DataProviderConfigurationSection config = ConfigurationManager.GetSection ("system.web/blog") as DataProviderConfigurationSection;
|
||||
if (config == null)
|
||||
throw new ConfigurationErrorsException("The configuration bloc for the blog provider was not found");
|
||||
BlogProviderConfigurationElement celt =
|
||||
config.Providers.GetElement (config.DefaultProvider);
|
||||
ProviderSettings celt =
|
||||
config.Providers[config.DefaultProvider];
|
||||
if (config == null)
|
||||
throw new ConfigurationErrorsException("The default blog provider was not found");
|
||||
ConstructorInfo ci = Type.GetType (celt.Type).GetConstructor (Type.EmptyTypes);
|
||||
BlogProvider bp = ci.Invoke (Type.EmptyTypes) as BlogProvider;
|
||||
NameValueCollection c = new NameValueCollection ();
|
||||
c.Add ("name", celt.Name);
|
||||
c.Add ("type", celt.Type);
|
||||
c.Add ("connectionStringName", celt.ConnectionStringName);
|
||||
c.Add ("description", celt.Description);
|
||||
c.Add ("applicationName", celt.ApplicationName);
|
||||
bp.Initialize (celt.Name, c);
|
||||
bp.Initialize (celt.Name, celt.Parameters);
|
||||
return bp;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,62 +0,0 @@
|
|||
using System;
|
||||
using System.Configuration;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Yavsc.Model.Blogs.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Blog provider configuration element.
|
||||
/// </summary>
|
||||
public class BlogProviderConfigurationElement : ConfigurationElement
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the name.
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
[ConfigurationProperty("name", IsRequired = true, IsKey=true)]
|
||||
public string Name {
|
||||
get { return (string)this ["name"]; }
|
||||
set { this ["name"] = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the type.
|
||||
/// </summary>
|
||||
/// <value>The type.</value>
|
||||
[ConfigurationProperty("type", IsRequired = true, IsKey=false)]
|
||||
public string Type {
|
||||
get { return (string)this ["type"]; }
|
||||
set { this ["type"] = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the connection string.
|
||||
/// </summary>
|
||||
/// <value>The name of the connection string.</value>
|
||||
[ConfigurationProperty("connectionStringName")]
|
||||
public string ConnectionStringName {
|
||||
get { return (string)this ["connectionStringName"]; }
|
||||
set { this ["connectionStringName"] = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the description.
|
||||
/// </summary>
|
||||
/// <value>The description.</value>
|
||||
[ConfigurationProperty("description")]
|
||||
public string Description {
|
||||
get { return (string)this ["description"]; }
|
||||
set { this ["description"] = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the application.
|
||||
/// </summary>
|
||||
/// <value>The name of the application.</value>
|
||||
[ConfigurationProperty("applicationName")]
|
||||
public string ApplicationName {
|
||||
get { return (string)this ["applicationName"]; }
|
||||
set { this ["applicationName"] = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
using System;
|
||||
using System.Configuration;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Yavsc.Model.Blogs.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Blog providers configuration collection.
|
||||
/// </summary>
|
||||
public class BlogProvidersConfigurationCollection : ConfigurationElementCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates the new element.
|
||||
/// </summary>
|
||||
/// <returns>The new element.</returns>
|
||||
protected override ConfigurationElement CreateNewElement ()
|
||||
{
|
||||
return new BlogProviderConfigurationElement();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the element key.
|
||||
/// </summary>
|
||||
/// <returns>The element key.</returns>
|
||||
/// <param name="element">Element.</param>
|
||||
protected override object GetElementKey (ConfigurationElement element)
|
||||
{
|
||||
return ((BlogProviderConfigurationElement) element).Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the element.
|
||||
/// </summary>
|
||||
/// <returns>The element.</returns>
|
||||
/// <param name="name">Name.</param>
|
||||
public BlogProviderConfigurationElement GetElement (string name)
|
||||
{
|
||||
return this.BaseGet(name) as BlogProviderConfigurationElement;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
using System;
|
||||
using System.Configuration;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Yavsc.Model.Blogs.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Blog providers configuration section.
|
||||
/// </summary>
|
||||
public class BlogProvidersConfigurationSection : ConfigurationSection
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the default provider.
|
||||
/// </summary>
|
||||
/// <value>The default provider.</value>
|
||||
[ConfigurationProperty("defaultProvider")]
|
||||
public string DefaultProvider {
|
||||
get { return (string) this ["defaultProvider"]; }
|
||||
set { this["defaultProvider"] = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the providers.
|
||||
/// </summary>
|
||||
/// <value>The providers.</value>
|
||||
[ConfigurationProperty("providers")]
|
||||
[ConfigurationCollection(typeof(BlogProvidersConfigurationCollection),
|
||||
AddItemName = "add",
|
||||
ClearItemsName = "clear",
|
||||
RemoveItemName = "remove")]
|
||||
public BlogProvidersConfigurationCollection Providers{
|
||||
get { return (BlogProvidersConfigurationCollection) this["providers"]; }
|
||||
set { this["providers"] = value; }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue