refactoring
This commit is contained in:
parent
347ffc8a5a
commit
b5d19c5da6
38 changed files with 149 additions and 117 deletions
|
|
@ -1,36 +0,0 @@
|
|||
using System;
|
||||
using System.Configuration;
|
||||
using System.Reflection;
|
||||
using System.Collections.Specialized;
|
||||
using Npgsql.Web.Blog.Configuration;
|
||||
using Yavsc.Model.Blogs;
|
||||
|
||||
namespace Npgsql.Web.Blog
|
||||
{
|
||||
public static class BlogHelper
|
||||
{
|
||||
public static BlogProvider GetProvider ()
|
||||
{
|
||||
BlogProvidersConfigurationSection config = ConfigurationManager.GetSection ("system.web/blog") as BlogProvidersConfigurationSection;
|
||||
if (config == null)
|
||||
throw new ConfigurationErrorsException("The configuration bloc for the blog provider was not found");
|
||||
BlogProviderConfigurationElement celt =
|
||||
config.Providers.GetElement (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);
|
||||
return bp;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
using System;
|
||||
using Yavsc.Model.Blogs;
|
||||
|
||||
|
||||
namespace Npgsql.Web.Blog
|
||||
{
|
||||
public static class BlogManager
|
||||
{
|
||||
public static long RemoveComment(long cmtid)
|
||||
{
|
||||
return Provider.RemoveComment (cmtid);
|
||||
}
|
||||
|
||||
public static void Comment (string from, long postid, string content, bool visible)
|
||||
{
|
||||
provider.Comment (from, postid, content);
|
||||
}
|
||||
|
||||
static BlogProvider provider;
|
||||
|
||||
public static BlogProvider Provider {
|
||||
get {
|
||||
if (provider == null)
|
||||
provider = BlogHelper.GetProvider();
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
public static BlogEntry GetPost (string username, string title)
|
||||
{
|
||||
return Provider.GetPost (username, title );
|
||||
}
|
||||
public static BlogEntry GetPost(long postid)
|
||||
{
|
||||
return Provider.GetPost (postid);
|
||||
}
|
||||
public static void Post(string username, string title, string content, bool visible)
|
||||
{
|
||||
Provider.Post(username, title, content, visible );
|
||||
}
|
||||
public static void UpdatePost(long postid, string content, bool visible)
|
||||
{
|
||||
Provider.UpdatePost(postid, content, visible);
|
||||
}
|
||||
public static BlogEntryCollection FindPost (string pattern, FindBlogEntryFlags searchflags, int pageIndex, int pageSize, out int totalRecords)
|
||||
{
|
||||
return Provider.FindPost (pattern, searchflags, pageIndex, pageSize, out totalRecords);
|
||||
}
|
||||
public static void RemovePost (string username, string title)
|
||||
{
|
||||
Provider.RemovePost (username, title);
|
||||
}
|
||||
public static BlogEntryCollection LastPosts (int pageIndex, int pageSize, out int totalRecords)
|
||||
{
|
||||
return Provider.LastPosts (pageIndex, pageSize, out totalRecords);
|
||||
}
|
||||
public static Comment[] GetComments(long postid, bool getHidden=true)
|
||||
{
|
||||
return Provider.GetComments (postid,getHidden);
|
||||
}
|
||||
/// <summary>
|
||||
/// Tag the specified post by postid.
|
||||
/// </summary>
|
||||
/// <param name="postid">Postid.</param>
|
||||
/// <returns>The tag identifier</returns>
|
||||
public static long Tag(long postid, string tag) {
|
||||
return Provider.Tag (postid, tag);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
using System;
|
||||
using System.Configuration;
|
||||
using System.Configuration.Provider;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Yavsc.Model.Blogs
|
||||
{
|
||||
public abstract class BlogProvider: ProviderBase
|
||||
{
|
||||
public abstract BlogEntry GetPost (long postid);
|
||||
public abstract BlogEntry GetPost (string username, string title);
|
||||
public abstract long GetPostId (string username, string title);
|
||||
|
||||
public abstract long Post (string username, string title, string content, bool visible);
|
||||
public abstract void UpdatePost (long postid, string content, bool visible);
|
||||
public abstract BlogEntryCollection FindPost (string pattern, FindBlogEntryFlags searchflags,
|
||||
int pageIndex, int pageSize, out int totalRecords);
|
||||
public abstract void RemovePost (string username, string title);
|
||||
public abstract void RemovePost (long postid);
|
||||
public abstract long RemoveComment (long cmtid);
|
||||
public abstract BlogEntryCollection LastPosts(int pageIndex, int pageSize, out int totalRecords);
|
||||
public abstract string BlogTitle (string username);
|
||||
public abstract long Comment (string from, long postid, string content);
|
||||
public abstract Comment[] GetComments (long postid, bool getHidden) ;
|
||||
public abstract bool AutoValidateComment { get; set; }
|
||||
public abstract void ValidateComment (long cmtid);
|
||||
public abstract void UpdateComment (long cmtid, string content, bool visible);
|
||||
public abstract long Tag (long postid,string tag);
|
||||
public abstract void RemoveTag (long tagid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
using System;
|
||||
using System.Configuration;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Npgsql.Web.Blog.Configuration
|
||||
{
|
||||
|
||||
public class BlogProviderConfigurationElement : ConfigurationElement
|
||||
{
|
||||
[ConfigurationProperty("name", IsRequired = true, IsKey=true)]
|
||||
public string Name {
|
||||
get { return (string)this ["name"]; }
|
||||
set { this ["name"] = value; }
|
||||
}
|
||||
|
||||
[ConfigurationProperty("type", IsRequired = true, IsKey=false)]
|
||||
public string Type {
|
||||
get { return (string)this ["type"]; }
|
||||
set { this ["type"] = value; }
|
||||
}
|
||||
|
||||
[ConfigurationProperty("connectionStringName")]
|
||||
public string ConnectionStringName {
|
||||
get { return (string)this ["connectionStringName"]; }
|
||||
set { this ["connectionStringName"] = value; }
|
||||
}
|
||||
|
||||
[ConfigurationProperty("description")]
|
||||
public string Description {
|
||||
get { return (string)this ["description"]; }
|
||||
set { this ["description"] = value; }
|
||||
}
|
||||
|
||||
[ConfigurationProperty("applicationName")]
|
||||
public string ApplicationName {
|
||||
get { return (string)this ["applicationName"]; }
|
||||
set { this ["applicationName"] = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
using System;
|
||||
using System.Configuration;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Npgsql.Web.Blog.Configuration
|
||||
{
|
||||
public class BlogProvidersConfigurationCollection : ConfigurationElementCollection
|
||||
{
|
||||
protected override ConfigurationElement CreateNewElement ()
|
||||
{
|
||||
return new BlogProviderConfigurationElement();
|
||||
}
|
||||
|
||||
protected override object GetElementKey (ConfigurationElement element)
|
||||
{
|
||||
return ((BlogProviderConfigurationElement) element).Name;
|
||||
}
|
||||
|
||||
public BlogProviderConfigurationElement GetElement (string name)
|
||||
{
|
||||
return this.BaseGet(name) as BlogProviderConfigurationElement;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
using System;
|
||||
using System.Configuration;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Npgsql.Web.Blog.Configuration
|
||||
{
|
||||
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; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
[ConfigurationProperty("providers")]
|
||||
[ConfigurationCollection(typeof(BlogProvidersConfigurationCollection),
|
||||
AddItemName = "add",
|
||||
ClearItemsName = "clear",
|
||||
RemoveItemName = "remove")]
|
||||
/// <summary>
|
||||
/// Gets or sets the providers.
|
||||
/// </summary>
|
||||
/// <value>The providers.</value>
|
||||
public BlogProvidersConfigurationCollection Providers{
|
||||
get { return (BlogProvidersConfigurationCollection) this["providers"]; }
|
||||
set { this["providers"] = value; }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -30,12 +30,6 @@
|
|||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<Compile Include="Configuration\BlogProviderConfigurationElement.cs" />
|
||||
<Compile Include="Configuration\BlogProvidersConfigurationCollection.cs" />
|
||||
<Compile Include="Configuration\BlogProvidersConfigurationSection.cs" />
|
||||
<Compile Include="BlogHelper.cs" />
|
||||
<Compile Include="BlogManager.cs" />
|
||||
<Compile Include="BlogProvider.cs" />
|
||||
<Compile Include="NpgsqlBlogProvider.cs" />
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue