本文整理汇总了C#中Raven.Smuggler.SmugglerDatabaseApi.ImportData方法的典型用法代码示例。如果您正苦于以下问题:C# SmugglerDatabaseApi.ImportData方法的具体用法?C# SmugglerDatabaseApi.ImportData怎么用?C# SmugglerDatabaseApi.ImportData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Raven.Smuggler.SmugglerDatabaseApi
的用法示例。
在下文中一共展示了SmugglerDatabaseApi.ImportData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MaxNumberOfItemsToProcessInSingleBatchShouldBeRespectedBySmuggler
public void MaxNumberOfItemsToProcessInSingleBatchShouldBeRespectedBySmuggler()
{
var path = Path.Combine(NewDataPath(forceCreateDir: true), "raven.dump");
using (var server = GetNewServer(configureConfig: configuration => configuration.MaxNumberOfItemsToProcessInSingleBatch = 1234))
{
var smuggler = new SmugglerDatabaseApi(options: new SmugglerDatabaseOptions { BatchSize = 4321 });
Assert.Equal(4321, smuggler.Options.BatchSize);
smuggler.ExportData(new SmugglerExportOptions<RavenConnectionStringOptions> { ToFile = path, From = new RavenConnectionStringOptions { Url = server.Configuration.ServerUrl } }).ResultUnwrap();
Assert.Equal(1234, smuggler.Options.BatchSize);
smuggler = new SmugglerDatabaseApi(options: new SmugglerDatabaseOptions { BatchSize = 4321 });
Assert.Equal(4321, smuggler.Options.BatchSize);
smuggler.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions> { FromFile = path, To = new RavenConnectionStringOptions { Url = server.Configuration.ServerUrl } }).Wait();
Assert.Equal(1234, smuggler.Options.BatchSize);
smuggler = new SmugglerDatabaseApi(options: new SmugglerDatabaseOptions { BatchSize = 1000 });
Assert.Equal(1000, smuggler.Options.BatchSize);
smuggler.ExportData(new SmugglerExportOptions<RavenConnectionStringOptions> { ToFile = path, From = new RavenConnectionStringOptions { Url = server.Configuration.ServerUrl } }).ResultUnwrap();
Assert.Equal(1000, smuggler.Options.BatchSize);
}
}
示例2: SmugglerShouldThrowIfDatabaseDoesNotExist
public async Task SmugglerShouldThrowIfDatabaseDoesNotExist()
{
var path = Path.GetTempFileName();
try
{
using (var store = NewRemoteDocumentStore())
{
var connectionStringOptions =
new RavenConnectionStringOptions
{
Url = store.Url,
DefaultDatabase = "DoesNotExist"
};
var smuggler = new SmugglerDatabaseApi();
var e = await AssertAsync.Throws<SmugglerException>(() => smuggler.ImportData(
new SmugglerImportOptions<RavenConnectionStringOptions> { FromFile = path, To = connectionStringOptions }));
Assert.Equal(string.Format("Smuggler does not support database creation (database 'DoesNotExist' on server '{0}' must exist before running Smuggler).", store.Url), e.Message);
e = await AssertAsync.Throws<SmugglerException>(() => smuggler.ExportData(
new SmugglerExportOptions<RavenConnectionStringOptions> { ToFile = path, From = connectionStringOptions }));
Assert.Equal(string.Format("Smuggler does not support database creation (database 'DoesNotExist' on server '{0}' must exist before running Smuggler).", store.Url), e.Message);
}
}
finally
{
IOExtensions.DeleteFile(path);
}
}
示例3: Sample1
public async void Sample1()
{
#region smuggler_api_2
// import only Documents
// from dump.raven file
// to NewNorthwind database (must exist)
// found on http://localhost:8080 server
SmugglerDatabaseApi smugglerApi = new SmugglerDatabaseApi(new SmugglerDatabaseOptions
{
OperateOnTypes = ItemType.Documents,
Incremental = false
});
SmugglerImportOptions<RavenConnectionStringOptions> importOptions = new SmugglerImportOptions<RavenConnectionStringOptions>
{
FromFile = "dump.raven",
To = new RavenConnectionStringOptions
{
DefaultDatabase = "NewNorthwind",
Url = "http://localhost:8080"
}
};
await smugglerApi.ImportData(importOptions, null);
#endregion
}
示例4: ImportingReplicationDestinationsDocumentWithInvalidSourceShouldReportOneAlertOnly
public void ImportingReplicationDestinationsDocumentWithInvalidSourceShouldReportOneAlertOnly()
{
var store1 = CreateStore();
var store2 = CreateStore();
var store3 = CreateStore();
TellFirstInstanceToReplicateToSecondInstance();
store2.Dispose();
store1.DatabaseCommands.Put("1", null, new RavenJObject(), new RavenJObject());
store1.DatabaseCommands.Put("2", null, new RavenJObject(), new RavenJObject());
var smuggler = new SmugglerDatabaseApi();
smuggler.ExportData(
new SmugglerExportOptions<RavenConnectionStringOptions>
{
ToFile = DumpFile,
From = new RavenConnectionStringOptions
{
Url = store1.Url,
DefaultDatabase = store1.DefaultDatabase
}
}).Wait(TimeSpan.FromSeconds(15));
Assert.True(File.Exists(DumpFile));
smuggler = new SmugglerDatabaseApi();
smuggler.ImportData(
new SmugglerImportOptions<RavenConnectionStringOptions>
{
FromFile = DumpFile,
To = new RavenConnectionStringOptions
{
Url = store3.Url,
DefaultDatabase = store3.DefaultDatabase
}
}).Wait(TimeSpan.FromSeconds(15));
Assert.NotNull(store3.DatabaseCommands.Get("1"));
Assert.NotNull(store3.DatabaseCommands.Get("2"));
int retries = 5;
JsonDocument container = null;
while (container == null && retries-- >0)
{
container = store3.DatabaseCommands.Get("Raven/Alerts");
if(container == null)
Thread.Sleep(100);
}
Assert.NotNull(container);
var alerts = container.DataAsJson["Alerts"].Values<RavenJObject>()
.ToList();
Assert.Equal(1, alerts.Count);
var alert = alerts.First();
Assert.True(alert["Title"].ToString().StartsWith("Wrong replication source:"));
}
示例5: NegativeFiltersShouldNotFilterOutWhenThereAreNoMatches
public void NegativeFiltersShouldNotFilterOutWhenThereAreNoMatches()
{
var path = Path.GetTempFileName();
var options = new SmugglerDatabaseOptions
{
Filters =
new EquatableList<FilterSetting>
{
new FilterSetting
{
Path = "Value",
ShouldMatch = false,
Values = new EquatableList<string> {"Value1"}
}
}
};
try
{
using (var store = NewRemoteDocumentStore())
{
Initialize(store);
var smuggler = new SmugglerDatabaseApi(options);
smuggler.ExportData(new SmugglerExportOptions<RavenConnectionStringOptions> { ToFile = path, From = new RavenConnectionStringOptions { Url = store.Url, DefaultDatabase = store.DefaultDatabase } }).Wait(TimeSpan.FromSeconds(15));
}
using (var store = NewRemoteDocumentStore())
{
var smuggler = new SmugglerDatabaseApi(options);
smuggler.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions> { FromFile = path, To = new RavenConnectionStringOptions { Url = store.Url, DefaultDatabase = store.DefaultDatabase } }).Wait(TimeSpan.FromSeconds(15));
Assert.NotNull(store.DatabaseCommands.Get("key/1"));
using (var session = store.OpenSession())
{
var product1 = session.Load<Product>(1);
var product2 = session.Load<Product>(2);
var product3 = session.Load<Product>(3);
Assert.Null(product1);
Assert.Null(product2);
Assert.NotNull(product3);
}
}
}
finally
{
IOExtensions.DeleteDirectory(path);
}
}
示例6: DateTimePreserved
public void DateTimePreserved()
{
var file = Path.GetTempFileName();
try
{
var docId = string.Empty;
using (var documentStore = NewRemoteDocumentStore())
{
using (var session = documentStore.OpenSession())
{
var foo = new Foo {Created = DateTime.Today};
session.Store(foo);
docId = foo.Id;
session.SaveChanges();
}
var smugglerApi = new SmugglerDatabaseApi();
smugglerApi.ExportData(new SmugglerExportOptions<RavenConnectionStringOptions> { ToFile = file, From = new RavenConnectionStringOptions { Url = documentStore.Url, DefaultDatabase = documentStore.DefaultDatabase } }).Wait(TimeSpan.FromSeconds(15));
}
using (var documentStore = NewRemoteDocumentStore())
{
var smugglerApi = new SmugglerDatabaseApi();
smugglerApi.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions> { FromFile = file, To = new RavenConnectionStringOptions { Url = documentStore.Url, DefaultDatabase = documentStore.DefaultDatabase } }).Wait(TimeSpan.FromSeconds(15));
using (var session = documentStore.OpenSession())
{
var created = session.Load<Foo>(docId).Created;
Assert.False(session.Advanced.HasChanges);
}
}
}
finally
{
if (File.Exists(file))
{
File.Delete(file);
}
}
}
示例7: SmugglerShouldNotThrowIfDatabaseExist1
public async Task SmugglerShouldNotThrowIfDatabaseExist1()
{
var path = Path.GetTempFileName();
try
{
using (var store = NewRemoteDocumentStore())
{
store.DatabaseCommands.GlobalAdmin.EnsureDatabaseExists("DoesNotExist");
var connectionStringOptions = new RavenConnectionStringOptions { Url = store.Url, DefaultDatabase = "DoesNotExist" };
var smuggler = new SmugglerDatabaseApi();
await smuggler.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions> { FromFile = path, To = connectionStringOptions });
await smuggler.ExportData(new SmugglerExportOptions<RavenConnectionStringOptions> { ToFile = path, From = connectionStringOptions });
}
}
finally
{
IOExtensions.DeleteFile(path);
}
}
示例8: SmugglerWithoutExcludeExpiredDocumentsShouldWork
public void SmugglerWithoutExcludeExpiredDocumentsShouldWork()
{
var path = Path.GetTempFileName();
try
{
using (var store = NewRemoteDocumentStore())
{
Initialize(store);
var smuggler = new SmugglerDatabaseApi();
smuggler.ExportData(new SmugglerExportOptions<RavenConnectionStringOptions> { ToFile = path, From = new RavenConnectionStringOptions { Url = store.Url, DefaultDatabase = store.DefaultDatabase } }).Wait(TimeSpan.FromSeconds(15));
}
using (var store = NewRemoteDocumentStore())
{
var smuggler = new SmugglerDatabaseApi();
smuggler.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions> { FromFile = path, To = new RavenConnectionStringOptions { Url = store.Url, DefaultDatabase = store.DefaultDatabase } }).Wait(TimeSpan.FromSeconds(15));
using (var session = store.OpenSession())
{
var product1 = session.Load<Product>(1);
var product2 = session.Load<Product>(2);
var product3 = session.Load<Product>(3);
Assert.NotNull(product1);
Assert.Null(product2);
Assert.NotNull(product3);
}
}
}
finally
{
IOExtensions.DeleteDirectory(path);
}
}
示例9: SmugglerShouldNotExportImportSubscribtionIdentities
public async Task SmugglerShouldNotExportImportSubscribtionIdentities()
{
using (var store = NewRemoteDocumentStore())
{
store.Subscriptions.Create(new SubscriptionCriteria());
var smuggler = new SmugglerDatabaseApi(new SmugglerDatabaseOptions { OperateOnTypes = ItemType.Documents });
using (var stream = new MemoryStream())
{
await smuggler.ExportData(new SmugglerExportOptions<RavenConnectionStringOptions>
{
From = new RavenConnectionStringOptions
{
DefaultDatabase = store.DefaultDatabase,
Url = store.Url
},
ToStream = stream
});
stream.Position = 0;
store.DatabaseCommands.GlobalAdmin.EnsureDatabaseExists("Northwind");
await smuggler.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions>
{
FromStream = stream,
To = new RavenConnectionStringOptions
{
DefaultDatabase = "Northwind",
Url = store.Url
}
});
}
}
}
示例10: SmugglerCanStripReplicationInformationDuringImport_Remote
public void SmugglerCanStripReplicationInformationDuringImport_Remote()
{
var path = NewDataPath(forceCreateDir: true);
var backupPath = Path.Combine(path, "backup.dump");
using (var store = NewRemoteDocumentStore(runInMemory: false))
{
store
.DatabaseCommands
.GlobalAdmin
.CreateDatabase(new DatabaseDocument
{
Id = "N1",
Settings =
{
{ Constants.ActiveBundles, "Replication" },
{ "Raven/DataDir", NewDataPath() }
}
});
var commands = store.DatabaseCommands.ForDatabase("N1");
commands.Put("keys/1", null, new RavenJObject(), new RavenJObject());
var doc = commands.Get("keys/1");
Assert.True(doc.Metadata.ContainsKey(Constants.RavenReplicationSource));
Assert.True(doc.Metadata.ContainsKey(Constants.RavenReplicationVersion));
commands.PutAttachment("keys/1", null, new MemoryStream(), new RavenJObject());
var attachment = commands.GetAttachment("keys/1");
Assert.True(attachment.Metadata.ContainsKey(Constants.RavenReplicationSource));
Assert.True(attachment.Metadata.ContainsKey(Constants.RavenReplicationVersion));
var smuggler = new SmugglerDatabaseApi(new SmugglerDatabaseOptions { StripReplicationInformation = true });
smuggler.ExportData(new SmugglerExportOptions<RavenConnectionStringOptions>
{
ToFile = backupPath,
From = new RavenConnectionStringOptions
{
Url = store.Url,
DefaultDatabase = "N1"
}
}).Wait(TimeSpan.FromSeconds(15));
store
.DatabaseCommands
.GlobalAdmin
.CreateDatabase(new DatabaseDocument
{
Id = "N2",
Settings =
{
{ Constants.ActiveBundles, "" },
{ "Raven/DataDir", NewDataPath() }
}
});
smuggler.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions>
{
FromFile = backupPath,
To = new RavenConnectionStringOptions
{
DefaultDatabase = "N2",
Url = store.Url
}
}).Wait(TimeSpan.FromSeconds(15));
commands = store.DatabaseCommands.ForDatabase("N2");
doc = commands.Get("keys/1");
Assert.False(doc.Metadata.ContainsKey(Constants.RavenReplicationSource));
Assert.False(doc.Metadata.ContainsKey(Constants.RavenReplicationVersion));
attachment = commands.GetAttachment("keys/1");
Assert.False(attachment.Metadata.ContainsKey(Constants.RavenReplicationSource));
Assert.False(attachment.Metadata.ContainsKey(Constants.RavenReplicationVersion));
store
.DatabaseCommands
.GlobalAdmin
.CreateDatabase(new DatabaseDocument
{
Id = "N3",
Settings =
{
{ Constants.ActiveBundles, "Replication" },
{ "Raven/DataDir", NewDataPath() }
}
});
smuggler.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions>
{
FromFile = backupPath,
To = new RavenConnectionStringOptions
{
DefaultDatabase = "N3",
Url = store.Url
}
}).Wait(TimeSpan.FromSeconds(15));
commands = store.DatabaseCommands.ForDatabase("N3");
doc = commands.Get("keys/1");
Assert.True(doc.Metadata.ContainsKey(Constants.RavenReplicationSource));
Assert.True(doc.Metadata.ContainsKey(Constants.RavenReplicationVersion));
//.........这里部分代码省略.........
示例11: PeriodicBackup_should_export_all_relevant_documents
public async Task PeriodicBackup_should_export_all_relevant_documents()
{
var existingData = new List<DummyDataEntry>();
var backupFolder = new DirectoryInfo(Path.GetTempPath() + "\\periodic_backup_" + Guid.NewGuid());
if (!backupFolder.Exists)
backupFolder.Create();
documentStore.DatabaseCommands.GlobalAdmin.CreateDatabase(new DatabaseDocument
{
Id = "SourceDB",
Settings =
{
{"Raven/ActiveBundles", "PeriodicBackup"},
{"Raven/DataDir", "~\\Databases\\SourceDB"}
}
});
documentStore.DatabaseCommands.GlobalAdmin.CreateDatabase(new DatabaseDocument
{
Id = "DestDB",
Settings = {{"Raven/DataDir", "~\\Databases\\DestDB"}}
});
//setup periodic export
using (var session = documentStore.OpenSession("SourceDB"))
{
session.Store(new PeriodicExportSetup {LocalFolderName = backupFolder.FullName, IntervalMilliseconds = 500},
PeriodicExportSetup.RavenDocumentKey);
session.SaveChanges();
}
//now enter dummy data
using (var session = documentStore.OpenSession())
{
for (int i = 0; i < 10000; i++)
{
var dummyDataEntry = new DummyDataEntry {Id = "Dummy/" + i, Data = "Data-" + i};
existingData.Add(dummyDataEntry);
session.Store(dummyDataEntry);
}
session.SaveChanges();
}
var connection = new RavenConnectionStringOptions {Url = documentStore.Url, DefaultDatabase = "DestDB"};
var smugglerApi = new SmugglerDatabaseApi { Options = { Incremental = true } };
await smugglerApi.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions> { FromFile = backupFolder.FullName, To = connection });
using (var session = documentStore.OpenSession())
{
var fetchedData = new List<DummyDataEntry>();
using (var streamingQuery = session.Advanced.Stream<DummyDataEntry>("Dummy/"))
{
while (streamingQuery.MoveNext())
fetchedData.Add(streamingQuery.Current.Document);
}
Assert.Equal(existingData.Count, fetchedData.Count);
Assert.True(existingData.Select(row => row.Data).ToHashSet().SetEquals(fetchedData.Select(row => row.Data)));
}
}
示例12: CanSkipFilesWhenUsingContinuations
public async Task CanSkipFilesWhenUsingContinuations()
{
var dataDir = NewDataPath(forceCreateDir: true);
var continuationToken = "Token";
using (var store = NewRemoteDocumentStore( dataDirectory: dataDir ))
{
store.Conventions.MaxNumberOfRequestsPerSession = 1000;
// Prepare everything.
int serverPort = new Uri(store.Url).Port;
var server = GetServer(serverPort);
var outputDirectory = Path.Combine(server.Configuration.DataDirectory, "Export");
string newDatabase = store.DefaultDatabase + "-Verify";
await store.AsyncDatabaseCommands.EnsureDatabaseExists(newDatabase);
// Prepare the first batch of documents on incremental setup.
var storedDocuments = new List<BigDocument>();
using (var session = store.OpenSession())
{
for (int i = 0; i < 10; i++)
{
var document = new BigDocument(3000);
storedDocuments.Add(document);
session.Store(document);
}
session.SaveChanges();
}
// Export the first batch
var dumper = new SmugglerDatabaseApi { Options = { Incremental = true } };
var exportResult = await dumper.ExportData(
new SmugglerExportOptions<RavenConnectionStringOptions>
{
ToFile = outputDirectory,
From = new RavenConnectionStringOptions
{
Url = "http://localhost:" + serverPort,
DefaultDatabase = store.DefaultDatabase,
}
});
Assert.NotNull(exportResult);
Assert.True(!string.IsNullOrWhiteSpace(exportResult.FilePath));
// Import the first batch
var importDumper = new SmugglerDatabaseApi { Options = { Incremental = true, ContinuationToken = continuationToken, BatchSize = 1 } };
await importDumper.ImportData(
new SmugglerImportOptions<RavenConnectionStringOptions>
{
FromFile = outputDirectory,
To = new RavenConnectionStringOptions
{
Url = "http://localhost:" + serverPort,
DefaultDatabase = newDatabase,
}
});
// Store the etags of the first batch to ensure we are not touching them (effectively skipping).
var docMap = new Dictionary<string, Etag>();
using (var session = store.OpenSession(newDatabase))
{
foreach (var sdoc in storedDocuments)
{
var doc = session.Load<BigDocument>(sdoc.Id);
Assert.NotNull(doc);
var etag = session.Advanced.GetEtagFor<BigDocument>(doc);
docMap[doc.Id] = etag;
}
}
// Prepare the second batch of documents on incremental setup.
using (var session = store.OpenSession())
{
for (int i = 0; i < 30; i++)
{
var document = new BigDocument(1000);
storedDocuments.Add(document);
session.Store(document);
}
session.SaveChanges();
}
// Export the second batch.
exportResult = await dumper.ExportData(
new SmugglerExportOptions<RavenConnectionStringOptions>
{
ToFile = outputDirectory,
From = new RavenConnectionStringOptions
{
Url = "http://localhost:" + serverPort,
DefaultDatabase = store.DefaultDatabase,
}
});
//.........这里部分代码省略.........
示例13: SingleAttachmentsImportShouldWork
public void SingleAttachmentsImportShouldWork(int size)
{
var data = new byte[size];
new Random().NextBytes(data);
using (var source = NewRemoteDocumentStore(databaseName: "fooDB"))
{
source.DatabaseCommands.ForSystemDatabase().CreateDatabase(new DatabaseDocument
{
Id = "fooDB2",
Settings = new Dictionary<string, string>
{
{"Raven/DataDir", "FooData" }
}
});
using (var stream = new MemoryStream(data))
{
stream.Position = 0;
source.DatabaseCommands.PutAttachment("foo", null, stream, new RavenJObject());
}
var smugglerApi = new SmugglerDatabaseApi();
var filename = "large-attachment-test.ravendump";
using (var fs = new FileStream(filename, FileMode.Create))
{
smugglerApi.ExportData(new SmugglerExportOptions<RavenConnectionStringOptions>
{
ToStream = fs,
From = new RavenConnectionStringOptions
{
Url = source.Url,
DefaultDatabase = "fooDB"
}
}).Wait();
fs.Flush();
}
using (var fs = new FileStream(filename, FileMode.Open))
{
smugglerApi.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions>
{
FromStream = fs,
To = new RavenConnectionStringOptions
{
Url = source.Url,
DefaultDatabase = "fooDB2"
}
}).Wait();
}
var attachment = source.DatabaseCommands.ForDatabase("fooDB2").GetAttachment("foo");
Assert.Equal(attachment.Data().ReadData(), data);
}
}
示例14: MultipleAttachmentsImportShouldWork
public void MultipleAttachmentsImportShouldWork(int size, int itemCount)
{
var buffer = new byte[size];
var random = new Random(size);
var dataList = new List<Data>();
for (int i = 0; i < itemCount; i++)
{
random.NextBytes(buffer);
dataList.Add(new Data
{
Foo = buffer.ToArray()
});
}
using (var source = NewRemoteDocumentStore(databaseName: "fooDB", fiddler: true))
{
source.DatabaseCommands.ForSystemDatabase().CreateDatabase(new DatabaseDocument
{
Id = "fooDB2",
Settings = new Dictionary<string, string>
{
{"Raven/DataDir", "FooData" }
}
});
source.DatabaseCommands.ForDatabase("fooDB").Put("foobar/1", null, RavenJObject.FromObject(new { Foo = "Bar1" }),
new RavenJObject());
source.DatabaseCommands.ForDatabase("fooDB").Put("foobar/2", null, RavenJObject.FromObject(new { Foo = "Bar2" }),
new RavenJObject());
int id = 1;
foreach (var dataItem in dataList)
{
using (var stream = new MemoryStream(dataItem.Foo))
{
stream.Position = 0;
source.DatabaseCommands.PutAttachment("foo/" + (id++), null, stream, new RavenJObject());
}
}
var smugglerApi = new SmugglerDatabaseApi();
var filename = "large-attachment-test.ravendump";
using (var fs = new FileStream(filename, FileMode.Create))
{
smugglerApi.ExportData(new SmugglerExportOptions<RavenConnectionStringOptions>
{
From = new RavenConnectionStringOptions
{
Url = source.Url,
DefaultDatabase = "fooDB"
},
ToStream = fs
}).Wait();
fs.Flush();
}
using (var fs = new FileStream(filename, FileMode.Open))
{
smugglerApi.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions>()
{
FromStream = fs,
To = new RavenConnectionStringOptions
{
Url = source.Url,
DefaultDatabase = "fooDB2"
}
}).Wait();
}
//make sure documents also were imported/exported correctly
Assert.Equal("Bar1", source.DatabaseCommands.ForDatabase("fooDB2")
.Get("foobar/1")
.DataAsJson.Value<string>("Foo"));
Assert.Equal("Bar2", source.DatabaseCommands.ForDatabase("fooDB2")
.Get("foobar/2")
.DataAsJson.Value<string>("Foo"));
id = 1;
foreach (var dataItem in dataList)
{
var attachment = source.DatabaseCommands.ForDatabase("fooDB2").GetAttachment("foo/" + (id++));
var fetchedData = attachment.Data().ReadData();
Assert.Equal(fetchedData, dataItem.Foo);
}
}
}
示例15: SmugglerCanUnderstandPeriodicBackupFormat
public void SmugglerCanUnderstandPeriodicBackupFormat()
{
var backupPath = NewDataPath("BackupFolder");
using (var store = NewDocumentStore())
{
string userId;
using (var session = store.OpenSession())
{
var periodicBackupSetup = new PeriodicExportSetup
{
LocalFolderName = backupPath,
IntervalMilliseconds = 100
};
session.Store(periodicBackupSetup, PeriodicExportSetup.RavenDocumentKey);
session.SaveChanges();
}
var backupStatus = GetPeriodicBackupStatus(store.SystemDatabase);
using (var session = store.OpenSession())
{
var user = new User { Name = "oren" };
session.Store(user);
userId = user.Id;
session.SaveChanges();
}
store.DatabaseCommands.PutAttachment("attach/1", null, new MemoryStream(new byte[] { 1, 2, 3, 4 }), new RavenJObject());
WaitForPeriodicExport(store.SystemDatabase, backupStatus);
store.DatabaseCommands.Delete(userId, null);
store.DatabaseCommands.DeleteAttachment("attach/1", null);
WaitForPeriodicExport(store.SystemDatabase, backupStatus);
}
using (var store = NewRemoteDocumentStore())
{
var dataDumper = new SmugglerDatabaseApi();
dataDumper.Options.Incremental = true;
dataDumper.ImportData(
new SmugglerImportOptions<RavenConnectionStringOptions>
{
FromFile = backupPath,
To = new RavenConnectionStringOptions { Url = store.Url }
}).Wait();
using (var session = store.OpenSession())
{
Assert.Null(session.Load<User>(1));
Assert.Null(store.DatabaseCommands.GetAttachment("attach/1"));
}
}
IOExtensions.DeleteDirectory(backupPath);
}