Exemple #1
0
        public void ProcessRequest(HttpContext context)
        {
            // retrieve params
            var clientId = context.Request.QueryString["clientId"];

            var handler = new RemoteSessionEventSourceHandler(context, clientId);

            try
            {
                handler.Open();

                // keep the http context open as long as the http client is connected
                while (context.Response.IsClientConnected)
                {
                    Thread.Sleep(1000);
                }
            }
            catch (Exception exc)
            {
                // rethrown
            }
            finally
            {
                handler.Close();
            }
        }
Exemple #2
0
        public RemoteSessionEventSourceHandler(HttpContext context)
        {
            _context = context;
            Session  = context.Session;

            try
            {
                if (_context.Session[HttpSessionStateVariables.RemoteSession.ToString()] == null)
                {
                    throw new NullReferenceException();
                }

                // retrieve the remote session for the given http session
                _remoteSession = (RemoteSession)_context.Session[HttpSessionStateVariables.RemoteSession.ToString()];

                // register the handler against the remote session manager
                lock (((ICollection)_remoteSession.Manager.EventSources).SyncRoot)
                {
                    // search for a previously registered handler
                    RemoteSessionEventSourceHandler oldEventSource = null;

                    foreach (var eventSource in _remoteSession.Manager.EventSources)
                    {
                        if (eventSource.Session.SessionID == _context.Session.SessionID)
                        {
                            oldEventSource = eventSource;
                            break;
                        }
                    }

                    // unregister the previous handler, if any
                    if (oldEventSource != null)
                    {
                        _remoteSession.Manager.EventSources.Remove(oldEventSource);
                    }

                    // register this handler
                    _remoteSession.Manager.EventSources.Add(this);
                }

                // mime type for event source
                _context.Response.ContentType = "text/event-stream";
                _context.Response.Headers.Add("Content-Type", "text/event-stream\n\n");
            }
            catch (Exception exc)
            {
                Trace.TraceError("Failed to retrieve the remote session for the http session {0}, ({1})", _context.Session.SessionID, exc);
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            var handler = new RemoteSessionEventSourceHandler(context);

            try
            {
                // keep the http context open as long as the http client is connected
                while (context.Response.IsClientConnected)
                {
                    Thread.Sleep(1000);
                }
            }
            catch (Exception exc)
            {
                Trace.TraceError("event source error for http session {0} ({1})", context.Session.SessionID, exc);
            }

            Trace.TraceInformation("event source closed for http session {0}", context.Session.SessionID);
        }