当前位置: 首页>>代码示例>>C#>>正文


C# DatabaseDataDumper.ImportData方法代码示例

本文整理汇总了C#中Raven.Database.Smuggler.DatabaseDataDumper.ImportData方法的典型用法代码示例。如果您正苦于以下问题:C# DatabaseDataDumper.ImportData方法的具体用法?C# DatabaseDataDumper.ImportData怎么用?C# DatabaseDataDumper.ImportData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Raven.Database.Smuggler.DatabaseDataDumper的用法示例。


在下文中一共展示了DatabaseDataDumper.ImportData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MaxNumberOfItemsToProcessInSingleBatchShouldBeRespectedByDataDumper

		public void MaxNumberOfItemsToProcessInSingleBatchShouldBeRespectedByDataDumper()
		{
			var path = Path.Combine(NewDataPath(forceCreateDir: true), "raven.dump");

			using (var server = GetNewServer(configureConfig: configuration => configuration.MaxNumberOfItemsToProcessInSingleBatch = 1234))
			{
                var dumper = new DatabaseDataDumper(server.SystemDatabase, options: new SmugglerDatabaseOptions { BatchSize = 4321 });
				Assert.Equal(4321, dumper.Options.BatchSize);

                dumper.ExportData(new SmugglerExportOptions<RavenConnectionStringOptions> { ToFile = path }).ResultUnwrap();

				Assert.Equal(1234, dumper.Options.BatchSize);

                dumper = new DatabaseDataDumper(server.SystemDatabase, options: new SmugglerDatabaseOptions { BatchSize = 4321 });
				Assert.Equal(4321, dumper.Options.BatchSize);

                dumper.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions> { FromFile = path }).Wait();

				Assert.Equal(1234, dumper.Options.BatchSize);

                dumper = new DatabaseDataDumper(server.SystemDatabase, options: new SmugglerDatabaseOptions { BatchSize = 1000 });
				Assert.Equal(1000, dumper.Options.BatchSize);

                dumper.ExportData(new SmugglerExportOptions<RavenConnectionStringOptions> { ToFile = path }).ResultUnwrap();

				Assert.Equal(1000, dumper.Options.BatchSize);
			}
		}
开发者ID:bbqchickenrobot,项目名称:ravendb,代码行数:28,代码来源:RavenDB_2605.cs

示例2: CanBackupToDirectory

        public void CanBackupToDirectory()
        {
            var backupPath = NewDataPath("BackupFolder");
            using (var store = NewDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new User { Name = "oren" });
                    var periodicBackupSetup = new PeriodicExportSetup
                    {
                        LocalFolderName = backupPath,
                        IntervalMilliseconds = 25
                    };
                    session.Store(periodicBackupSetup, PeriodicExportSetup.RavenDocumentKey);

                    session.SaveChanges();

                }
                SpinWait.SpinUntil(() => store.DatabaseCommands.Get(PeriodicExportStatus.RavenDocumentKey) != null, 10000);

            }

            using (var store = NewDocumentStore())
            {
                var dataDumper = new DatabaseDataDumper(store.SystemDatabase) { Options = { Incremental = true } };
                dataDumper.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions> { FromFile = backupPath }).Wait();

                using (var session = store.OpenSession())
                {
                    Assert.Equal("oren", session.Load<User>(1).Name);
                }
            }
            IOExtensions.DeleteDirectory(backupPath);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:34,代码来源:PeriodicBackupTests.cs

示例3: SmugglerTransformShouldRecognizeNumericPropertiesEvenThoughTheyHaveTheSameNames

		public async Task SmugglerTransformShouldRecognizeNumericPropertiesEvenThoughTheyHaveTheSameNames()
		{
			using (var stream = new MemoryStream())
			{
				var testObject = new RavenJObject
				{
					{"Range", new RavenJArray {new RavenJObject {{"Min", 2.4}}}},
					{"Min", 1}
				};

				using (var store = NewDocumentStore())
				{
					store.DatabaseCommands.Put("docs/1", null, testObject, new RavenJObject());

					var smuggler = new DatabaseDataDumper(store.DocumentDatabase, new SmugglerDatabaseOptions
					{
						TransformScript = EmptyTransform
					});

					await smuggler.ExportData(new SmugglerExportOptions<RavenConnectionStringOptions>
					{
						From = new EmbeddedRavenConnectionStringOptions
								{
									DefaultDatabase = store.DefaultDatabase
								},
						ToStream = stream
					});
				}

				stream.Position = 0;

				using (var store = NewDocumentStore())
				{
					var smuggler = new DatabaseDataDumper(store.DocumentDatabase, new SmugglerDatabaseOptions
					{
						TransformScript = EmptyTransform
					});

					await smuggler.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions>
					{
						FromStream = stream,
						To = new EmbeddedRavenConnectionStringOptions
						{
							DefaultDatabase = store.DefaultDatabase
						}
					});

					var doc = store.DatabaseCommands.Get("docs/1").DataAsJson;
					Assert.NotNull(doc);
					Assert.Equal(testObject["Min"].Type, doc["Min"].Type);
					Assert.Equal(((RavenJObject)((RavenJArray)testObject["Range"])[0])["Min"].Type, ((RavenJObject)((RavenJArray)doc["Range"])[0])["Min"].Type);

					Assert.True(RavenJToken.DeepEquals(testObject, doc));
				}
			}
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:56,代码来源:RavenDB_1733.cs

示例4: CanFullBackupToDirectory

        public void CanFullBackupToDirectory()
        {
            var backupPath = NewDataPath("BackupFolder", forceCreateDir: true);
            try
            {
                using (var store = NewDocumentStore())
                {
                    store.DatabaseCommands.PutAttachment("attach/1", null, new MemoryStream(new byte[] { 1,2,3,4,5 }), new RavenJObject());

                    using (var session = store.OpenSession())
                    {
                        session.Store(new User { Name = "oren" });
                        var periodicBackupSetup = new PeriodicExportSetup
                        {
                            LocalFolderName = backupPath,
                            FullBackupIntervalMilliseconds = 500
                        };
                        session.Store(periodicBackupSetup, PeriodicExportSetup.RavenDocumentKey);

                        session.SaveChanges();
                    }

                    WaitForNextFullBackup(store);
                }
                using (var store = NewDocumentStore())
                {
	                var dataDumper = new DatabaseDataDumper(store.SystemDatabase) { Options = { Incremental = false } };
                    dataDumper.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions>
                    {
                        FromFile = Directory.GetFiles(Path.GetFullPath(backupPath))
                          .Where(file => ".ravendb-full-dump".Equals(Path.GetExtension(file), StringComparison.InvariantCultureIgnoreCase))
                          .OrderBy(File.GetLastWriteTimeUtc).First()
                    }).Wait();

                    using (var session = store.OpenSession())
                    {
                        Assert.Equal("oren", session.Load<User>(1).Name);
                        Assert.NotNull(store.DatabaseCommands.GetAttachment("attach/1"));
                    }
                }
            }
            finally
            {
                IOExtensions.DeleteDirectory(backupPath);
            }


        }
开发者ID:bbqchickenrobot,项目名称:ravendb,代码行数:48,代码来源:RavenDB_1537.cs

示例5: CanGetCorrectResult

        public async Task CanGetCorrectResult()
        {
            using (var store = NewDocumentStore())
            {
                var dataDumper = new DatabaseDataDumper(store.SystemDatabase);
                using (var stream = typeof(TroyMapReduceImport).Assembly.GetManifestResourceStream("Raven.Tests.MailingList.Sandbox.ravendump"))
                {
                    await dataDumper.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions> { FromStream = stream });
                }

                using(var s = store.OpenSession())
                {
                    var objects = s.Query<object>("LogEntry/CountByDate")
                        .Customize(x => x.WaitForNonStaleResults())
                        .ToList();
                    Assert.Equal(4, objects.Count);
                }
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:19,代码来源:TroyMapReduceImport.cs

示例6: SmugglerTransformShouldWorkForDatabaseDataDumper

        public async Task SmugglerTransformShouldWorkForDatabaseDataDumper()
        {
            var path = NewDataPath(forceCreateDir: true);
            var backupPath = Path.Combine(path, "backup.dump");

            using (var store = NewDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new Foo { Name = "N1" });
                    session.Store(new Foo { Name = "N2" });

                    session.SaveChanges();
                }
                var smugglerApi = new DatabaseDataDumper(store.DocumentDatabase);
                smugglerApi.Options.TransformScript =
                    @"function(doc) { 
                        var id = doc['@metadata']['@id']; 
                        if(id === 'foos/1')
                            return null;
                        return doc;
                    }";
                await smugglerApi.ExportData(
                    new SmugglerExportOptions<RavenConnectionStringOptions>
                    {
                        ToFile = backupPath,
                        From = new EmbeddedRavenConnectionStringOptions
                        {
                            DefaultDatabase = store.DefaultDatabase
                        }
                    });
            }

            using (var documentStore = NewDocumentStore())
            {
                var smugglerApi = new DatabaseDataDumper(documentStore.DocumentDatabase);
                smugglerApi.Options.TransformScript =
                    @"function(doc) { 
                        var id = doc['@metadata']['@id']; 
                        if(id === 'foos/1')
                            return null;
                        return doc;
                    }";
                await smugglerApi.ImportData(
                    new SmugglerImportOptions<RavenConnectionStringOptions>
                    {
                        FromFile = backupPath,
                        To = new EmbeddedRavenConnectionStringOptions
                        {
                            DefaultDatabase = documentStore.DefaultDatabase
                        }
                    });

                using (var session = documentStore.OpenSession())
                {
                    var foos = session.Query<Foo>()
                                      .Customize(customization => customization.WaitForNonStaleResultsAsOfNow())
                                      .ToList();

                    Assert.Equal(1, foos.Count);
                    Assert.Equal("foos/2", foos[0].Id);
                    Assert.Equal("N2", foos[0].Name);

                    Assert.Null(session.Load<Foo>(1));
                }
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:67,代码来源:SmugglerIdentitiesTests.cs

示例7: SmugglerCanStripReplicationInformationDuringImport_Embedded

        public void SmugglerCanStripReplicationInformationDuringImport_Embedded()
        {
            using (var stream = new MemoryStream())
            {
                using (var store = NewDocumentStore(activeBundles: "Replication"))
                {
                    var commands = store.DatabaseCommands;
                    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 DatabaseDataDumper(store.DocumentDatabase, new SmugglerDatabaseOptions { StripReplicationInformation = true });
                    smuggler.ExportData(new SmugglerExportOptions<RavenConnectionStringOptions> { ToStream = stream, From = new RavenConnectionStringOptions { DefaultDatabase = store.DefaultDatabase } }).Wait(TimeSpan.FromSeconds(15));
                }

                stream.Position = 0;

                using (var store = NewDocumentStore())
                {
                    var smuggler = new DatabaseDataDumper(store.DocumentDatabase, new SmugglerDatabaseOptions { StripReplicationInformation = true });
                    smuggler.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions>
                    {
                        FromStream = stream,
                        To = new RavenConnectionStringOptions
                        {
                            DefaultDatabase = store.DefaultDatabase,
                        }
                    }).Wait(TimeSpan.FromSeconds(15));

                    var commands = store.DatabaseCommands;
                    var doc = commands.Get("keys/1");
                    Assert.False(doc.Metadata.ContainsKey(Constants.RavenReplicationSource));
                    Assert.False(doc.Metadata.ContainsKey(Constants.RavenReplicationVersion));
                    var attachment = commands.GetAttachment("keys/1");
                    Assert.False(attachment.Metadata.ContainsKey(Constants.RavenReplicationSource));
                    Assert.False(attachment.Metadata.ContainsKey(Constants.RavenReplicationVersion));
                }

                stream.Position = 0;

                using (var store = NewDocumentStore(activeBundles: "Replication"))
                {
                    var smuggler = new DatabaseDataDumper(store.DocumentDatabase, new SmugglerDatabaseOptions { StripReplicationInformation = true });
                    smuggler.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions>
                    {
                        FromStream = stream,
                        To = new RavenConnectionStringOptions
                        {
                            DefaultDatabase = store.DefaultDatabase,
                        }
                    }).Wait(TimeSpan.FromSeconds(15));

                    var commands = store.DatabaseCommands;
                    var doc = commands.Get("keys/1");
                    Assert.True(doc.Metadata.ContainsKey(Constants.RavenReplicationSource));
                    Assert.True(doc.Metadata.ContainsKey(Constants.RavenReplicationVersion));
                    var attachment = commands.GetAttachment("keys/1");
                    Assert.True(attachment.Metadata.ContainsKey(Constants.RavenReplicationSource));
                    Assert.True(attachment.Metadata.ContainsKey(Constants.RavenReplicationVersion));
                }
            }

        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:69,代码来源:SmugglerIdentitiesTests.cs

示例8: CanBackupAttachmentDeletion

        public void CanBackupAttachmentDeletion()
        {
            var backupPath = NewDataPath("BackupFolder");
            using (var store = NewDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    var periodicBackupSetup = new PeriodicExportSetup
                    {
                        LocalFolderName = backupPath,
                        IntervalMilliseconds = 250
                    };
                    session.Store(periodicBackupSetup, PeriodicExportSetup.RavenDocumentKey);

                    session.SaveChanges();
                }

                var backupStatus = GetPeriodicBackupStatus(store.SystemDatabase);

                store.DatabaseCommands.PutAttachment("attach/1", null, new MemoryStream(new byte[] { 1, 2, 3, 4 }), new RavenJObject());

                WaitForPeriodicExport(store.SystemDatabase, backupStatus);

                store.DatabaseCommands.DeleteAttachment("attach/1", null);

                WaitForPeriodicExport(store.SystemDatabase, backupStatus);

            }

            using (var store = NewDocumentStore())
            {
                var dataDumper = new DatabaseDataDumper(store.SystemDatabase) { Options = { Incremental = true } };
                dataDumper.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions> { FromFile = backupPath }).Wait();

                Assert.Null(store.DatabaseCommands.GetAttachment("attach/1"));
            }

            IOExtensions.DeleteDirectory(backupPath);
        }
开发者ID:JackWangCUMT,项目名称:ravendb,代码行数:39,代码来源:SmugglerExecutionTests.cs

示例9: CanBackupDocumentDeletion

        public void CanBackupDocumentDeletion()
        {
            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();
                }

                WaitForPeriodicExport(store.SystemDatabase, backupStatus);

                store.DatabaseCommands.Delete(userId, null);

                WaitForPeriodicExport(store.SystemDatabase, backupStatus, x => x.LastDocsDeletionEtag);

            }

            using (var store = NewDocumentStore())
            {
                var dataDumper = new DatabaseDataDumper(store.SystemDatabase) { Options = { Incremental = true } };
                dataDumper.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions> { FromFile = backupPath }).Wait();

                using (var session = store.OpenSession())
                {
                    Assert.Null(session.Load<User>(1));
                }
            }

            IOExtensions.DeleteDirectory(backupPath);
        }
开发者ID:JackWangCUMT,项目名称:ravendb,代码行数:49,代码来源:SmugglerExecutionTests.cs

示例10: AssertUsersCountInBackup

        private void AssertUsersCountInBackup(int expectedNumberOfUsers, string file)
        {
            using (var store = NewDocumentStore())
            {
                var dataDumper = new DatabaseDataDumper(store.SystemDatabase);
                dataDumper.Options.Incremental = false;
                dataDumper.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions> { FromFile = file }).Wait();

                WaitForIndexing(store);

                using (var session = store.OpenSession())
                {
                    Assert.Equal(expectedNumberOfUsers, session.Query<User>().Count());
                }
            }
        }
开发者ID:JackWangCUMT,项目名称:ravendb,代码行数:16,代码来源:SmugglerExecutionTests.cs

示例11: VerifyDump

        private void VerifyDump(string backupPath, Action<EmbeddableDocumentStore> action)
        {
            using (var store = NewDocumentStore())
            {
                var dumper = new DatabaseDataDumper(store.SystemDatabase) { Options = { Incremental = true } };
                dumper.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions> { FromFile = backupPath }).Wait();

                action(store);
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:10,代码来源:RavenDB_1603.cs

示例12: CanDisableVersioningDuringImport_Embedded

		public async Task CanDisableVersioningDuringImport_Embedded()
		{
			using (var stream = new MemoryStream())
			{
				long countOfDocuments;
				using (var store = NewDocumentStore())
				{
					using (var session = store.OpenSession())
					{
						for (int i = 0; i < 10; i++)
						{
							session.Store(new User());
							session.Store(new Address());
						}

						session.SaveChanges();
					}

					countOfDocuments = store.DatabaseCommands.GetStatistics().CountOfDocuments;

					var smuggler = new DatabaseDataDumper(store.DocumentDatabase, new SmugglerDatabaseOptions());

					await smuggler.ExportData(new SmugglerExportOptions<RavenConnectionStringOptions>
					{
						ToStream = stream,
						From = new RavenConnectionStringOptions()
						{
							DefaultDatabase = store.DefaultDatabase
						}
					});
				}

				stream.Position = 0;

				using (var store = NewDocumentStore(activeBundles: "Versioning"))
				{
					using (var session = store.OpenSession())
					{
						session.Store(new Bundles.Versioning.Data.VersioningConfiguration
						{
							Exclude = false,
							Id = "Raven/Versioning/DefaultConfiguration",
							MaxRevisions = 5
						});

						session.SaveChanges();
					}

					var smuggler = new DatabaseDataDumper(store.DocumentDatabase, new SmugglerDatabaseOptions
					{
						ShouldDisableVersioningBundle = true
					});

					await smuggler.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions>()
					{
						FromStream = stream,
						To = new RavenConnectionStringOptions()
						{
							DefaultDatabase = store.DefaultDatabase
						}
					});

					var countOfDocsAfterImport = store.DatabaseCommands.GetStatistics().CountOfDocuments;

					Assert.Equal(countOfDocuments, countOfDocsAfterImport - 1); // one additional doc for versioning bundle configuration

					var metadata = store.DatabaseCommands.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())
					{
						session.Store(new User(), "users/arek");

						session.SaveChanges();

						var revisionsFor = session.Advanced.GetRevisionsFor<User>("users/arek", 0, 10);

						Assert.Equal(1, revisionsFor.Length);
					}
				}
			}
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:84,代码来源:SmugglerWithDisabledVersioning_RavenDB_3219.cs

示例13: can_export_all_attachments

        public async Task can_export_all_attachments()
        {
            var backupPath = NewDataPath("BackupFolder");
            try
            {
                using (var store = NewDocumentStore())
                {
                    for (var i = 0; i < 1000; i++)
                    {
                        store.DatabaseCommands.PutAttachment(
                            "attachments/" + (i + 1),
                            null,
                            new MemoryStream(new[] { (byte)i }),
                            new RavenJObject());
                    }

                    var task1 = Task.Run(async () =>
                    {
                        // now perform full backup
                        var dumper = new DatabaseDataDumper(store.SystemDatabase)
                        {
                            Options =
                            {
                                BatchSize = 10,
                                Incremental = true
                            }
                        };
                        await dumper.ExportData(new SmugglerExportOptions<RavenConnectionStringOptions> { ToFile = backupPath });
                    });
                    var task2 = Task.Run(() =>
                    {
                        // change the one document, this document should be exported (any version of it)
                        for (var i = 0; i < 100; i++)
                        {
                            store.DatabaseCommands.PutAttachment(
                                "attachments/1000", 
                                null,
                                new MemoryStream(new[] { (byte)i }), 
                                new RavenJObject());
                        }
                    });

                    await Task.WhenAll(task1, task2);
                }

                using (var embeddableStore = NewDocumentStore())
                {
                    // import all the data
                    var dumper = new DatabaseDataDumper(embeddableStore.SystemDatabase) { Options = { Incremental = true } };
                    dumper.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions> { FromFile = backupPath }).Wait();

                    var attachemnt = embeddableStore.DatabaseCommands.GetAttachment("attachments/1000");
                    Assert.NotNull(attachemnt);

                    var attachments = embeddableStore.DatabaseCommands.GetAttachments(0, Etag.Empty, 1024).ToList();
                    Assert.Equal(1000, attachments.Count);

                    var stats = embeddableStore.DatabaseCommands.GetStatistics();
                    Assert.Equal(1000, stats.CountOfAttachments);
                }
            }
            finally
            {
                IOExtensions.DeleteDirectory(backupPath);
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:66,代码来源:RavenDB-4085.cs

示例14: CanBackupToDirectory_MultipleBackups

        public void CanBackupToDirectory_MultipleBackups()
        {
            var backupPath = NewDataPath("BackupFolder");
            using (var store = NewDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new User { Name = "oren" });
                    var periodicBackupSetup = new PeriodicExportSetup
                    {
                        LocalFolderName = backupPath,
                        IntervalMilliseconds = 25
                    };
                    session.Store(periodicBackupSetup, PeriodicExportSetup.RavenDocumentKey);

                    session.SaveChanges();

                }
                SpinWait.SpinUntil(() =>
                {
                    var jsonDocument = store.DatabaseCommands.Get(PeriodicExportStatus.RavenDocumentKey);
                    if (jsonDocument == null)
                        return false;
                    var periodicBackupStatus = jsonDocument.DataAsJson.JsonDeserialization<PeriodicExportStatus>();
                    return periodicBackupStatus.LastDocsEtag != Etag.Empty && periodicBackupStatus.LastDocsEtag != null;
                });

                var etagForBackups= store.DatabaseCommands.Get(PeriodicExportStatus.RavenDocumentKey).Etag;
                using (var session = store.OpenSession())
                {
                    session.Store(new User { Name = "ayende" });
                    session.SaveChanges();
                }
                SpinWait.SpinUntil(() =>
                     store.DatabaseCommands.Get(PeriodicExportStatus.RavenDocumentKey).Etag != etagForBackups);

            }

            using (var store = NewDocumentStore())
            {
                var dataDumper = new DatabaseDataDumper(store.SystemDatabase) { Options = {Incremental = true}};
                dataDumper.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions> { FromFile = backupPath }).Wait();

                using (var session = store.OpenSession())
                {
                    Assert.Equal("oren", session.Load<User>(1).Name);
                    Assert.Equal("ayende", session.Load<User>(2).Name);
                }
            }
            IOExtensions.DeleteDirectory(backupPath);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:51,代码来源:PeriodicBackupTests.cs

示例15: ImportDatabase

		public async Task<HttpResponseMessage> ImportDatabase(int batchSize, bool includeExpiredDocuments, bool stripReplicationInformation, ItemType operateOnTypes, string filtersPipeDelimited, string transformScript)
		{
			if (!Request.Content.IsMimeMultipartContent())
			{
				throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
			}

			string tempPath = Path.GetTempPath();
			var fullTempPath = tempPath + Constants.TempUploadsDirectoryName;
			if (File.Exists(fullTempPath))
				File.Delete(fullTempPath);
			if (Directory.Exists(fullTempPath) == false)
				Directory.CreateDirectory(fullTempPath);

			var streamProvider = new MultipartFileStreamProvider(fullTempPath);
			await Request.Content.ReadAsMultipartAsync(streamProvider).ConfigureAwait(false);
			var uploadedFilePath = streamProvider.FileData[0].LocalFileName;
			
			string fileName = null;
			var fileContent = streamProvider.Contents.SingleOrDefault();
			if (fileContent != null)
			{
				fileName = fileContent.Headers.ContentDisposition.FileName.Replace("\"", string.Empty);
			}

			var status = new ImportOperationStatus();
			var cts = new CancellationTokenSource();
			
			var task = Task.Run(async () =>
			{
				try
				{
					using (var fileStream = File.Open(uploadedFilePath, FileMode.Open, FileAccess.Read))
					{
						var dataDumper = new DatabaseDataDumper(Database);
						dataDumper.Progress += s => status.LastProgress = s;
                        var smugglerOptions = dataDumper.Options;
						smugglerOptions.BatchSize = batchSize;
						smugglerOptions.ShouldExcludeExpired = !includeExpiredDocuments;
					    smugglerOptions.StripReplicationInformation = stripReplicationInformation;
						smugglerOptions.OperateOnTypes = operateOnTypes;
						smugglerOptions.TransformScript = transformScript;
						smugglerOptions.CancelToken = cts;

						// Filters are passed in without the aid of the model binder. Instead, we pass in a list of FilterSettings using a string like this: pathHere;;;valueHere;;;true|||againPathHere;;;anotherValue;;;false
						// Why? Because I don't see a way to pass a list of a values to a WebAPI method that accepts a file upload, outside of passing in a simple string value and parsing it ourselves.
						if (filtersPipeDelimited != null)
						{
							smugglerOptions.Filters.AddRange(filtersPipeDelimited
								.Split(new string[] { "|||" }, StringSplitOptions.RemoveEmptyEntries)
								.Select(f => f.Split(new string[] { ";;;" }, StringSplitOptions.RemoveEmptyEntries))
								.Select(o => new FilterSetting { Path = o[0], Values = new List<string> { o[1] }, ShouldMatch = bool.Parse(o[2]) }));
						}

						await dataDumper.ImportData(new SmugglerImportOptions<RavenConnectionStringOptions> { FromStream = fileStream });
					}
				}
				catch (Exception e)
				{
				    status.Faulted = true;
				    status.State = RavenJObject.FromObject(new
				                                           {
				                                               Error = e.ToString()
				                                           });
					if (cts.Token.IsCancellationRequested)
					{
                        status.State = RavenJObject.FromObject(new { Error = "Task was cancelled"  });
						cts.Token.ThrowIfCancellationRequested(); //needed for displaying the task status as canceled and not faulted
					}

                    if (e is InvalidDataException)
                    {
                        status.ExceptionDetails = e.Message;
                    }
                    else if (e is Imports.Newtonsoft.Json.JsonReaderException)
                    {
                        status.ExceptionDetails = "Failed to load JSON Data. Please make sure you are importing .ravendump file, exported by smuggler (aka database export). If you are importing a .ravnedump file then the file may be corrupted";
                    }
                    else
                    {
                        status.ExceptionDetails = e.ToString();
                    }
					throw;
				}
				finally
				{
					status.Completed = true;
					File.Delete(uploadedFilePath);
				}
			}, cts.Token);

			long id;
			Database.Tasks.AddTask(task, status, new TaskActions.PendingTaskDescription
			{
				StartTime = SystemTime.UtcNow,
				TaskType = TaskActions.PendingTaskType.ImportDatabase,
				Payload = fileName,
				
			}, out id, cts);

//.........这里部分代码省略.........
开发者ID:jrusbatch,项目名称:ravendb,代码行数:101,代码来源:StudioTasksController.cs


注:本文中的Raven.Database.Smuggler.DatabaseDataDumper.ImportData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。