private async Task <GistModel> Save() { if (_files.Count == 0) { throw new Exception("You cannot create a Gist without atleast one file! Please correct and try again."); } try { var createGist = new GistCreateModel { Description = Description ?? string.Empty, Public = Public, Files = Files.ToDictionary(x => x.Key, x => new GistCreateModel.File { Content = x.Value }) }; IsSaving = true; var newGist = (await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.AuthenticatedUser.Gists.CreateGist(createGist))).Data; Messenger.Publish(new GistAddMessage(this, newGist)); return(newGist); } finally { IsSaving = false; } }
public GistCreateViewModel(IApplicationService applicationService) { _applicationService = applicationService; Title = "Create Gist"; Files = new Dictionary <string, string>(); SaveCommand = ReactiveCommand.CreateAsyncTask(async t => { if (_files == null || _files.Count == 0) { throw new Exception("You cannot create a Gist without atleast one file! Please correct and try again."); } 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); _createdGistSubject.OnNext((await _applicationService.Client.ExecuteAsync(request)).Data); DismissCommand.ExecuteIfCan(); }); }
private async Task Save() { if (_files.Count == 0) { DisplayAlert("You cannot create a Gist without atleast one file! Please correct and try again."); return; } try { var createGist = new GistCreateModel() { Description = Description, Public = Public, Files = Files.ToDictionary(x => x.Key, x => new GistCreateModel.File { Content = x.Value }) }; IsSaving = true; var newGist = (await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.AuthenticatedUser.Gists.CreateGist(createGist))).Data; Messenger.Publish(new GistAddMessage(this, newGist)); ChangePresentation(new MvxClosePresentationHint(this)); } catch (Exception e) { DisplayAlert("Unable to create new gist! Please try again."); } finally { IsSaving = false; } }
public GitHubRequest <GistModel> CreateGist(GistCreateModel gist) { //Great... The RestSharp serializer can't handle this object... //Dictionary<string, obj> confuses it and converts it into {"key": "ok", "value": "dokie"} //instead of {"ok": "dokie"} var obj = new Dictionary <string, object>(); obj.Add("description", gist.Description); obj.Add("public", gist.Public); var files = new Dictionary <string, object>(); obj.Add("files", files); if (gist.Files != null) { foreach (var f in gist.Files.Keys) { var content = new Dictionary <string, object>(); files.Add(f, content); content.Add("content", gist.Files[f].Content); } } return(GitHubRequest.Post <GistModel>(Client.ApiUri + "/gists", obj)); }
public GistCreateViewModel(IApplicationService applicationService, IAlertDialogFactory alertDialogFactory) { _applicationService = applicationService; CurrentAccount = applicationService.Account; Title = "Create Gist"; IsPublic = true; var files = new ReactiveList <Tuple <string, string> >(); Files = files.CreateDerivedCollection(x => { var item = new GistFileItemViewModel(x.Item1, x.Item2); item.EditCommand.Subscribe(_ => NavigateTo(new GistFileEditViewModel(y => { var i = files.IndexOf(x); files.Remove(x); files.Insert(i, y); return(Task.FromResult(0)); }) { Filename = x.Item1, Description = x.Item2 })); item.DeleteCommand.Subscribe(_ => files.Remove(x)); return(item); }); SaveCommand = ReactiveCommand.CreateAsyncTask(Files.CountChanged.Select(x => x > 0), async t => { var createGist = new GistCreateModel { Description = Description, Public = IsPublic, Files = Files.ToDictionary(x => x.Name, x => new GistCreateModel.File { Content = x.Content }) }; var request = _applicationService.Client.AuthenticatedUser.Gists.CreateGist(createGist); using (alertDialogFactory.Activate("Creating Gist...")) return((await _applicationService.Client.ExecuteAsync(request)).Data); }); SaveCommand.Subscribe(_ => Dismiss()); AddGistFileCommand = ReactiveCommand.Create() .WithSubscription(_ => NavigateTo(new GistFileAddViewModel(x => { if (Files.Any(y => y.Name == x.Item1)) { throw new Exception("Gist already contains a file with that name!"); } files.Add(x); return(Task.FromResult(0)); }))); }
public CreateGistViewController() : base(true) { Title = "Create Gist"; Style = UITableViewStyle.Grouped; NavigationItem.RightBarButtonItem = new UIBarButtonItem(Theme.CurrentTheme.SaveButton, UIBarButtonItemStyle.Plain, (s, e) => Save()); _model = new GistCreateModel() { Public = true }; _model.Files = new Dictionary<string, GistCreateModel.File>(); }
public CreateGistController() : base(true) { Title = "Create Gist"; Style = UITableViewStyle.Grouped; NavigationItem.LeftBarButtonItem = new UIBarButtonItem (NavigationButton.Create(Images.Buttons.Cancel, Discard)); NavigationItem.RightBarButtonItem = new UIBarButtonItem(NavigationButton.Create(Images.Buttons.Save, Save)); _model = new GistCreateModel() { Public = true }; _model.Files = new Dictionary<string, GistCreateModel.File>(); }
public CreateGistViewController() : base(true) { Title = "Create Gist"; Style = UITableViewStyle.Grouped; NavigationItem.RightBarButtonItem = new UIBarButtonItem(NavigationButton.Create(CodeFramework.Theme.CurrentTheme.SaveButton, Save)); _model = new GistCreateModel() { Public = true }; _model.Files = new Dictionary <string, GistCreateModel.File>(); }
public CreateGistController() : base(true) { Title = "Create Gist"; Style = UITableViewStyle.Grouped; NavigationItem.LeftBarButtonItem = new UIBarButtonItem(NavigationButton.Create(Images.Buttons.Cancel, Discard)); NavigationItem.RightBarButtonItem = new UIBarButtonItem(NavigationButton.Create(Images.Buttons.Save, Save)); _model = new GistCreateModel() { Public = true }; _model.Files = new Dictionary <string, GistCreateModel.File>(); }
public GistCreateViewModel(IApplicationService applicationService) { _applicationService = applicationService; SaveCommand = new ReactiveCommand(); SaveCommand.RegisterAsyncTask(async t => { if (_files == null || _files.Count == 0) throw new Exception("You cannot create a Gist without atleast one file! Please correct and try again."); var createGist = new GistCreateModel { Description = Description, Public = Public, Files = Files.ToDictionary(x => x.Key, x => new GistCreateModel.File { Content = x.Value }) }; var newGist = (await _applicationService.Client.ExecuteAsync(_applicationService.Client.AuthenticatedUser.Gists.CreateGist(createGist))).Data; CreatedGist = newGist; DismissCommand.ExecuteIfCan(); }); }
private async Task<GistModel> Save() { if (_files.Count == 0) throw new Exception("You cannot create a Gist without atleast one file! Please correct and try again."); try { var createGist = new GistCreateModel { Description = Description ?? string.Empty, Public = Public, Files = Files.ToDictionary(x => x.Key, x => new GistCreateModel.File { Content = x.Value }) }; IsSaving = true; var newGist = (await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.AuthenticatedUser.Gists.CreateGist(createGist))).Data; Messenger.Publish(new GistAddMessage(this, newGist)); return newGist; } finally { IsSaving = false; } }
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); }); }