private static void HandleGetLinkedChildrenResult(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, Action <IGetLinkedUsersResult> callback, GuestControllerResult <ChildrenResponse> result)
 {
     try
     {
         if (!result.Success || result.Response.error != null)
         {
             callback(MakeGenericFailure());
         }
         else
         {
             List <Profile> list = (result.Response.data == null) ? null : result.Response.data.children;
             if (list == null)
             {
                 callback(MakeGenericFailure());
             }
             else
             {
                 LinkedUsersGetter.Get(logger, mixWebCallFactory, list, delegate(LinkedUser[] users)
                 {
                     callback((users == null) ? MakeGenericFailure() : new GetLinkedUsersResult(success: true, users));
                 });
             }
         }
     }
     catch (Exception arg)
     {
         logger.Critical("Unhandled exception: " + arg);
         callback(MakeGenericFailure());
     }
 }
Example #2
0
        public IInternalSession Create(string swid)
        {
            byte[] localStorageKey = keychain.LocalStorageKey;
            IDocumentCollection <AlertDocument>            documentCollection  = GetDocumentCollection <AlertDocument>(swid, "Alerts", databaseDirectoryCreator, localStorageKey, documentCollectionFactory);
            IDocumentCollection <FriendDocument>           documentCollection2 = GetDocumentCollection <FriendDocument>(swid, "Friends", databaseDirectoryCreator, localStorageKey, documentCollectionFactory);
            IDocumentCollection <FriendInvitationDocument> documentCollection3 = GetDocumentCollection <FriendInvitationDocument>(swid, "FriendInvitations", databaseDirectoryCreator, localStorageKey, documentCollectionFactory);
            IDocumentCollection <UserDocument>             documentCollection4 = GetDocumentCollection <UserDocument>(swid, "Users", databaseDirectoryCreator, localStorageKey, documentCollectionFactory);

            databaseCorruptionHandler.Add(documentCollection4);
            string       dirPath      = BuildDocCollectionPath(databaseDirectoryCreator, swid);
            UserDatabase userDatabase = new UserDatabase(documentCollection, documentCollection2, documentCollection3, documentCollection4, localStorageKey, dirPath, epochTime, documentCollectionFactory, databaseCorruptionHandler, coroutineManager);

            database.ClearServerTimeOffsetMillis();
            epochTime.OffsetMilliseconds = database.GetServerTimeOffsetMillis() ?? 0;
            logger.Debug("Initial time offset: " + epochTime.Offset);
            SessionDocument sessionDocument = database.GetSessionDocument(swid);

            keychain.PushNotificationKey = sessionDocument.CurrentSymmetricEncryptionKey;
            IWebCallEncryptor      webCallEncryptor      = webCallEncryptorFactory.Create(sessionDocument.CurrentSymmetricEncryptionKey, sessionDocument.SessionId);
            IGuestControllerClient guestControllerClient = guestControllerClientFactory.Create(swid);
            ISessionRefresher      sessionRefresher      = sessionRefresherFactory.Create(mixSessionStarter, guestControllerClient);
            IMixWebCallFactory     mixWebCallFactory     = mixWebCallFactoryFactory.Create(webCallEncryptor, swid, sessionDocument.GuestControllerAccessToken, sessionRefresher);

            guestControllerClient.OnAccessTokenChanged += delegate(object sender, AbstractGuestControllerAccessTokenChangedEventArgs e)
            {
                mixWebCallFactory.GuestControllerAccessToken = e.GuestControllerAccessToken;
            };
            AssetLoader             assetLoader           = new AssetLoader(logger, wwwCallFactory);
            IList <IInternalFriend> friends               = CreateFriends(userDatabase);
            AgeBandType             ageBandType           = AgeBandTypeConverter.Convert(sessionDocument.AgeBand);
            DateTime               lastRefreshTime        = epochTime.FromSeconds(sessionDocument.LastProfileRefreshTime);
            RegistrationProfile    registrationProfile    = new RegistrationProfile(logger, sessionDocument.DisplayNameText, sessionDocument.ProposedDisplayName, sessionDocument.ProposedDisplayNameStatus, sessionDocument.FirstName, sessionDocument.AccountStatus, lastRefreshTime, sessionDocument.CountryCode);
            GetStateResponseParser getStateResponseParser = new GetStateResponseParser(logger);
            NotificationPoller     notificationPoller     = new NotificationPoller(logger, mixWebCallFactory, notificationQueue, pollCountdownStopwatch, getStateResponseParser, epochTime, random, database, swid);
            DisplayName            displayName            = new DisplayName(sessionDocument.DisplayNameText);
            LocalUser              localUser              = new LocalUser(logger, displayName, swid, friends, ageBandType, database, userDatabase, registrationProfile, mixWebCallFactory, guestControllerClient, notificationQueue, encryptor, epochTime);
            Session session = new Session(logger, localUser, sessionDocument.GuestControllerAccessToken, sessionDocument.PushNotificationToken != null, notificationPoller, coroutineManager, database, userDatabase, guestControllerClient, mixWebCallFactory, epochTime, databaseCorruptionHandler, sessionStatus, keychain, getStateResponseParser, clientVersion, notificationQueue);

            try
            {
                NotificationHandler.Handle(notificationDispatcher, userDatabase, localUser, epochTime);
                notificationQueue.LatestSequenceNumber = sessionDocument.LatestNotificationSequenceNumber;
                IEnumerable <IncomingFriendInvitation> incomingFriendInvitations = GetIncomingFriendInvitations(userDatabase, localUser);
                foreach (IncomingFriendInvitation item in incomingFriendInvitations)
                {
                    localUser.AddIncomingFriendInvitation(item);
                }
                IEnumerable <OutgoingFriendInvitation> outgoingFriendInvitations = GetOutgoingFriendInvitations(userDatabase, localUser);
                foreach (OutgoingFriendInvitation item2 in outgoingFriendInvitations)
                {
                    localUser.AddOutgoingFriendInvitation(item2);
                }
            }
            catch (Exception)
            {
                session.Dispose();
                throw;
            }
            return(session);
        }
Example #3
0
 public static void Report(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, string userId, ReportUserReason reason, Action successCallback, Action failureCallback)
 {
     try
     {
         ReportPlayerRequest reportPlayerRequest = new ReportPlayerRequest();
         reportPlayerRequest.ReportedUserId = userId;
         reportPlayerRequest.Reason         = reason.ToString();
         ReportPlayerRequest request = reportPlayerRequest;
         IWebCall <ReportPlayerRequest, BaseResponse> webCall = mixWebCallFactory.ModerationReportPlayerPut(request);
         webCall.OnResponse += delegate
         {
             successCallback();
         };
         webCall.OnError += delegate
         {
             failureCallback();
         };
         webCall.Execute();
     }
     catch (Exception ex)
     {
         logger.Critical("Unhandled exception: " + ex);
         failureCallback();
     }
 }
 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;
 }
Example #5
0
 public static void ModerateText(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, string text, bool isTrusted, Action <ModerateTextResponse> successCallback, Action failureCallback)
 {
     try
     {
         ModerateTextRequest moderateTextRequest = new ModerateTextRequest();
         moderateTextRequest.Text             = text;
         moderateTextRequest.ModerationPolicy = (isTrusted ? "Trusted" : "UnTrusted");
         ModerateTextRequest request = moderateTextRequest;
         IWebCall <ModerateTextRequest, ModerateTextResponse> webCall = mixWebCallFactory.ModerationTextPut(request);
         webCall.OnResponse += delegate(object sender, WebCallEventArgs <ModerateTextResponse> e)
         {
             ModerateTextResponse response = e.Response;
             if (ValidateModerateTextResponse(response))
             {
                 successCallback(response);
             }
             else
             {
                 logger.Critical("Failed to validate moderate text response: " + JsonParser.ToJson(response));
                 failureCallback();
             }
         };
         webCall.OnError += delegate
         {
             failureCallback();
         };
         webCall.Execute();
     }
     catch (Exception ex)
     {
         logger.Critical("Unhandled exception: " + ex);
         failureCallback();
     }
 }
Example #6
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;
 }
Example #7
0
 public static void SetAway(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, Action <BaseResponse> successCallback, Action failureCallback)
 {
     try
     {
         SetPresenceRequest setPresenceRequest = new SetPresenceRequest();
         setPresenceRequest.State = "away";
         SetPresenceRequest request = setPresenceRequest;
         IWebCall <SetPresenceRequest, BaseResponse> webCall = mixWebCallFactory.PresencePut(request);
         webCall.OnResponse += delegate(object sender, WebCallEventArgs <BaseResponse> e)
         {
             BaseResponse response = e.Response;
             successCallback(response);
         };
         webCall.OnError += delegate
         {
             failureCallback();
         };
         webCall.Execute();
     }
     catch (Exception arg)
     {
         logger.Critical("Unhandled exception: " + arg);
         failureCallback();
     }
 }
Example #8
0
 public LocalUser(AbstractLogger logger, IDisplayName displayName, string swid, IList <IInternalFriend> friends, AgeBandType ageBandType, IDatabase database, IUserDatabase userDatabase, IInternalRegistrationProfile registrationProfile, IMixWebCallFactory mixWebCallFactory, IGuestControllerClient guestControllerClient, INotificationQueue notificationQueue, IEncryptor encryptor, IEpochTime epochTime)
 {
     DisplayName = displayName;
     FirstName   = registrationProfile.FirstName;
     Swid        = swid;
     Id          = swid;
     this.logger = logger;
     this.registrationProfile   = registrationProfile;
     this.mixWebCallFactory     = mixWebCallFactory;
     this.friends               = friends;
     this.ageBandType           = ageBandType;
     this.database              = database;
     this.userDatabase          = userDatabase;
     incomingFriendInvitations  = new List <IInternalIncomingFriendInvitation>();
     outgoingFriendInvitations  = new List <IInternalOutgoingFriendInvitation>();
     oldInvitationIds           = new List <long>();
     unidentifiedUsers          = new List <IInternalUnidentifiedUser>();
     this.guestControllerClient = guestControllerClient;
     this.notificationQueue     = notificationQueue;
     this.encryptor             = encryptor;
     this.epochTime             = epochTime;
     guestControllerClient.OnLegalMarketingUpdateRequired += delegate(object sender, AbstractLegalMarketingUpdateRequiredEventArgs e)
     {
         this.OnLegalMarketingUpdateRequired(this, e);
     };
 }
Example #9
0
        public static void UpdateDisplayName(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, string displayName, Action <IUpdateDisplayNameResult> callback)
        {
            try
            {
                SetDisplayNameRequest setDisplayNameRequest = new SetDisplayNameRequest();
                setDisplayNameRequest.DisplayName = displayName;
                SetDisplayNameRequest request = setDisplayNameRequest;
                IWebCall <SetDisplayNameRequest, SetDisplayNameResponse> webCall = mixWebCallFactory.DisplaynamePut(request);
                webCall.OnResponse += delegate(object sender, WebCallEventArgs <SetDisplayNameResponse> e)
                {
                    SetDisplayNameResponse response = e.Response;
                    if (ValidateSetDisplayNameResponse(response))
                    {
                        callback(new UpdateDisplayNameResult(success: true));
                    }
                    else
                    {
                        logger.Critical("Failed to validate update display name response!");
                        callback(new UpdateDisplayNameResult(success: false));
                    }
                };
                webCall.OnError += delegate(object sender, WebCallErrorEventArgs e)
                {
                    switch (e.Status)
                    {
                    case "DISPLAYNAME_MODERATION_FAILED":
                        logger.Warning("Failed to update display name due to moderation failure: " + e.Message);
                        callback(new UpdateDisplayNameFailedModerationResult(success: false));
                        break;

                    case "DISPLAYNAME_ASSIGNMENT_FAILED":
                        logger.Warning("Failed to update display name due to assignment failure: " + e.Message);
                        callback(new UpdateDisplayNameExistsResult(success: false));
                        break;

                    default:
                        callback(new UpdateDisplayNameResult(success: false));
                        break;
                    }
                };
                webCall.Execute();
            }
            catch (Exception ex)
            {
                logger.Critical("Unhandled exception: " + ex);
                callback(new UpdateDisplayNameResult(success: false));
            }
        }
        public static void Get(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, IList <Profile> profiles, Action <LinkedUser[]> callback)
        {
            IWebCall <GetUsersByUserIdRequest, GetUsersResponse> webCall = mixWebCallFactory.UsersByUserIdPost(new GetUsersByUserIdRequest
            {
                UserIds = profiles.Select((Profile u) => u.swid).ToList()
            });

            webCall.OnResponse += delegate(object sender, WebCallEventArgs <GetUsersResponse> e)
            {
                HandleGetUsersByIdSuccess(logger, e.Response, profiles, callback);
            };
            webCall.OnError += delegate
            {
                callback(null);
            };
            webCall.Execute();
        }
		private void Start(string swid, string guestControllerAccessToken, RSAParameters rsaParameters, Action<MixSessionStartResult> successCallback, Action failureCallback)
		{
			try
			{
				ISessionRefresher sessionRefresher = sessionRefresherFactory.Create(this);
				IMixWebCallFactory mixWebCallFactory = mixWebCallFactoryFactory.Create(sessionStartEncryptor, swid, guestControllerAccessToken, sessionRefresher);
				StartUserSessionRequest request = BuildRequest(swid, rsaParameters);
				IWebCall<StartUserSessionRequest, StartUserSessionResponse> webCall = mixWebCallFactory.SessionUserPut(request);
				webCall.OnResponse += delegate(object sender, WebCallEventArgs<StartUserSessionResponse> e)
				{
					StartUserSessionResponse response = e.Response;
					if (!ValidateResponse(response))
					{
						logger.Critical("Error parsing the session start response: " + JsonParser.ToJson(response));
						failureCallback();
					}
					else
					{
						long sessionId = response.SessionId.Value;
						byte[] ciphertext = Convert.FromBase64String(response.EncryptedSymmetricKey);
						byte[] symmetricKey = rsaEncryptor.Decrypt(ciphertext, rsaParameters);
						keychain.PushNotificationKey = symmetricKey;
						database.UpdateSessionDocument(swid, delegate(SessionDocument doc)
						{
							doc.PreviousSymmetricEncryptionKey = doc.CurrentSymmetricEncryptionKey;
							doc.CurrentSymmetricEncryptionKey = symmetricKey;
							doc.SessionId = sessionId;
							doc.LatestNotificationSequenceNumber = 0L;
						});
						IWebCallEncryptor webCallEncryptor = webCallEncryptorFactory.Create(symmetricKey, sessionId);
						MixSessionStartResult obj = new MixSessionStartResult(webCallEncryptor);
						successCallback(obj);
					}
				};
				webCall.OnError += delegate
				{
					failureCallback();
				};
				webCall.Execute(force: true);
			}
			catch (Exception ex)
			{
				logger.Critical("Unhandled exception: " + ex);
				failureCallback();
			}
		}
Example #12
0
 private static void Enable(AbstractLogger logger, IDatabase database, IMixWebCallFactory mixWebCallFactory, string token, string tokenType, string provisionId, bool enableVisible, string swid, Action successCallback, Action failureCallback)
 {
     try
     {
         TogglePushNotificationRequest togglePushNotificationRequest = new TogglePushNotificationRequest();
         togglePushNotificationRequest.PushToken = new PushToken
         {
             Token     = token,
             TokenType = tokenType
         };
         togglePushNotificationRequest.State             = (enableVisible ? "ALL" : "ONLY_SILENT");
         togglePushNotificationRequest.IosProvisioningId = provisionId;
         TogglePushNotificationRequest request = togglePushNotificationRequest;
         IWebCall <TogglePushNotificationRequest, BaseResponse> webCall = mixWebCallFactory.PushNotificationsSettingPost(request);
         webCall.OnResponse += delegate
         {
             try
             {
                 database.UpdateSessionDocument(swid, delegate(SessionDocument sessionDoc)
                 {
                     sessionDoc.PushNotificationToken           = token;
                     sessionDoc.PushNotificationTokenType       = tokenType;
                     sessionDoc.VisiblePushNotificationsEnabled = enableVisible;
                     sessionDoc.ProvisionId = provisionId;
                 });
                 successCallback();
             }
             catch (Exception ex2)
             {
                 logger.Critical("Unhandled exception: " + ex2);
                 failureCallback();
             }
         };
         webCall.OnError += delegate
         {
             failureCallback();
         };
         webCall.Execute();
     }
     catch (Exception ex)
     {
         logger.Critical("Unhandled exception: " + ex);
         failureCallback();
     }
 }
Example #13
0
 public static void Search(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, string displayName, IUserDatabase userDatabase, Action <IInternalUnidentifiedUser> successCallback, Action failureCallback)
 {
     try
     {
         DisplayNameSearchRequest displayNameSearchRequest = new DisplayNameSearchRequest();
         displayNameSearchRequest.DisplayName = displayName;
         DisplayNameSearchRequest request = displayNameSearchRequest;
         IWebCall <DisplayNameSearchRequest, DisplayNameSearchResponse> webCall = mixWebCallFactory.SearchDisplaynamePost(request);
         webCall.OnResponse += delegate(object sender, WebCallEventArgs <DisplayNameSearchResponse> e)
         {
             DisplayNameSearchResponse response = e.Response;
             if (ValidateResponse(response))
             {
                 userDatabase.InsertUserDocument(new UserDocument
                 {
                     DisplayName = response.DisplayName,
                     FirstName   = response.FirstName,
                     Swid        = null,
                     HashedSwid  = null
                 });
                 IInternalUnidentifiedUser obj = RemoteUserFactory.CreateUnidentifiedUser(response.DisplayName, response.FirstName, userDatabase);
                 successCallback(obj);
             }
             else
             {
                 logger.Critical("Failed to validate display name search response: " + JsonParser.ToJson(response));
                 failureCallback();
             }
         };
         webCall.OnError += delegate(object sender, WebCallErrorEventArgs e)
         {
             logger.Debug("Failed to find user: "******"Unhandled exception: " + arg);
         failureCallback();
     }
 }
 public static void Recommend(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, IUserDatabase userDatabase, Action <IEnumerable <IInternalUnidentifiedUser> > successCallback, Action failureCallback)
 {
     try
     {
         BaseUserRequest request = new BaseUserRequest();
         IWebCall <BaseUserRequest, GetFriendshipRecommendationResponse> webCall = mixWebCallFactory.FriendshipRecommendPost(request);
         webCall.OnResponse += delegate(object sender, WebCallEventArgs <GetFriendshipRecommendationResponse> e)
         {
             List <FriendRecommendation> friendRecommendations = e.Response.FriendRecommendations;
             if (friendRecommendations == null)
             {
                 failureCallback();
             }
             else
             {
                 foreach (FriendRecommendation item in friendRecommendations)
                 {
                     userDatabase.InsertUserDocument(new UserDocument
                     {
                         DisplayName = item.DisplayName,
                         FirstName   = item.FirstName,
                         Swid        = null,
                         HashedSwid  = null
                     });
                 }
                 IInternalUnidentifiedUser[] obj = (from item in friendRecommendations
                                                    select RemoteUserFactory.CreateUnidentifiedUser(item.DisplayName, item.FirstName, userDatabase)).ToArray();
                 successCallback(obj);
             }
         };
         webCall.OnError += delegate
         {
             failureCallback();
         };
         webCall.Execute();
     }
     catch (Exception arg)
     {
         logger.Critical("Unhandled exception: " + arg);
         failureCallback();
     }
 }
 private static void HandleGetClaimableChildrenResult(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, Action <IGetLinkedUsersResult> callback, GuestControllerResult <ChildrenResponse> result)
 {
     try
     {
         if (!result.Success || result.Response.error != null || result.Response.data == null)
         {
             callback(MakeGenericFailure());
             return;
         }
         LinkedUsersGetter.Get(logger, mixWebCallFactory, result.Response.data.children, delegate(LinkedUser[] users)
         {
             callback((users == null) ? MakeGenericFailure() : new GetLinkedUsersResult(success: true, users));
         });
     }
     catch (Exception ex)
     {
         logger.Critical("Unhandled exception: " + ex);
         callback(MakeGenericFailure());
     }
 }
    private static void CreateDependencies(string guestControllerHostUrl, string guestControllerSpoofedIpAddress, string mixApiHostUrl, string oneIdClientId, string mixClientToken, string clientVersion, ICoroutineManager coroutineManager, IKeychain keychain, AbstractLogger logger, string localStorageDirPath, string languageCode, out ISessionLogin sessionLogin, out ISessionRegister sessionRegister, out ISessionRestorer sessionRestorer, out ISessionReuser sessionReuser, out IOfflineSessionCreator offlineSessionCreator)
    {
        SystemStopwatchFactory    systemStopwatchFactory    = new SystemStopwatchFactory();
        SystemWwwFactory          wwwFactory                = new SystemWwwFactory();
        WwwCallFactory            wwwCallFactory            = new WwwCallFactory(logger, coroutineManager, systemStopwatchFactory, wwwFactory);
        FileSystem                fileSystem                = new FileSystem();
        DatabaseDirectoryCreator  databaseDirectoryCreator  = new DatabaseDirectoryCreator(fileSystem, localStorageDirPath);
        DocumentCollectionFactory documentCollectionFactory = new DocumentCollectionFactory();
        string sdkDatabasesDirectory = databaseDirectoryCreator.GetSdkDatabasesDirectory();
        DatabaseCorruptionHandler databaseCorruptionHandler = new DatabaseCorruptionHandler(logger, fileSystem, sdkDatabasesDirectory);
        SystemRandom    random       = new SystemRandom();
        SystemEpochTime epochTime    = new SystemEpochTime();
        Database        database     = new Database(keychain.LocalStorageKey, random, epochTime, databaseDirectoryCreator, documentCollectionFactory, databaseCorruptionHandler);
        MixWebCallQueue webCallQueue = new MixWebCallQueue();
        MixSessionStartWebCallEncryptor sessionStartEncryptor    = new MixSessionStartWebCallEncryptor();
        MixWebCallFactoryFactory        mixWebCallFactoryFactory = new MixWebCallFactoryFactory(logger, mixApiHostUrl, mixClientToken, wwwCallFactory, webCallQueue, epochTime, database);
        NotificationDispatcher          notificationDispatcher   = new NotificationDispatcher();
        NotificationQueue          notificationQueue             = new NotificationQueue(notificationDispatcher);
        SessionStatus              sessionStatus           = new SessionStatus(isPaused: true);
        NoOpSessionRefresher       sessionRefresher        = new NoOpSessionRefresher();
        JsonWebCallEncryptor       webCallEncryptor        = new JsonWebCallEncryptor();
        IMixWebCallFactory         webCallFactory          = mixWebCallFactoryFactory.Create(webCallEncryptor, string.Empty, string.Empty, sessionRefresher);
        RsaEncryptor               rsaEncryptor            = new RsaEncryptor();
        MixEncryptor               encryptor               = new MixEncryptor();
        MixWebCallEncryptorFactory webCallEncryptorFactory = new MixWebCallEncryptorFactory(encryptor);
        SessionRefresherFactory    sessionRefresherFactory = new SessionRefresherFactory(webCallQueue);
        MixSessionStarter          mixSessionStarter       = new MixSessionStarter(logger, rsaEncryptor, database, webCallEncryptorFactory, sessionStartEncryptor, mixWebCallFactoryFactory, keychain, coroutineManager, sessionRefresherFactory);
        IStopwatch pollCountdownStopwatch = systemStopwatchFactory.Create();
        GuestControllerClientFactory guestControllerClientFactory = new GuestControllerClientFactory(wwwCallFactory, guestControllerSpoofedIpAddress, database, guestControllerHostUrl, oneIdClientId, logger);
        SessionFactory sessionFactory = new SessionFactory(logger, coroutineManager, pollCountdownStopwatch, epochTime, databaseCorruptionHandler, notificationQueue, notificationDispatcher, sessionStatus, mixWebCallFactoryFactory, webCallEncryptorFactory, mixSessionStarter, keychain, sessionRefresherFactory, guestControllerClientFactory, random, encryptor, fileSystem, wwwCallFactory, localStorageDirPath, clientVersion, databaseDirectoryCreator, documentCollectionFactory, database);
        AgeBandBuilder ageBandBuilder = new AgeBandBuilder(logger, webCallFactory);

        Disney.Mix.SDK.Internal.RegistrationConfigurationGetter registrationConfigurationGetter = new Disney.Mix.SDK.Internal.RegistrationConfigurationGetter(logger, guestControllerClientFactory, ageBandBuilder);
        LegalMarketingErrorsBuilder legalMarketingErrorsBuilder = new LegalMarketingErrorsBuilder(registrationConfigurationGetter, languageCode, epochTime);

        sessionLogin          = new SessionLogin(logger, guestControllerClientFactory, mixSessionStarter, database, legalMarketingErrorsBuilder, sessionFactory);
        sessionRegister       = new SessionRegister(logger, guestControllerClientFactory, database, mixSessionStarter, sessionFactory);
        sessionRestorer       = new SessionRestorer(logger, guestControllerClientFactory, database, sessionFactory);
        sessionReuser         = new SessionReuser(logger, database, mixSessionStarter, sessionFactory);
        offlineSessionCreator = new OfflineSessionCreator(logger, sessionFactory, database);
    }
Example #17
0
 public static void Expire(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, Action <bool> callback)
 {
     try
     {
         BaseUserRequest request = new BaseUserRequest();
         IWebCall <BaseUserRequest, BaseResponse> webCall = mixWebCallFactory.IntegrationTestSupportUserSessionExpirePost(request);
         webCall.OnResponse += delegate
         {
             callback(obj: true);
         };
         webCall.OnError += delegate
         {
             callback(obj: false);
         };
         webCall.Execute();
     }
     catch (Exception arg)
     {
         logger.Critical("Unhandled exception: " + arg);
         callback(obj: false);
     }
 }
Example #18
0
 public static void TemporarilyBan(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, Action <bool> callback)
 {
     try
     {
         BaseUserRequest request = new BaseUserRequest();
         IWebCall <BaseUserRequest, BaseResponse> webCall = mixWebCallFactory.IntegrationTestSupportModerationTempBanPut(request);
         webCall.OnResponse += delegate
         {
             callback(obj: true);
         };
         webCall.OnError += delegate
         {
             callback(obj: false);
         };
         webCall.Execute();
     }
     catch (Exception ex)
     {
         logger.Critical("Unhandled exception: " + ex);
         callback(obj: false);
     }
 }
 public static void ValidateDisplayNames(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, IEnumerable <string> displayNames, Action <IValidateDisplayNamesResult> callback)
 {
     try
     {
         List <string> list = new List <string>();
         list.AddRange(displayNames);
         ValidateDisplayNamesRequest validateRequest = new ValidateDisplayNamesRequest
         {
             DisplayNames = list
         };
         IWebCall <ValidateDisplayNamesRequest, ValidateDisplayNamesResponse> webCall = mixWebCallFactory.DisplaynameValidatePost(validateRequest);
         webCall.OnResponse += delegate(object sender, WebCallEventArgs <ValidateDisplayNamesResponse> e)
         {
             ValidateDisplayNamesResponse response = e.Response;
             if (response.DisplayNames != null)
             {
                 callback(new ValidateDisplayNamesResult(success: true, response.DisplayNames));
             }
             else
             {
                 string text = string.Join(",", validateRequest.DisplayNames.ToArray());
                 logger.Critical("Failed to validate display names " + text);
                 callback(new ValidateDisplayNamesResult(success: false, Enumerable.Empty <string>()));
             }
         };
         webCall.OnError += delegate
         {
             callback(new ValidateDisplayNamesResult(success: false, Enumerable.Empty <string>()));
         };
         webCall.Execute();
     }
     catch (Exception ex)
     {
         logger.Critical("Unhandled exception: " + ex);
         callback(new ValidateDisplayNamesResult(success: false, Enumerable.Empty <string>()));
     }
 }
 public static void ValidateDisplayNameV2(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, string displayName, Action <IValidateDisplayNameResult> callback)
 {
     try
     {
         ValidateDisplayNameRequest validateDisplayNameRequest = new ValidateDisplayNameRequest();
         validateDisplayNameRequest.DisplayName = displayName;
         ValidateDisplayNameRequest request = validateDisplayNameRequest;
         IWebCall <ValidateDisplayNameRequest, ValidateDisplayNameResponse> webCall = mixWebCallFactory.DisplaynameValidateV2Post(request);
         webCall.OnResponse += delegate(object sender, WebCallEventArgs <ValidateDisplayNameResponse> e)
         {
             ValidateDisplayNameResponse response = e.Response;
             if (response.DisplayNameStatus == "VALID")
             {
                 callback(new ValidateDisplayNameResult(success: true));
             }
             else if (response.DisplayNameStatus == "IN_USE")
             {
                 callback(new ValidateDisplayNameExistsResult(success: false, response.DisplayNames));
             }
             else
             {
                 callback(new ValidateDisplayNameFailedModerationResult(success: false));
             }
         };
         webCall.OnError += delegate
         {
             callback(new ValidateDisplayNameFailedModerationResult(success: false));
         };
         webCall.Execute();
     }
     catch (Exception ex)
     {
         logger.Critical("Unhandled exception: " + ex);
         callback(new ValidateDisplayNameFailedModerationResult(success: false));
     }
 }
 public static void Unfriend(AbstractLogger logger, INotificationQueue notificationQueue, IMixWebCallFactory mixWebCallFactory, string friendSwid, Action successCallback, Action failureCallback)
 {
     try
     {
         RemoveFriendshipRequest removeFriendshipRequest = new RemoveFriendshipRequest();
         removeFriendshipRequest.FriendUserId = friendSwid;
         RemoveFriendshipRequest request = removeFriendshipRequest;
         IWebCall <RemoveFriendshipRequest, RemoveFriendshipResponse> webCall = mixWebCallFactory.FriendshipDeletePost(request);
         webCall.OnResponse += delegate(object sender, WebCallEventArgs <RemoveFriendshipResponse> e)
         {
             RemoveFriendshipResponse     response     = e.Response;
             RemoveFriendshipNotification notification = response.Notification;
             if (NotificationValidator.Validate(notification))
             {
                 notificationQueue.Dispatch(notification, successCallback, failureCallback);
             }
             else
             {
                 logger.Critical("Failed to validate remove friendship response: " + JsonParser.ToJson(response));
                 failureCallback();
             }
         };
         webCall.OnError += delegate
         {
             failureCallback();
         };
         webCall.Execute();
     }
     catch (Exception arg)
     {
         logger.Critical("Unhandled exception: " + arg);
         failureCallback();
     }
 }
 public AgeBandBuilder(AbstractLogger logger, IMixWebCallFactory webCallFactory)
 {
     this.logger         = logger;
     this.webCallFactory = webCallFactory;
 }
Example #23
0
 public static void SendMassPushNotification(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, Action <bool> callback)
 {
     logger.Critical("Not Implemented : SendMassPushNotification");
     callback(obj: false);
 }
Example #24
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));
            });
        }
Example #25
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));
 }
Example #26
0
        public static void DisableVisiblePushNotifications(AbstractLogger logger, IDatabase database, IMixWebCallFactory mixWebCallFactory, string swid, Action <IDisableVisiblePushNotificationsResult> callback)
        {
            SessionDocument sessionDocument = database.GetSessionDocument(swid);

            if (sessionDocument.PushNotificationToken == null)
            {
                callback(new DisableVisiblePushNotificationsResult(success: false));
                return;
            }
            Enable(logger, database, mixWebCallFactory, sessionDocument.PushNotificationToken, sessionDocument.PushNotificationTokenType, sessionDocument.ProvisionId, enableVisible: false, swid, delegate
            {
                callback(new DisableVisiblePushNotificationsResult(success: true));
            }, delegate
            {
                callback(new DisableVisiblePushNotificationsResult(success: false));
            });
        }
 public static void GetChildren(AbstractLogger logger, IGuestControllerClient guestControllerClient, IMixWebCallFactory mixWebCallFactory, Action <IGetLinkedUsersResult> callback)
 {
     try
     {
         guestControllerClient.GetClaimableChildren(delegate(GuestControllerResult <ChildrenResponse> r)
         {
             HandleGetClaimableChildrenResult(logger, mixWebCallFactory, callback, r);
         });
     }
     catch (Exception arg)
     {
         logger.Critical("Unhandled exception: " + arg);
         callback(MakeGenericFailure());
     }
 }
 public static void Send(AbstractLogger logger, INotificationQueue notificationQueue, IMixWebCallFactory mixWebCallFactory, string inviteeDisplayName, bool requestTrust, Action <long> successCallback, Action <ISendFriendInvitationResult> failureCallback)
 {
     try
     {
         AddFriendshipInvitationRequest addFriendshipInvitationRequest = new AddFriendshipInvitationRequest();
         addFriendshipInvitationRequest.InviteeDisplayName = inviteeDisplayName;
         addFriendshipInvitationRequest.IsTrusted          = requestTrust;
         AddFriendshipInvitationRequest request = addFriendshipInvitationRequest;
         IWebCall <AddFriendshipInvitationRequest, AddFriendshipInvitationResponse> webCall = mixWebCallFactory.FriendshipInvitationPut(request);
         webCall.OnResponse += delegate(object sender, WebCallEventArgs <AddFriendshipInvitationResponse> e)
         {
             AddFriendshipInvitationResponse response = e.Response;
             if (NotificationValidator.Validate(response.Notification))
             {
                 notificationQueue.Dispatch(response.Notification, delegate
                 {
                     successCallback(response.Notification.Invitation.FriendshipInvitationId.Value);
                 }, delegate
                 {
                     failureCallback(new SendFriendInvitationResult(success: false, null));
                 });
             }
             else
             {
                 logger.Critical("Failed to validate invitation: " + JsonParser.ToJson(response));
                 failureCallback(new SendFriendInvitationResult(success: false, null));
             }
         };
         webCall.OnError += delegate(object sender, WebCallErrorEventArgs e)
         {
             string status  = e.Status;
             string message = e.Message;
             string text    = status;
             if (text != null && text == "INVITATION_ALREADY_EXISTS")
             {
                 logger.Error("Failed to send invitation because it already exists: " + message);
                 failureCallback(new SendFriendInvitationAlreadyExistsResult(success: false, null));
             }
             else
             {
                 failureCallback(new SendFriendInvitationResult(success: false, null));
             }
         };
         webCall.Execute();
     }
     catch (Exception ex)
     {
         logger.Critical("Unhandled exception: " + ex);
         failureCallback(new SendFriendInvitationResult(success: false, null));
     }
 }
Example #29
0
 public void ReconcileWithLocalUser(IMixWebCallFactory mixWebCallFactory, GetStateResponse response, IInternalLocalUser localUser, IUserDatabase userDatabase)
 {
     ReconcileFriends(response, localUser, userDatabase);
     ReconcileFriendInvitations(response, localUser, userDatabase);
 }
Example #30
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));
     }
 }