public CreateFileViewModel(ISessionService applicationService, IAlertDialogFactory alertDialogFactory) { Title = "Create File"; this.WhenAnyValue(x => x.Name).Subscribe(x => CommitMessage = "Created " + x); _canCommit = this.WhenAnyValue(x => x.Name) .Select(x => !string.IsNullOrEmpty(x)) .ToProperty(this, x => x.CanCommit); SaveCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Name).Select(x => !string.IsNullOrEmpty(x)), async _ => { var content = Content ?? string.Empty; var path = Path; if (string.IsNullOrEmpty(Path)) path = "/"; path = System.IO.Path.Combine(path, Name); var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].UpdateContentFile(path, CommitMessage, content, null, Branch); await applicationService.Client.ExecuteAsync(request); Dismiss(); }); DismissCommand = ReactiveCommand.CreateAsyncTask(async t => { if (string.IsNullOrEmpty(Name) && string.IsNullOrEmpty(Content)) return true; return await alertDialogFactory.PromptYesNo("Discard File?", "Are you sure you want to discard this file?"); }); DismissCommand.Where(x => x).Subscribe(_ => Dismiss()); }
public CreateFileViewModel(ISessionService sessionService, IAlertDialogFactory alertDialogFactory) { Title = "Create File"; this.WhenAnyValue(x => x.Name) .Subscribe(x => CommitMessage = "Created " + x); GoToCommitMessageCommand = ReactiveCommand.Create( this.WhenAnyValue(x => x.Name, x => !string.IsNullOrEmpty(x))); SaveCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Name).Select(x => !string.IsNullOrEmpty(x)), async _ => { var content = Content ?? string.Empty; var path = System.IO.Path.Combine(Path ?? string.Empty, Name); var request = new Octokit.CreateFileRequest(CommitMessage, content) { Branch = Branch }; using (alertDialogFactory.Activate("Commiting...")) return await sessionService.GitHubClient.Repository.Content.CreateFile(RepositoryOwner, RepositoryName, path, request); }); SaveCommand.Subscribe(x => Dismiss()); DismissCommand = ReactiveCommand.CreateAsyncTask(async t => { if (string.IsNullOrEmpty(Name) && string.IsNullOrEmpty(Content)) return true; return await alertDialogFactory.PromptYesNo("Discard File?", "Are you sure you want to discard this file?"); }); DismissCommand.Where(x => x).Subscribe(_ => Dismiss()); }
public CreateFileViewModel(ISessionService sessionService, IAlertDialogFactory alertDialogFactory) { Title = "Create File"; this.WhenAnyValue(x => x.Name) .Subscribe(x => CommitMessage = "Created " + x); _canCommit = this.WhenAnyValue(x => x.Name) .Select(x => !string.IsNullOrEmpty(x)) .ToProperty(this, x => x.CanCommit); SaveCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Name).Select(x => !string.IsNullOrEmpty(x)), async _ => { var content = Content ?? string.Empty; var path = System.IO.Path.Combine(Path ?? string.Empty, Name); var request = new Octokit.CreateFileRequest(CommitMessage, content) { Branch = Branch }; using (alertDialogFactory.Activate("Commiting...")) return(await sessionService.GitHubClient.Repository.Content.CreateFile(RepositoryOwner, RepositoryName, path, request)); }); SaveCommand.Subscribe(x => Dismiss()); DismissCommand = ReactiveCommand.CreateAsyncTask(async t => { if (string.IsNullOrEmpty(Name) && string.IsNullOrEmpty(Content)) { return(true); } return(await alertDialogFactory.PromptYesNo("Discard File?", "Are you sure you want to discard this file?")); }); DismissCommand.Where(x => x).Subscribe(_ => Dismiss()); }
public FeedbackComposerViewModel(ISessionService applicationService, IAlertDialogFactory alertDialogFactory) { this.WhenAnyValue(x => x.IsFeature).Subscribe(x => Title = x ? "New Feature" : "Bug Report"); SubmitCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Subject).Select(x => !string.IsNullOrEmpty(x)), async _ => { if (string.IsNullOrEmpty(Subject)) throw new ArgumentException(string.Format("You must provide a title for this {0}!", IsFeature ? "feature" : "bug")); var labels = await applicationService.GitHubClient.Issue.Labels.GetAllForRepository(CodeHubOwner, CodeHubName); var createLabels = labels.Where(x => string.Equals(x.Name, IsFeature ? "feature request" : "bug", StringComparison.OrdinalIgnoreCase)).Select(x => x.Name).Distinct(); var createIssueRequest = new Octokit.NewIssue(Subject) { Body = Description }; foreach (var label in createLabels) createIssueRequest.Labels.Add(label); var createdIssue = await applicationService.GitHubClient.Issue.Create(CodeHubOwner, CodeHubName, createIssueRequest); _createdIssueSubject.OnNext(createdIssue); Dismiss(); }); DismissCommand = ReactiveCommand.CreateAsyncTask(async t => { if (string.IsNullOrEmpty(Description) && string.IsNullOrEmpty(Subject)) return true; var itemType = IsFeature ? "feature" : "bug"; return await alertDialogFactory.PromptYesNo("Discard " + itemType.Transform(To.TitleCase) + "?", "Are you sure you want to discard this " + itemType + "?"); }); DismissCommand.Where(x => x).Subscribe(_ => Dismiss()); }
protected override async System.Threading.Tasks.Task <bool> Discard() { if (_lastChanged <= _lastLoaded) { return(true); } return(await _alertDialogFactory.PromptYesNo("Discard Gist?", "Are you sure you want to discard this gist?")); }
protected override async System.Threading.Tasks.Task <bool> Discard() { if (string.IsNullOrEmpty(Description) && Files.Count == 0) { return(true); } return(await _alertDialogFactory.PromptYesNo("Discard Gist?", "Are you sure you want to discard this gist?")); }
protected override async Task <bool> Discard() { if (string.IsNullOrEmpty(Subject) && string.IsNullOrEmpty(Content)) { return(true); } return(await _alertDialogFactory.PromptYesNo("Discard Issue?", "Are you sure you want to discard this update?")); }
public EditFileViewModel(ISessionService sessionService, IAlertDialogFactory alertDialogFactory) { Title = "Edit"; this.WhenAnyValue(x => x.Path) .IsNotNull() .Subscribe(x => CommitMessage = "Updated " + x.Substring(x.LastIndexOf('/') + 1)); this.WhenAnyValue(x => x.Text) .Subscribe(x => _lastEdit = DateTime.Now); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { var path = Path; if (!path.StartsWith("/", StringComparison.Ordinal)) { path = "/" + path; } var request = sessionService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetContentFile(path, Branch ?? "master"); request.UseCache = false; var data = await sessionService.Client.ExecuteAsync(request); BlobSha = data.Data.Sha; var content = Convert.FromBase64String(data.Data.Content); Text = System.Text.Encoding.UTF8.GetString(content, 0, content.Length) ?? string.Empty; _lastLoad = DateTime.Now; }); GoToCommitMessageCommand = ReactiveCommand.Create(); SaveCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.CommitMessage).Select(x => !string.IsNullOrEmpty(x)), async _ => { var path = Path.TrimStart('/'); var request = new Octokit.UpdateFileRequest(CommitMessage, Text, BlobSha) { Branch = Branch }; using (alertDialogFactory.Activate("Commiting...")) return(await sessionService.GitHubClient.Repository.Content.UpdateFile(RepositoryOwner, RepositoryName, path, request)); }); SaveCommand.Subscribe(x => Dismiss()); DismissCommand = ReactiveCommand.CreateAsyncTask(async t => { if (string.IsNullOrEmpty(Text)) { return(true); } if (_lastEdit <= _lastLoad) { return(true); } return(await alertDialogFactory.PromptYesNo("Discard Edit?", "Are you sure you want to discard these changes?")); }); DismissCommand.Where(x => x).Subscribe(_ => Dismiss()); }
public ComposerViewModel(string title, Func<string, Task> saveFunc, IAlertDialogFactory alertDialogFactory) { Title = title; SaveCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Text).Select(x => !string.IsNullOrEmpty(x)), t => saveFunc(Text)); SaveCommand.AlertExecuting(alertDialogFactory, "Saving..."); SaveCommand.Subscribe(x => Dismiss()); DismissCommand = ReactiveCommand.CreateAsyncTask(async t => { if (string.IsNullOrEmpty(Text)) return true; return await alertDialogFactory.PromptYesNo("Discard Comment?", "Are you sure you want to discard this comment?"); }); DismissCommand.Where(x => x).Subscribe(_ => Dismiss()); }
public ComposerViewModel(string title, Func <string, Task> saveFunc, IAlertDialogFactory alertDialogFactory) { Title = title; SaveCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Text).Select(x => !string.IsNullOrEmpty(x)), t => saveFunc(Text)); SaveCommand.AlertExecuting(alertDialogFactory, "Saving..."); SaveCommand.Subscribe(x => Dismiss()); DismissCommand = ReactiveCommand.CreateAsyncTask(async t => { if (string.IsNullOrEmpty(Text)) { return(true); } return(await alertDialogFactory.PromptYesNo("Discard Comment?", "Are you sure you want to discard this comment?")); }); DismissCommand.Where(x => x).Subscribe(_ => Dismiss()); }
public FeedbackComposerViewModel(ISessionService applicationService, IAlertDialogFactory alertDialogFactory) { this.WhenAnyValue(x => x.IsFeature).Subscribe(x => Title = x ? "New Feature" : "Bug Report"); SubmitCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Subject).Select(x => !string.IsNullOrEmpty(x)), async _ => { if (string.IsNullOrEmpty(Subject)) { throw new ArgumentException(string.Format("You must provide a title for this {0}!", IsFeature ? "feature" : "bug")); } var labels = await applicationService.GitHubClient.Issue.Labels.GetAllForRepository(CodeHubOwner, CodeHubName); var createLabels = labels.Where(x => string.Equals(x.Name, IsFeature ? "feature request" : "bug", StringComparison.OrdinalIgnoreCase)).Select(x => x.Name).Distinct(); var createIssueRequest = new Octokit.NewIssue(Subject) { Body = Description }; foreach (var label in createLabels) { createIssueRequest.Labels.Add(label); } var createdIssue = await applicationService.GitHubClient.Issue.Create(CodeHubOwner, CodeHubName, createIssueRequest); _createdIssueSubject.OnNext(createdIssue); Dismiss(); }); DismissCommand = ReactiveCommand.CreateAsyncTask(async t => { if (string.IsNullOrEmpty(Description) && string.IsNullOrEmpty(Subject)) { return(true); } var itemType = IsFeature ? "feature" : "bug"; return(await alertDialogFactory.PromptYesNo("Discard " + itemType.Transform(To.TitleCase) + "?", "Are you sure you want to discard this " + itemType + "?")); }); DismissCommand.Where(x => x).Subscribe(_ => Dismiss()); }
public EditFileViewModel(ISessionService applicationService, IAlertDialogFactory alertDialogFactory) { Title = "Edit"; this.WhenAnyValue(x => x.Path) .IsNotNull() .Subscribe(x => CommitMessage = "Updated " + x.Substring(x.LastIndexOf('/') + 1)); this.WhenAnyValue(x => x.Text) .Subscribe(x => _lastEdit = DateTime.Now); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { var path = Path; if (!path.StartsWith("/", StringComparison.Ordinal)) path = "/" + path; var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].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) ?? string.Empty; _lastLoad = DateTime.Now; }); SaveCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.CommitMessage).Select(x => !string.IsNullOrEmpty(x)), async _ => { var path = Path.StartsWith("/", StringComparison.Ordinal) ? Path : string.Concat("/", Path); var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName] .UpdateContentFile(path, CommitMessage, Text, BlobSha, Branch); using (alertDialogFactory.Activate("Commiting...")) { var response = await applicationService.Client.ExecuteAsync(request); _sourceChangedSubject.OnNext(response.Data); } Dismiss(); }); DismissCommand = ReactiveCommand.CreateAsyncTask(async t => { if (string.IsNullOrEmpty(Text)) return true; if (_lastEdit <= _lastLoad) return true; return await alertDialogFactory.PromptYesNo("Discard Edit?", "Are you sure you want to discard these changes?"); }); DismissCommand.Where(x => x).Subscribe(_ => Dismiss()); }