Exemple #1
0
        public virtual async Task SideBySideExecuteAsync(IAsyncDatabaseCommands asyncDatabaseCommands, DocumentConvention documentConvention, Etag minimumEtagBeforeReplace = null, DateTime?replaceTimeUtc = null, CancellationToken token = default(CancellationToken))
        {
            Conventions = documentConvention;
            var indexDefinition = CreateIndexDefinition();
            var serverDef       = await asyncDatabaseCommands.GetIndexAsync(IndexName, token).ConfigureAwait(false);

            if (serverDef != null)
            {
                if (CurrentOrLegacyIndexDefinitionEquals(documentConvention, serverDef, indexDefinition))
                {
                    return;
                }

                var replaceIndexName = "ReplacementOf/" + IndexName;
                await asyncDatabaseCommands.PutIndexAsync(replaceIndexName, indexDefinition, token).ConfigureAwait(false);

                await asyncDatabaseCommands
                .PutAsync(Constants.IndexReplacePrefix + replaceIndexName,
                          null,
                          RavenJObject.FromObject(new IndexReplaceDocument {
                    IndexToReplace = serverDef.Name, MinimumEtagBeforeReplace = minimumEtagBeforeReplace, ReplaceTimeUtc = replaceTimeUtc
                }),
                          new RavenJObject(),
                          token).ConfigureAwait(false);
            }
            else
            {
                // since index doesn't exist yet - create it in normal mode
                await asyncDatabaseCommands.PutIndexAsync(IndexName, indexDefinition, token).ConfigureAwait(false);
            }
        }
Exemple #2
0
        ///<summary>
        /// Ensures that the database exists, creating it if needed
        ///</summary>
        public static Task EnsureDatabaseExistsAsync(this IAsyncDatabaseCommands self, string name, bool ignoreFailures = false)
        {
            self = self.ForDefaultDatabase();
            var doc   = MultiDatabase.CreateDatabaseDocument(name);
            var docId = "Raven/Databases/" + name;

            return(self.GetAsync(docId)
                   .ContinueWith(get =>
            {
                if (get.Result != null)
                {
                    return get;
                }

                return (Task)self.PutAsync(docId, null, doc, new RavenJObject());
            })
                   .Unwrap()
                   .ContinueWith(x =>
            {
                if (ignoreFailures == false)
                {
                    x.Wait();                             // will throw on error
                }
                var observedException = x.Exception;
                GC.KeepAlive(observedException);
            }));
        }
        internal static async Task AfterExecuteAsync(IAsyncDatabaseCommands asyncDatabaseCommands, string indexName, ScriptedIndexResults scripts, CancellationToken token)
        {
            var documentId = GetScriptedIndexResultsDocumentId(indexName);
            scripts.Id = documentId;

            var oldDocument = await asyncDatabaseCommands.GetAsync(documentId, token).ConfigureAwait(false);
            var newDocument = RavenJObject.FromObject(scripts);
            if (oldDocument != null && RavenJToken.DeepEquals(oldDocument.DataAsJson, newDocument))
                return;

            await asyncDatabaseCommands.PutAsync(documentId, null, newDocument, null, token).ConfigureAwait(false);
            await asyncDatabaseCommands.ResetIndexAsync(indexName, token).ConfigureAwait(false);
        }
Exemple #4
0
        private async Task UpdateSideBySideIndexAsync(IAsyncDatabaseCommands asyncDatabaseCommands, Etag minimumEtagBeforeReplace, DateTime?replaceTimeUtc, CancellationToken token, string replaceIndexName, IndexDefinition indexDefinition, DocumentConvention documentConvention)
        {
            await asyncDatabaseCommands.PutIndexAsync(replaceIndexName, indexDefinition, true, token).ConfigureAwait(false);

            await asyncDatabaseCommands
            .PutAsync(Constants.IndexReplacePrefix + replaceIndexName,
                      null,
                      RavenJObject.FromObject(new IndexReplaceDocument {
                IndexToReplace = IndexName, MinimumEtagBeforeReplace = minimumEtagBeforeReplace, ReplaceTimeUtc = replaceTimeUtc
            }),
                      new RavenJObject(),
                      token).ConfigureAwait(false);

            await AfterExecuteAsync(asyncDatabaseCommands, documentConvention, token).ConfigureAwait(false);
        }
Exemple #5
0
        internal static async Task AfterExecuteAsync(IAsyncDatabaseCommands asyncDatabaseCommands, string indexName, ScriptedIndexResults scripts, CancellationToken token)
        {
            var documentId = GetScriptedIndexResultsDocumentId(indexName);

            scripts.Id = documentId;

            var oldDocument = await asyncDatabaseCommands.GetAsync(documentId, token).ConfigureAwait(false);

            var newDocument = RavenJObject.FromObject(scripts);

            if (oldDocument != null && RavenJToken.DeepEquals(oldDocument.DataAsJson, newDocument))
            {
                return;
            }

            await asyncDatabaseCommands.PutAsync(documentId, null, newDocument, null, token).ConfigureAwait(false);

            await asyncDatabaseCommands.ResetIndexAsync(indexName, token).ConfigureAwait(false);
        }
        ///<summary>
        /// Ensures that the database exists, creating it if needed
        ///</summary>
        public static Task EnsureDatabaseExistsAsync(this IAsyncDatabaseCommands self, string name)
        {
            var doc = JObject.FromObject(new DatabaseDocument
            {
                Settings =
                {
                    { "Raven/DataDir", Path.Combine("~", Path.Combine("Tenants", name)) }
                }
            });
            var docId = "Raven/Databases/" + name;

            return(self.GetAsync(docId)
                   .ContinueWith(get =>
            {
                if (get.Result != null)
                {
                    return get;
                }

                return (Task)self.PutAsync(docId, null, doc, new JObject());
            })
                   .Unwrap());
        }
        ///<summary>
        /// Ensures that the database exists, creating it if needed
        ///</summary>
        public static Task EnsureDatabaseExistsAsync(this IAsyncDatabaseCommands self, string name, bool ignoreFailures = false)
        {
            self = self.ForDefaultDatabase();
            AssertValidName(name);
            var doc = RavenJObject.FromObject(new DatabaseDocument
            {
                Settings =
                {
                    { "Raven/DataDir", Path.Combine("~", Path.Combine("Tenants", name)) }
                }
            });

            doc.Remove("Id");
            var docId = "Raven/Databases/" + name;

            return(self.GetAsync(docId)
                   .ContinueWith(get =>
            {
                if (get.Result != null)
                {
                    return get;
                }

                return (Task)self.PutAsync(docId, null, doc, new RavenJObject());
            })
                   .Unwrap()
                   .ContinueWith(x =>
            {
                if (ignoreFailures == false)
                {
                    x.Wait();                             // will throw on error
                }
                var observedException = x.Exception;
                GC.KeepAlive(observedException);
            }));
        }
		private Task PutDocumentAsync(IAsyncDatabaseCommands databaseCommands, JsonDocument document)
		{
			return databaseCommands.PutAsync(HiLoDocumentKey, document.Etag,
								 document.DataAsJson,
								 document.Metadata);
		}
Exemple #9
0
 private Task PutDocumentAsync(IAsyncDatabaseCommands databaseCommands, JsonDocument document)
 {
     return(databaseCommands.PutAsync(HiLoDocumentKey, document.Etag,
                                      document.DataAsJson,
                                      document.Metadata));
 }