Пример #1
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);
     };
 }
Пример #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);
        }
Пример #3
0
 public AgeBand(IRegistrationPermissions permissions, IEnumerable <ILegalDocument> legalDocuments, IEnumerable <string> legalDocumentsTypeOrder, IEnumerable <IMarketingItem> marketing, AgeBandType type, string countryCode)
 {
     Permissions             = permissions;
     LegalDocuments          = legalDocuments;
     LegalDocumentsTypeOrder = legalDocumentsTypeOrder;
     Marketing   = marketing;
     AgeBandType = type;
     CountryCode = countryCode;
 }
    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));
    }
Пример #5
0
 private void GetChildTrustPermission(string childSwid, AgeBandType childAgeBand, Action <IPermissionResult> callback)
 {
     if (childAgeBand == AgeBandType.Adult || childAgeBand == AgeBandType.Teen)
     {
         callback(new PermissionNotRequiredResult());
     }
     else
     {
         PermissionGetter.GetPermission(logger, guestControllerClient, "MIX_TRUSTEDFRIENDSCOMMUNICATIONS", childSwid, callback);
     }
 }
Пример #6
0
 public LinkedUser(string username, string firstName, string lastName, IDisplayName displayName, string email, string parentEmail, AgeBandType ageBand, DateTime?dateOfBirth, string swid)
 {
     Username    = username;
     FirstName   = firstName;
     LastName    = lastName;
     DisplayName = displayName;
     Email       = email;
     ParentEmail = parentEmail;
     AgeBand     = ageBand;
     DateOfBirth = dateOfBirth;
     Swid        = swid;
 }
Пример #7
0
 private void ApproveChildTrustPermission(string childSwid, AgeBandType childAgeBand, ActivityApprovalStatus status, Action <IPermissionResult> callback)
 {
     if (AgeBandType != AgeBandType.Adult)
     {
         callback(new PermissionFailedNotAdultResult());
     }
     else if (childAgeBand == AgeBandType.Adult || childAgeBand == AgeBandType.Teen)
     {
         callback(new PermissionNotRequiredResult());
     }
     else
     {
         PermissionApprover.ApprovePermission(logger, guestControllerClient, "MIX_TRUSTEDFRIENDSCOMMUNICATIONS", childSwid, status, callback);
     }
 }
Пример #8
0
    public static string Convert(AgeBandType ageBand)
    {
        switch (ageBand)
        {
        case AgeBandType.Adult:
            return("ADULT");

        case AgeBandType.Teen:
            return("TEEN");

        case AgeBandType.Child:
            return("CHILD");

        default:
            return("UNKNOWN");
        }
    }
Пример #9
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);
     }
 }