示例#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;
 }
 public NotificationPoller(AbstractLogger logger, IMixWebCallFactory webCallFactory, INotificationQueue queue, IStopwatch pollCountdownStopwatch, IGetStateResponseParser getStateResponseParser, IEpochTime epochTime, IRandom random, IDatabase database, string localUserSwid)
 {
     usePollIntervals        = true;
     missedNotificationTimes = new Dictionary <long, long>();
     isPaused                    = true;
     this.logger                 = logger;
     this.webCallFactory         = webCallFactory;
     this.queue                  = queue;
     this.pollCountdownStopwatch = pollCountdownStopwatch;
     this.getStateResponseParser = getStateResponseParser;
     this.epochTime              = epochTime;
     this.random                 = random;
     this.database               = database;
     this.localUserSwid          = localUserSwid;
     PollIntervals               = new int[1] {
         2147483647
     };
     PokeIntervals = new int[1] {
         2147483647
     };
     MaximumMissingNotificationTime = int.MaxValue;
     Jitter              = 0;
     IntervalIndex       = 0;
     queue.OnQueued     += HandleQueued;
     queue.OnDispatched += HandleQueueDispatched;
 }
示例#3
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));
 }
示例#4
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));
            });
        }
示例#5
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));
     }
 }