Пример #1
0
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"/> interface.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
        public override void ProcessRequest(HttpContext context)
        {
            PollingResult result;

            try
            {
                var session = GetSession(context);
                result = session.HandlePollingRequest(context);
            }
            catch (Exception ex)
            {
                //Application should handle the request and give a valid result.
                //Any exception is a sign that session is not valid anymore.
                result = new LongPollingResult
                {
                    type    = "rpc",
                    name    = "message",
                    success = false,
                    data    = new DextopRemoteMethodCallException
                    {
                        exception = ex.Message,
                        type      = "session"
                    }
                };
            }

            context.Response.ContentType = "application/json";
            DextopUtil.Encode(result, context.Response.Output);
        }
 internal LongPollingResult EndHandlingLongPollingRequest(IAsyncResult asyncResult, int start)
 {
     var result = new LongPollingResult
     {
         type = "rpc",
         name = "message"
     };
     try
     {
         if (previousLongPollingResult != null && start < previousLongPollingResult.nextStart)
         {
             result = ((Func<LongPollingResult>)GetPreviousLongPollingResult).EndInvoke(asyncResult);
         }
         else
         {
             var msgs = messageQueue.EndTake(asyncResult);
             result.nextStart = start + msgs.Count;
             result.data = msgs;
             result.success = true;
             previousLongPollingResult = result;
         }
     }
     catch (Exception ex)
     {
         result.success = false;
         result.data = new DextopRemoteMethodCallException
         {
             type = "rpc",
             exception = ex.Message,
             stackTrace = ex.StackTrace
         };
     }
     return result;
 }
Пример #3
0
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"/> interface.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
        public override void ProcessRequest(HttpContext context)
        {
            PollingResult result;
            try
            {
                var session = GetSession(context);
                result = session.HandlePollingRequest(context);
            }
            catch (Exception ex)
            {
                //Application should handle the request and give a valid result.
                //Any exception is a sign that session is not valid anymore.
                result = new LongPollingResult
                {
                    type = "rpc",
                    name = "message",
                    success = false,
                    data = new DextopRemoteMethodCallException
                    {
                        exception = ex.Message,
                        type = "session"
                    }
                };
            }

            context.Response.ContentType = "application/json";
            DextopUtil.Encode(result, context.Response.Output);
        }
Пример #4
0
        internal LongPollingResult HandleLongPollingRequest(HttpContext context)
        {
            var result = new LongPollingResult
            {
                type = "rpc",
                name = "message"
            };
            try
            {
                int start;
                if (!int.TryParse(context.Request["start"], out start))
                    start = 0;

                int nextStart;
                var msgs = PopMessagesOrWait(start, out nextStart, TimeSpan.FromSeconds(20));
                result.nextStart = nextStart;
                result.data = msgs;
                result.success = true;
            }
            catch (Exception ex)
            {
                result.success = false;
                result.data = new DextopRemoteMethodCallException
                {
                    type = "rpc",
                    exception = ex.Message,
                    stackTrace = ex.StackTrace
                };
            }
            return result;
        }
Пример #5
0
        void IHttpAsyncHandler.EndProcessRequest(IAsyncResult asyncResult)
        {
            if (errorHandler != null)
            {
                errorHandler.EndInvoke(asyncResult);
            }
            else
            {
                LongPollingResult result;
                try
                {
                    result = session.EndHandlingLongPollingRequest(asyncResult, start);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Long polling exception.", ex);
                    //Application should handle the request and give a valid result.
                    //Any exception is a sign that session is not valid anymore.
                    result = new LongPollingResult
                    {
                        type = "rpc",
                        name = "message",
                        success = false,
                        data = new DextopRemoteMethodCallException
                        {
                            exception = ex.Message,
                            type = "session"
                        }
                    };
                }

                context.Response.ContentType = "application/json";
                DextopUtil.Encode(result, context.Response.Output);
            }
        }
        void IHttpAsyncHandler.EndProcessRequest(IAsyncResult asyncResult)
        {
            if (errorHandler != null)
            {
                errorHandler.EndInvoke(asyncResult);
            }
            else
            {
                LongPollingResult result;
                try
                {
                    result = session.EndHandlingLongPollingRequest(asyncResult, start);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Long polling exception.", ex);
                    //Application should handle the request and give a valid result.
                    //Any exception is a sign that session is not valid anymore.
                    result = new LongPollingResult
                    {
                        type    = "rpc",
                        name    = "message",
                        success = false,
                        data    = new DextopRemoteMethodCallException
                        {
                            exception = ex.Message,
                            type      = "session"
                        }
                    };
                }

                context.Response.ContentType = "application/json";
                DextopUtil.Encode(result, context.Response.Output);
            }
        }
        void WriteException(HttpContext context, Exception ex)
        {
            //Application should handle the request and give a valid result.
            //Any exception is a sign that session is not valid anymore.
            var result = new LongPollingResult
            {
                type    = "rpc",
                name    = "message",
                success = false,
                data    = new DextopRemoteMethodCallException
                {
                    exception = ex.Message,
                    type      = "session"
                }
            };

            context.Response.ContentType = "application/json";
            DextopUtil.Encode(result, context.Response.Output);
        }
Пример #8
0
        void WriteException(HttpContext context, Exception ex)
        {
            //Application should handle the request and give a valid result.
            //Any exception is a sign that session is not valid anymore.
            var result = new LongPollingResult
            {
                type = "rpc",
                name = "message",
                success = false,
                data = new DextopRemoteMethodCallException
                {
                    exception = ex.Message,
                    type = "session"
                }
            };

            context.Response.ContentType = "application/json";
            DextopUtil.Encode(result, context.Response.Output);
        }