本文整理汇总了C#中Raven.Smuggler.SmugglerDatabaseApi.Between方法的典型用法代码示例。如果您正苦于以下问题:C# SmugglerDatabaseApi.Between方法的具体用法?C# SmugglerDatabaseApi.Between怎么用?C# SmugglerDatabaseApi.Between使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Raven.Smuggler.SmugglerDatabaseApi
的用法示例。
在下文中一共展示了SmugglerDatabaseApi.Between方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SmugglerBetweenOperationShouldNotCreateDatabases
public void SmugglerBetweenOperationShouldNotCreateDatabases()
{
using (var store = NewRemoteDocumentStore())
{
var smugglerApi = new SmugglerDatabaseApi();
var options = new SmugglerBetweenOptions<RavenConnectionStringOptions>
{
From = new RavenConnectionStringOptions
{
Url = store.Url,
DefaultDatabase = "DB1"
},
To = new RavenConnectionStringOptions
{
Url = store.Url,
DefaultDatabase = "DB2"
}
};
var aggregateException = Assert.Throws<AggregateException>(() => smugglerApi.Between(options).Wait());
var exception = aggregateException.ExtractSingleInnerException();
Assert.True(exception.Message.StartsWith("Smuggler does not support database creation (database 'DB1' on server"));
store.DatabaseCommands.GlobalAdmin.EnsureDatabaseExists("DB1");
aggregateException = Assert.Throws<AggregateException>(() => smugglerApi.Between(options).Wait());
exception = aggregateException.ExtractSingleInnerException();
Assert.True(exception.Message.StartsWith("Smuggler does not support database creation (database 'DB2' on server"));
}
}
示例2: Using_smuggler_between_servers_should_take_into_accound_files_related_while_smuggling
public async Task Using_smuggler_between_servers_should_take_into_accound_files_related_while_smuggling()
{
using (var server1 = GetNewServer(8090))
using (var server2 = GetNewServer(8091))
using (var store1 = NewRemoteDocumentStore(ravenDbServer: server1))
using (var store2 = NewRemoteDocumentStore(ravenDbServer: server2))
{
var smugglerApi = new SmugglerDatabaseApi();
var createdUsers = AddDocuments(store1);
var users = new ConcurrentBag<User>();
foreach (var user in createdUsers)
users.Add(user);
var addDocsTask = Task.Run(() =>
{
var createdUsersInParallel = AddDocuments(store1);
foreach(var user in createdUsersInParallel)
users.Add(user);
});
var smugglingTask = smugglerApi.Between(new SmugglerBetweenOptions<RavenConnectionStringOptions>
{
From = new RavenConnectionStringOptions
{
Url = store1.Url,
DefaultDatabase = store1.DefaultDatabase
},
To = new RavenConnectionStringOptions
{
Url = store2.Url,
DefaultDatabase = store2.DefaultDatabase
}
});
await smugglingTask;
await addDocsTask; //not necessary -> smuggling task should effectively do this as well
WaitForIndexing(store2);
using (var session = store2.OpenSession())
Assert.Equal(users.Count, session.Query<User>().Count());
}
}
示例3: ShouldSmuggleIdentitiesBetweenDatabases
public async Task ShouldSmuggleIdentitiesBetweenDatabases()
{
using (var server1 = GetNewServer(port: 8079))
using (var store1 = NewRemoteDocumentStore(ravenDbServer: server1, databaseName: "Database1"))
{
using (var session = store1.OpenAsyncSession("Database1"))
{
await session.StoreAsync(new User {Id = "users/", Name = "Arek"});
await session.SaveChangesAsync();
}
store1.DatabaseCommands.SeedIdentityFor("users/", 10);
using (var server2 = GetNewServer(port: 8078))
{
using (var store2 = NewRemoteDocumentStore(ravenDbServer: server2, databaseName: "Database2"))
{
var smugglerApi = new SmugglerDatabaseApi();
await smugglerApi.Between(new SmugglerBetweenOptions<RavenConnectionStringOptions>
{
From = new RavenConnectionStringOptions {Url = "http://localhost:8079", DefaultDatabase = "Database1"},
To = new RavenConnectionStringOptions {Url = "http://localhost:8078", DefaultDatabase = "Database2"}
});
using (var session = store2.OpenAsyncSession("Database2"))
{
await session.StoreAsync(new User { Id = "users/", Name = "Oren" });
await session.SaveChangesAsync();
}
var documents = (await store2.AsyncDatabaseCommands.GetDocumentsAsync(0, 10)).OrderBy(x => x.Key).ToArray();
Assert.Equal(2, documents.Length);
Assert.Equal("users/1", documents[0].Key);
Assert.Equal("users/11", documents[1].Key);
}
}
}
}
示例4: CanUseBetween
public async Task CanUseBetween()
{
using (var server1 = new RavenDbServer(new RavenConfiguration()
{
Port = Port1,
ServerName = ServerName1
})
{
RunInMemory = true,
UseEmbeddedHttpServer = true
}.Initialize())
{
var doc = MultiDatabase.CreateDatabaseDocument("db1");
((ServerClient)server1.DocumentStore.DatabaseCommands.ForSystemDatabase()).GlobalAdmin.CreateDatabase(doc);
using (var store1 = new DocumentStore
{
Url = "http://localhost:" + Port1,
DefaultDatabase = "db1"
}.Initialize())
{
new Users_ByName().Execute(store1);
new UsersTransformer().Execute(store1);
using (var session = store1.OpenSession("db1"))
{
session.Store(new User { Name = "Name1", LastName = "LastName1" });
session.Store(new User { Name = "Name2", LastName = "LastName2" });
session.SaveChanges();
}
store1.DatabaseCommands.PutAttachment("attachement1", null, new MemoryStream(new byte[] { 3 }), new RavenJObject());
using (var server2 = new RavenDbServer(new RavenConfiguration()
{
Port = Port2,
ServerName = ServerName2
})
{
RunInMemory = true,
UseEmbeddedHttpServer = true
}.Initialize())
{
var doc2 = MultiDatabase.CreateDatabaseDocument("db2");
((ServerClient)server2.DocumentStore.DatabaseCommands.ForSystemDatabase()).GlobalAdmin.CreateDatabase(doc2);
using (var store2 = new DocumentStore
{
Url = "http://localhost:" + Port2,
DefaultDatabase = "db2"
}.Initialize())
{
var smugglerApi = new SmugglerDatabaseApi();
await smugglerApi.Between(new SmugglerBetweenOptions<RavenConnectionStringOptions>
{
From = new RavenConnectionStringOptions { Url = "http://localhost:" + Port1, DefaultDatabase = "db1" },
To = new RavenConnectionStringOptions { Url = "http://localhost:" + Port2, DefaultDatabase = "db2" }
});
var docs = store2.DatabaseCommands.GetDocuments(0, 10);
Assert.Equal(3, docs.Length);
var indexes = store2.DatabaseCommands.GetIndexes(0,10);
Assert.Equal(1, indexes.Length);
var transformers = store2.DatabaseCommands.GetTransformers(0, 10);
Assert.Equal(1, transformers.Length);
var attachments = store2.DatabaseCommands.GetAttachments(0, new Etag(), 10);
Assert.Equal(1, attachments.Length);
}
}
}
}
}
示例5: ShouldImportHiloWhenRavenEntityNameFilterIsUsed_Between
public async Task ShouldImportHiloWhenRavenEntityNameFilterIsUsed_Between()
{
using (var store1 = CreateStore())
using (var store2 = CreateStore())
{
using (var session = store1.OpenSession())
{
session.Store(new Person { Name = "John" });
session.Store(new Person { Name = "Edward" });
session.Store(new Address { Street = "Main Street" });
session.SaveChanges();
}
using (var stream = new MemoryStream())
{
var smugglerApi = new SmugglerDatabaseApi(new SmugglerDatabaseOptions
{
Filters =
{
new FilterSetting
{
Path = "@metadata.Raven-Entity-Name",
ShouldMatch = true,
Values = { "People" }
}
}
});
await smugglerApi.Between(new SmugglerBetweenOptions<RavenConnectionStringOptions>
{
From = new RavenConnectionStringOptions
{
DefaultDatabase = store1.DefaultDatabase,
Url = store1.Url
},
To = new RavenConnectionStringOptions
{
DefaultDatabase = store2.DefaultDatabase,
Url = store2.Url
}
});
}
WaitForIndexing(store2);
using (var session = store2.OpenSession())
{
var people = session
.Query<Person>()
.ToList();
Assert.Equal(2, people.Count);
var addresses = session
.Query<Address>()
.ToList();
Assert.Equal(0, addresses.Count);
var hilo = session.Advanced.DocumentStore.DatabaseCommands.Get("Raven/Hilo/People");
Assert.NotNull(hilo);
}
}
}
示例6: CanDisableVersioningDuringImport_Between_Remote
public async Task CanDisableVersioningDuringImport_Between_Remote()
{
using (var server = GetNewServer())
{
using (var store = NewRemoteDocumentStore(ravenDbServer: server))
{
store
.DatabaseCommands
.GlobalAdmin
.CreateDatabase(new DatabaseDocument
{
Id = "Import",
Settings =
{
{ Constants.ActiveBundles, "Versioning" },
{ "Raven/DataDir", NewDataPath() }
}
});
using (var session = store.OpenSession())
{
for (int i = 0; i < 10; i++)
{
session.Store(new User());
session.Store(new Address());
}
session.SaveChanges();
}
var countOfDocuments = store.DatabaseCommands.GetStatistics().CountOfDocuments;
store.DatabaseCommands.ForDatabase("Import").Put("Raven/Versioning/DefaultConfiguration", null, RavenJObject.FromObject(new Bundles.Versioning.Data.VersioningConfiguration
{
Exclude = false,
Id = "Raven/Versioning/DefaultConfiguration",
MaxRevisions = 5
}), new RavenJObject());
var smuggler = new SmugglerDatabaseApi(new SmugglerDatabaseOptions()
{
ShouldDisableVersioningBundle = true
});
await smuggler.Between(new SmugglerBetweenOptions<RavenConnectionStringOptions>()
{
From = new RavenConnectionStringOptions()
{
Url = store.Url,
DefaultDatabase = store.DefaultDatabase
},
To = new RavenConnectionStringOptions()
{
Url = store.Url,
DefaultDatabase = "Import"
}
});
var countOfDocsAfterImport = store.DatabaseCommands.ForDatabase("Import").GetStatistics().CountOfDocuments;
Assert.Equal(countOfDocuments, countOfDocsAfterImport - 1); // one additional doc for versioning bundle configuration
var metadata = store.DatabaseCommands.ForDatabase("Import").Get("users/1").Metadata;
Assert.True(metadata.ContainsKey(Constants.RavenIgnoreVersioning) == false, "Metadata contains temporary " + Constants.RavenIgnoreVersioning + " marker");
// after import versioning should be active
using (var session = store.OpenSession("Import"))
{
session.Store(new User(), "users/arek");
session.SaveChanges();
var revisionsFor = session.Advanced.GetRevisionsFor<User>("users/arek", 0, 10);
Assert.Equal(1, revisionsFor.Length);
}
}
}
}
示例7: Sample2
public async void Sample2()
{
#region smuggler_api_3
// export Documents and Indexes
// from Northwind database
// found on http://localhost:8080
// and import them to NewNorthwind
// found on the same server
SmugglerDatabaseApi smugglerApi = new SmugglerDatabaseApi(new SmugglerDatabaseOptions
{
OperateOnTypes = ItemType.Documents | ItemType.Indexes,
Incremental = false
});
await smugglerApi.Between(
new SmugglerBetweenOptions<RavenConnectionStringOptions>
{
From = new RavenConnectionStringOptions
{
Url = "http://localhost:8080",
DefaultDatabase = "Northwind"
},
To = new RavenConnectionStringOptions
{
Url = "http://localhost:8080",
DefaultDatabase = "NewNorthwind"
}
});
#endregion
}