Пример #1
0
 internal static void setController(PersistanceTypes persistance)
 {
     switch (persistance)
     {
         case PersistanceTypes.Persistance1:
             idbc = new DBC();
             break;
     }
 }
Пример #2
0
 internal static void setController(PersistanceTypes persistance)
 {
     switch (persistance)
     {
     case PersistanceTypes.Persistance1:
         idbc = new DBC();
         break;
     }
 }
        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 + "'" );
            }
        }