Esempio n. 1
0
        public ConnectionList(CommonLibs.Utils.Tasks.TasksQueue tasksQueue)
        {
            LOG( "Constructor" );

            FatalExceptionHandler = DefaultFatalExceptionHandler;

            TasksQueue = tasksQueue;
        }
Esempio n. 2
0
 public static void ShowException(string windowTitle, CommonLibs.ExceptionManager.Manager manager)
 {
     var window = new Window() { Title=windowTitle };
     window.Width = 640;
     window.Height = 480;
     var managerControl = new ManagerControl() { ExceptionManager=manager };
     window.Content = managerControl;
     var rc = window.ShowDialog();
 }
Esempio n. 3
0
 /// <summary>
 /// Message handler that throws an exception
 /// </summary>
 public static void TestCrashHandler(CommonLibs.Web.LongPolling.Message requestMessage)
 {
     int a = 0;
     int b = 1;
     a = b/a;
 }
 public static void ShowActionEntry(string windowTitle, ActionEntry entry, CommonLibs.ExceptionManager.CreateManagerDelegate exceptionManagerFactory)
 {
     var window = new Window() { Title=windowTitle };
     window.Width = 640;
     window.Height = 480;
     var control = new ActionEntryControl();
     if( exceptionManagerFactory != null )
         control.ExceptionManagerFactory = exceptionManagerFactory;
     control.ActionEntry = entry;
     window.Content = control;
     var rc = window.ShowDialog();
 }
Esempio n. 5
0
 public TestManager(CommonLibs.ExceptionManager.ObjectElement tree)
     : base(tree)
 {
     Translate = TestException.Translate;
 }
Esempio n. 6
0
        private void ConnectionEntry_StaleTimeout(CommonLibs.Utils.Tasks.TaskEntry taskEntry, ConnectionEntry connectionEntry)
        {
            LOG( "ConnectionEntry_StaleTimeout() - Start" );
            var messagesToSend = new List<KeyValuePair<IConnection,RootMessage>>();
            lock( LockObject )
            {
                ASSERT( connectionEntry != null, "Missing parameter 'connectionEntry'" );

                if( (connectionEntry.StaleTimeout == null)
                 || (connectionEntry.StaleTimeout.ID != taskEntry.ID) )
                {
                    LOG( "*** The state of the ConnectionEntry changed between the trigger of the timeout and the Locker.EnterWriteLock() in this method" );
                    // ^^ Chances this happens are very low. This is more a sign of something wrong is going on.

                    // This timeout trigger is not valid anymore => discard it
                    return;
                }
                LOG( "ConnectionEntry_StaleTimeout('" + taskEntry + "', " + connectionEntry.ConnectionID + ") - Lock aquired" );

                // Discard the TaskEntry that just triggered
                //connectionEntry.StaleTimeout.Dispose(); <= Don't dispose it, it is still running, it's this one!!!
                connectionEntry.StaleTimeout = null;

                var connectionID = connectionEntry.ConnectionID;
                var sessionID = connectionEntry.SessionID;
                ASSERT( !string.IsNullOrEmpty(connectionID), "'connectionEntry.ConnectionID' is missing" );
                ASSERT( !string.IsNullOrEmpty(sessionID), "'connectionEntry.SessionID' is missing" );
                CheckValidity();
                ASSERT( AllConnections.ContainsKey(connectionID), "This ConnectionEntry is not handled by this ConnectionList" );
                ASSERT( connectionEntry.Connection != null, "We are supposed to declare a long-polling HTTP connection stale. An active Connection is supposed to be present here" );

                // Ask the peer to reconnect
                messagesToSend.Add( new KeyValuePair<IConnection,RootMessage>(connectionEntry.Connection, RootMessage.CreateResetRootMessage()) );
                connectionEntry.Connection = null;

                // Start the DisconnectionTimeout
                LOG( "ConnectionEntry_StaleTimeout('" + taskEntry + "', " + connectionEntry.ConnectionID + ") - Creating DisconnectionTimeout" );
                connectionEntry.DisconnectionTimeout = TasksQueue.CreateTask( 0, 0, 0, DisconnectionSeconds, 0, (taskEntryParm)=>{ConnectionEntry_DisconnectionTimeout(taskEntryParm, connectionEntry);} );
                LOG( "ConnectionEntry_StaleTimeout('" + taskEntry + "', " + connectionEntry.ConnectionID + ") - Created DisconnectionTimeout " + connectionEntry.DisconnectionTimeout );

                CheckValidity();
                LOG( "ConnectionEntry_StaleTimeout('" + taskEntry + "', " + connectionEntry.ConnectionID + ") - Exit" );
            }

            // Send messages (NB: must be outside any lock()s )
            foreach( var pair in messagesToSend )
                pair.Key.SendResponseMessage( pair.Value );
        }
Esempio n. 7
0
        private void ConnectionEntry_DisconnectionTimeout(CommonLibs.Utils.Tasks.TaskEntry taskEntry, ConnectionEntry connectionEntry)
        {
            LOG( "ConnectionEntry_DisconnectionTimeout() - Start" );

            var customObjects = new List<object>();

            string connectionID;
            lock( LockObject )
            {
                ASSERT( taskEntry != null, "Missing parameter 'taskEntry'" );
                ASSERT( connectionEntry != null, "Missing parameter 'connectionEntry'" );
                if( (connectionEntry.DisconnectionTimeout == null)
                    || (connectionEntry.DisconnectionTimeout.ID != taskEntry.ID) )
                {
                    LOG( "*** The state of the ConnectionEntry changed between the trigger of the timeout and the Locker.EnterWriteLock() in this method" );
                    // ^^ Chances this happens are very low. This is more a sign of something wrong is going on.

                    // This timeout trigger is not valid anymore => discard it
                    return;
                }
                LOG( "ConnectionEntry_DisconnectionTimeout('" + taskEntry + "', " + connectionEntry.ConnectionID + ") - Lock aquired" );

                // Discard the TaskEntry that just triggered
                //connectionEntry.DisconnectionTimeout.Dispose(); <= Don't dispose it, it is still running, it's this one!!!
                connectionEntry.DisconnectionTimeout = null;

                connectionID = connectionEntry.ConnectionID;
                var sessionID = connectionEntry.SessionID;
                ASSERT( !string.IsNullOrEmpty(connectionID), "'connectionEntry.ConnectionID' is missing" );
                ASSERT( !string.IsNullOrEmpty(sessionID), "'connectionEntry.SessionID' is missing" );
                CheckValidity();
                ASSERT( AllConnections.ContainsKey(connectionID), "This ConnectionEntry is not handled by this ConnectionList" );
                ASSERT( connectionEntry.Connection == null, "We are supposed to declare a long-polling HTTP connection definately disconnected. An active Connection is not supposed to be present here" );

                // This connection is considered definately lost => Remove it from 'AllSessions' ...
                SessionEntry sessionEntry;
                if(! AllSessions.TryGetValue(sessionID, out sessionEntry) )
                {
                    FAIL( "The connection '" + connectionID + "' is reqested to be removed but SessionID '" + sessionID + "' is not in 'AllSessions'" );
                }
                else
                {
                    if(! sessionEntry.ConnectionIDs.Remove(connectionID) )
                        FAIL( "The connection '" + connectionID + "' is reqested to be removed but is not in 'AllSessions'" );
                }

                // ... and from 'AllConnections' ...
                if(! AllConnections.Remove(connectionID) )
                {
                    FAIL( "The connection '" + connectionID + "' is reqested to be removed but is not in 'AllConnections'" );
                }

                // ... and Dispose() it.
                customObjects.AddRange( connectionEntry.CustomObjects.Select(v=>v.Value) );
                connectionEntry.Dispose();

                CheckValidity();
                LOG( "ConnectionEntry_DisconnectionTimeout('" + taskEntry + "', " + connectionEntry.ConnectionID + ") - Release lock" );
            }

            // Fire ConnectionLost event
            ConnectionLostInvokeCallbacks( connectionID );

            // Dispose CustomObjects that are IDisposable
            if( customObjects != null )
            {
                foreach( var obj in customObjects )
                {
                    var disposable = obj as IDisposable;
                    if( disposable != null )
                    {
                        try { disposable.Dispose(); }
                        catch(System.Exception ex)  { FAIL( "'disposable.Dispose()' threw an exception (" + ex.GetType().FullName + "): " + ex.Message ); }
                    }
                }
            }

            LOG( "ConnectionEntry_DisconnectionTimeout('" + taskEntry + "', " + connectionEntry.ConnectionID + ") - Exit" );
        }
Esempio n. 8
0
 /// <summary>
 /// Simple message handler that sends the original message back to sender without any other processing
 /// </summary>
 public static void PingMessageHandler(CommonLibs.Web.LongPolling.Message requestMessage)
 {
     var responseMessage = CommonLibs.Web.LongPolling.Message.CreateResponseMessage( requestMessage );
     LongPolling.HttpHandler.MessageHandlerStatic.SendMessageToConnection( requestMessage.SenderConnectionID, responseMessage );
 }