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); }
private void CreateKeyValues(Action <IDocumentCollection <KeyValueDocument> > operation) { string dirPath = directoryCreator.CreateSdkDirectory("KeyValues"); try { using (IDocumentCollection <KeyValueDocument> documentCollection = documentCollectionFactory.CreateHighSecurityFileSystemCollection <KeyValueDocument>(dirPath, encryptionKey)) { databaseCorruptionHandler.Add(documentCollection); operation(documentCollection); databaseCorruptionHandler.Remove(documentCollection); } } catch (CorruptionException ex) { databaseCorruptionHandler.HandleCorruption(ex); throw; } }