public ExportDatabaseCommand(ExportTaskSectionModel taskModel, Action <string> output)
 {
     this.output    = output;
     this.taskModel = taskModel;
     smuggler       = new SmugglerApi(new SmugglerOptions
     {
         BatchSize = BatchSize
     }, DatabaseCommands, output);
 }
		public ExportDatabaseCommand(ExportTaskSectionModel taskModel, Action<string> output)
		{
			this.output = output;
			this.taskModel = taskModel;
			smuggler = new SmugglerApi(new SmugglerOptions
			{
				BatchSize = BatchSize
			}, DatabaseCommands, output);
		}
Example #3
0
        private void ExecuteInternal()
        {
            includeAttachments  = taskModel.IncludeAttachments.Value;
            includeDocuments    = taskModel.IncludeDocuments.Value;
            includeIndexes      = taskModel.IncludeIndexes.Value;
            includeTransformers = taskModel.IncludeTransforms.Value;

            if (includeDocuments == false && includeAttachments == false && includeIndexes == false && includeTransformers == false)
            {
                return;
            }

            var openFile = new OpenFileDialog
            {
                Filter = "Raven Dumps|*.ravendump;*.raven.dump",
            };

            if (openFile.ShowDialog() != true)
            {
                return;
            }

            taskModel.TaskStatus       = TaskStatus.Started;
            taskModel.CanExecute.Value = false;
            output(String.Format("Importing from {0}", openFile.File.Name));

            var stream = openFile.File.OpenRead();

            ItemType operateOnTypes = 0;

            if (includeDocuments)
            {
                operateOnTypes |= ItemType.Documents;
            }

            if (includeAttachments)
            {
                operateOnTypes |= ItemType.Attachments;
            }

            if (includeIndexes)
            {
                operateOnTypes |= ItemType.Indexes;
            }

            if (includeTransformers)
            {
                operateOnTypes |= ItemType.Transformers;
            }

            if (taskModel.UseCollections.Value)
            {
                foreach (var collection in taskModel.Collections.Where(collection => collection.Selected))
                {
                    taskModel.Filters.Add(new FilterSetting {
                        Path = "@metadata.Raven-Entity-Name", Value = collection.Name, ShouldMatch = true
                    });
                }
            }

            var smugglerOptions = new SmugglerOptions
            {
                BatchSize            = taskModel.Options.Value.BatchSize,
                Filters              = taskModel.Filters.ToList(),
                TransformScript      = taskModel.ScriptData,
                ShouldExcludeExpired = taskModel.Options.Value.ShouldExcludeExpired,
                OperateOnTypes       = operateOnTypes
            };

            smuggler = new SmugglerApi(smugglerOptions, DatabaseCommands, output);

            smuggler.ImportData(stream, smugglerOptions)
            .Catch(exception => Infrastructure.Execute.OnTheUI(() => taskModel.ReportError(exception)))
            .Finally(() =>
            {
                taskModel.TaskStatus       = TaskStatus.Ended;
                taskModel.CanExecute.Value = true;
            });
        }
		private void ExecuteInternal()
		{
			includeAttachments = taskModel.IncludeAttachments.Value;
			includeDocuments = taskModel.IncludeDocuments.Value;
			includeIndexes = taskModel.IncludeIndexes.Value;
			includeTransformers = taskModel.IncludeTransforms.Value;
			
			if (includeDocuments == false && includeAttachments == false && includeIndexes == false && includeTransformers == false)
				return;
			
			var openFile = new OpenFileDialog
			{
				Filter = "Raven Dumps|*.ravendump;*.raven.dump",
			};

			if (openFile.ShowDialog() != true)
				return;

			taskModel.TaskStatus = TaskStatus.Started;
			taskModel.CanExecute.Value = false;
			output(String.Format("Importing from {0}", openFile.File.Name));

			var stream = openFile.File.OpenRead();

			ItemType operateOnTypes = 0;

			if (includeDocuments)
			{
				operateOnTypes |= ItemType.Documents;
			}

			if (includeAttachments)
			{
				operateOnTypes |= ItemType.Attachments;
			}

			if (includeIndexes)
			{
				operateOnTypes |= ItemType.Indexes;
			}

			if (includeTransformers)
			{
				operateOnTypes |= ItemType.Transformers;
			}

			if (taskModel.UseCollections.Value)
			{
				foreach (var collection in taskModel.Collections.Where(collection => collection.Selected))
				{
					taskModel.Filters.Add(new FilterSetting { Path = "@metadata.Raven-Entity-Name", Value = collection.Name, ShouldMatch = true });
				}
			}

			var smugglerOptions = new SmugglerOptions
			{
				BatchSize = taskModel.Options.Value.BatchSize,
				Filters = taskModel.Filters.ToList(),
				TransformScript = taskModel.ScriptData,
				ShouldExcludeExpired = taskModel.Options.Value.ShouldExcludeExpired,
				OperateOnTypes = operateOnTypes
			};

			smuggler = new SmugglerApi(smugglerOptions, DatabaseCommands, output);

			smuggler.ImportData(stream, smugglerOptions)
			        .Catch(exception => Infrastructure.Execute.OnTheUI(() => taskModel.ReportError(exception)))
			        .Finally(() =>
			        {
				        taskModel.TaskStatus = TaskStatus.Ended;
				        taskModel.CanExecute.Value = true;
			        });
		}