protected async override Task<DatabaseTaskOutcome> RunImplementation() { var statistics = await DatabaseCommands.GetStatisticsAsync(); if (statistics.CountOfDocuments > 0) { ReportError("Database already contains documents"); return DatabaseTaskOutcome.Error; } Report("Creating Sample Data, Please wait..."); // this code assumes a small enough dataset, and doesn't do any sort // of paging or batching whatsoever. using (var sampleData = typeof(CreateSampleDataTask).Assembly.GetManifestResourceStream("Raven.Studio.Assets.EmbeddedData.Northwind.dump")) { Report("Reading documents"); var smugglerOptions = new SmugglerOptions { OperateOnTypes = ItemType.Documents | ItemType.Indexes | ItemType.Transformers, ShouldExcludeExpired = false, }; var smuggler = new SmugglerApi(smugglerOptions, DatabaseCommands, s => Report(s)); await smuggler.ImportData(sampleData, smugglerOptions); } return DatabaseTaskOutcome.Succesful; }
private async Task<DatabaseTaskOutcome> ExecuteInternal() { if (includeDocuments == false && includeAttachements == false && includeIndexes == false && includeTransformers == false) return DatabaseTaskOutcome.Abandoned; var openFile = new OpenFileDialog { Filter = "Raven Dumps|*.ravendump;*.raven.dump", }; if (openFile.ShowDialog() != true) return DatabaseTaskOutcome.Abandoned; Report(String.Format("Importing from {0}", openFile.File.Name)); using (var stream = openFile.File.OpenRead()) { ItemType operateOnTypes = 0; if (includeDocuments) { operateOnTypes |= ItemType.Documents; } if (includeAttachements) { operateOnTypes |= ItemType.Attachments; } if (includeIndexes) { operateOnTypes |= ItemType.Indexes; } if (includeTransformers) { operateOnTypes |= ItemType.Transformers; } var smugglerOptions = new SmugglerOptions { BatchSize = batchSize, Filters = filterSettings, TransformScript = transformScript, ShouldExcludeExpired = shouldExcludeExpired, OperateOnTypes = operateOnTypes }; var smuggler = new SmugglerApi(smugglerOptions, DatabaseCommands, message => Report(message)); await smuggler.ImportData(stream, smugglerOptions); } return DatabaseTaskOutcome.Succesful; }
protected override async Task<DatabaseTaskOutcome> RunImplementation() { if (includeDocuments == false && includeAttachements == false && includeIndexes == false && includeTransformers == false) return DatabaseTaskOutcome.Abandoned; var saveFile = new SaveFileDialog { DefaultExt = ".ravendump", Filter = "Raven Dumps|*.ravendump;*.raven.dump", }; var name = ApplicationModel.Database.Value.Name; var normalizedName = new string(name.Select(ch => Path.GetInvalidPathChars().Contains(ch) ? '_' : ch).ToArray()); var defaultFileName = string.Format("Dump of {0}, {1}", normalizedName, DateTimeOffset.Now.ToString("dd MMM yyyy HH-mm", CultureInfo.InvariantCulture)); try { saveFile.DefaultFileName = defaultFileName; } catch { } if (saveFile.ShowDialog() != true) { return DatabaseTaskOutcome.Abandoned; } using (var stream = saveFile.OpenFile()) { ItemType operateOnTypes = 0; if (includeDocuments) { operateOnTypes |= ItemType.Documents; } if (includeAttachements) { operateOnTypes |= ItemType.Attachments; } if (includeIndexes) { operateOnTypes |= ItemType.Indexes; } if (includeTransformers) { operateOnTypes |= ItemType.Transformers; } var smuggler = new SmugglerApi(new SmugglerOptions { BatchSize = batchSize }, DatabaseCommands, message => Report(message)); var forwardtoUiBoundStream = new ForwardtoUIBoundStream(stream); var taskGeneration = new Task<Task>(() => smuggler.ExportData(forwardtoUiBoundStream, new SmugglerOptions { BatchSize = batchSize, Filters = filterSettings, TransformScript = transformScript, ShouldExcludeExpired = shouldExcludeExpired, OperateOnTypes = operateOnTypes }, false)); ThreadPool.QueueUserWorkItem(state => taskGeneration.Start()); await taskGeneration.Unwrap(); forwardtoUiBoundStream.Flush(); stream.Flush(); } return DatabaseTaskOutcome.Succesful; }