using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Web;
using System.Xml;
using System.Threading;
namespace Core
{
public class ReceiveResponsesHandler : IHttpAsyncHandler
{
public ReceiveResponsesHandler()
{
}
HttpContext m_Context = null;
IAsyncResult IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
{
m_Context = context;
string sessionId = context.Request.Params["SessionID"];
string clientVersion = context.Request.Params["ClientVersion"];
string serverVersion = context.Request.Params["ServerVersion"];
ResponsesListener asyncResult = new ResponsesListener(sessionId, cb, extraData);
try
{
if (serverVersion != ServerImpl.Instance.Version) throw new IncompatibleException();
if (!String.IsNullOrEmpty(clientVersion) && clientVersion != "1.0.1.7") throw new IncompatibleException();
string username = ServerImpl.Instance.GetUserName(context);
if (string.IsNullOrEmpty(username)) throw new UnauthorizedException();
AccountState state = SessionManagement.Instance.GetAccountState(username);
if (state.Receive(sessionId, asyncResult))
{
ThreadPool.QueueUserWorkItem(asyncResult.Complete);
}
}
catch (Exception ex)
{
asyncResult.Cache(Utility.RenderHashJson("IsSucceed", false, "Exception", ex));
ThreadPool.QueueUserWorkItem(asyncResult.Complete);
}
return asyncResult;
}
void IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
{
//将消息发送到客户端
ResponsesListener asyncResult = result as ResponsesListener;
asyncResult.Send(m_Context);
}
void IHttpHandler.ProcessRequest(HttpContext context)
{
}
bool IHttpHandler.IsReusable
{
get { return true; }
}
}
class UnauthorizedException : Exception
{
}
class IncompatibleException : Exception
{
}
}
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Web;
using System.Xml;
using System.Threading;
using System.Web.SessionState;
using System.Reflection;
namespace Core
{
public class SendCommandHandler : IHttpHandler
{
void IHttpHandler.ProcessRequest(HttpContext context)
{
Exception error = null;
String data = null;
try
{
System.IO.Stream inputStream = context.Request.InputStream;
Byte[] buffer = new Byte[inputStream.Length];
inputStream.Read(buffer, 0, (int)inputStream.Length);
string content = context.Request.ContentEncoding.GetString(buffer);
XmlDocument doc = new XmlDocument();
doc.LoadXml(content);
String[] handlerInfo = doc.DocumentElement.GetAttribute("Handler").Split(new char[] { ' ' });
String cmdId = doc.DocumentElement.GetAttribute("ID");
String sessionId = doc.DocumentElement.GetAttribute("SessionID");
bool isAsyn = Boolean.Parse(doc.DocumentElement.GetAttribute("IsAsyn"));
Assembly assembly = Assembly.Load(handlerInfo[0]);
Type handlerType = assembly.GetType(handlerInfo[1]);
ConstructorInfo ctor = handlerType.GetConstructor(new Type[] { typeof(HttpContext), typeof(String), typeof(String), typeof(String) });
CommandHandler handler = ctor.Invoke(new object[] { context, sessionId, cmdId, doc.DocumentElement.InnerXml }) as CommandHandler;
if (isAsyn)
{
ThreadPool.QueueUserWorkItem(handler.Process);
}
else
{
data = handler.Process();
}
}
catch (Exception ex)
{
error = ex;
}
if (error == null)
{
context.Response.Write(Utility.RenderHashJson("IsSucceed", true, "Data", new JsonText(data)));
}
else
{
context.Response.Write(Utility.RenderHashJson("IsSucceed", false, "Exception", error));
}
}
bool IHttpHandler.IsReusable
{
get { return true; }
}
}
public abstract class CommandHandler
{
HttpContext _context = null;
public HttpContext Context
{
get { return _context; }
}
String _data;
public String Data
{
get { return _data; }
}
String _id;
public String CommandID
{
get { return _id; }
}
String _sessionId;
public String SessionID
{
get { return _sessionId; }
}
public String UserName
{
get { return ServerImpl.Instance.GetUserName(_context); }
}
public CommandHandler(HttpContext context, String sessionId, String id, String data)
{
_context = context;
_data = data;
_id = id;
_sessionId = sessionId;
}
public abstract void Process(object data);
public abstract String Process();
}
}
<?xml version="1.0" encoding="utf-8"?>
<!--
注意: 除了手动编辑此文件以外,您还可以使用 Web 管理工具来
配置应用程序的设置。
可以使用 Visual Studio 中的“网站”->“Asp.Net 配置”选项。
设置和注释的完整列表在 machine.config.comments 中,
该文件通常位于
\Windows\Microsoft.Net\Framework\v2.x\Config 中
-->
<configuration>
<appSettings>
<add key="FileRoot" value="Files"/>
<add key="DefaultPage" value="/Lesktop/Default.aspx"/>
</appSettings>
<connectionStrings/>
<system.web>
<httpHandlers>
<add path="response.aspx" verb="*" type="Core.ReceiveResponsesHandler"/>
<add path="command.aspx" verb="*" type="Core.SendCommandHandler"/>
<add path="download.aspx" verb="*" type="Core.Web.DownloadHandler"/>
<add path="sendfile.aspx" verb="*" type="Core.Web.SendFileHandler"/>
<add path="Config.js.aspx" verb="*" type="Core.Web.DownloadJsHandler"/>
<add path="Embed.js.aspx" verb="*" type="Core.Web.DownloadJsHandler"/>
<add path="headimg.aspx" verb="*" type="Core.Web.DownloadHandler"/>
</httpHandlers>
</system.web>
</configuration>
Kenney 发表于 2014-4-14 09:44
这个不错啊 大哥是自己写的 还是参考了人家的资料啊 表情可以多个管理的地方就好了
JamesCool 发表于 2014-4-14 21:44
如果就这个项目有个详细的开发或教程视频就好了,可以学到更多,也方便了不少。
站长苏飞 发表于 2014-4-14 22:14
这个先自己看看吧,目前是没空写
站长苏飞 发表于 2014-4-14 22:14
这个先自己看看吧,目前是没空写
站长苏飞 发表于 2014-4-14 22:14
这个先自己看看吧,目前是没空写
hai635691736 发表于 2014-5-13 18:23
站长呀 我是新手 怎么运行呀 求帮助
hai635691736 发表于 2014-5-13 18:23
站长呀 我是新手 怎么运行呀 求帮助
self001 发表于 2014-4-11 13:16
受教了\,下载下来学习学习
黄小波 发表于 2014-5-14 16:24
没看懂怎么办
a1120448377 发表于 2014-6-24 10:17
站长,用VS什么版本写的? 连VS2008都打不开
dongfei520 发表于 2014-8-12 16:14
为什么要把web 项目分开来写 不能写一个项目里面吗
欢迎光临 苏飞论坛 (http://www.sufeinet.com/) | Powered by Discuz! X3.4 |