예제 #1
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());
                    }
                }
        }