温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:LiveBlog v1.0测试版源码
当前文件:
LiveBlog/LiveBlog.Core/Providers/BlogService.cs,打开代码结构图
LiveBlog/LiveBlog.Core/Providers/BlogService.cs,打开代码结构图1Using#region Using 2
3
using System; 4
using System.Collections.Generic; 5
using System.Collections.Specialized; 6
using System.Configuration; 7
using System.Configuration.Provider; 8
using System.Web.Configuration; 9
using System.Web; 10
using LiveBlog.Core; 11
12
#endregion 13
14
namespace LiveBlog.Core.Providers 15
...{ 16
/**//// <summary> 17
/// The proxy class for communication between 18
/// the business objects and the providers. 19
/// </summary> 20
public static class BlogService 21
...{ 22
23
Provider model#region Provider model 24
25
private static BlogProvider _provider; 26
private static BlogProviderCollection _providers; 27
private static object _lock = new object(); 28
29
/**//// <summary> 30
/// Gets the current provider. 31
/// </summary> 32
public static BlogProvider Provider 33
...{ 34
get ...{ return _provider; } 35
} 36
37
/**//// <summary> 38
/// Gets a collection of all registered providers. 39
/// </summary> 40
public static BlogProviderCollection Providers 41
...{ 42
get ...{ return _providers; } 43
} 44
45
/**//// <summary> 46
/// Load the providers from the web.config. 47
/// </summary> 48
private static void LoadProviders() 49
...{ 50
// Avoid claiming lock if providers are already loaded 51
if (_provider == null) 52
...{ 53
lock (_lock) 54
...{ 55
// Do this again to make sure _provider is still null 56
if (_provider == null) 57
...{ 58
// Get a reference to the <blogProvider> section 59
BlogProviderSection section = (BlogProviderSection)WebConfigurationManager.GetSection("LiveBlog/blogProvider"); 60
61
// Load registered providers and point _provider 62
// to the default provider 63
_providers = new BlogProviderCollection(); 64
ProvidersHelper.InstantiateProviders(section.Providers, _providers, typeof(BlogProvider)); 65
_provider = _providers[section.DefaultProvider]; 66
67
if (_provider == null) 68
throw new ProviderException("Unable to load default BlogProvider"); 69
} 70
} 71
} 72
} 73
74
#endregion 75
76
Posts#region Posts 77
78
/**//// <summary> 79
/// Returns a Post based on the specified id. 80
/// </summary> 81
public static Post SelectPost(Guid id) 82
...{ 83
LoadProviders(); 84
return _provider.SelectPost(id); 85
} 86
87
/**//// <summary> 88
/// Persists a new Post in the current provider. 89
/// </summary> 90
public static void InsertPost(Post post) 91
...{ 92
LoadProviders(); 93
_provider.InsertPost(post); 94
} 95
96
/**//// <summary> 97
/// Updates an exsiting Post. 98
/// </summary> 99
public static void UpdatePost(Post post) 100
...{ 101
LoadProviders(); 102
_provider.UpdatePost(post); 103
} 104
105
/**//// <summary> 106
/// Deletes the specified Post from the current provider. 107
/// </summary> 108
public static void DeletePost(Post post) 109
...{ 110
LoadProviders(); 111
_provider.DeletePost(post); 112
} 113
114
/**//// <summary> 115
/// 116
/// </summary> 117
/// <returns></returns> 118
public static List<Post> FillPosts() 119
...{ 120
LoadProviders(); 121
return _provider.FillPosts(); 122
} 123
124
#endregion 125
126
Pages#region Pages 127
128
/**//// <summary> 129
/// Returns a Page based on the specified id. 130
/// </summary> 131
public static Page SelectPage(Guid id) 132
...{ 133
LoadProviders(); 134
return _provider.SelectPage(id); 135
} 136
137
/**//// <summary> 138
/// Persists a new Page in the current provider. 139
/// </summary> 140
public static void InsertPage(Page page) 141
...{ 142
LoadProviders(); 143
_provider.InsertPage(page); 144
} 145
146
/**//// <summary> 147
/// Updates an exsiting Page. 148
/// </summary> 149
public static void UpdatePage(Page page) 150
...{ 151
LoadProviders(); 152
_provider.UpdatePage(page); 153
} 154
155
/**//// <summary> 156
/// Deletes the specified Page from the current provider. 157
/// </summary> 158
public static void DeletePage(Page page) 159
...{ 160
LoadProviders(); 161
_provider.DeletePage(page); 162
} 163
164
/**//// <summary> 165
/// 166
/// </summary> 167
/// <returns></returns> 168
public static List<Page> FillPages() 169
...{ 170
LoadProviders(); 171
return _provider.FillPages(); 172
} 173
174
#endregion 175
176
Categories#region Categories 177
178
/**//// <summary> 179
/// Returns a Category based on the specified id. 180
/// </summary> 181
public static Category SelectCategory(Guid id) 182
...{ 183
LoadProviders(); 184
return _provider.SelectCategory(id); 185
} 186
187
/**//// <summary> 188
/// Persists a new Category in the current provider. 189
/// </summary> 190
public static void InsertCategory(Category category) 191
...{ 192
LoadProviders(); 193
_provider.InsertCategory(category); 194
} 195
196
/**//// <summary> 197
/// Updates an exsiting Category. 198
/// </summary> 199
public static void UpdateCategory(Category category) 200
...{ 201
LoadProviders(); 202
_provider.UpdateCategory(category); 203
} 204
205
/**//// <summary> 206
/// Deletes the specified Category from the current provider. 207
/// </summary> 208
public static void DeleteCategory(Category category) 209
...{ 210
LoadProviders(); 211
_provider.DeleteCategory(category); 212
} 213
214
/**//// <summary> 215
/// 216
/// </summary> 217
/// <returns></returns> 218
public static List<Category> FillCategories() 219
...{ 220
LoadProviders(); 221
return _provider.FillCategories(); 222
} 223
224
#endregion 225
226
Settings#region Settings 227
228
/**//// <summary> 229
/// Loads the settings from the provider and returns 230
/// them in a StringDictionary for the BlogSettings class to use. 231
/// </summary> 232
public static System.Collections.Specialized.StringDictionary LoadSettings() 233
...{ 234
LoadProviders(); 235
return _provider.LoadSettings(); 236
} 237
238
/**//// <summary> 239
/// Save the settings to the current provider. 240
/// </summary> 241
public static void SaveSettings(System.Collections.Specialized.StringDictionary settings) 242
...{ 243
LoadProviders(); 244
_provider.SaveSettings(settings); 245
} 246
247
#endregion 248
249
Ping services#region Ping services 250
251
/**//// <summary> 252
/// Loads the ping services. 253
/// </summary> 254
public static StringCollection LoadPingServices() 255
...{ 256
LoadProviders(); 257
return _provider.LoadPingServices(); 258
} 259
260
/**//// <summary> 261
/// Saves the ping services. 262
/// </summary> 263
/// <param name="services">The services.</param> 264
public static void SavePingServices(StringCollection services) 265
...{ 266
LoadProviders(); 267
_provider.SavePingServices(services); 268
} 269
270
#endregion 271
272
} 273
} 274




