public override void Execute(object parameter) { AskUser.SelectItem("Load", "Choose saved patching to load", () => ApplicationModel.Current.Server.Value.DocumentStore.OpenAsyncSession().Advanced. LoadStartingWithAsync <PatchDocument>("Studio/Patch/").ContinueWith( task => { IList <string> objects = task.Result.Select(document => document.Id.Substring("Studio/Patch/".Length)).ToList(); return(objects); })) .ContinueOnSuccessInTheUIThread(result => ApplicationModel.Current.Server.Value.DocumentStore.OpenAsyncSession(). LoadAsync <PatchDocument>("Studio/Patch/" + result) .ContinueOnSuccessInTheUIThread(patch => { if (patch == null) { ApplicationModel.Current.Notifications.Add(new Notification("Could not find Patch document named " + result, NotificationLevel.Error)); } else { patchModel.PatchOn = patch.PatchOnOption; patchModel.QueryDoc.SetText(patch.Query); patchModel.Script.SetText(patch.Script); patchModel.SelectedItem = patch.SelectedItem; patchModel.Values = new ObservableCollection <PatchValue>(patch.Values); patchModel.UpdateDoc(result); } })); }
public override void Execute(object parameter) { AskUser.QuestionAsync("Save", "Please enter a name").ContinueOnSuccessInTheUIThread(name => { var doc = new PatchDocument { PatchOnOption = patchModel.PatchOn, Query = patchModel.QueryDoc.CurrentSnapshot.GetText(LineTerminator.Newline), Script = patchModel.Script.CurrentSnapshot.GetText(LineTerminator.Newline), SelectedItem = patchModel.SelectedItem, Id = "Studio/Patch/" + name, Values = patchModel.Values.ToList() }; var session = ApplicationModel.Current.Server.Value.DocumentStore.OpenAsyncSession(); session.Store(doc); session.SaveChangesAsync().ContinueOnSuccessInTheUIThread(() => patchModel.UpdateDoc(name)); }); }