Exemplo n.º 1
0
		public Task<HttpResponseMessage> ExportFilesystem(StudioTasksController.ExportData smugglerOptionsJson)
		{
			var requestString = smugglerOptionsJson.SmugglerOptions;
			SmugglerFilesOptions smugglerOptions;

			using (var jsonReader = new RavenJsonTextReader(new StringReader(requestString)))
			{
				var serializer = JsonExtensions.CreateDefaultJsonSerializer();
				smugglerOptions = (SmugglerFilesOptions)serializer.Deserialize(jsonReader, typeof(SmugglerFilesOptions));
			}


			var result = GetEmptyMessage();

			// create PushStreamContent object that will be called when the output stream will be ready.
			result.Content = new PushStreamContent(async (outputStream, content, arg3) =>
			{
				try
				{
					var dataDumper = new FilesystemDataDumper(FileSystem, smugglerOptions);
					await dataDumper.ExportData(
						new SmugglerExportOptions<FilesConnectionStringOptions>
						{
							ToStream = outputStream
						}).ConfigureAwait(false);
				}
				finally
				{
					outputStream.Close();
				}
			});

			var fileName = String.IsNullOrEmpty(smugglerOptions.NoneDefualtFileName) || (smugglerOptions.NoneDefualtFileName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) ?
				string.Format("Dump of {0}, {1}", this.FileSystemName, DateTime.Now.ToString("yyyy-MM-dd HH-mm", CultureInfo.InvariantCulture)) :
				smugglerOptions.NoneDefualtFileName;
			result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
			{
				FileName = fileName + ".ravendump"
			};

			return new CompletedTask<HttpResponseMessage>(result);
		}
Exemplo n.º 2
0
        public async Task export_result_cannot_contain_neither_files_scheduled_for_deletion_nor_tombstones(string storage)
        {
            var exportStream = new MemoryStream();

            using (var store = this.NewStore(requestedStorage: storage))
            {
                using (var session = store.OpenAsyncSession())
                {
                    for (int i = 0; i < 10; i++)
                        session.RegisterUpload("prefix-" + i + ".file", CreateUniformFileStream(10));

                    await session.SaveChangesAsync();
                }

                using (var session = store.OpenAsyncSession())
                {
                    session.RegisterFileDeletion("prefix-3.file");

                    await session.SaveChangesAsync();
                }

                var fs = GetFileSystem();

                var exporter = new FilesystemDataDumper(fs);

                await exporter.ExportData(
                       new SmugglerExportOptions<FilesConnectionStringOptions>
                       {
                           ToStream = exportStream
                       }).ConfigureAwait(false);


                using (var import = NewStore(1))
                {
                    exportStream.Position = 0;

                    var importedFs = GetFileSystem(1);
                    var importer = new FilesystemDataDumper(importedFs);

                    await importer.ImportData(new SmugglerImportOptions<FilesConnectionStringOptions> { FromStream = exportStream });

                    importedFs.Storage.Batch(accessor =>
                    {
                        Assert.Equal(9, accessor.GetFilesAfter(Etag.Empty, 100).Count());
                    });
                }
            }
        }