Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        private static IAgeBand CreateAgeBand(SiteConfigurationData siteConfig, ConfigurationAgeBand configurationAgeBand, string configurationAgeBandKey, bool registration, IList <RegistrationText> legalTexts)
        {
            IRegistrationPermissions     permissions             = CreateRegistrationPermissions(registration ? configurationAgeBand.CREATE : configurationAgeBand.UPDATE);
            IEnumerable <ILegalDocument> legalDocuments          = BuildLegalDocs(siteConfig.legal, configurationAgeBandKey, registration, legalTexts);
            IEnumerable <string>         legalDocumentsTypeOrder = GetLegalDocumentsTypeOrder(siteConfig.legal, configurationAgeBandKey);
            IEnumerable <IMarketingItem> marketing = BuildMarketingItems(siteConfig, configurationAgeBandKey, registration, legalTexts);
            AgeBandType type    = AgeBandTypeConverter.Convert(configurationAgeBandKey);
            string      country = configurationAgeBand.country;

            return(new AgeBand(permissions, legalDocuments, legalDocumentsTypeOrder, marketing, type, country));
        }
Ejemplo n.º 3
0
 private static void HandleGetUsersByIdSuccess(AbstractLogger logger, GetUsersResponse response, IList <Profile> profiles, Action <LinkedUser[]> callback)
 {
     try
     {
         if (response.Users == null)
         {
             logger.Critical("Returned users array is null");
             callback(null);
             return;
         }
         Dictionary <Profile, User> profileToUser = new Dictionary <Profile, User>();
         foreach (Profile profile2 in profiles)
         {
             List <User>       users     = response.Users;
             Func <User, bool> predicate = (User u) => profile2.swid == u.UserId;
             User user = users.FirstOrDefault(predicate);
             if (user == null)
             {
                 logger.Critical("Returned users doesn't have " + profile2.swid + ": " + response.Users);
                 callback(null);
                 return;
             }
             profileToUser[profile2] = user;
         }
         LinkedUser[] obj = profiles.Select(delegate(Profile profile)
         {
             DateTime?dateOfBirth    = GuestControllerUtils.ParseDateTime(logger, profile.dateOfBirth);
             AgeBandType ageBand     = AgeBandTypeConverter.Convert(profile.ageBand);
             User user2              = profileToUser[profile];
             DisplayName displayName = new DisplayName(user2.DisplayName);
             return(new LinkedUser(profile.username, profile.firstName, profile.lastName, displayName, profile.email, profile.parentEmail, ageBand, dateOfBirth, profile.swid));
         }).ToArray();
         callback(obj);
     }
     catch (Exception ex)
     {
         logger.Critical("Unhandled exception: " + ex);
         callback(null);
     }
 }
Ejemplo n.º 4
0
 private static bool ValidateAgeBandKey(string key)
 {
     return(AgeBandTypeConverter.Convert(key) != AgeBandType.Unknown);
 }