public UserGistsViewModel(IApplicationService applicationService) { _applicationService = applicationService; Username = _applicationService.Account.Username; GoToCreateGistCommand = ReactiveCommand.Create(); GoToCreateGistCommand.Subscribe(_ => { var vm = this.CreateViewModel <GistCreateViewModel>(); NavigateTo(vm); }); this.WhenAnyValue(x => x.Username).Subscribe(x => { if (IsMine) { Title = "My Gists"; } else if (x == null) { Title = "Gists"; } else if (x.EndsWith("s", StringComparison.OrdinalIgnoreCase)) { Title = x + "' Gists"; } else { Title = x + "'s Gists"; } }); }
public IssueEditViewModel(IApplicationService applicationService) { _applicationService = applicationService; GoToDescriptionCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)); GoToDescriptionCommand.Subscribe(_ => { var vm = CreateViewModel <ComposerViewModel>(); vm.Text = Issue.Body; vm.SaveCommand.Subscribe(__ => { Issue.Body = vm.Text; vm.DismissCommand.ExecuteIfCan(); }); ShowViewModel(vm); }); this.WhenAnyValue(x => x.Issue).Where(x => x != null).Subscribe(x => { Title = x.Title; AssignedTo = x.Assignee; Milestone = x.Milestone; Labels = x.Labels.ToArray(); Content = x.Body; IsOpen = string.Equals(x.State, "open"); }); }
public MyIssuesViewModel(ISessionService sessionService) : base(sessionService) { _sessionService = sessionService; Title = "My Issues"; Filter = MyIssuesFilterModel.CreateOpenFilter(); _selectedFilter = this.WhenAnyValue(x => x.Filter) .Select(x => { if (x == null || _openFilter.Equals(x)) return 0; return _closedFilter.Equals(x) ? 1 : -1; }) .ToProperty(this, x => x.SelectedFilter); this.WhenAnyValue(x => x.Filter).Skip(1).Subscribe(filter => { InternalItems.Clear(); LoadCommand.ExecuteIfCan(); CustomFilterEnabled = !(filter == _closedFilter || filter == _openFilter); }); GoToFilterCommand = ReactiveCommand.Create(); GoToFilterCommand.Subscribe(_ => { var vm = this.CreateViewModel<MyIssuesFilterViewModel>(); vm.Init(Filter); vm.SaveCommand.Subscribe(filter => Filter = filter); NavigateTo(vm); }); }
public EditSourceViewModel(IApplicationService applicationService) { SaveCommand = ReactiveCommand.Create(); SaveCommand.Subscribe(_ => { var vm = CreateViewModel<CommitMessageViewModel>(); vm.Username = Username; vm.Repository = Repository; vm.Path = Path; vm.Text = Text; vm.BlobSha = BlobSha; vm.Branch = Branch; vm.ContentChanged.Subscribe(x => Content = x); ShowViewModel(vm); }); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { var path = Path; if (!path.StartsWith("/", StringComparison.Ordinal)) path = "/" + path; var request = applicationService.Client.Users[Username].Repositories[Repository].GetContentFile(path, Branch ?? "master"); request.UseCache = false; var data = await applicationService.Client.ExecuteAsync(request); BlobSha = data.Data.Sha; var content = Convert.FromBase64String(data.Data.Content); Text = System.Text.Encoding.UTF8.GetString(content, 0, content.Length); }); }
public MainWindowViewModel() { Editor = new NitraTextEditorViewModel(this); Settings = Settings.Default; var canFindSymbolDefinitions = this.WhenAny(v => v.CurrentSuite, v => v.CurrentFile, (suite, test) => suite != null && test != null); FindSymbolDefinitions = ReactiveCommand.Create(canFindSymbolDefinitions); FindSymbolDefinitions.ThrownExceptions.Subscribe(e => StatusText = "GOTO definition failed!"); FindSymbolDefinitions.Subscribe(OnFindSymbolDefinitions); FindSymbolReferences = ReactiveCommand.Create(canFindSymbolDefinitions); FindSymbolReferences.ThrownExceptions.Subscribe(e => StatusText = "Find all references definition failed!"); FindSymbolReferences.Subscribe(OnFindSymbolReferences); Changing.Where(c => c.PropertyName == "Workspace") .Subscribe(_ => { if (Workspace != null) { Workspace.Dispose(); } }); }
public IssueEditViewModel(IApplicationService applicationService) { _applicationService = applicationService; GoToDescriptionCommand = new ReactiveCommand(this.WhenAnyValue(x => x.Issue, x => x != null)); GoToDescriptionCommand.Subscribe(_ => { var vm = CreateViewModel<ComposerViewModel>(); vm.Text = Issue.Body; vm.SaveCommand.Subscribe(__ => { Issue.Body = vm.Text; vm.DismissCommand.ExecuteIfCan(); }); ShowViewModel(vm); }); this.WhenAnyValue(x => x.Issue).Where(x => x != null).Subscribe(x => { Title = x.Title; AssignedTo = x.Assignee; Milestone = x.Milestone; Labels = x.Labels.ToArray(); Content = x.Body; IsOpen = string.Equals(x.State, "open"); }); }
public MyIssuesViewModel(ISessionService sessionService) : base(sessionService) { _sessionService = sessionService; Title = "My Issues"; Filter = MyIssuesFilterModel.CreateOpenFilter(); _selectedFilter = this.WhenAnyValue(x => x.Filter) .Select(x => { if (x == null || _openFilter.Equals(x)) { return(0); } return(_closedFilter.Equals(x) ? 1 : -1); }) .ToProperty(this, x => x.SelectedFilter); this.WhenAnyValue(x => x.Filter).Skip(1).Subscribe(filter => { IssuesBacking.Clear(); LoadCommand.ExecuteIfCan(); CustomFilterEnabled = !(filter == _closedFilter || filter == _openFilter); }); GoToFilterCommand = ReactiveCommand.Create(); GoToFilterCommand.Subscribe(_ => { var vm = this.CreateViewModel <MyIssuesFilterViewModel>(); vm.Init(Filter); vm.SaveCommand.Subscribe(filter => Filter = filter); NavigateTo(vm); }); }
public LanguagesViewModel() { Title = "Languages"; DismissCommand = ReactiveCommand.Create(); DismissCommand.Subscribe(_ => this.Dismiss()); Items = InternalItems.CreateDerivedCollection( x => new LanguageItemViewModel(x.Name, x.Slug), filter: x => x.Name.StartsWith(SearchKeyword ?? string.Empty, StringComparison.OrdinalIgnoreCase), signalReset: this.WhenAnyValue(x => x.SearchKeyword)); Items .Changed.Select(_ => Unit.Default) .Merge(this.WhenAnyValue(x => x.SelectedLanguage).Select(_ => Unit.Default)) .Select(_ => SelectedLanguage) .Where(x => x != null) .Subscribe(x => { foreach (var l in Items) { l.Selected = l.Slug == x.Slug; } }); this.WhenAnyValue(x => x.SelectedLanguage) .IsNotNull() .Subscribe(_ => Dismiss()); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { var languageRepository = new LanguageRepository(); var langs = await languageRepository.GetLanguages(); langs.Insert(0, LanguageRepository.DefaultLanguage); InternalItems.Reset(langs); }); }
public EditSourceViewModel(IApplicationService applicationService) { SaveCommand = ReactiveCommand.Create(); SaveCommand.Subscribe(_ => { var vm = CreateViewModel <CommitMessageViewModel>(); vm.Username = Username; vm.Repository = Repository; vm.Path = Path; vm.Text = Text; vm.BlobSha = BlobSha; vm.Branch = Branch; vm.ContentChanged.Subscribe(x => Content = x); ShowViewModel(vm); }); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { var path = Path; if (!path.StartsWith("/", StringComparison.Ordinal)) { path = "/" + path; } var request = applicationService.Client.Users[Username].Repositories[Repository].GetContentFile(path, Branch ?? "master"); request.UseCache = false; var data = await applicationService.Client.ExecuteAsync(request); BlobSha = data.Data.Sha; var content = Convert.FromBase64String(data.Data.Content); Text = System.Text.Encoding.UTF8.GetString(content, 0, content.Length); }); }
internal BubbleViewModel(BubbleMatrixViewModel bubbleMatrix, int row, int column) { if (bubbleMatrix == null) { throw new ArgumentNullException("bubbleMatrix"); } if (row < 0 || bubbleMatrix.RowCount <= row) { throw new ArgumentOutOfRangeException("row"); } if (column < 0 || bubbleMatrix.ColumnCount <= column) { throw new ArgumentOutOfRangeException("column"); } _bubbleMatrix = bubbleMatrix; MoveTo(row, column); this.BubbleType = GetRandomBubbleType(); BurstBubbleGroupCommand = new ReactiveCommand(); BurstBubbleGroupCommand.Subscribe(x => _bubbleMatrix.BurstBubbleGroup()); }
public EditSourceViewModel(IApplicationService applicationService) { SaveCommand = new ReactiveCommand(); SaveCommand.Subscribe(_ => { var vm = CreateViewModel<CommitMessageViewModel>(); vm.SaveCommand.RegisterAsyncTask(async t => { var request = applicationService.Client.Users[Username].Repositories[Repository] .UpdateContentFile(Path, vm.Message, Text, BlobSha, Branch); var response = await applicationService.Client.ExecuteAsync(request); Content = response.Data; DismissCommand.ExecuteIfCan(); }); ShowViewModel(vm); }); LoadCommand.RegisterAsyncTask(async t => { var path = Path; if (!path.StartsWith("/", StringComparison.Ordinal)) path = "/" + path; var request = applicationService.Client.Users[Username].Repositories[Repository].GetContentFile(path, Branch ?? "master"); request.UseCache = false; var data = await applicationService.Client.ExecuteAsync(request); BlobSha = data.Data.Sha; Text = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(data.Data.Content)); }); }
public UserGistsViewModel(ISessionService sessionService) : base(sessionService) { _sessionService = sessionService; Username = _sessionService.Account.Username; GoToCreateGistCommand = ReactiveCommand.Create(); GoToCreateGistCommand.Subscribe(_ => { var vm = this.CreateViewModel<GistCreateViewModel>(); vm.SaveCommand .Delay(TimeSpan.FromMilliseconds(200)) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => InternalItems.Insert(0, x)); NavigateTo(vm); }); this.WhenAnyValue(x => x.Username).Subscribe(x => { if (IsMine) Title = "My Gists"; else if (x == null) Title = "Gists"; else if (x.EndsWith("s", StringComparison.OrdinalIgnoreCase)) Title = x + "' Gists"; else Title = x + "'s Gists"; }); }
public RepositoryCloneViewModel( IRepositoryHost repositoryHost, IRepositoryCloneService cloneService, IOperatingSystem operatingSystem, INotificationService notificationService) { this.repositoryHost = repositoryHost; this.cloneService = cloneService; this.operatingSystem = operatingSystem; this.notificationService = notificationService; Title = string.Format(CultureInfo.CurrentCulture, Resources.CloneTitle, repositoryHost.Title); Repositories = new ReactiveList <IRepositoryModel>(); loadRepositoriesCommand = ReactiveCommand.CreateAsyncObservable(OnLoadRepositories); isLoading = this.WhenAny(x => x.LoadingFailed, x => x.Value) .CombineLatest(loadRepositoriesCommand.IsExecuting, (failed, loading) => !failed && loading) .ToProperty(this, x => x.IsLoading); loadRepositoriesCommand.Subscribe(Repositories.AddRange); filterTextIsEnabled = this.WhenAny(x => x.Repositories.Count, x => x.Value > 0) .ToProperty(this, x => x.FilterTextIsEnabled); noRepositoriesFound = this.WhenAny(x => x.FilterTextIsEnabled, x => x.IsLoading, x => x.LoadingFailed , (any, loading, failed) => !any.Value && !loading.Value && !failed.Value) .ToProperty(this, x => x.NoRepositoriesFound); var filterResetSignal = this.WhenAny(x => x.FilterText, x => x.Value) .DistinctUntilChanged(StringComparer.OrdinalIgnoreCase) .Throttle(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler); FilteredRepositories = Repositories.CreateDerivedCollection( x => x, filter: FilterRepository, signalReset: filterResetSignal ); var baseRepositoryPath = this.WhenAny( x => x.BaseRepositoryPath, x => x.SelectedRepository, (x, y) => x.Value); BaseRepositoryPathValidator = ReactivePropertyValidator.ForObservable(baseRepositoryPath) .IfNullOrEmpty("Please enter a repository path") .IfTrue(x => x.Length > 200, "Path too long") .IfContainsInvalidPathChars("Path contains invalid characters") .IfPathNotRooted("Please enter a valid path") .IfTrue(IsAlreadyRepoAtPath, Resources.RepositoryNameValidatorAlreadyExists); var canCloneObservable = this.WhenAny( x => x.SelectedRepository, x => x.BaseRepositoryPathValidator.ValidationResult.IsValid, (x, y) => x.Value != null && y.Value); canClone = canCloneObservable.ToProperty(this, x => x.CanClone); CloneCommand = ReactiveCommand.CreateAsyncObservable(canCloneObservable, OnCloneRepository); browseForDirectoryCommand.Subscribe(_ => ShowBrowseForDirectoryDialog()); this.WhenAny(x => x.BaseRepositoryPathValidator.ValidationResult, x => x.Value) .Subscribe(); BaseRepositoryPath = cloneService.DefaultClonePath; }
/// <summary> /// Bind ReactiveCommand to button's interactable and onClick and register onClick action to command. /// </summary> public static IDisposable BindToOnClick(this IReactiveCommand <Unit> command, UnityEngine.UI.Button button, Action <Unit> onClick) { var d1 = command.CanExecute.SubscribeToInteractable(button); var d2 = button.OnClickAsObservable().SubscribeWithState(command, (x, c) => c.Execute(x)); var d3 = command.Subscribe(onClick); return(StableCompositeDisposable.Create(d1, d2, d3)); }
protected GistFileModifyViewModel(Func<Tuple<string, string>, Task> saveFunc) { var validObservable = this.WhenAnyValue(x => x.Filename, x => x.Description, (x, y) => !string.IsNullOrEmpty(x) && !string.IsNullOrEmpty(y)); SaveCommand = ReactiveCommand.CreateAsyncTask(validObservable, async _ => await saveFunc(Tuple.Create(Filename, Description))); SaveCommand.Subscribe(_ => Dismiss()); }
protected GistFileModifyViewModel(Func <Tuple <string, string>, Task> saveFunc) { var validObservable = this.WhenAnyValue(x => x.Filename, x => x.Description, (x, y) => !string.IsNullOrEmpty(x) && !string.IsNullOrEmpty(y)); SaveCommand = ReactiveCommand.CreateAsyncTask(validObservable, async _ => await saveFunc(Tuple.Create(Filename, Description))); SaveCommand.Subscribe(_ => Dismiss()); }
public GistCommentViewModel(IApplicationService applicationService, IImgurService imgurService, IMediaPickerFactory mediaPicker, IAlertDialogFactory alertDialogFactory) : base(imgurService, mediaPicker, alertDialogFactory) { Title = "Add Comment"; SaveCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Text).Select(x => !string.IsNullOrEmpty(x)), async t => await applicationService.GitHubClient.Gist.Comment.Create(int.Parse(Id), Text)); SaveCommand.Subscribe(x => Dismiss()); }
public IssueCommentViewModel(IApplicationService applicationService, IImgurService imgurService, IMediaPickerFactory mediaPicker, IAlertDialogFactory alertDialogFactory) : base(imgurService, mediaPicker, alertDialogFactory) { Title = "Add Comment"; SaveCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Text).Select(x => !string.IsNullOrEmpty(x)), t => applicationService.GitHubClient.Issue.Comment.Create(RepositoryOwner, RepositoryName, Id, Text)); SaveCommand.Subscribe(x => Dismiss()); }
public static Task <T> WaitUntilExecuteAsync <T>(this IReactiveCommand <T> source, CancellationToken cancellationToken = default(CancellationToken)) { var tcs = new CancellableTaskCompletionSource <T>(); var subscription = source.Subscribe(x => tcs.TrySetResult(x), ex => tcs.TrySetException(ex), () => tcs.TrySetCanceled()); cancellationToken.Register(Callback, Tuple.Create(tcs, subscription), false); return(tcs.Task); }
public IssueCommentViewModel(IApplicationService applicationService) { Title = "Add Comment"; SaveCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Text).Select(x => !string.IsNullOrEmpty(x)), async t => { var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[Id].CreateComment(Text); return((await applicationService.Client.ExecuteAsync(request)).Data); }); SaveCommand.Subscribe(x => Dismiss()); }
public OrganizationViewModel(IApplicationService applicationService) { GoToMembersCommand = new ReactiveCommand(); GoToMembersCommand.Subscribe(_ => { var vm = CreateViewModel<OrganizationMembersViewModel>(); vm.OrganizationName = Name; ShowViewModel(vm); }); GoToTeamsCommand = new ReactiveCommand(); GoToTeamsCommand.Subscribe(_ => { var vm = CreateViewModel<TeamsViewModel>(); vm.OrganizationName = Name; ShowViewModel(vm); }); GoToFollowersCommand = new ReactiveCommand(); GoToFollowersCommand.Subscribe(_ => { var vm = CreateViewModel<UserFollowersViewModel>(); vm.Username = Name; ShowViewModel(vm); }); GoToEventsCommand = new ReactiveCommand(); GoToEventsCommand.Subscribe(_ => { var vm = CreateViewModel<UserEventsViewModel>(); vm.Username = Name; ShowViewModel(vm); }); GoToGistsCommand = new ReactiveCommand(); GoToGistsCommand.Subscribe(_ => { var vm = CreateViewModel<UserGistsViewModel>(); vm.Username = Name; ShowViewModel(vm); }); GoToRepositoriesCommand = new ReactiveCommand(); GoToRepositoriesCommand.Subscribe(_ => { var vm = CreateViewModel<OrganizationRepositoriesViewModel>(); vm.Name = Name; ShowViewModel(vm); }); LoadCommand.RegisterAsyncTask(t => this.RequestModel(applicationService.Client.Organizations[Name].Get(), t as bool?, response => Organization = response.Data)); }
public UserGistsViewModel(IApplicationService applicationService) { _applicationService = applicationService; Username = _applicationService.Account.Username; GoToCreateGistCommand = ReactiveCommand.Create(); GoToCreateGistCommand.Subscribe(_ => { var vm = CreateViewModel <GistCreateViewModel>(); ShowViewModel(vm); }); }
public EnterpriseSupportViewModel() { Title = "Support"; SubmitFeedbackCommand = ReactiveCommand.Create(); GoToGitHubCommand = ReactiveCommand.Create(); GoToGitHubCommand.Subscribe(_ => { var vm = this.CreateViewModel<WebBrowserViewModel>(); vm.Init("https://github.com/thedillonb/CodeHub"); NavigateTo(vm); }); }
public EnterpriseSupportViewModel() { Title = "Support"; SubmitFeedbackCommand = ReactiveCommand.Create(); GoToGitHubCommand = ReactiveCommand.Create(); GoToGitHubCommand.Subscribe(_ => { var vm = this.CreateViewModel <WebBrowserViewModel>(); vm.Init("https://github.com/thedillonb/CodeHub"); NavigateTo(vm); }); }
public AboutViewModel(IEnvironmentalService environmentService) { _environmentService = environmentService; GoToSourceCodeCommand = ReactiveCommand.Create(); GoToSourceCodeCommand.Subscribe(x => { var vm = CreateViewModel <RepositoryViewModel>(); vm.RepositoryOwner = "thedillonb"; vm.RepositoryName = "codehub"; ShowViewModel(vm); }); }
public PullRequestCommentViewModel(IApplicationService applicationService) { Title = "Add Comment"; SaveCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Text).Select(x => !string.IsNullOrEmpty(x)), t => { var req = new Octokit.PullRequestReviewCommentCreate(Text, null, null, 0); return(applicationService.GitHubClient.PullRequest.Comment.Create(RepositoryOwner, RepositoryName, Id, req)); }); SaveCommand.Subscribe(x => Dismiss()); }
public CommitCommentViewModel(IApplicationService applicationService, IImgurService imgurService, IMediaPickerFactory mediaPicker, IAlertDialogFactory alertDialogFactory) : base(imgurService, mediaPicker, alertDialogFactory) { SaveCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Text).Select(x => !string.IsNullOrEmpty(x)), t => { var commitComment = new Octokit.NewCommitComment(Text); return(applicationService.GitHubClient.Repository.RepositoryComments.Create(RepositoryOwner, RepositoryName, Node, commitComment)); }); SaveCommand.Subscribe(x => Dismiss()); }
public AboutViewModel(IEnvironmentalService environmentService) { _environmentService = environmentService; GoToSourceCodeCommand = new ReactiveCommand(); GoToSourceCodeCommand.Subscribe(x => { var vm = CreateViewModel<RepositoryViewModel>(); vm.RepositoryOwner = "thedillonb"; vm.RepositoryName = "codehub"; ShowViewModel(vm); }); }
private void LoadCommands() { CommandOpen = ReactiveCommand.Create(Observable.Return(true)); CommandOpen.Subscribe(_ => ExecuteOpen()); CommandSave = ReactiveCommand.Create(Observable.Return(true)); CommandSave.Subscribe(_ => ExecuteSave()); CommandSaveAs = ReactiveCommand.Create(Observable.Return(true)); CommandSaveAs.Subscribe(_ => ExecuteSaveAs()); CommandExit = ReactiveCommand.Create(Observable.Return(true)); CommandExit.Subscribe(_ => ExecuteExit()); }
public IntelliSensePopupViewModel(NitraTextEditorViewModel editor) { Items = new ReactiveList <PopupItemViewModel>(); var canSelect = this.WhenAny(v => v.SelectedPopupItem, item => item.Value != null); Select = ReactiveCommand.Create(canSelect); Select.Subscribe(_ => { editor.SelectText(SelectedPopupItem.File, SelectedPopupItem.Span); IsVisible = false; SelectedPopupItem = null; }); }
public NewAccountViewModel() { GoToDotComLoginCommand = ReactiveCommand.Create(); GoToDotComLoginCommand.Subscribe(_ => CreateAndShowViewModel <LoginViewModel>()); GoToEnterpriseLoginCommand = ReactiveCommand.Create(); GoToEnterpriseLoginCommand.Subscribe(_ => { var vm = CreateViewModel <AddAccountViewModel>(); vm.IsEnterprise = true; ShowViewModel(vm); }); }
public EventItemViewModel( EventModel eventModel, IReadOnlyCollection<BaseEventsViewModel.TextBlock> headerBlocks, IReadOnlyCollection<BaseEventsViewModel.TextBlock> bodyBlocks, Action gotoAction = null) { Event = eventModel; HeaderBlocks = headerBlocks ?? new BaseEventsViewModel.TextBlock[0]; BodyBlocks = bodyBlocks ?? new BaseEventsViewModel.TextBlock[0]; GoToCommand = ReactiveCommand.Create(); if (gotoAction != null) GoToCommand.Subscribe(x => gotoAction()); }
public IntelliSensePopupViewModel(NitraTextEditorViewModel editor) { Items = new ReactiveList<PopupItemViewModel>(); var canSelect = this.WhenAny(v => v.SelectedPopupItem, item => item.Value != null); Select = ReactiveCommand.Create(canSelect); Select.Subscribe(_ => { editor.SelectText(SelectedPopupItem.File, SelectedPopupItem.Span); IsVisible = false; SelectedPopupItem = null; }); }
public RepositoryCloneViewModel( IRepositoryHost repositoryHost, IRepositoryCloneService cloneService, IOperatingSystem operatingSystem, IVSServices vsServices) { this.repositoryHost = repositoryHost; this.cloneService = cloneService; this.operatingSystem = operatingSystem; this.vsServices = vsServices; Title = string.Format(CultureInfo.CurrentCulture, Resources.CloneTitle, repositoryHost.Title); Repositories = new ReactiveList <IRepositoryModel>(); loadRepositoriesCommand = ReactiveCommand.CreateAsyncObservable(OnLoadRepositories); isLoading = this.WhenAny(x => x.LoadingFailed, x => x.Value) .CombineLatest(loadRepositoriesCommand.IsExecuting, (failed, loading) => !failed && loading) .ToProperty(this, x => x.IsLoading); loadRepositoriesCommand.Subscribe(Repositories.AddRange); filterTextIsEnabled = this.WhenAny(x => x.Repositories.Count, x => x.Value > 0) .ToProperty(this, x => x.FilterTextIsEnabled); noRepositoriesFound = this.WhenAny(x => x.FilterTextIsEnabled, x => x.IsLoading, x => x.LoadingFailed , (any, loading, failed) => !any.Value && !loading.Value && !failed.Value) .ToProperty(this, x => x.NoRepositoriesFound); var filterResetSignal = this.WhenAny(x => x.FilterText, x => x.Value) .DistinctUntilChanged(StringComparer.OrdinalIgnoreCase) .Throttle(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler); FilteredRepositories = Repositories.CreateDerivedCollection( x => x, filter: FilterRepository, signalReset: filterResetSignal ); BaseRepositoryPathValidator = this.CreateBaseRepositoryPathValidator(); var canCloneObservable = this.WhenAny( x => x.SelectedRepository, x => x.BaseRepositoryPathValidator.ValidationResult.IsValid, (x, y) => x.Value != null && y.Value); canClone = canCloneObservable.ToProperty(this, x => x.CanClone); CloneCommand = ReactiveCommand.CreateAsyncObservable(canCloneObservable, OnCloneRepository); browseForDirectoryCommand.Subscribe(_ => ShowBrowseForDirectoryDialog()); this.WhenAny(x => x.BaseRepositoryPathValidator.ValidationResult, x => x.Value) .Subscribe(); BaseRepositoryPath = cloneService.DefaultClonePath; }
public static Task <T> WaitUntilExecuteAsync <T>(this IReactiveCommand <T> source, CancellationToken cancellationToken = default(CancellationToken)) { var tcs = new CancellableTaskCompletionSource <T>(); var disposable = new SingleAssignmentDisposable(); disposable.Disposable = source.Subscribe(x => { disposable.Dispose(); // finish subscription. tcs.TrySetResult(x); }, ex => tcs.TrySetException(ex), () => tcs.TrySetCanceled()); cancellationToken.Register(Callback, Tuple.Create(tcs, disposable.Disposable), false); return(tcs.Task); }
public NewAccountViewModel() { GoToDotComLoginCommand = new ReactiveCommand(); GoToDotComLoginCommand.Subscribe(_ => CreateAndShowViewModel<LoginViewModel>()); GoToEnterpriseLoginCommand = new ReactiveCommand(); GoToEnterpriseLoginCommand.Subscribe(_ => { var vm = CreateViewModel<AddAccountViewModel>(); vm.IsEnterprise = true; ShowViewModel(vm); }); }
public RepositoryCloneViewModel( IRepositoryHost repositoryHost, IRepositoryCloneService cloneService, IOperatingSystem operatingSystem, INotificationService notificationService) { this.repositoryHost = repositoryHost; this.cloneService = cloneService; this.operatingSystem = operatingSystem; this.notificationService = notificationService; Title = string.Format(CultureInfo.CurrentCulture, Resources.CloneTitle, repositoryHost.Title); Repositories = new ReactiveList<IRepositoryModel>(); loadRepositoriesCommand = ReactiveCommand.CreateAsyncObservable(OnLoadRepositories); isLoading = this.WhenAny(x => x.LoadingFailed, x => x.Value) .CombineLatest(loadRepositoriesCommand.IsExecuting, (failed, loading) => !failed && loading) .ToProperty(this, x => x.IsLoading); loadRepositoriesCommand.Subscribe(Repositories.AddRange); filterTextIsEnabled = this.WhenAny(x => x.Repositories.Count, x => x.Value > 0) .ToProperty(this, x => x.FilterTextIsEnabled); noRepositoriesFound = this.WhenAny(x => x.FilterTextIsEnabled, x => x.IsLoading, x => x.LoadingFailed , (any, loading, failed) => !any.Value && !loading.Value && !failed.Value) .ToProperty(this, x => x.NoRepositoriesFound); var filterResetSignal = this.WhenAny(x => x.FilterText, x => x.Value) .DistinctUntilChanged(StringComparer.OrdinalIgnoreCase) .Throttle(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler); FilteredRepositories = Repositories.CreateDerivedCollection( x => x, filter: FilterRepository, signalReset: filterResetSignal ); BaseRepositoryPathValidator = this.CreateBaseRepositoryPathValidator(); var canCloneObservable = this.WhenAny( x => x.SelectedRepository, x => x.BaseRepositoryPathValidator.ValidationResult.IsValid, (x, y) => x.Value != null && y.Value); canClone = canCloneObservable.ToProperty(this, x => x.CanClone); CloneCommand = ReactiveCommand.CreateAsyncObservable(canCloneObservable, OnCloneRepository); browseForDirectoryCommand.Subscribe(_ => ShowBrowseForDirectoryDialog()); this.WhenAny(x => x.BaseRepositoryPathValidator.ValidationResult, x => x.Value) .Subscribe(); BaseRepositoryPath = cloneService.DefaultClonePath; }
public EventItemViewModel( EventModel eventModel, IReadOnlyCollection <BaseEventsViewModel.TextBlock> headerBlocks, IReadOnlyCollection <BaseEventsViewModel.TextBlock> bodyBlocks, Action gotoAction = null) { Event = eventModel; HeaderBlocks = headerBlocks ?? new BaseEventsViewModel.TextBlock[0]; BodyBlocks = bodyBlocks ?? new BaseEventsViewModel.TextBlock[0]; GoToCommand = ReactiveCommand.Create(); if (gotoAction != null) { GoToCommand.Subscribe(x => gotoAction()); } }
public MainViewModel(IAccountsService accountsService) { GoToSettingsCommand = new ReactiveCommand(); GoToSettingsCommand.Subscribe(_ => ShowViewModel(CreateViewModel <SettingsViewModel>())); GoToAccountsCommand = new ReactiveCommand(); GoToAccountsCommand.Subscribe(_ => ShowViewModel(CreateViewModel <AccountsViewModel>())); GoToProfileCommand = new ReactiveCommand(); GoToProfileCommand.Subscribe(_ => { var vm = CreateViewModel <ProfileViewModel>(); vm.UserSlug = accountsService.ActiveAccount.Username; ShowViewModel(vm); }); }
public IssueAddViewModel(IApplicationService applicationService) { _applicationService = applicationService; GoToDescriptionCommand = ReactiveCommand.Create(); GoToDescriptionCommand.Subscribe(_ => { var vm = CreateViewModel <MarkdownComposerViewModel>(); vm.Text = Content; vm.SaveCommand.Subscribe(__ => { Content = vm.Text; vm.DismissCommand.ExecuteIfCan(); }); ShowViewModel(vm); }); }
public StartupViewModel(IApplicationService applicationService) { StartupCommand = ReactiveCommand.Create(); StartupCommand.Subscribe(_ => { if (applicationService.Load()) { var vm = CreateViewModel <MainViewModel>(); ShowViewModel(vm); } else { var vm = CreateViewModel <LoginViewModel>(); ShowViewModel(vm); } }); }
public IssueAddViewModel(IApplicationService applicationService) { _applicationService = applicationService; GoToDescriptionCommand = ReactiveCommand.Create(); GoToDescriptionCommand.Subscribe(_ => { var vm = CreateViewModel<MarkdownComposerViewModel>(); vm.Text = Content; vm.SaveCommand.Subscribe(__ => { Content = vm.Text; vm.DismissCommand.ExecuteIfCan(); }); ShowViewModel(vm); }); }
public ReleaseViewModel(IApplicationService applicationService, IMarkdownService markdownService, IShareService shareService) { ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.ReleaseModel).Select(x => x != null)); ShareCommand.Subscribe(_ => shareService.ShareUrl(ReleaseModel.HtmlUrl)); GoToGitHubCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.ReleaseModel).Select(x => x != null)); GoToGitHubCommand.Subscribe(_ => GoToUrlCommand.ExecuteIfCan(ReleaseModel.HtmlUrl)); GoToLinkCommand = ReactiveCommand.Create(); GoToLinkCommand.OfType <string>().Subscribe(x => GoToUrlCommand.ExecuteIfCan(x)); _contentText = this.WhenAnyValue(x => x.ReleaseModel).IsNotNull() .Select(x => markdownService.Convert(x.Body)).ToProperty(this, x => x.ContentText); LoadCommand = ReactiveCommand.CreateAsyncTask(x => this.RequestModel(applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetRelease(ReleaseId), x as bool?, r => ReleaseModel = r.Data)); }
public MainWindowViewModel() { Editor = new NitraTextEditorViewModel(this); Settings = Settings.Default; var canFindSymbolDefinitions = this.WhenAny(v => v.CurrentSuite, v => v.CurrentTest, (suite, test) => suite != null && test != null); FindSymbolDefinitions = ReactiveCommand.Create(canFindSymbolDefinitions); FindSymbolDefinitions.ThrownExceptions.Subscribe(e => StatusText = "GOTO definition failed!"); FindSymbolDefinitions.Subscribe(OnFindSymbolDefinitions); FindSymbolReferences = ReactiveCommand.Create(canFindSymbolDefinitions); FindSymbolReferences.ThrownExceptions.Subscribe(e => StatusText = "Find all references definition failed!"); FindSymbolReferences.Subscribe(OnFindSymbolReferences); }
public ReadmeViewModel(IApplicationService applicationService, IMarkdownService markdownService, IShareService shareService) { ShareCommand = new ReactiveCommand(this.WhenAnyValue(x => x.ContentModel, x => x != null)); ShareCommand.Subscribe(_ => shareService.ShareUrl(ContentModel.HtmlUrl)); GoToGitHubCommand = new ReactiveCommand(this.WhenAnyValue(x => x.ContentModel, x => x != null)); GoToGitHubCommand.Subscribe(_ => GoToUrlCommand.ExecuteIfCan(ContentModel.HtmlUrl)); GoToLinkCommand = new ReactiveCommand(); GoToLinkCommand.OfType<string>().Subscribe(x => GoToUrlCommand.ExecuteIfCan(x)); LoadCommand.RegisterAsyncTask(x => this.RequestModel(applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetReadme(), x as bool?, r => { ContentModel = r.Data; ContentText = markdownService.Convert(Encoding.UTF8.GetString(Convert.FromBase64String(ContentModel.Content))); })); }
public MainWindowViewModel() { Editor = new NitraTextEditorViewModel(this); Settings = Settings.Default; var canFindSymbolDefinitions = this.WhenAny(v => v.CurrentSuite, v => v.CurrentFile, (suite, test) => suite != null && test != null); FindSymbolDefinitions = ReactiveCommand.Create(canFindSymbolDefinitions); FindSymbolDefinitions.ThrownExceptions.Subscribe(e => StatusText = "GOTO definition failed!"); FindSymbolDefinitions.Subscribe(OnFindSymbolDefinitions); FindSymbolReferences = ReactiveCommand.Create(canFindSymbolDefinitions); FindSymbolReferences.ThrownExceptions.Subscribe(e => StatusText = "Find all references definition failed!"); FindSymbolReferences.Subscribe(OnFindSymbolReferences); Changing.Where(c => c.PropertyName == "Workspace") .Subscribe(_ => { if (Workspace != null) Workspace.Dispose(); }); }
public RepositoryViewModel(ISessionService applicationService, IAccountsRepository accountsService, IActionMenuFactory actionMenuService) { ApplicationService = applicationService; _accountsService = accountsService; var validRepositoryObservable = this.WhenAnyValue(x => x.Repository).Select(x => x != null); this.WhenAnyValue(x => x.RepositoryName).Subscribe(x => Title = x); this.WhenAnyValue(x => x.Repository).Subscribe(x => { Stargazers = x != null ? (int?)x.StargazersCount : null; Watchers = x != null ? (int?)x.SubscribersCount : null; }); this.WhenAnyValue(x => x.Repository.Description) .Select(x => Emojis.FindAndReplace(x)) .ToProperty(this, x => x.Description, out _description); ToggleStarCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.IsStarred).Select(x => x.HasValue), t => ToggleStar()); ToggleWatchCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.IsWatched, x => x.HasValue), t => ToggleWatch()); GoToOwnerCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository).Select(x => x != null)); GoToOwnerCommand.Select(_ => Repository.Owner).Subscribe(x => { if (string.Equals(x.Type, "organization", StringComparison.OrdinalIgnoreCase)) { var vm = this.CreateViewModel<OrganizationViewModel>(); vm.Init(RepositoryOwner); NavigateTo(vm); } else { var vm = this.CreateViewModel<UserViewModel>(); vm.Init(RepositoryOwner); NavigateTo(vm); } }); PinCommand = ReactiveCommand.Create(validRepositoryObservable); PinCommand.Subscribe(x => PinRepository()); GoToForkParentCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository, x => x != null && x.Fork && x.Parent != null)); GoToForkParentCommand.Subscribe(x => { var vm = this.CreateViewModel<RepositoryViewModel>(); vm.RepositoryOwner = Repository.Parent.Owner.Login; vm.RepositoryName = Repository.Parent.Name; vm.Repository = Repository.Parent; NavigateTo(vm); }); GoToStargazersCommand = ReactiveCommand.Create(); GoToStargazersCommand.Subscribe(_ => { var vm = this.CreateViewModel<RepositoryStargazersViewModel>(); vm.Init(RepositoryOwner, RepositoryName); NavigateTo(vm); }); GoToWatchersCommand = ReactiveCommand.Create(); GoToWatchersCommand.Subscribe(_ => { var vm = this.CreateViewModel<RepositoryWatchersViewModel>(); vm.Init(RepositoryOwner, RepositoryName); NavigateTo(vm); }); GoToEventsCommand = ReactiveCommand.Create(); GoToEventsCommand.Subscribe(_ => { var vm = this.CreateViewModel<RepositoryEventsViewModel>(); vm.Init(RepositoryOwner, RepositoryName); NavigateTo(vm); }); GoToIssuesCommand = ReactiveCommand.Create(); GoToIssuesCommand .Select(_ => this.CreateViewModel<IssuesViewModel>()) .Select(x => x.Init(RepositoryOwner, RepositoryName)) .Subscribe(NavigateTo); GoToReadmeCommand = ReactiveCommand.Create(); GoToReadmeCommand .Select(_ => this.CreateViewModel<ReadmeViewModel>()) .Select(x => x.Init(RepositoryOwner, RepositoryName)) .Subscribe(NavigateTo); GoToBranchesCommand = ReactiveCommand.Create(); GoToBranchesCommand .Select(_ => this.CreateViewModel<CommitBranchesViewModel>()) .Select(x => x.Init(RepositoryOwner, RepositoryName)) .Subscribe(NavigateTo); GoToCommitsCommand = ReactiveCommand.Create(); GoToCommitsCommand.Subscribe(_ => { if (Branches != null && Branches.Count == 1) { var vm = this.CreateViewModel<CommitsViewModel>(); var branch = Repository == null ? null : Repository.DefaultBranch; NavigateTo(vm.Init(RepositoryOwner, RepositoryName, branch)); } else { GoToBranchesCommand.ExecuteIfCan(); } }); GoToPullRequestsCommand = ReactiveCommand.Create(); GoToPullRequestsCommand.Subscribe(_ => { var vm = this.CreateViewModel<PullRequestsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; NavigateTo(vm); }); GoToSourceCommand = ReactiveCommand.Create(); GoToSourceCommand.Subscribe(_ => { var vm = this.CreateViewModel<BranchesAndTagsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; NavigateTo(vm); }); GoToContributors = ReactiveCommand.Create(); GoToContributors.Subscribe(_ => { var vm = this.CreateViewModel<RepositoryContributorsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; NavigateTo(vm); }); GoToForksCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel<RepositoryForksViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; NavigateTo(vm); }); GoToReleasesCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel<ReleasesViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; NavigateTo(vm); }); ShareCommand = ReactiveCommand.Create(validRepositoryObservable); ShareCommand.Subscribe(sender => actionMenuService.ShareUrl(sender, Repository.HtmlUrl)); var canShowMenu = this.WhenAnyValue(x => x.Repository, x => x.IsStarred, x => x.IsWatched) .Select(x => x.Item1 != null && x.Item2 != null && x.Item3 != null); ShowMenuCommand = ReactiveCommand.CreateAsyncTask(canShowMenu, sender => { var menu = actionMenuService.Create(); menu.AddButton(IsPinned ? "Unpin from Slideout Menu" : "Pin to Slideout Menu", PinCommand); menu.AddButton(IsStarred.Value ? "Unstar This Repo" : "Star This Repo", ToggleStarCommand); menu.AddButton(IsWatched.Value ? "Unwatch This Repo" : "Watch This Repo", ToggleWatchCommand); menu.AddButton("Show in GitHub", GoToHtmlUrlCommand); menu.AddButton("Share", ShareCommand); return menu.Show(sender); }); var gotoWebUrl = new Action<string>(x => { var vm = this.CreateViewModel<WebBrowserViewModel>(); vm.Init(x); NavigateTo(vm); }); GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository, x => x != null && !string.IsNullOrEmpty(x.HtmlUrl))); GoToHtmlUrlCommand.Select(_ => Repository.HtmlUrl).Subscribe(gotoWebUrl); GoToHomepageCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository, x => x != null && !string.IsNullOrEmpty(x.Homepage))); GoToHomepageCommand.Select(_ => Repository.Homepage).Subscribe(gotoWebUrl); LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => { var t1 = applicationService.Client.ExecuteAsync(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Get()); applicationService.Client.ExecuteAsync(applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetReadme()) .ToBackground(x => Readme = x.Data); applicationService.Client.ExecuteAsync(applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetBranches()) .ToBackground(x => Branches = x.Data); applicationService.GitHubClient.Activity.Watching.CheckWatched(RepositoryOwner, RepositoryName) .ToBackground(x => IsWatched = x); applicationService.GitHubClient.Activity.Starring.CheckStarred(RepositoryOwner, RepositoryName) .ToBackground(x => IsStarred = x); applicationService.Client.ExecuteAsync(applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetContributors()) .ToBackground(x => Contributors = x.Data.Count); // applicationService.GitHubClient.Repository.GetAllLanguages(RepositoryOwner, RepositoryName) // .ToBackground(x => Languages = x.Count); applicationService.Client.ExecuteAsync(applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetReleases()) .ToBackground(x => Releases = x.Data.Count); Repository = (await t1).Data; }); }
public MyIssuesViewModel(ISessionService sessionService) : base(sessionService) { _applicationService = sessionService; Title = "My Issues"; Filter = MyIssuesFilterModel.CreateOpenFilter(); _selectedFilter = this.WhenAnyValue(x => x.Filter) .Select(x => { if (x == null || _openFilter.Equals(x)) return 0; return _closedFilter.Equals(x) ? 1 : -1; }) .ToProperty(this, x => x.SelectedFilter); this.WhenAnyValue(x => x.Filter).Skip(1).Subscribe(_ => { IssuesBacking.Clear(); LoadCommand.ExecuteIfCan(); }); GoToFilterCommand = ReactiveCommand.Create(); GoToFilterCommand.Subscribe(_ => { var vm = this.CreateViewModel<MyIssuesFilterViewModel>(); vm.Ascending = Filter.Ascending; vm.FilterType = Filter.FilterType; vm.Labels = Filter.Labels; vm.State = Filter.Open; vm.SortType = Filter.SortType; vm.SaveCommand.Subscribe(__ => { Filter = new MyIssuesFilterModel { Ascending = vm.Ascending, FilterType = vm.FilterType, Labels = vm.Labels, Open = vm.State, SortType = vm.SortType }; CustomFilterEnabled = true; }); NavigateTo(vm); }); }
public MenuViewModel(IApplicationService applicationService, IAccountsService accountsService) : base(accountsService) { _applicationService = applicationService; GoToNotificationsCommand = new ReactiveCommand(); GoToNotificationsCommand.Subscribe(_ => { var vm = CreateViewModel<NotificationsViewModel>(); ShowViewModel(vm); }); GoToAccountsCommand = new ReactiveCommand(); GoToAccountsCommand.Subscribe(_ => CreateAndShowViewModel<AccountsViewModel>()); GoToProfileCommand = new ReactiveCommand(); GoToProfileCommand.Subscribe(_ => { var vm = CreateViewModel<ProfileViewModel>(); vm.Username = Account.Username; ShowViewModel(vm); }); GoToMyIssuesCommand = new ReactiveCommand(); GoToMyIssuesCommand.Subscribe(_ => CreateAndShowViewModel<MyIssuesViewModel>()); GoToUpgradesCommand = new ReactiveCommand(); GoToUpgradesCommand.Subscribe(_ => CreateAndShowViewModel<UpgradesViewModel>()); GoToAboutCommand = new ReactiveCommand(); GoToAboutCommand.Subscribe(_ => CreateAndShowViewModel<AboutViewModel>()); GoToRepositoryCommand = new ReactiveCommand(); GoToRepositoryCommand.OfType<RepositoryIdentifier>().Subscribe(x => { var vm = CreateViewModel<RepositoryViewModel>(); vm.RepositoryOwner = x.Owner; vm.RepositoryName = x.Name; ShowViewModel(vm); }); GoToSettingsCommand = new ReactiveCommand(); GoToSettingsCommand.Subscribe(_ => CreateAndShowViewModel<SettingsViewModel>()); GoToNewsCommand = new ReactiveCommand(); GoToNewsCommand.Subscribe(_ => CreateAndShowViewModel<NewsViewModel>()); GoToOrganizationsCommand = new ReactiveCommand(); GoToOrganizationsCommand.Subscribe(_ => { var vm = CreateViewModel<OrganizationsViewModel>(); vm.Username = Account.Username; ShowViewModel(vm); }); GoToTrendingRepositoriesCommand = new ReactiveCommand(); GoToTrendingRepositoriesCommand.Subscribe(_ => CreateAndShowViewModel<RepositoriesTrendingViewModel>()); GoToExploreRepositoriesCommand = new ReactiveCommand(); GoToExploreRepositoriesCommand.Subscribe(_ => CreateAndShowViewModel<RepositoriesExploreViewModel>()); GoToOrganizationEventsCommand = new ReactiveCommand(); GoToOrganizationEventsCommand.OfType<string>().Subscribe(name => { var vm = CreateViewModel<UserEventsViewModel>(); vm.Username = name; ShowViewModel(vm); }); GoToOrganizationCommand = new ReactiveCommand(); GoToOrganizationCommand.OfType<string>().Subscribe(name => { var vm = CreateViewModel<OrganizationViewModel>(); vm.Name = name; ShowViewModel(vm); }); GoToOwnedRepositoriesCommand = new ReactiveCommand(); GoToOwnedRepositoriesCommand.Subscribe(_ => { var vm = CreateViewModel<UserRepositoriesViewModel>(); vm.Username = Account.Username; ShowViewModel(vm); }); GoToStarredRepositoriesCommand = new ReactiveCommand(); GoToStarredRepositoriesCommand.Subscribe(_ => CreateAndShowViewModel<RepositoriesStarredViewModel>()); GoToPublicGistsCommand = new ReactiveCommand(); GoToPublicGistsCommand.Subscribe(_ => CreateAndShowViewModel<PublicGistsViewModel>()); GoToStarredGistsCommand = new ReactiveCommand(); GoToStarredGistsCommand.Subscribe(_ => CreateAndShowViewModel<StarredGistsViewModel>()); GoToMyGistsCommand = new ReactiveCommand(); GoToMyGistsCommand.Subscribe(_ => { var vm = CreateViewModel<UserGistsViewModel>(); vm.Username = Account.Username; ShowViewModel(vm); }); GoToMyEvents = new ReactiveCommand(); GoToMyEvents.Subscribe(_ => { var vm = CreateViewModel<UserEventsViewModel>(); vm.Username = Account.Username; ShowViewModel(vm); }); LoadCommand = new ReactiveCommand(); LoadCommand.Subscribe(_ => { var notificationRequest = applicationService.Client.Notifications.GetAll(); notificationRequest.RequestFromCache = false; notificationRequest.CheckIfModified = false; applicationService.Client.ExecuteAsync(notificationRequest) .ContinueWith(t => Notifications = t.Result.Data.Count); applicationService.Client.ExecuteAsync(applicationService.Client.AuthenticatedUser.GetOrganizations()) .ContinueWith(t => Organizations = t.Result.Data.Select(y => y.Login).ToList()); }); }
public GistViewModel(IApplicationService applicationService, IShareService shareService) { _applicationService = applicationService; Comments = new ReactiveCollection<GistCommentModel>(); ShareCommand = new ReactiveCommand(this.WhenAnyValue(x => x.Gist, x => x != null)); ShareCommand.Subscribe(_ => shareService.ShareUrl(Gist.HtmlUrl)); ToggleStarCommand = new ReactiveCommand(this.WhenAnyValue(x => x.IsStarred, x => x.HasValue)); ToggleStarCommand.RegisterAsyncTask(async t => { try { if (!IsStarred.HasValue) return; var request = IsStarred.Value ? _applicationService.Client.Gists[Id].Unstar() : _applicationService.Client.Gists[Id].Star(); await _applicationService.Client.ExecuteAsync(request); IsStarred = !IsStarred.Value; } catch (Exception e) { throw new Exception("Unable to start gist. Please try again.", e); } }); ForkCommand = new ReactiveCommand(); ForkCommand.RegisterAsyncTask(async t => { var data = await _applicationService.Client.ExecuteAsync(_applicationService.Client.Gists[Id].ForkGist()); var forkedGist = data.Data; var vm = CreateViewModel<GistViewModel>(); vm.Id = forkedGist.Id; vm.Gist = forkedGist; ShowViewModel(vm); }); GoToViewableFileCommand = new ReactiveCommand(); GoToViewableFileCommand.OfType<GistFileModel>().Subscribe(x => { var vm = CreateViewModel<GistViewableFileViewModel>(); vm.GistFile = x; ShowViewModel(vm); }); GoToHtmlUrlCommand = new ReactiveCommand(this.WhenAnyValue(x => x.Gist, x => x != null && !string.IsNullOrEmpty(x.HtmlUrl))); GoToHtmlUrlCommand.Subscribe(_ => GoToUrlCommand.ExecuteIfCan(Gist.HtmlUrl)); GoToFileSourceCommand = new ReactiveCommand(); GoToFileSourceCommand.OfType<GistFileModel>().Subscribe(x => { var vm = CreateViewModel<GistFileViewModel>(); vm.Id = Id; vm.GistFile = x; vm.Filename = x.Filename; ShowViewModel(vm); }); GoToUserCommand = new ReactiveCommand(this.WhenAnyValue(x => x.Gist, x => x != null)); GoToUserCommand.Subscribe(x => { var vm = CreateViewModel<ProfileViewModel>(); vm.Username = Gist.Owner.Login; ShowViewModel(vm); }); GoToForksCommand = new ReactiveCommand(); LoadCommand.RegisterAsyncTask(t => { var forceCacheInvalidation = t as bool?; var t1 = this.RequestModel(_applicationService.Client.Gists[Id].Get(), forceCacheInvalidation, response => Gist = response.Data); this.RequestModel(_applicationService.Client.Gists[Id].IsGistStarred(), forceCacheInvalidation, response => IsStarred = response.Data).FireAndForget(); Comments.SimpleCollectionLoad(_applicationService.Client.Gists[Id].GetComments(), forceCacheInvalidation).FireAndForget(); return t1; }); }
public TestViewModel(IDialogService dialogService) { _dialogService = dialogService; var changeTime = ReactiveCommand.CreateAsyncObservable(_ => Observable.Return(DateTime.UtcNow.ToLocalTime().ToString())); changeTime.Subscribe(s => Hello = s); var asyncHelloCommand = ReactiveCommand.CreateAsyncTask(_ => Task.Run(() => { Thread.Sleep(2000); Debug.WriteLine(Thread.CurrentThread.IsThreadPoolThread); return _random.NextDouble().ToString(); } )); asyncHelloCommand.Subscribe(s => Rando = s); _sayHelloCommand = ReactiveCommand.CreateCombined(new IReactiveCommand[]{changeTime, asyncHelloCommand}); _showDialogCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Hello, s => !string.IsNullOrWhiteSpace(s))); // // var dialog2Command = ReactiveCommand.CreateAsyncObservable(o => // { // if (o is Answer) // { // return Observable.Return((Answer)o); // } // return Observable.Empty<Answer>(); // }); // // dialog2Command // .Where(a => a == Answer.Ok) // .Subscribe(o => // { // throw new Exception("AAAAAAAAA"); // }); // _showDialogCommand.Subscribe(x => // { // Hello = null; // }); var answer = new Subject<Answer>(); answer.Subscribe(o => _dialogService.ShowInformation("Hello")); var b = true; _showDialogCommand.Subscribe(_ => { var asyncCommand = ReactiveCommand.CreateAsyncObservable(o => { Hello = null; b = !b; if (b) { throw (new InvalidOperationException("OOOOOOOO")); } answer.OnNext( _dialogService.ShowQuestion( "Do it to it", "NEWWW CAPRION", new[]{Answer.Abort, Answer.Cancel, Answer.No, Answer.Ok, Answer.Retry, Answer.Yes, })); return Observable.Return(Unit.Default); }); asyncCommand.ExecuteAsync().Subscribe(); }); _showDialogCommand.ThrownExceptions .Subscribe(ex => _dialogService.ShowException(ex, "message")); _counter = Observable.Generate(0, i => true, i => i + 1, i => i, i => TimeSpan.FromSeconds(.01)) .ToProperty(this, t => t.Counter); }
private void ImplementCommands () { FetchNewArticles = ReactiveCommand.CreateAsyncTask (async param => { var priority = param == null ? Priority.UserInitiated : (Priority)param; var newAndUpdatedArticles = await _repository.FetchNewArticles(State.Articles, priority); State.Articles.InsertRange(0, newAndUpdatedArticles.Item1); for (int i = 0; i < newAndUpdatedArticles.Item2.Count; i++) { State.Articles[i] = newAndUpdatedArticles.Item2[i]; } return newAndUpdatedArticles.Item1; }); FetchNewElectionArticles = ReactiveCommand.CreateAsyncTask (async param => { var priority = param == null ? Priority.UserInitiated : (Priority)param; if (State.ElectionArticles.Count > 0) { var latestArticle = State.ElectionArticles.OrderByDescending(article => article.CreatedAt).First(); return await _electionArticlesService.GetElectionArticlesAfterAsync(latestArticle, (Priority)priority); } else { return await _electionArticlesService.GetRemoteElectionArticlesAsync((Priority)priority); } }); FetchNewElectionArticles.Subscribe (async newArticles => { State.ElectionArticles.InsertRange(0, newArticles); var articlesKeyValue = newArticles.ToDictionary(x => "election-article-" + x.Id.ToString()); foreach (var pair in articlesKeyValue) { await _cache.InsertObject<ElectionArticle> (pair.Key, pair.Value); } }); FetchNewEvents = ReactiveCommand.CreateAsyncTask (async param => { var priority = param == null ? Priority.UserInitiated : (Priority)param; if (State.Events.Count > 0) { var latestEvent = State.Events.OrderByDescending(ev => ev.CreatedAt).First(); return await _eventsService.GetEventsAfterAsync(latestEvent, (Priority)priority); } else { return await _eventsService.GetRemoteEventsAsync((Priority)priority); } }); FetchNewEvents.Subscribe (async newEvents => { State.Events.InsertRange(0, newEvents); var eventsKeyValue = newEvents.ToDictionary(x => "event-" + x.Id.ToString()); foreach (var pair in eventsKeyValue) { await _cache.InsertObject<Event>(pair.Key, pair.Value); } }); }
protected BaseIssueViewModel( ISessionService applicationService, IMarkdownService markdownService, IActionMenuFactory actionMenuFactory, IAlertDialogFactory alertDialogFactory) { _applicationService = applicationService; _markdownService = markdownService; _alertDialogFactory = alertDialogFactory; _assigneesCache = new Lazy<Task<IReadOnlyList<Octokit.User>>>(() => _applicationService.GitHubClient.Issue.Assignee.GetAllForRepository(RepositoryOwner, RepositoryName)); _milestonesCache = new Lazy<Task<IReadOnlyList<Octokit.Milestone>>>(() => _applicationService.GitHubClient.Issue.Milestone.GetAllForRepository(RepositoryOwner, RepositoryName)); _labelsCache = new Lazy<Task<IReadOnlyList<Octokit.Label>>>(() => _applicationService.GitHubClient.Issue.Labels.GetAllForRepository(RepositoryOwner, RepositoryName)); IssueUpdated.Subscribe(x => Issue = x); var issuePresenceObservable = this.WhenAnyValue(x => x.Issue, x => x.CanModify) .Select(x => x.Item1 != null && x.Item2); Events = InternalEvents.CreateDerivedCollection(x => x); this.WhenAnyValue(x => x.Issue.Comments) .ToProperty(this, x => x.CommentCount, out _commentsCount); _participants = Events.Changed .Select(_ => Events.Select(y => y.Actor).Distinct().Count()) .Select(x => x == 0 ? 1 : x) .ToProperty(this, x => x.Participants); GoToAssigneesCommand = ReactiveCommand.Create(issuePresenceObservable); GoToLabelsCommand = ReactiveCommand.Create(issuePresenceObservable); GoToMilestonesCommand = ReactiveCommand.Create(issuePresenceObservable); _assignedUser = this.WhenAnyValue(x => x.Issue.Assignee) .ToProperty(this, x => x.AssignedUser); _assignedMilestone = this.WhenAnyValue(x => x.Issue.Milestone) .ToProperty(this, x => x.AssignedMilestone); _assignedLabels = this.WhenAnyValue(x => x.Issue.Labels) .ToProperty(this, x => x.AssignedLabels); _isClosed = this.WhenAnyValue(x => x.Issue.State) .Select(x => x == Octokit.ItemState.Closed) .ToProperty(this, x => x.IsClosed); _markdownDescription = this.WhenAnyValue(x => x.Issue) .Select(x => ((x == null || string.IsNullOrEmpty(x.Body)) ? null : x.Body)) .Where(x => x != null) .Select(x => GetMarkdownDescription().ToObservable()) .Switch() .ToProperty(this, x => x.MarkdownDescription, null, RxApp.MainThreadScheduler); LoadCommand = ReactiveCommand.CreateAsyncTask(t => Load(applicationService)); GoToOwnerCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)); GoToOwnerCommand .Select(_ => this.CreateViewModel<UserViewModel>()) .Select(x => x.Init(Issue.User.Login)) .Subscribe(NavigateTo); ToggleStateCommand = ReactiveCommand.CreateAsyncTask(issuePresenceObservable, async t => { try { var updatedIssue = await applicationService.GitHubClient.Issue.Update(RepositoryOwner, RepositoryName, Id, new Octokit.IssueUpdate { State = (Issue.State == Octokit.ItemState.Open) ? Octokit.ItemState.Closed : Octokit.ItemState.Open }); _issueUpdatedObservable.OnNext(updatedIssue); } catch (Exception e) { var close = (Issue.State == Octokit.ItemState.Open) ? "close" : "open"; throw new Exception("Unable to " + close + " the item. " + e.Message, e); } RetrieveEvents().ToBackground(x => InternalEvents.Reset(x)); }); AddCommentCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = new ComposerViewModel(async s => { var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[Id].CreateComment(s); var comment = (await applicationService.Client.ExecuteAsync(request)).Data; InternalEvents.Add(new IssueCommentItemViewModel(comment)); }, alertDialogFactory); NavigateTo(vm); }); ShowMenuCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Issue).Select(x => x != null), sender => { var menu = actionMenuFactory.Create(); menu.AddButton("Edit", GoToEditCommand); menu.AddButton(Issue.State == Octokit.ItemState.Closed ? "Open" : "Close", ToggleStateCommand); menu.AddButton("Comment", AddCommentCommand); menu.AddButton("Share", ShareCommand); menu.AddButton("Show in GitHub", GoToHtmlUrlCommand); return menu.Show(sender); }); GoToEditCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel<IssueEditViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.Id = Id; vm.Issue = Issue; vm.SaveCommand.Subscribe(_issueUpdatedObservable.OnNext); NavigateTo(vm); }); GoToUrlCommand = ReactiveCommand.Create(); GoToUrlCommand.OfType<string>().Subscribe(GoToUrl); GoToUrlCommand.OfType<Uri>().Subscribe(x => GoToUrl(x.AbsoluteUri)); var hasHtmlObservable = this.WhenAnyValue(x => x.HtmlUrl).Select(x => x != null); ShareCommand = ReactiveCommand.Create(hasHtmlObservable); ShareCommand.Subscribe(sender => actionMenuFactory.ShareUrl(sender, HtmlUrl)); GoToHtmlUrlCommand = ReactiveCommand.Create(hasHtmlObservable); GoToHtmlUrlCommand.Subscribe(_ => GoToUrl(HtmlUrl.AbsoluteUri)); }