Exemplo n.º 1
0
        public static void OnUploadCreated(ConnectionList connectionList, string connectionID, GenericPageFile pageFile, HttpRequest request)
        {
            var message = Message.CreateEmtpyMessage( "ServerMessage" );
            message[ "Message" ] = ""+DateTime.Now + " OnUploadCreated";
            LongPolling.HttpHandler.MessageHandlerStatic.SendMessageToConnection( connectionID, message );

            pageFile.OnUploadStarted = (rqst,uploadFileName)=>{ OnUploadStarted(pageFile, uploadFileName); };
            pageFile.OnUploadTerminated = (rqst,fileName,filePath,succes,size)=>{ OnUploadTerminated(pageFile, fileName, filePath, succes, size); };
        }
Exemplo n.º 2
0
        internal static void Initialize()
        {
            TasksQueueStatic = new CommonLibs.Utils.Tasks.TasksQueue();
            ConnectionListStatic = new CommonLibs.Web.LongPolling.ConnectionList( TasksQueueStatic );
            MessageHandlerStatic = new CommonLibs.Web.LongPolling.MessageHandler( TasksQueueStatic, ConnectionListStatic );

            #if DEBUG
                // Increase stale & disconnection timeouts during development so unwanted disconnections don't occures when using breakpoints
                ConnectionListStatic.DisconnectionSeconds = 60*60;  // 1H
                ConnectionListStatic.StaleConnectionSeconds = 60*60;  // 1H
            #endif

            // Registering message handlers
            MessageHandlerStatic.AddMessageHandler( SiteMaster.PingMessageType, SiteMaster.PingMessageHandler );
            MessageHandlerStatic.AddMessageHandler( "Test01_TestCrash", Test01Crash.TestCrashHandler );
        }
Exemplo n.º 3
0
        internal static void Initialize()
        {
            TasksQueueStatic     = new CommonLibs.Utils.Tasks.TasksQueue();
            ConnectionListStatic = new CommonLibs.Web.LongPolling.ConnectionList(TasksQueueStatic);
            MessageHandlerStatic = new CommonLibs.Web.LongPolling.MessageHandler(TasksQueueStatic, ConnectionListStatic);

                        #if DEBUG
            // Increase stale & disconnection timeouts during development so unwanted disconnections don't occures when using breakpoints
            ConnectionListStatic.DisconnectionSeconds   = 60 * 60;                  // 1H
            ConnectionListStatic.StaleConnectionSeconds = 60 * 60;                  // 1H
                        #endif

            // Registering message handlers
            MessageHandlerStatic.AddMessageHandler(SiteMaster.PingMessageType, SiteMaster.PingMessageHandler);
            MessageHandlerStatic.AddMessageHandler("Test01_TestCrash", Test01Crash.TestCrashHandler);
        }
Exemplo n.º 4
0
            internal ConnectionEntry(ConnectionList connectionList, string sessionID, string connectionID)
            {
                CommonLibs.Utils.Debug.ASSERT( connectionList != null, this, "Missing parameter 'connectionList'" );
                CommonLibs.Utils.Debug.ASSERT( !string.IsNullOrEmpty(connectionID), this, "Missing parameter 'connectionID'" );

                ConnectionList = connectionList;
                SessionID = sessionID;
                ConnectionID = connectionID;
                Disposed = false;
            }
        public ConnectionPersistentObject(ConnectionList connectionList, PersistanceTypes persistanceType, string connectionID, string sessionID=null)
        {
            ASSERT( connectionList != null, "Missing parameter 'connectionList'" );
            ASSERT(	( persistanceType == PersistanceTypes.Connection && (!string.IsNullOrEmpty(connectionID)) )
                ||	( persistanceType == PersistanceTypes.Session && (!string.IsNullOrEmpty(sessionID)) ), "Missing either 'connectionID' or 'sessionID' parameter" );

            ConnectionList = connectionList;
            if( sessionID != null )
            {
                ASSERT( sessionID != "", "Missing parameter 'sessionID'" );
                SessionID = sessionID;
            }
            else
            {
                SessionID = CommonLibs.Web.LongPolling.ConnectionList.GetSessionID( HttpContext.Current );
                ASSERT( !string.IsNullOrEmpty(SessionID), "'" + GetType().FullName + "' objects cannot be created outside an HTTP context with the ASP.NET's session accessible" );
            }

            switch( persistanceType )
            {
                case PersistanceTypes.Connection:
                    PersistanceType = PersistanceTypes.Connection;
                    ASSERT( !string.IsNullOrEmpty(connectionID), "Missing parameter 'connectionID'" );
                    ConnectionID = connectionID;

                    if(! ConnectionList.CheckConnectionIsValid(SessionID, ConnectionID) )
                        // This connection is not registered to this ConnectionList
                        throw new ArgumentException( "Connection '" + ConnectionID + "' of session '" + SessionID + "' does not exist" );

                    // Assign ConnectionLostCallback
                    ConnectionLostCallback = new Action<string>( ConnectionList_ConnectionLost );
                    ConnectionList.ConnectionLost += ConnectionLostCallback;

                    if(! ConnectionList.CheckConnectionIsValid(SessionID, ConnectionID) )
                    {
                        // Very unlikely, but this connection has just been closed !
                        // => Since this may have occured right after the first 'CheckConnectionIsValid()' AND right before the 'ConnectionList.ConnectionLost' event assignment,
                        //		the 'ConnectionList_ConnectionLost()' callback might never be called...
                        // => Manually unregister the callback
                        FAIL( "The connection '" + ConnectionID + "' has been unexpectedly closed" );
                        ConnectionList.ConnectionLost -= ConnectionLostCallback;

                        throw new ArgumentException( "Connection '" + ConnectionID + "' of session '" + SessionID + "' does not exist" );
                    }
                    break;

                case PersistanceTypes.Session:
                    PersistanceType = PersistanceTypes.Session;
                    ASSERT( connectionID == null, "Parameter 'connectionID' should not be specified here" );
                    ConnectionID = null;

                    if(! ConnectionList.CheckSessionIsValid(SessionID) )
                        // This session is not registered to this ConnectionList
                        throw new ArgumentException( "Session '" + SessionID + "' does not exist" );

                    // Assign SessionClosedCallback
                    SessionClosedCallback = new Action<string>( ConnectionList_SessionClosed );
                    ConnectionList.SessionClosed += new Action<string>(ConnectionList_SessionClosed);

                    if(! ConnectionList.CheckSessionIsValid(SessionID) )
                    {
                        // Very unlikely, but this session has just been closed !
                        // => Since this may have occured right after the first 'CheckSessionIsValid()' AND right before the 'ConnectionList.SessionClosed' event assignment,
                        //		the 'ConnectionList_SessionClosed()' callback might never be called...
                        // => Manually unregister the callback
                        FAIL( "The session '" + SessionID + "' has been unexpectedly closed" );
                        ConnectionList.SessionClosed -= SessionClosedCallback;

                        throw new ArgumentException( "Session '" + SessionID + "' does not exist" );
                    }
                    break;

                default:
                    throw new NotImplementedException( "Unknown persistanceType '" + persistanceType + "'" );
            }
        }
Exemplo n.º 6
0
        public MessageHandler(TasksQueue tasksQueue, ConnectionList connectionList)
        {
            LOG( "Constructor" );

            TaskQueue = tasksQueue;
            ConnectionList = connectionList;
            FatalExceptionHandler = DefaultFatalExceptionHandler;

            ConnectionList.ConnectionRegistered += (value)=>
                {
                    CheckPendingQueueForConnection( value );
                };
            ConnectionList.ConnectionLost += ConnectionList_ConnectionLost;
        }