public ChangesetDiffViewModel(IApplicationService applicationService, IFilesystemService filesystemService) { Comments = new ReactiveList <CommentModel>(); GoToCommentCommand = ReactiveCommand.Create(); GoToCommentCommand.OfType <int?>().Subscribe(line => { var vm = CreateViewModel <CommentViewModel>(); ReactiveUI.Legacy.ReactiveCommandMixins.RegisterAsyncTask(vm.SaveCommand, async t => { var req = applicationService.Client.Users[Username].Repositories[Repository].Commits[Branch].Comments.Create(vm.Comment, Filename, line); var response = await applicationService.Client.ExecuteAsync(req); Comments.Add(response.Data); vm.DismissCommand.ExecuteIfCan(); }); ShowViewModel(vm); }); this.WhenAnyValue(x => x.Filename).Subscribe(x => { if (string.IsNullOrEmpty(x)) { Title = "Diff"; } else { _actualFilename = Path.GetFileName(Filename) ?? Filename.Substring(Filename.LastIndexOf('/') + 1); Title = _actualFilename; } }); _loadCommand = ReactiveCommand.CreateAsyncTask(async t => { var branch = applicationService.Client.Users[Username].Repositories[Repository].Commits[Branch]; //Make sure we have this information. If not, go get it if (CommitFile == null) { var data = await applicationService.Client.ExecuteAsync(branch.Get()); CommitFile = data.Data.Files.First(x => string.Equals(x.Filename, Filename)); } string path; using (var stream = filesystemService.CreateTempFile(out path)) { using (var fs = new StreamWriter(stream)) { fs.Write(CommitFile.Patch); } } SourceItem = new FileSourceItemViewModel { FilePath = path }; await Comments.SimpleCollectionLoad(branch.Comments.GetAll(), t as bool?); }); }
public ChangesetDiffViewModel(IApplicationService applicationService, IActionMenuFactory actionMenuFactory) { var comments = new ReactiveList <CommitComment>(); Comments = comments.CreateDerivedCollection(x => x); GoToCommentCommand = ReactiveCommand.Create(); GoToCommentCommand.OfType <int?>().Subscribe(line => { // var vm = this.CreateViewModel<CommentViewModel>(); // ReactiveUI.Legacy.ReactiveCommandMixins.RegisterAsyncTask(vm.SaveCommand, async t => // { // var req = applicationService.Client.Users[Username].Repositories[Repository].Commits[Branch].Comments.Create(vm.Comment, Filename, line); // var response = await applicationService.Client.ExecuteAsync(req); // comments.Add(response.Data); // Dismiss(); // }); // NavigateTo(vm); }); _patch = this.WhenAnyValue(x => x.CommitFile) .IsNotNull().Select(x => x.Patch).ToProperty(this, x => x.Patch); this.WhenAnyValue(x => x.Filename).Subscribe(x => { if (string.IsNullOrEmpty(x)) { Title = "Diff"; } else { _actualFilename = Path.GetFileName(Filename) ?? Filename.Substring(Filename.LastIndexOf('/') + 1); Title = _actualFilename; } }); ShowMenuCommand = ReactiveCommand.CreateAsyncTask(_ => { var sheet = actionMenuFactory.Create(Title); sheet.AddButton("Add Comment", ReactiveCommand.Create()); return(sheet.Show()); }); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { applicationService.GitHubClient.Repository.RepositoryComments.GetForCommit(Username, Repository, Branch) .ToBackground(x => comments.Reset(x)); var commits = await applicationService.GitHubClient.Repository.Commits.Get(Username, Repository, Branch); CommitFile = commits.Files.FirstOrDefault(x => string.Equals(x.Filename, Filename, StringComparison.Ordinal)); }); }