示例#1
0
        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)
            {
                ServerImpl.Instance.WriteLog(String.Format("{0}:{2}\r\n{1}", ex.GetType().Name, ex.StackTrace, ex.Message));
                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));
            }
        }
示例#2
0
        void IHttpHandler.ProcessRequest(HttpContext context)
        {
            Exception exception = null;
            string    str       = null;

            try
            {
                Stream inputStream = context.Request.InputStream;
                byte[] buffer      = new byte[inputStream.Length];
                inputStream.Read(buffer, 0, (int)inputStream.Length);
                string      xml      = context.Request.ContentEncoding.GetString(buffer);
                XmlDocument document = new XmlDocument();
                document.LoadXml(xml);
                string[]       strArray  = document.DocumentElement.GetAttribute("Handler").Split(new char[] { ' ' });
                string         attribute = document.DocumentElement.GetAttribute("ID");
                string         str4      = document.DocumentElement.GetAttribute("SessionID");
                bool           flag      = bool.Parse(document.DocumentElement.GetAttribute("IsAsyn"));
                CommandHandler handler   = Assembly.Load(strArray[0]).GetType(strArray[1]).GetConstructor(new Type[] { typeof(HttpContext), typeof(string), typeof(string), typeof(string) }).Invoke(new object[] { context, str4, attribute, document.DocumentElement.InnerXml }) as CommandHandler;
                if (flag)
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(handler.Process));
                }
                else
                {
                    str = handler.Process();
                }
            }
            catch (Exception exception2)
            {
                exception = exception2;
            }
            if (exception == null)
            {
                context.Response.Write(Utility.RenderHashJson(new object[] { "IsSucceed", true, "Data", new JsonText(str) }));
            }
            else
            {
                context.Response.Write(Utility.RenderHashJson(new object[] { "IsSucceed", false, "Exception", exception }));
            }
        }