commentserviceproxy.cs
来自「该项目中对 SQLHelper 类进行了简单封装」· CS 代码 · 共 114 行
CS
114 行
/*
* CommentServiceProxy.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.CommentServiceRef;
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 CommentServiceProxy : ICommentService, IDisposable
{
// 缓存键集合
private static readonly IList<string> g_cacheKeyList = new List<string>();
// 代理对象
private CommentServiceClient m_proxyObj = null;
#region 类构造器
/// <summary>
/// 类默认构造器
/// </summary>
public CommentServiceProxy()
{
this.m_proxyObj = new CommentServiceClient();
this.m_proxyObj.Open();
}
#endregion
#region ICommentService Members
public void Append(Comment newComment)
{
this.m_proxyObj.Append(newComment);
foreach (string cacheKey in g_cacheKeyList)
HttpContext.Current.Cache.Remove(cacheKey);
g_cacheKeyList.Clear();
}
public void Delete(int commentUID)
{
this.m_proxyObj.Delete(commentUID);
foreach (string cacheKey in g_cacheKeyList)
HttpContext.Current.Cache.Remove(cacheKey);
g_cacheKeyList.Clear();
}
public IList<Comment> ViewCommentList(int belongToArticleUID)
{
string cacheKey = null;
// 计算缓存键
cacheKey = "CommentServiceProxy.ViewCommentList(belongToArticleUID = {0})";
cacheKey = String.Format(cacheKey, belongToArticleUID);
if (g_cacheKeyList.Contains(cacheKey) == false)
g_cacheKeyList.Add(cacheKey);
// 从缓存中获取评论集合
IList<Comment> commentList = HttpContext.Current.Cache[cacheKey] as IList<Comment>;
if (commentList != null)
return commentList;
// 调用远程服务获取评论列表
commentList = this.m_proxyObj.ViewCommentList(belongToArticleUID);
// 缓存评论列表, 20 分钟后过期
HttpContext.Current.Cache.Insert(cacheKey, commentList, null,
DateTime.Now.AddMinutes(20), Cache.NoSlidingExpiration);
return commentList;
}
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 + =
减小字号Ctrl + -
显示快捷键?