⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 articleserviceproxy.cs

📁 该项目中对 SQLHelper 类进行了简单封装
💻 CS
字号:
/* 
 * ArticleServiceProxy.cs @Microsoft Visual Studio 2008 <.NET Framework 3.5>
 * AfritXia
 * 2008-02-04
 * 
 * Copyright(c) http://www.AfritXia.NET/
 * 
 */

using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.Web;
using System.Web.Caching;

using NET.AfritXia.MyHome.HomeManagement.HomeAppServer.ArticleServiceRef;
using NET.AfritXia.MyHome.Model;
using NET.AfritXia.MyHome.Model.Message;
using NET.AfritXia.MyHome.ServiceInterface;

namespace NET.AfritXia.MyHome.HomeManagement.CodeLand.ServiceProxy
{
	/// <summary>
	/// 文章服务代理类
	/// </summary>
	public class ArticleServiceProxy : IArticleService, IDisposable
	{
		// 缓存键集合
		private static readonly IList<string> g_cacheKeyList = new List<string>();
		// 代理对象
		private ArticleServiceClient m_proxyObj = null;

		#region 类构造器
		/// <summary>
		/// 类默认构造器
		/// </summary>
		public ArticleServiceProxy() : base()
		{
			this.m_proxyObj = new ArticleServiceClient();
			this.m_proxyObj.Open();
		}
		#endregion

		#region IArticleService Members
		public void Append(Article newArticle)
		{
			this.m_proxyObj.Append(newArticle);

			foreach (string cacheKey in g_cacheKeyList)
				HttpContext.Current.Cache.Remove(cacheKey);

			g_cacheKeyList.Clear();
		}

		public void Delete(int articleUID)
		{
			this.m_proxyObj.Delete(articleUID);

			foreach (string cacheKey in g_cacheKeyList)
				HttpContext.Current.Cache.Remove(cacheKey);

			g_cacheKeyList.Clear();
		}

		public void Update(Article newArticle)
		{
			this.m_proxyObj.Update(newArticle);

			foreach (string cacheKey in g_cacheKeyList)
				HttpContext.Current.Cache.Remove(cacheKey);

			g_cacheKeyList.Clear();
		}

		public IList<Article> GetArticleList(int orderGist, int startRecord, int maxRecords, out int allRecordCount)
		{
			allRecordCount = 0;

			string cacheKey = null;

			// 计算缓存键
			cacheKey = "ArticleServiceProxy.GetArticleList(orderGist = {0}, startRecord = {1}, maxRecords = {2}, -1)";
			cacheKey = String.Format(cacheKey, orderGist, startRecord, maxRecords);

			if (g_cacheKeyList.Contains(cacheKey) == false)
				g_cacheKeyList.Add(cacheKey);

			// 从缓存中获取文章列表
			IList<Article> articleList = HttpContext.Current.Cache[cacheKey] as List<Article>;

			if (articleList != null)
				return articleList;

			// 调用远程服务获取文章列表
			articleList = this.m_proxyObj.GetArticleList(orderGist, startRecord, maxRecords, out allRecordCount);

			// 缓存文章列表, 20 分钟后过期
			HttpContext.Current.Cache.Insert(cacheKey, articleList, null,
				DateTime.Now.AddMinutes(20), Cache.NoSlidingExpiration);

			return articleList;
		}

		public Article ViewArticle(int articleUID)
		{
			string cacheKey = null;

			// 计算缓存键
			cacheKey = "ArticleServiceProxy.ViewArticle(articleUID = {0})";
			cacheKey = String.Format(cacheKey, articleUID);

			if (g_cacheKeyList.Contains(cacheKey) == false)
				g_cacheKeyList.Add(cacheKey);

			// 从缓存中获取文章
			Article article = HttpContext.Current.Cache[cacheKey] as Article;

			if (article != null)
				return article;

			// 调用远程服务获取文章
			article = this.m_proxyObj.ViewArticle(articleUID);

			// 缓存文章, 20 分钟后过期
			HttpContext.Current.Cache.Insert(cacheKey, article, null,
				DateTime.Now.AddMinutes(20), Cache.NoSlidingExpiration);

			return article;
		}

		public string Actor
		{
			set
			{
				this.m_proxyObj.Actor = value;
			}

			get
			{
				return this.m_proxyObj.Actor;
			}
		}
		#endregion

		#region IDisposable Members
		public void Dispose()
		{
			this.m_proxyObj.Close();
		}
		#endregion
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -