refactoring

This commit is contained in:
Paul Schneider 2015-06-12 00:52:58 +02:00
commit 7fc21f1056
25 changed files with 179 additions and 335 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -1,3 +1,19 @@
2015-06-12 Paul Schneider <paul@pschneider.fr>
* YavscModel.csproj:
* BlogHelper.cs:
* CircleManager.cs:
* WorkFlowManager.cs:
* NewEstimateEvenArgs.cs:
* Provider.cs:
* DataProviderConfigurationSection.cs:
* ProviderCollection.cs:
* WorkflowConfiguration.cs:
* BlogProviderConfigurationElement.cs:
* BlogProvidersConfigurationSection.cs:
* BlogProvidersConfigurationCollection.cs:
* CatalogProvidersConfigurationSection.cs:
2015-06-10 Paul Schneider <paul@pschneider.fr>
* Circle.cs: refactoring

View file

@ -58,9 +58,11 @@ namespace Yavsc.Model.Circles
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);
ProtectedConfigurationSection pSection =
config.GetSection("circleProviders")
as ProtectedConfigurationSection;
DataProviderConfigurationSection pSection =
config.GetSection("system.web/circleProviders")
as DataProviderConfigurationSection;
if (pSection == null)
throw new ConfigurationErrorsException ("no circleProviders section defined");
ProviderSettingsCollection providerSettings =

View file

@ -0,0 +1,72 @@
//
// CircleConfigurationSection.cs
//
// Author:
// Paul Schneider <paul@pschneider.fr>
//
// Copyright (c) 2015 GNU GPL
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Configuration;
namespace Yavsc.Model
{
/// <summary>
/// Data provider configuration section.
/// </summary>
public class DataProviderConfigurationSection: ConfigurationSection
{
/// <summary>
/// Initializes a new instance of the <see cref="Yavsc.Model.DataProviderConfigurationSection"/> class.
/// </summary>
public DataProviderConfigurationSection ()
{
}
/// <summary>
/// Gets or sets the default provider.
/// </summary>
/// <value>The default provider.</value>
[ConfigurationProperty ("defaultProvider")]
public string DefaultProvider {
get {
return (string)base ["defaultProvider"];
}
set {
base ["defaultProvider"] = value;
}
}
/// <summary>
/// Gets or sets the providers.
/// </summary>
/// <value>The providers.</value>
[ConfigurationProperty ("providers")]
[ConfigurationCollection(typeof(ProviderSettingsCollection),
AddItemName = "add",
ClearItemsName = "clear",
RemoveItemName = "remove")]
public ProviderSettingsCollection Providers {
get {
return (ProviderSettingsCollection)base ["providers"];
}
set {
base ["providers"] = value;
}
}
}
}

View file

@ -7,7 +7,7 @@ namespace Yavsc.Model.FrontOffice.Configuration
/// <summary>
/// Catalog providers configuration section.
/// </summary>
public class CatalogProvidersConfigurationSection : ConfigurationSection
[Obsolete("Use DataProviderConfiguration instead")] public class CatalogProvidersConfigurationSection : ConfigurationSection
{
/// <summary>
/// Gets or sets the default provider.

View file

@ -1,60 +0,0 @@
using System;
using System.Configuration;
namespace Yavsc.Model.WorkFlow.Configuration
{
/// <summary>
/// WF provider.
/// </summary>
public class WFProvider:ConfigurationElement
{
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
[ConfigurationProperty("name", IsKey=true, IsRequired=true)]
public string Name {
get {
return (string) base ["name"];
}
set { base ["name"] = value; }
}
/// <summary>
/// Gets or sets the type.
/// </summary>
/// <value>The type.</value>
[ConfigurationProperty("type")]
public string Type {
get { return (string) this ["type"]; }
set {
this ["type"] = 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;
}
}
/// <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; }
}
}
}

View file

@ -1,39 +0,0 @@
using System;
using System.Configuration;
namespace Yavsc.Model.WorkFlow.Configuration
{
/// <summary>
/// WF provider collection.
/// </summary>
public class WFProviderCollection : ConfigurationElementCollection
{
/// <summary>
/// Gets the element key.
/// </summary>
/// <returns>The element key.</returns>
/// <param name="element">Element.</param>
protected override object GetElementKey (ConfigurationElement element)
{
return ((WFProvider) element).Name;
}
/// <summary>
/// Creates the new element.
/// </summary>
/// <returns>The new element.</returns>
protected override ConfigurationElement CreateNewElement ()
{
return new WFProvider();
}
/// <summary>
/// Gets the element.
/// </summary>
/// <returns>The element.</returns>
/// <param name="name">Name.</param>
public WFProvider GetElement (string name)
{
return this.BaseGet (name) as WFProvider;
}
}
}

View file

@ -1,41 +0,0 @@
using System;
using System.Configuration;
namespace Yavsc.Model.WorkFlow.Configuration
{
/// <summary>
/// Workflow configuration.
/// </summary>
public class WorkflowConfiguration : ConfigurationSection
{
/// <summary>
/// Gets or sets the default provider.
/// </summary>
/// <value>The default provider.</value>
[ConfigurationProperty("defaultProvider")]
public string DefaultProvider {
get { return (string)base ["defaultProvider"]; }
set { base ["defaultProvider"] = value; }
}
/// <summary>
/// Gets or sets the providers.
/// </summary>
/// <value>The providers.</value>
[ConfigurationProperty("providers")]
[ConfigurationCollection(typeof(WFProvider),
AddItemName = "add",
ClearItemsName = "clear",
RemoveItemName = "remove")]
public WFProviderCollection Providers {
get {
return this["providers"] as WFProviderCollection;
}
set {
this["providers"]=value;
}
}
}
}

View file

@ -1,7 +1,6 @@
using System;
using Yavsc.Model.WorkFlow;
using System.Configuration;
using Yavsc.Model.WorkFlow.Configuration;
using System.Collections.Specialized;
namespace Yavsc.Model.WorkFlow

View file

@ -1,9 +1,9 @@
using System;
using Yavsc.Model.WorkFlow;
using System.Configuration;
using Yavsc.Model.WorkFlow.Configuration;
using System.Collections.Specialized;
using Yavsc.Model.FrontOffice;
using System.Configuration.Provider;
namespace Yavsc.Model.WorkFlow
{
@ -123,10 +123,10 @@ namespace Yavsc.Model.WorkFlow
/// <value>The content provider.</value>
public IContentProvider ContentProvider {
get {
WorkflowConfiguration c = (WorkflowConfiguration) ConfigurationManager.GetSection ("system.web/workflow");
DataProviderConfigurationSection c = (DataProviderConfigurationSection) ConfigurationManager.GetSection ("system.web/workflow");
if (c == null)
throw new Exception ("No system.web/workflow configuration section found");
WFProvider confprov = c.Providers.GetElement (c.DefaultProvider);
ProviderSettings confprov = c.Providers[c.DefaultProvider] as ProviderSettings;
if (confprov == null)
throw new Exception ("Default workflow provider not found (system.web/workflow@defaultProvider)");
string clsName = confprov.Type;
@ -147,12 +147,7 @@ namespace Yavsc.Model.WorkFlow
System.Reflection.ConstructorInfo ci =cpt.GetConstructor (System.Type.EmptyTypes);
contentProvider = (IContentProvider)ci.Invoke (System.Type.EmptyTypes);
}
NameValueCollection config = new NameValueCollection ();
config.Add ("name", confprov.Name);
config.Add ("connectionStringName", confprov.ConnectionStringName);
config.Add ("applicationName", confprov.ApplicationName);
contentProvider.Initialize (confprov.Name, config);
contentProvider.Initialize (confprov.Name, confprov.Parameters);
return contentProvider;
}

View file

@ -67,13 +67,7 @@
<Compile Include="Blogs\BlogManager.cs" />
<Compile Include="Blogs\BlogProvider.cs" />
<Compile Include="WorkFlow\WorkFlowManager.cs" />
<Compile Include="WorkFlow\Configuration\Provider.cs" />
<Compile Include="WorkFlow\Configuration\ProviderCollection.cs" />
<Compile Include="WorkFlow\Configuration\WorkflowConfiguration.cs" />
<Compile Include="Blogs\BlogHelper.cs" />
<Compile Include="Blogs\Configuration\BlogProviderConfigurationElement.cs" />
<Compile Include="Blogs\Configuration\BlogProvidersConfigurationCollection.cs" />
<Compile Include="Blogs\Configuration\BlogProvidersConfigurationSection.cs" />
<Compile Include="WorkFlow\NewEstimateEvenArgs.cs" />
<Compile Include="LocalizedText.fr.Designer.cs">
<DependentUpon>LocalizedText.fr.resx</DependentUpon>
@ -163,6 +157,7 @@
<Compile Include="Circles\CircleInfoCollection.cs" />
<Compile Include="Circles\CircleManager.cs" />
<Compile Include="Circles\CircleProvider.cs" />
<Compile Include="DataProviderConfigurationSection.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>