Exemplo n.º 1
0
        public override async Task Execute()
        {
            var            state = GetLastMigrationState();
            const ItemType types = ItemType.Documents | ItemType.Indexes | ItemType.Transformers | ItemType.Attachments;

            var databaseMigrationOptions = new DatabaseMigrationOptions
            {
                BatchSize      = 1024,
                OperateOnTypes = types,
                //TODO: ExportDeletions = state != null,
                StartDocsEtag                = state?.LastDocsEtag ?? LastEtagsInfo.EtagEmpty,
                StartDocsDeletionEtag        = state?.LastDocDeleteEtag ?? LastEtagsInfo.EtagEmpty,
                StartAttachmentsEtag         = state?.LastAttachmentsEtag ?? LastEtagsInfo.EtagEmpty,
                StartAttachmentsDeletionEtag = state?.LastAttachmentsDeleteEtag ?? LastEtagsInfo.EtagEmpty
            };

            // getting a new operation id was added in v3.5
            var operationId = _majorVersion == MajorVersion.V30 ? 0 : await GetOperationId();

            object exportData;

            if (_majorVersion == MajorVersion.V30)
            {
                exportData = new ExportDataV3
                {
                    SmugglerOptions = JsonConvert.SerializeObject(databaseMigrationOptions)
                };
            }
            else
            {
                exportData = new ExportDataV35
                {
                    DownloadOptions = JsonConvert.SerializeObject(databaseMigrationOptions),
                    ProgressTaskId  = operationId
                };
            }

            var exportOptions = JsonConvert.SerializeObject(exportData);

            await MigrateDatabase(exportOptions);

            await SaveLastState(operationId);
        }
Exemplo n.º 2
0
        public override async Task Execute()
        {
            var state         = GetLastMigrationState();
            var originalState = state;

            var operateOnTypes = GenerateOperateOnTypes();

            if (operateOnTypes == ItemType.None && Options.ImportRavenFs == false)
            {
                throw new BadRequestException("No types to import");
            }

            if (Options.ImportRavenFs)
            {
                Parameters.Result.AddInfo("Started processing RavenFS files");
                Parameters.OnProgress.Invoke(Parameters.Result.Progress);

                var lastRavenFsEtag = await MigrateRavenFs(state?.LastRavenFsEtag ?? LastEtagsInfo.EtagEmpty, Parameters.Result);

                state = GetLastMigrationState() ?? GenerateLastEtagsInfo();
                state.LastRavenFsEtag = lastRavenFsEtag;
                await SaveLastOperationState(state);
            }

            if (operateOnTypes != ItemType.None)
            {
                if (Options.ImportRavenFs && operateOnTypes.HasFlag(ItemType.Documents) == false)
                {
                    Parameters.Result.Documents.Processed = true;
                    Parameters.OnProgress.Invoke(Parameters.Result.Progress);
                }

                var databaseMigrationOptions = new DatabaseMigrationOptions
                {
                    BatchSize                    = 1024,
                    OperateOnTypes               = operateOnTypes,
                    ExportDeletions              = originalState != null,
                    StartDocsEtag                = state?.LastDocsEtag ?? LastEtagsInfo.EtagEmpty,
                    StartDocsDeletionEtag        = state?.LastDocDeleteEtag ?? LastEtagsInfo.EtagEmpty,
                    StartAttachmentsEtag         = state?.LastAttachmentsEtag ?? LastEtagsInfo.EtagEmpty,
                    StartAttachmentsDeletionEtag = state?.LastAttachmentsDeleteEtag ?? LastEtagsInfo.EtagEmpty
                };

                // getting a new operation id was added in v3.5
                var operationId = _majorVersion == MajorVersion.V30 ? 0 : await GetOperationId();

                object exportData;
                if (_majorVersion == MajorVersion.V30)
                {
                    exportData = new ExportDataV3
                    {
                        SmugglerOptions = JsonConvert.SerializeObject(databaseMigrationOptions)
                    };
                }
                else
                {
                    exportData = new ExportDataV35
                    {
                        DownloadOptions = JsonConvert.SerializeObject(databaseMigrationOptions),
                        ProgressTaskId  = operationId
                    };
                }

                var exportOptions = JsonConvert.SerializeObject(exportData);
                var canGetLastStateByOperationId = _buildVersion >= 35215;

                await MigrateDatabase(exportOptions, readLegacyEtag : canGetLastStateByOperationId == false);

                var lastState = await GetLastState(canGetLastStateByOperationId, operationId);

                if (lastState != null)
                {
                    // refresh the migration state, in case we are running here with a RavenFS concurrently
                    lastState.LastRavenFsEtag = GetLastMigrationState()?.LastRavenFsEtag ?? LastEtagsInfo.EtagEmpty;
                    await SaveLastOperationState(lastState);
                }
            }
            else
            {
                if (Options.ImportRavenFs)
                {
                    Parameters.Result.Documents.Processed = true;
                }

                DatabaseSmuggler.EnsureProcessed(Parameters.Result);
            }
        }