public async Task Between(SmugglerBetweenOperations betweenOperations, SmugglerDatabaseOptions databaseOptions)
        {
            var exportOperations = betweenOperations.From;
            var importOperations = betweenOperations.To;

            exportOperations.Configure(databaseOptions);
            exportOperations.Initialize(databaseOptions);

            importOperations.Configure(databaseOptions);
            importOperations.Initialize(databaseOptions);

            if (string.IsNullOrEmpty(betweenOperations.IncrementalKey))
            {
                betweenOperations.IncrementalKey = exportOperations.GetIdentifier();
            }

            var incremental = new ExportIncremental();

            if (databaseOptions.Incremental)
            {
                var jsonDocument = importOperations.GetDocument(SmugglerExportIncremental.RavenDocumentKey);
                if (jsonDocument != null)
                {
                    var smugglerExportIncremental = jsonDocument.DataAsJson.JsonDeserialization <SmugglerExportIncremental>();
                    ExportIncremental value;
                    if (smugglerExportIncremental.ExportIncremental.TryGetValue(betweenOperations.IncrementalKey, out value))
                    {
                        incremental = value;
                    }

                    databaseOptions.StartDocsEtag        = incremental.LastDocsEtag ?? Etag.Empty;
                    databaseOptions.StartAttachmentsEtag = incremental.LastAttachmentsEtag ?? Etag.Empty;
                }
            }

            if (databaseOptions.OperateOnTypes.HasFlag(ItemType.Indexes))
            {
                await ExportIndexes(exportOperations, importOperations).ConfigureAwait(false);
            }

            if (databaseOptions.OperateOnTypes.HasFlag(ItemType.Transformers))
            {
                await ExportTransformers(exportOperations, importOperations).ConfigureAwait(false);
            }

            if (databaseOptions.OperateOnTypes.HasFlag(ItemType.Documents))
            {
                incremental.LastDocsEtag = await ExportDocuments(exportOperations, importOperations, databaseOptions).ConfigureAwait(false);
            }

            if (databaseOptions.OperateOnTypes.HasFlag(ItemType.Attachments))
            {
                incremental.LastAttachmentsEtag = await ExportAttachments(exportOperations, importOperations, databaseOptions).ConfigureAwait(false);
            }

            await ExportIdentities(exportOperations, importOperations, databaseOptions.OperateOnTypes).ConfigureAwait(false);

            if (databaseOptions.Incremental)
            {
                var smugglerExportIncremental = new SmugglerExportIncremental();
                var jsonDocument = importOperations.GetDocument(SmugglerExportIncremental.RavenDocumentKey);
                if (jsonDocument != null)
                {
                    smugglerExportIncremental = jsonDocument.DataAsJson.JsonDeserialization <SmugglerExportIncremental>();
                }
                smugglerExportIncremental.ExportIncremental[betweenOperations.IncrementalKey] = incremental;

                var smugglerDoc = RavenJObject.FromObject(smugglerExportIncremental);

                smugglerDoc.Add("@metadata", new RavenJObject
                {
                    { "@id", SmugglerExportIncremental.RavenDocumentKey }
                });

                await importOperations.PutDocument(smugglerDoc, (int)DocumentHelpers.GetRoughSize(smugglerDoc)).ConfigureAwait(false);

                await importOperations.PutDocument(null, -1).ConfigureAwait(false); // force flush
            }
        }
        public static async Task Between(SmugglerBetweenOptions<RavenConnectionStringOptions> betweenOptions, SmugglerDatabaseOptions databaseOptions)
		{
			SetDatabaseNameIfEmpty(betweenOptions.From);
			SetDatabaseNameIfEmpty(betweenOptions.To);

			using (var exportStore = CreateStore(betweenOptions.From))
			using (var importStore = CreateStore(betweenOptions.To))
			{
				SmugglerDatabaseApi.ValidateThatServerIsUpAndDatabaseExists(betweenOptions.From, exportStore);
				SmugglerDatabaseApi.ValidateThatServerIsUpAndDatabaseExists(betweenOptions.To, importStore);

				var exportBatchSize = GetBatchSize(exportStore, databaseOptions);
				var importBatchSize = GetBatchSize(importStore, databaseOptions);

				var exportStoreSupportedFeatures = await DetectServerSupportedFeatures(exportStore);
				var importStoreSupportedFeatures = await DetectServerSupportedFeatures(importStore);

				if (string.IsNullOrEmpty(betweenOptions.IncrementalKey))
				{
					betweenOptions.IncrementalKey = ((AsyncServerClient)exportStore.AsyncDatabaseCommands).Url;
				}

				var incremental = new ExportIncremental();
				if (databaseOptions.Incremental)
				{
					var jsonDocument = await importStore.AsyncDatabaseCommands.GetAsync(SmugglerExportIncremental.RavenDocumentKey);
					if (jsonDocument != null)
					{
						var smugglerExportIncremental = jsonDocument.DataAsJson.JsonDeserialization<SmugglerExportIncremental>();
						ExportIncremental value;
						if (smugglerExportIncremental.ExportIncremental.TryGetValue(betweenOptions.IncrementalKey, out value))
						{
							incremental = value;
						}

						databaseOptions.StartDocsEtag = incremental.LastDocsEtag ?? Etag.Empty;
						databaseOptions.StartAttachmentsEtag = incremental.LastAttachmentsEtag ?? Etag.Empty;
					}
				}

				if (databaseOptions.OperateOnTypes.HasFlag(ItemType.Indexes))
				{
					await ExportIndexes(exportStore, importStore, exportBatchSize);
				}
				if (databaseOptions.OperateOnTypes.HasFlag(ItemType.Transformers) && exportStoreSupportedFeatures.IsTransformersSupported && importStoreSupportedFeatures.IsTransformersSupported)
				{
					await ExportTransformers(exportStore, importStore, exportBatchSize);
				}
				if (databaseOptions.OperateOnTypes.HasFlag(ItemType.Documents))
				{
					incremental.LastDocsEtag = await ExportDocuments(exportStore, importStore, databaseOptions, exportStoreSupportedFeatures, exportBatchSize, importBatchSize);
				}
				if (databaseOptions.OperateOnTypes.HasFlag(ItemType.Attachments))
				{
					incremental.LastAttachmentsEtag = await ExportAttachments(exportStore, importStore, databaseOptions, exportBatchSize);
				}
				if (exportStoreSupportedFeatures.IsIdentitiesSmugglingSupported && importStoreSupportedFeatures.IsIdentitiesSmugglingSupported)
				{
                    await ExportIdentities(exportStore, importStore, databaseOptions.OperateOnTypes);
				}

				if (databaseOptions.Incremental)
				{
					var smugglerExportIncremental = new SmugglerExportIncremental();
					var jsonDocument = await importStore.AsyncDatabaseCommands.GetAsync(SmugglerExportIncremental.RavenDocumentKey);
					if (jsonDocument != null)
					{
						smugglerExportIncremental = jsonDocument.DataAsJson.JsonDeserialization<SmugglerExportIncremental>();
					}
					smugglerExportIncremental.ExportIncremental[betweenOptions.IncrementalKey] = incremental;
					await importStore.AsyncDatabaseCommands.PutAsync(SmugglerExportIncremental.RavenDocumentKey, null, RavenJObject.FromObject(smugglerExportIncremental), new RavenJObject());
				}
			}
		}
Пример #3
0
        public static async Task Between(SmugglerBetweenOptions betweenOptions, SmugglerOptions options)
        {
            SetDatabaseNameIfEmpty(betweenOptions.From);
            SetDatabaseNameIfEmpty(betweenOptions.To);

            using (var exportStore = CreateStore(betweenOptions.From))
                using (var importStore = CreateStore(betweenOptions.To))
                {
                    SmugglerApi.ValidateThatServerIsUpAndDatabaseExists(betweenOptions.From, exportStore);
                    SmugglerApi.ValidateThatServerIsUpAndDatabaseExists(betweenOptions.To, importStore);

                    var exportBatchSize = GetBatchSize(exportStore, options);
                    var importBatchSize = GetBatchSize(importStore, options);

                    var exportStoreSupportedFeatures = await DetectServerSupportedFeatures(exportStore);

                    var importStoreSupportedFeatures = await DetectServerSupportedFeatures(importStore);

                    if (string.IsNullOrEmpty(betweenOptions.IncrementalKey))
                    {
                        betweenOptions.IncrementalKey = ((AsyncServerClient)exportStore.AsyncDatabaseCommands).Url;
                    }

                    var incremental = new ExportIncremental();
                    if (options.Incremental)
                    {
                        var jsonDocument = await importStore.AsyncDatabaseCommands.GetAsync(SmugglerExportIncremental.RavenDocumentKey);

                        if (jsonDocument != null)
                        {
                            var smugglerExportIncremental = jsonDocument.DataAsJson.JsonDeserialization <SmugglerExportIncremental>();
                            ExportIncremental value;
                            if (smugglerExportIncremental.ExportIncremental.TryGetValue(betweenOptions.IncrementalKey, out value))
                            {
                                incremental = value;
                            }

                            options.StartDocsEtag        = incremental.LastDocsEtag ?? Etag.Empty;
                            options.StartAttachmentsEtag = incremental.LastAttachmentsEtag ?? Etag.Empty;
                        }
                    }

                    if (options.OperateOnTypes.HasFlag(ItemType.Indexes))
                    {
                        await ExportIndexes(exportStore, importStore, exportBatchSize);
                    }
                    if (options.OperateOnTypes.HasFlag(ItemType.Transformers) && exportStoreSupportedFeatures.IsTransformersSupported && importStoreSupportedFeatures.IsTransformersSupported)
                    {
                        await ExportTransformers(exportStore, importStore, exportBatchSize);
                    }
                    if (options.OperateOnTypes.HasFlag(ItemType.Documents))
                    {
                        incremental.LastDocsEtag = await ExportDocuments(exportStore, importStore, options, exportStoreSupportedFeatures, exportBatchSize, importBatchSize);
                    }
                    if (options.OperateOnTypes.HasFlag(ItemType.Attachments))
                    {
                        incremental.LastAttachmentsEtag = await ExportAttachments(exportStore, importStore, options, exportBatchSize);
                    }

                    if (options.Incremental)
                    {
                        var smugglerExportIncremental = new SmugglerExportIncremental();
                        var jsonDocument = await importStore.AsyncDatabaseCommands.GetAsync(SmugglerExportIncremental.RavenDocumentKey);

                        if (jsonDocument != null)
                        {
                            smugglerExportIncremental = jsonDocument.DataAsJson.JsonDeserialization <SmugglerExportIncremental>();
                        }
                        smugglerExportIncremental.ExportIncremental[betweenOptions.IncrementalKey] = incremental;
                        await importStore.AsyncDatabaseCommands.PutAsync(SmugglerExportIncremental.RavenDocumentKey, null, RavenJObject.FromObject(smugglerExportIncremental), new RavenJObject());
                    }
                }
        }