public FeedbackComposerViewModel(IApplicationService applicationService) { 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.GetForRepository(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(); }); }
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 FeedbackComposerViewModel( IApplicationService applicationService = null, IAlertDialogService alertDialogService = null) { applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>(); alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>(); this.WhenAnyValue(x => x.IsFeature) .Subscribe(x => Title = x ? "New Feature" : "Bug Report"); SubmitCommand = ReactiveCommand.CreateFromTask(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 labelName = IsFeature ? "enhancement" : "bug"; var createLabels = labels .Where(x => string.Equals(x.Name, labelName, StringComparison.OrdinalIgnoreCase)) .Select(x => x.Name) .Distinct(); var createIssueRequest = new Octokit.NewIssue(Subject) { Body = Description }; foreach (var label in createLabels) { createIssueRequest.Labels.Add(label); } await applicationService.GitHubClient.Issue.Create(CodeHubOwner, CodeHubName, createIssueRequest); }, this.WhenAnyValue(x => x.Subject).Select(x => !string.IsNullOrEmpty(x))); SubmitCommand .ThrownExceptions .Select(x => new UserError("There was a problem trying to post your feedback: " + x.Message)) .SelectMany(Interactions.Errors.Handle) .Subscribe(); DismissCommand = ReactiveCommand.CreateFromTask(async t => { if (string.IsNullOrEmpty(Description) && string.IsNullOrEmpty(Subject)) { return(true); } var itemType = IsFeature ? "feature" : "bug"; return(await alertDialogService.PromptYesNo( "Discard " + itemType.Transform(To.TitleCase) + "?", "Are you sure you want to discard this " + itemType + "?")); }); }
public FeedbackComposerViewModel( IApplicationService applicationService, IImgurService imgurService, IMediaPickerFactory mediaPicker, IAlertDialogFactory alertDialogService) { 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.GetForRepository(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(); }); PostToImgurCommand = ReactiveCommand.CreateAsyncTask(async _ => { var photo = await mediaPicker.PickPhoto(); var memoryStream = new MemoryStream(); await photo.Save(Splat.CompressedBitmapFormat.Jpeg, 0.8f, memoryStream); using (alertDialogService.Activate("Uploading...")) { var model = await imgurService.SendImage(memoryStream.ToArray()); if (model == null || model.Data == null || model.Data.Link == null) { throw new InvalidOperationException("Unable to upload to Imgur. Please try again later."); } return(model.Data.Link); } }); PostToImgurCommand.ThrownExceptions .Where(x => !(x is TaskCanceledException)) .Subscribe(x => alertDialogService.Alert("Upload Error", x.Message)); }
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 FeedbackComposerViewModel( IApplicationService applicationService = null, IAlertDialogService alertDialogService = null) { applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>(); alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>(); SubmitCommand = ReactiveCommand.CreateFromTask(async _ => { if (string.IsNullOrEmpty(Subject)) { throw new ArgumentException("You must provide a title for this issue!"); } var createIssueRequest = new Octokit.NewIssue(Subject) { Body = Description }; await applicationService.GitHubClient.Issue.Create(CodeHubOwner, CodeHubName, createIssueRequest); }, this.WhenAnyValue(x => x.Subject).Select(x => !string.IsNullOrEmpty(x))); SubmitCommand .ThrownExceptions .Select(ex => new UserError("There was a problem trying to post your feedback.", ex)) .SelectMany(Interactions.Errors.Handle) .Subscribe(); DismissCommand = ReactiveCommand.CreateFromTask(async t => { if (string.IsNullOrEmpty(Description) && string.IsNullOrEmpty(Subject)) { return(true); } return(await alertDialogService.PromptYesNo( "Discard Issue?", "Are you sure you want to discard this issue?")); }); }
protected override Task<Octokit.Issue> Save() { try { var labels = Labels.Selected?.Select(y => y.Name).ToArray(); var milestone = Milestones.Selected?.Number; var user = Assignees.Selected?.Login; var newIssue = new Octokit.NewIssue(Subject) { Body = Content, Assignee = user, Milestone = milestone }; foreach (var label in labels) newIssue.Labels.Add(label); return _applicationService.GitHubClient.Issue.Create(RepositoryOwner, RepositoryName, newIssue); } catch (Exception e) { throw new Exception("Unable to save new issue! Please try again.", e); } }