Exemplo n.º 1
0
        public long StartMigratingSingleDatabase(DatabaseMigrationSettings databaseMigrationSettings, DocumentDatabase database)
        {
            var operationId = database.Operations.GetNextOperationId();
            var cancelToken = new OperationCancelToken(database.DatabaseShutdown);
            var result      = new SmugglerResult();

            var databaseName = databaseMigrationSettings.DatabaseName;

            database.Operations.AddOperation(null,
                                             $"Database name: '{databaseName}' from url: {_serverUrl}",
                                             Operations.OperationType.DatabaseMigrationRavenDb,
                                             taskFactory: onProgress => Task.Run(async() =>
            {
                onProgress?.Invoke(result.Progress);

                var message = $"Importing from RavenDB {EnumHelper.GetDescription(_buildMajorVersion)}";

                result.AddInfo(message);

                using (cancelToken)
                {
                    try
                    {
                        var migrationStateKey = $"{MigrationStateKeyBase}" +
                                                $"{EnumHelper.GetDescription(_buildMajorVersion)}/" +
                                                $"{databaseName}/" +
                                                $"{_serverUrl}";

                        var options = new MigratorOptions
                        {
                            MigrationStateKey = migrationStateKey,
                            ServerUrl         = _serverUrl,
                            DatabaseName      = databaseName,
                            ApiKey            = _apiKey,
                            TransformScript   = databaseMigrationSettings.TransformScript,
                            EnableBasicAuthenticationOverUnsecuredHttp = _enableBasicAuthenticationOverUnsecuredHttp,
                            SkipServerCertificateValidation            = _skipServerCertificateValidation,
                            RemoveAnalyzers = databaseMigrationSettings.RemoveAnalyzers,
                            ImportRavenFs   = databaseMigrationSettings.ImportRavenFs,
                            OperateOnTypes  = databaseMigrationSettings.OperateOnTypes,
                            OperateOnDatabaseRecordTypes = databaseMigrationSettings.OperateOnDatabaseRecordTypes
                        };

                        var parameters = new MigratorParameters
                        {
                            HttpClient  = _httpClient,
                            Result      = result,
                            OnProgress  = onProgress,
                            Database    = database,
                            CancelToken = cancelToken
                        };

                        AbstractMigrator migrator;
                        switch (_buildMajorVersion)
                        {
                        case MajorVersion.V2:
                            migrator = new Migrator_V2(options, parameters);
                            break;

                        case MajorVersion.V30:
                        case MajorVersion.V35:
                            migrator = new Migrator_V3(options, parameters, _buildMajorVersion, _buildVersion);
                            break;

                        case MajorVersion.V4:
                            migrator = new Importer(options, parameters, _buildVersion);
                            break;

                        default:
                            throw new ArgumentOutOfRangeException(nameof(_buildMajorVersion), _buildMajorVersion, null);
                        }

                        await migrator.Execute();
                    }
                    catch (Exception e)
                    {
                        result.AddError($"Error occurred during database migration named: {databaseName}." +
                                        $"Exception: {e.Message}");

                        throw;
                    }
                }

                return((IOperationResult)result);
            }, cancelToken.Token), id: operationId, token: cancelToken);

            return(operationId);
        }
Exemplo n.º 2
0
        public long StartMigrateSingleDatabase(string sourceDatabaseName, DocumentDatabase database)
        {
            var operationId = database.Operations.GetNextOperationId();
            var cancelToken = new OperationCancelToken(_cancellationToken);
            var result      = new SmugglerResult();

            database.Operations.AddOperation(null,
                                             $"Database name: '{sourceDatabaseName}' from url: {_serverUrl}",
                                             Operations.OperationType.DatabaseMigration,
                                             taskFactory: onProgress => Task.Run(async() =>
            {
                onProgress?.Invoke(result.Progress);

                var message = $"Importing from RavenDB {GetDescription(_version)}, " +
                              $"build version: {_buildVersion}";

                if (string.IsNullOrWhiteSpace(_fullVersion) == false)
                {
                    message += $", full version: {_fullVersion}";
                }

                result.AddMessage(message);

                using (cancelToken)
                {
                    try
                    {
                        var migrationStateKey = $"{MigrationStateKeyBase}/" +
                                                $"{GetDescription(_version)}/" +
                                                $"{sourceDatabaseName}/" +
                                                $"{_serverUrl}";

                        AbstractMigrator migrator;
                        switch (_version)
                        {
                        case MajorVersion.V2:
                            migrator = new Migrator_V2(_serverUrl, sourceDatabaseName, result, onProgress, database, _client, cancelToken);
                            break;

                        case MajorVersion.V30:
                        case MajorVersion.V35:
                            migrator = new Migrator_V3(_serverUrl, sourceDatabaseName, result, onProgress,
                                                       database, _client, migrationStateKey, _version, cancelToken);
                            break;

                        case MajorVersion.V4:
                            migrator = new Importer(_serverUrl, sourceDatabaseName, result, onProgress, database, migrationStateKey, cancelToken);
                            break;

                        default:
                            throw new ArgumentOutOfRangeException(nameof(_version), _version, null);
                        }

                        using (migrator)
                        {
                            await migrator.Execute();
                        }
                    }
                    catch (Exception e)
                    {
                        result.AddError($"Error occurred during database migration named: {sourceDatabaseName}." +
                                        $"Exception: {e.Message}");

                        throw;
                    }
                }

                return((IOperationResult)result);
            }, cancelToken.Token), id: operationId, token: cancelToken);

            return(operationId);
        }