Ejemplo n.º 1
0
 public Session(AbstractLogger logger, IInternalLocalUser localUser, string guestControllerAccessToken, bool pushNotificationsEnabled, INotificationPoller notificationPoller, ICoroutineManager coroutineManager, IDatabase database, IUserDatabase userDatabase, IGuestControllerClient guestControllerClient, IMixWebCallFactory mixWebCallFactory, IEpochTime epochTime, DatabaseCorruptionHandler databaseCorruptionHandler, ISessionStatus sessionStatus, IKeychain keychain, IGetStateResponseParser getStateResponseParser, string clientVersion, INotificationQueue notificationQueue)
 {
     this.logger                                     = logger;
     this.localUser                                  = localUser;
     this.notificationPoller                         = notificationPoller;
     this.coroutineManager                           = coroutineManager;
     this.database                                   = database;
     this.userDatabase                               = userDatabase;
     this.guestControllerClient                      = guestControllerClient;
     this.mixWebCallFactory                          = mixWebCallFactory;
     this.epochTime                                  = epochTime;
     this.databaseCorruptionHandler                  = databaseCorruptionHandler;
     this.sessionStatus                              = sessionStatus;
     this.keychain                                   = keychain;
     this.getStateResponseParser                     = getStateResponseParser;
     this.clientVersion                              = clientVersion;
     this.notificationQueue                          = notificationQueue;
     GuestControllerAccessToken                      = guestControllerAccessToken;
     guestControllerClient.OnAccessTokenChanged     += HandleGuestControllerAccessTokenChanged;
     guestControllerClient.OnAuthenticationLost     += HandleAuthenticationLost;
     mixWebCallFactory.OnAuthenticationLost         += HandleAuthenticationLost;
     localUser.OnPushNotificationsToggled           += HandlePushNotificationsToggled;
     localUser.OnPushNotificationReceived           += HandlePushNotificationReceived;
     localUser.OnDisplayNameUpdated                 += HandleDisplayNameUpdated;
     databaseCorruptionHandler.OnCorruptionDetected += HandleCorruptionDetected;
     updateEnumerator                                = Update();
     coroutineManager.Start(updateEnumerator);
     notificationPoller.OnNotificationsPolled += HandleNotificationsPolled;
     notificationPoller.UsePollIntervals       = !pushNotificationsEnabled;
     this.sessionStatus.IsPaused = true;
     notificationPoller.OnSynchronizationError += HandleNotificationPollerSynchronizationError;
 }
Ejemplo n.º 2
0
 private static void HandleGetStateSynced(IGetStateResponseParser getStateResponseParser, GetStateResponse response, IMixWebCallFactory mixWebCallFactory, IInternalLocalUser localUser, IUserDatabase userDatabase, INotificationPoller notificationPoller, Action <IResumeSessionResult> callback)
 {
     getStateResponseParser.ParsePollIntervals(response, out var pollIntervals, out var pokeIntervals);
     notificationPoller.PollIntervals = pollIntervals;
     notificationPoller.PokeIntervals = pokeIntervals;
     notificationPoller.Jitter        = response.NotificationIntervalsJitter.Value;
     notificationPoller.MaximumMissingNotificationTime = response.NotificationSequenceThreshold.Value;
     getStateResponseParser.ReconcileWithLocalUser(mixWebCallFactory, response, localUser, userDatabase);
     callback(new ResumeSessionResult(success: true));
 }
Ejemplo n.º 3
0
        public static void Resume(AbstractLogger logger, IGetStateResponseParser getStateResponseParser, IEpochTime epochTime, string clientVersion, INotificationQueue notificationQueue, IMixWebCallFactory mixWebCallFactory, IInternalLocalUser localUser, IDatabase database, IUserDatabase userDatabase, INotificationPoller notificationPoller, Action <IResumeSessionResult> callback)
        {
            epochTime.OffsetMilliseconds = database.GetServerTimeOffsetMillis() ?? 0;
            logger.Debug("Initial time offset: " + epochTime.Offset);
            SessionDocument sessionDocument      = database.GetSessionDocument(localUser.Swid);
            long            lastNotificationTime = sessionDocument.LastNotificationTime;

            StateGetter.GetState(logger, epochTime, clientVersion, database, userDatabase, notificationQueue, mixWebCallFactory, localUser.Swid, lastNotificationTime, delegate(GetStateResponse response)
            {
                HandleGetStateSuccess(logger, getStateResponseParser, response, mixWebCallFactory, localUser, userDatabase, notificationPoller, callback);
            }, delegate
            {
                callback(new ResumeSessionResult(success: false));
            });
        }
Ejemplo n.º 4
0
 private static void HandleGetStateSuccess(AbstractLogger logger, IGetStateResponseParser getStateResponseParser, GetStateResponse response, IMixWebCallFactory mixWebCallFactory, IInternalLocalUser localUser, IUserDatabase userDatabase, INotificationPoller notificationPoller, Action <IResumeSessionResult> callback)
 {
     try
     {
         userDatabase.SyncToGetStateResponse(response, delegate
         {
             HandleGetStateSynced(getStateResponseParser, response, mixWebCallFactory, localUser, userDatabase, notificationPoller, callback);
         });
     }
     catch (Exception ex)
     {
         logger.Critical("Unhandled exception: " + ex);
         callback(new ResumeSessionResult(success: false));
     }
 }