/// <summary> /// Executes the index creation using in side-by-side mode. /// </summary> /// <param name="databaseCommands"></param> /// <param name="documentConvention"></param> public virtual void SideBySideExecute(IDatabaseCommands databaseCommands, DocumentConvention documentConvention, Etag minimumEtagBeforeReplace = null, DateTime?replaceTimeUtc = null) { Conventions = documentConvention; var indexDefinition = CreateIndexDefinition(); var serverDef = databaseCommands.GetIndex(IndexName); if (serverDef != null) { if (CurrentOrLegacyIndexDefinitionEquals(documentConvention, serverDef, indexDefinition)) { return; } var replaceIndexName = "ReplacementOf/" + IndexName; databaseCommands.PutIndex(replaceIndexName, indexDefinition); databaseCommands .Put(Constants.IndexReplacePrefix + replaceIndexName, null, RavenJObject.FromObject(new IndexReplaceDocument { IndexToReplace = serverDef.Name, MinimumEtagBeforeReplace = minimumEtagBeforeReplace, ReplaceTimeUtc = replaceTimeUtc }), new RavenJObject()); } else { // since index doesn't exist yet - create it in normal mode databaseCommands.PutIndex(IndexName, indexDefinition); } }
///<summary> /// Ensures that the database exists, creating it if needed ///</summary> /// <remarks> /// This operation happens _outside_ of any transaction /// </remarks> public static void EnsureDatabaseExists(this IDatabaseCommands self, string name, bool ignoreFailures = false) { self = self.ForDefaultDatabase(); var doc = MultiDatabase.CreateDatabaseDocument(name); var docId = "Raven/Databases/" + name; using (new TransactionScope(TransactionScopeOption.Suppress)) { try { if (self.Get(docId) != null) { return; } self.Put(docId, null, doc, new RavenJObject()); } catch (Exception) { if (ignoreFailures == false) { throw; } } } }
///<summary> /// Ensures that the database exists, creating it if needed ///</summary> /// <remarks> /// This operation happens _outside_ of any transaction /// </remarks> public static void EnsureDatabaseExists(this IDatabaseCommands 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; using (new TransactionScope(TransactionScopeOption.Suppress)) { try { if (self.Get(docId) != null) { return; } self.Put(docId, null, doc, new RavenJObject()); } catch (Exception) { if (ignoreFailures == false) { throw; } } } }
protected void SetupReplication(IDatabaseCommands source, IEnumerable <RavenJObject> destinations) { Assert.NotEmpty(destinations); source.Put(Constants.RavenReplicationDestinations, null, new RavenJObject { { "Destinations", new RavenJArray(destinations) } }, new RavenJObject()); }
public static void AddUserToDatabase(IDocumentStore documentStore, string username) { IDatabaseCommands systemCommands = documentStore .DatabaseCommands .ForSystemDatabase(); WindowsAuthDocument windowsAuthDocument = GetWindowsAuthDocument(systemCommands); AddOrUpdateAuthUser(windowsAuthDocument, username, "<system>"); RavenJObject ravenJObject = RavenJObject.FromObject(windowsAuthDocument); systemCommands.Put("Raven/Authorization/WindowsSettings", null, ravenJObject, new RavenJObject()); }
private static void SetupReplication(IDatabaseCommands source, params string[] urls) { source.Put(Constants.RavenReplicationDestinations, null, new RavenJObject { { "Destinations", new RavenJArray(urls.Select(url => new RavenJObject { { "Url", url } })) } }, new RavenJObject()); }
protected void RemoveReplication(IDatabaseCommands source) { source.Put( Constants.RavenReplicationDestinations, null, new RavenJObject { { "Destinations", new RavenJArray() } }, new RavenJObject()); }
internal static void AfterExecute(IDatabaseCommands databaseCommands, string indexName, ScriptedIndexResults scripts) { var documentId = GetScriptedIndexResultsDocumentId(indexName); scripts.Id = documentId; var oldDocument = databaseCommands.Get(documentId); var newDocument = RavenJObject.FromObject(scripts); if (oldDocument != null && RavenJToken.DeepEquals(oldDocument.DataAsJson, newDocument)) return; databaseCommands.Put(documentId, null, newDocument, null); databaseCommands.ResetIndex(indexName); }
private void UpdateSideBySideIndex(IDatabaseCommands databaseCommands, Etag minimumEtagBeforeReplace, DateTime?replaceTimeUtc, string replaceIndexName, IndexDefinition indexDefinition, DocumentConvention documentConvention) { databaseCommands.PutIndex(replaceIndexName, indexDefinition, true); databaseCommands .Put(Constants.IndexReplacePrefix + replaceIndexName, null, RavenJObject.FromObject(new IndexReplaceDocument { IndexToReplace = IndexName, MinimumEtagBeforeReplace = minimumEtagBeforeReplace, ReplaceTimeUtc = replaceTimeUtc }), new RavenJObject()); AfterExecute(databaseCommands, documentConvention); }
protected void SetupReplication(IDatabaseCommands source, params string[] urls) { Assert.NotEmpty(urls); source.Put(replication::Raven.Bundles.Replication.ReplicationConstants.RavenReplicationDestinations, null, new RavenJObject { { "Destinations", new RavenJArray(urls.Select(url => new RavenJObject { { "Url", url } })) } }, new RavenJObject()); }
static void InvokePut(IDatabaseCommands systemCommands, RavenJObject ravenJObject) { try { systemCommands.Put("Raven/Authorization/WindowsSettings", null, ravenJObject, new RavenJObject()); } catch (TargetInvocationException exception) { //need to catch OperationVetoedException here but cant do it in a strong typed way since the namespace of OperationVetoedException changed in 2.5 if (exception.InnerException.Message.Contains("Cannot setup Windows Authentication without a valid commercial license.")) { throw new Exception("RavenDB requires a Commercial license to configure windows authentication. Please either install your RavenDB license or contact [email protected] if you need a copy of the RavenDB license."); } throw; } }
internal static void AfterExecute(IDatabaseCommands databaseCommands, string indexName, ScriptedIndexResults scripts) { var documentId = GetScriptedIndexResultsDocumentId(indexName); scripts.Id = documentId; var oldDocument = databaseCommands.Get(documentId); var newDocument = RavenJObject.FromObject(scripts); if (oldDocument != null && RavenJToken.DeepEquals(oldDocument.DataAsJson, newDocument)) { return; } databaseCommands.Put(documentId, null, newDocument, null); databaseCommands.ResetIndex(indexName); }
///<summary> /// Ensures that the database exists, creating it if needed ///</summary> /// <remarks> /// This operation happens _outside_ of any transaction /// </remarks> public static void EnsureDatabaseExists(this IDatabaseCommands self, string name) { AssertValidName(name); var doc = RavenJObject.FromObject(new DatabaseDocument { Settings = { { "Raven/DataDir", Path.Combine("~", Path.Combine("Tenants", name)) } } }); var docId = "Raven/Databases/" + name; if (self.Get(docId) != null) { return; } using (new TransactionScope(TransactionScopeOption.Suppress)) self.Put(docId, null, doc, new RavenJObject()); }
private void PutDocument(JsonDocument document) { databaseCommands.Put(HiLoDocumentKey, document.Etag, document.DataAsJson, document.Metadata); }
private void PutDocument(JsonDocument document) { databaseCommands.Put(RavenKeyGeneratorsHilo + tag, document.Etag, document.DataAsJson, document.Metadata); }
public Task <PutResult> PutAsync(string key, Etag etag, RavenJObject document, RavenJObject metadata) { return(new CompletedTask <PutResult>(databaseCommands.Put(key, etag, document, metadata))); }
private void PutDocument(IDatabaseCommands databaseCommands,JsonDocument document) { databaseCommands.Put(HiLoDocumentKey, document.Etag, document.DataAsJson, document.Metadata); }
private static void SetupReplication(IDatabaseCommands source, params string[] urls) { source.Put(Constants.RavenReplicationDestinations, null, new RavenJObject { { "Destinations", new RavenJArray(urls.Select(url => new RavenJObject { {"Url", url} })) } }, new RavenJObject()); }
static bool InvokePut(IDatabaseCommands systemCommands, RavenJObject ravenJObject) { try { systemCommands.Put("Raven/Authorization/WindowsSettings", null, ravenJObject, new RavenJObject()); return true; } catch (ErrorResponseException exception) { if (exception.Message.Contains("Cannot setup Windows Authentication without a valid commercial license.")) { throw new Exception("RavenDB requires a Commercial license to configure windows authentication. Please either install your RavenDB license or contact [email protected] if you need a copy of the RavenDB license."); } throw; } }