private IObservable <string> GetPasswordsSequence()
        {
            var isUserBased     = this.WhenAnyValue(x => x.IsUserLogon);
            var userBasedLogon  = UserBasedLogin.WhenAnyValue(x => x.Password);
            var emailBasedLogon = EmailBasedLogin.WhenAnyValue(x => x.VerifiedPassword);
            var usernames       = userBasedLogon.CombineLatest(emailBasedLogon, (u, w) => new { Username = u, Email = w });
            var sequence        = isUserBased.CombineLatest(usernames, (userBased, user) => userBased ? user.Username : user.Email);

            return(sequence);
        }
        public SettingsViewModel(FileOpenCommands commands, IDialogService dialogService, IVirtualDashboardsRepository virtualDashboardsRepository)
        {
            this.virtualDashboardsRepository = virtualDashboardsRepository;
            settings            = new SettingsSaver(this, ApplicationData.Current.RoamingSettings);
            BrowseFolderCommand = commands.BrowseFolderCommand;
            BrowseFolderCommand.Subscribe(x =>
            {
                if (VideoFolderToken != null)
                {
                    StorageApplicationPermissions.FutureAccessList.Clear();
                }

                var token        = StorageApplicationPermissions.FutureAccessList.Add(x);
                VideoFolder      = x.Path;
                VideoFolderToken = token;
            });

            videoFolder         = BrowseFolderCommand.ToProperty(this, x => x.Folder);
            IsAccountConfigured = this.WhenAnyValue(x => x.Username, x => x.Password,
                                                    (u, p) => new[] { u, p }.All(s => !string.IsNullOrEmpty(s)));

            IsVideoFolderFolderConfigured = this.WhenAnyValue(x => x.VideoFolder, x => !string.IsNullOrEmpty(x));

            UnitPack = UnitPacks.FirstOrDefault(pack => pack.Id == StringUnitPack) ?? UnitPacks.First();
            this.WhenAnyValue(x => x.UnitPack).Subscribe(x => StringUnitPack = UnitPack.Id);

            RemoveFolderCommand = ReactiveCommand.Create(() =>
            {
                StorageApplicationPermissions.FutureAccessList.Clear();

                VideoFolder      = null;
                VideoFolderToken = null;
            }, this.WhenAnyValue(x => x.VideoFolderToken, selector: s => s != null));

            UserBasedLogin  = new UserBasedLogin();
            EmailBasedLogin = new EmailBasedLogin(dialogService);

            var usernamesSequence = GetUsernamesSequence();
            var passwordSequence  = GetPasswordsSequence();


            username = usernamesSequence.ToProperty(this, x => x.Username);
            password = passwordSequence.ToProperty(this, x => x.Password);

            dashboardPreview =
                this.WhenAnyValue(x => x.VirtualDashboard, x => x.UnitPack,
                                  (vd, up) => CreatePreviewViewModel(up, vd)).ToProperty(this, x => x.DashboardPreview);
        }