public SetupVM( ISettingsService Settings, IConnectivityService Connectivity, [Dispatcher] IScheduler Dispatcher, IDiversityServiceClient Repository ) { this.Repository = Repository; this.Settings = Settings; // On First Page Visit (App Launch) // If There already is a configuration (Settings) // Go To Home Page this.FirstActivation() .SelectMany(_ => Settings.CurrentSettings()) .Select(x => (x != null) ? Page.Home : Page.SetupWelcome) .ToMessage(Messenger); _IsOnlineAvailable = this.ObservableToProperty(Connectivity.WifiAvailable(), x => x.IsOnlineAvailable, false, Dispatcher); // Show current login data in case of Reset Settings.SettingsObservable() .Subscribe(SetLogin); // Command To begin Setup this.ShowLogin = new ReactiveCommand(); ShowLogin.Select(_ => Page.SetupLogin) .ToMessage(Messenger); // Command Condition var userPassAndWifi = Observable.CombineLatest( Connectivity.WifiAvailable(), this.WhenAny(x => x.UserName, x => x.GetValue()).Select(string.IsNullOrWhiteSpace), this.WhenAny(x => x.Password, x => x.GetValue()).Select(string.IsNullOrWhiteSpace), (wifi, a, b) => wifi & !(a | b)); // Command and Errorhandling this.GetRepositories = new ReactiveAsyncCommand(userPassAndWifi); GetRepositories.ShowInFlightNotification(Notifications, DiversityResources.Setup_Info_ValidatingLogin); GetRepositories.ThrownExceptions .ShowServiceErrorNotifications(Notifications) .ShowErrorNotifications(Notifications) .Subscribe(); var loginAndRepo = GetRepositories.RegisterAsyncObservable(GetRepositoriesObservable).Publish().PermaRef(); // Page Navigation if Login Successful // i.e. Any repositories have been returned loginAndRepo .Snd() .Subscribe(NavigateOrNotifyInvalidCredentials); // Repo Selection this.Database = new ListSelectionHelper<string>(Dispatcher); loginAndRepo .Select(t => t.Item2) .Merge(EmptyProjectsOnLoginStart()) .Subscribe(Database.ItemsObserver); // Settings Propagation LatestLogin = loginAndRepo .Fst() .MostRecent(null) .GetEnumerator(); // Command Condition var repoSelected = Database.SelectedItemObservable .Select(repo => repo != NoRepo) .AndNoItemsInFlight(GetRepositories); // Command and Errorhandling this.GetProjects = new ReactiveAsyncCommand(repoSelected); GetProjects.ShowInFlightNotification(Notifications, DiversityResources.Setup_Info_GettingProjects); GetProjects.ThrownExceptions .ShowServiceErrorNotifications(Notifications) .ShowErrorNotifications(Notifications) .Subscribe(); var loginAndProjects = GetProjects.RegisterAsyncObservable(GetProjectsObservable).Publish().PermaRef(); // Page Navigation loginAndProjects .Select(_ => Page.SetupProject) .ToMessage(Messenger); // Project Selection Project = new ListSelectionHelper<Project>(Dispatcher); loginAndProjects .Snd() .Merge( EmptyReposOnRepoChange() ) .Subscribe(Project.ItemsObserver); // Settings Propagation LatestLoginWithRepo = loginAndProjects .Fst() .MostRecent(null) .GetEnumerator(); // Command Condition var projectSelected = Project.SelectedItemObservable .Select(p => p != NoProject) .AndNoItemsInFlight(GetProjects); // Command and Errorhandling this.GetProfile = new ReactiveAsyncCommand(projectSelected); GetProfile.ShowInFlightNotification(Notifications, DiversityResources.Setup_Info_GettingProfile); GetProfile.ThrownExceptions .ShowServiceErrorNotifications(Notifications) .ShowErrorNotifications(Notifications) .Subscribe(); var loginWithProfile = GetProfile.RegisterAsyncObservable(GetProfileObservable).Publish().PermaRef(); // Page Navigation loginWithProfile .Select(_ => Page.SetupGPS) .ToMessage(Messenger); // Settings Propagation LatestLoginWithProfile = loginWithProfile .MostRecent(null) .GetEnumerator(); // Command And Page Navigation this.Save = new ReactiveAsyncCommand(); Save.RegisterAsyncObservable(SaveSettings) .Select(_ => Page.SetupVocabulary) .ToMessage(Messenger); }