Raven.Studio.Models.PatchModel.UpdateCollectionSource C# (CSharp) Method

UpdateCollectionSource() public method

public UpdateCollectionSource ( ) : void
return void
	    public void UpdateCollectionSource()
	    {
            recentDocuments.Clear();
		    NewDoc.SetText("");
		    ShowAfterPrompt = true;
	        if (PatchOn == PatchOnOptions.Collection)
	        {
                QueryResults.SetChangesObservable(d => d.IndexChanges
					.Where(n => n.Name.Equals(CollectionsIndex, StringComparison.InvariantCulture))
					.Select(m => Unit.Default));

				if (string.IsNullOrWhiteSpace(SelectedItem) == false)
					queryCollectionSource.UpdateQuery(CollectionsIndex, new IndexQuery {Query = "Tag:" + SelectedItem});
	        }
            else if (PatchOn == PatchOnOptions.Index)
            {
                QueryResults.SetChangesObservable(d => d.IndexChanges
					.Where(n => n.Name.Equals(SelectedItem, StringComparison.InvariantCulture))
					.Select(m => Unit.Default));

				if (string.IsNullOrWhiteSpace(SelectedItem) == false)
					queryCollectionSource.UpdateQuery(SelectedItem, new IndexQuery { Query = QueryDoc.CurrentSnapshot.Text, SkipTransformResults = true, });
            }
	    }

Usage Example

Ejemplo n.º 1
0
        public override void Execute(object parameter)
        {
            AskUser.ConfirmationAsync("Patch Documents", "Are you sure you want to apply this patch to all matching documents?")
            .ContinueWhenTrueInTheUIThread(() =>
            {
                var values = patchModel.GetValues();
                if (values == null)
                {
                    return;
                }
                var request = new ScriptedPatchRequest {
                    Script = patchModel.Script.CurrentSnapshot.Text, Values = values
                };

                switch (patchModel.PatchOn)
                {
                case PatchOnOptions.Document:
                    var commands = new ICommandData[1];
                    commands[0]  = new ScriptedPatchCommandData
                    {
                        Patch = request,
                        Key   = patchModel.SelectedItem
                    };

                    ApplicationModel.Database.Value.AsyncDatabaseCommands.BatchAsync(commands).Catch().
                    ContinueOnSuccessInTheUIThread(
                        () => ApplicationModel.Database.Value.AsyncDatabaseCommands.GetAsync(patchModel.SelectedItem).
                        ContinueOnSuccessInTheUIThread(
                            doc =>
                    {
                        patchModel.OriginalDoc.SetText(doc.ToJson().ToString());
                        patchModel.NewDoc.SetText("");
                        patchModel.ShowAfterPrompt = true;
                    }));
                    break;

                case PatchOnOptions.Collection:
                    ApplicationModel.Database.Value.AsyncDatabaseCommands.UpdateByIndex(PatchModel.CollectionsIndex,
                                                                                        new IndexQuery {
                        Query = "Tag:" + patchModel.SelectedItem
                    }, request)
                    .ContinueOnSuccessInTheUIThread(() => patchModel.UpdateCollectionSource())
                    .Catch();
                    break;

                case PatchOnOptions.Index:
                    ApplicationModel.Database.Value.AsyncDatabaseCommands.UpdateByIndex(patchModel.SelectedItem, new IndexQuery()
                    {
                        Query = patchModel.QueryDoc.CurrentSnapshot.Text
                    },
                                                                                        request)
                    .ContinueOnSuccessInTheUIThread(() => patchModel.UpdateCollectionSource())
                    .Catch();
                    break;
                }
            });
        }