public MarkdownAccessoryViewModel( IImgurService imgurService, IMediaPickerFactory mediaPicker, IAlertDialogFactory alertDialogFactory, IDefaultValueService defaultValueService) { PostToImgurCommand = ReactiveCommand.CreateAsyncTask(async _ => { if (!defaultValueService.GetOrDefault(IMGUR_UPLOAD_WARN, false)) { defaultValueService.Set(IMGUR_UPLOAD_WARN, true); await alertDialogFactory.Alert("Please Read!", IMGUR_UPLOAD_WARN_MESSAGE); } var photo = await mediaPicker.PickPhoto(); var memoryStream = new MemoryStream(); await photo.Save(Splat.CompressedBitmapFormat.Jpeg, 0.8f, memoryStream); using (alertDialogFactory.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 => alertDialogFactory.Alert("Upload Error", x.Message)); }
public MarkdownAccessoryViewModel( IImgurService imgurService, IMediaPickerFactory mediaPicker, IAlertDialogFactory alertDialogFactory, IDefaultValueService defaultValueService) { PostToImgurCommand = ReactiveCommand.CreateAsyncTask(async _ => { if (!defaultValueService.GetOrDefault(IMGUR_UPLOAD_WARN, false)) { defaultValueService.Set(IMGUR_UPLOAD_WARN, true); await alertDialogFactory.Alert("Please Read!", IMGUR_UPLOAD_WARN_MESSAGE); } var photo = await mediaPicker.PickPhoto(); var memoryStream = new MemoryStream(); await photo.Save(Splat.CompressedBitmapFormat.Jpeg, 0.8f, memoryStream); using (alertDialogFactory.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 => alertDialogFactory.Alert("Upload Error", x.Message)); }
protected override void OnLoadError(object sender, UIWebErrorArgs e) { base.OnLoadError(sender, e); //Frame interrupted error if (e.Error.Code == 102 || e.Error.Code == -999) { return; } _alertDialogService.Alert("Error", "Unable to communicate with GitHub. " + e.Error.LocalizedDescription).ToBackground(); }
protected AddAccountViewModel(IAlertDialogFactory alertDialogFactory) { _alertDialogFactory = alertDialogFactory; Title = "Login"; this.WhenAnyValue(x => x.AttemptedAccount).Where(x => x != null).Subscribe(x => { Username = x.Username; Domain = x.Domain; }); LoginCommand = ReactiveCommand.CreateAsyncTask(async _ => { if (string.IsNullOrEmpty(Username)) throw new ArgumentException("Must have a valid username!"); if (string.IsNullOrEmpty(Password)) throw new ArgumentException("Must have a valid password!"); if (string.IsNullOrEmpty(Domain)) throw new ArgumentException("Must have a valid GitHub domain!"); using (alertDialogFactory.Activate("Logging in...")) return await Login(); }); LoginCommand.ThrownExceptions.Subscribe(x => { if (x is LoginService.TwoFactorRequiredException) PromptForTwoFactor().ToBackground(); else _alertDialogFactory.Alert("Error", x.Message).ToBackground(); }); LoginCommand.Subscribe(x => MessageBus.Current.SendMessage(new LogoutMessage())); }
protected AddAccountViewModel(IAlertDialogFactory alertDialogFactory) { _alertDialogFactory = alertDialogFactory; Title = "Login"; this.WhenAnyValue(x => x.AttemptedAccount).Where(x => x != null).Subscribe(x => { Username = x.Username; Domain = x.Domain; }); var canLogin = this.WhenAnyValue(x => x.Username, y => y.Password, z => z.Domain, (x, y, z) => !string.IsNullOrEmpty(x) && !string.IsNullOrEmpty(y) && !string.IsNullOrEmpty(z)); LoginCommand = ReactiveCommand.CreateAsyncTask(canLogin, async _ => { using (alertDialogFactory.Activate("Logging in...")) return await Login(); }); LoginCommand.ThrownExceptions.Subscribe(x => { if (x is LoginService.TwoFactorRequiredException) PromptForTwoFactor().ToBackground(); else _alertDialogFactory.Alert("Error", x.Message).ToBackground(); }); LoginCommand.Subscribe(x => MessageBus.Current.SendMessage(new LogoutMessage())); }
protected override void OnLoadError(object sender, UIWebErrorArgs e) { base.OnLoadError(sender, e); if (e.Error.Code == 102) { _alertDialogFactory.Alert("Oh no!", "Looks like CodeHub cannot display this type of file. Sorry about that :("); } }
private async Task Load() { var account = await _accountsService.GetDefault(); // Account no longer exists if (account == null) { await GoToAccountsOrNewUser(); return; } try { Status = string.Format("Logging in {0}", account.Username); Avatar = new GitHubAvatar(account.AvatarUrl); IsLoggingIn = true; await _sessionService.SetSessionAccount(account); // NavigateTo(this.CreateViewModel<MenuViewModel>()); NavigateTo(this.CreateViewModel <UserViewModel>().Init("thedillonb")); StarOrWatch(); } catch (UnauthorizedException) { _alertDialogFactory.Alert("Unable to login!", "Your credentials are no longer valid for this account.") .ToObservable() .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(_ => NavigateTo(this.CreateViewModel <AccountsViewModel>())); } catch (Exception e) { _alertDialogFactory.Alert("Unable to login!", e.Message) .ToObservable() .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(_ => NavigateTo(this.CreateViewModel <AccountsViewModel>())); } finally { IsLoggingIn = false; } }
protected override void OnLoadError(object sender, UIWebErrorArgs e) { base.OnLoadError(sender, e); //Frame interrupted error if (e.Error.Code == 102) { return; } if (ViewModel.IsEnterprise) { var alert = _alertDialogService.Alert("Error", "Unable to communicate with GitHub with given Url. " + e.Error.LocalizedDescription); alert.ContinueWith(t => ViewModel.LoadCommand.ExecuteIfCan(), TaskContinuationOptions.OnlyOnRanToCompletion); } else { _alertDialogService.Alert("Error", "Unable to communicate with GitHub. " + e.Error.LocalizedDescription); } }
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)); }
protected AddAccountViewModel(IAlertDialogFactory alertDialogFactory) { _alertDialogFactory = alertDialogFactory; Title = "Login"; this.WhenAnyValue(x => x.AttemptedAccount).Where(x => x != null).Subscribe(x => { Username = x.Username; Domain = x.Domain; }); LoginCommand = ReactiveCommand.CreateAsyncTask(async _ => { if (string.IsNullOrEmpty(Username)) { throw new ArgumentException("Must have a valid username!"); } if (string.IsNullOrEmpty(Password)) { throw new ArgumentException("Must have a valid password!"); } if (string.IsNullOrEmpty(Domain)) { throw new ArgumentException("Must have a valid GitHub domain!"); } using (alertDialogFactory.Activate("Logging in...")) return(await Login()); }); LoginCommand.ThrownExceptions.Subscribe(x => { if (x is LoginService.TwoFactorRequiredException) { PromptForTwoFactor().ToBackground(); } else { _alertDialogFactory.Alert("Error", x.Message).ToBackground(); } }); LoginCommand.Subscribe(x => MessageBus.Current.SendMessage(new LogoutMessage())); }
public EnterpriseSupportViewController(IAlertDialogFactory alertDialogFactory) { this.WhenAnyValue(x => x.ViewModel.SubmitFeedbackCommand) .Switch() .Subscribe(_ => { var ctrl = new MFMailComposeViewController(); ctrl.SetSubject("CodeHub Support"); ctrl.SetToRecipients(new [] { "*****@*****.**" }); ctrl.Finished += (sender, e) => DismissViewController(true, () => { if (e.Result == MFMailComposeResult.Sent) { alertDialogFactory.Alert("Sent!", "Thanks for your feedback!"); } }); PresentViewController(ctrl, true, null); }); Appearing .Select(_ => NavigationController) .Where(x => x != null) .Subscribe(x => x.NavigationBar.ShadowImage = new UIImage()); }
public GistCreateViewModel(IApplicationService applicationService, IAlertDialogFactory alertDialogFactory) { _applicationService = applicationService; CurrentAccount = applicationService.Account; Title = "Create Gist"; Files = new Dictionary <string, string>(); IsPublic = true; SaveCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Files).Select(x => x.Count > 0), async t => { var createGist = new GistCreateModel { Description = Description, Public = IsPublic, Files = Files.ToDictionary(x => x.Key, x => new GistCreateModel.File { Content = x.Value }) }; var request = _applicationService.Client.AuthenticatedUser.Gists.CreateGist(createGist); using (alertDialogFactory.Activate("Creating Gist...")) _createdGistSubject.OnNext((await _applicationService.Client.ExecuteAsync(request)).Data); Dismiss(); }); AddGistFileCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel <ModifyGistViewModel>(); vm.Title = "New File"; vm.SaveCommand.Subscribe(__ => { if (Files.ContainsKey(vm.Filename)) { alertDialogFactory.Alert("File already exists!", "Gist already contains a file with that name!"); } else { Files.Add(vm.Filename, vm.Description); Files = new Dictionary <string, string>(Files); vm.Dismiss(); } }); NavigateTo(vm); }); ModifyGistFileCommand = ReactiveCommand.Create(); // Analysis disable once ConvertClosureToMethodGroup // Don't remove the lambda below. It doesn't actually seem to work correctly ModifyGistFileCommand.OfType <string>().Where(x => Files.ContainsKey(x)).Subscribe(x => { var vm = this.CreateViewModel <ModifyGistViewModel>(); vm.Title = vm.Filename = x; vm.Description = Files[x]; vm.SaveCommand.Subscribe(__ => { Files.Remove(x); Files[vm.Filename] = vm.Description; Files = new Dictionary <string, string>(Files); vm.Dismiss(); }); NavigateTo(vm); }); }