コード例 #1
0
        /// <summary>
        /// Helper method that calls the creation of an instance of the Database Migration Service
        /// </summary>
        /// <returns>The instance of PSDataMigrationService that was created.</returns>
        public DataMigrationService CreateService()
        {
            // Get the virtual subnet id from the network and the subnet name
            // string vnetId = GetVirtualSubnetId(SubnetName);

            // Create Sku
            ServiceSku sku = new ServiceSku()
            {
                Name = Sku
            };

            // Create a DMS model
            DataMigrationService serviceParams = new DataMigrationService();

            serviceParams.Location        = Location;
            serviceParams.Sku             = sku;
            serviceParams.VirtualSubnetId = VirtualSubnetId;

            DataMigrationService response = null;

            try
            {
                response = DataMigrationClient.Services.CreateOrUpdate(serviceParams, ResourceGroupName, Name);
            }
            catch (ApiErrorException ex)
            {
                ThrowAppropriateException(ex);
            }

            return(response);
        }
コード例 #2
0
        private ProjectTask CreateDMSSqlTask(MockContext context,
                                             DataMigrationServiceClient client,
                                             ResourceGroup resourceGroup,
                                             DataMigrationService service,
                                             string dmsProjectName,
                                             string dmsTaskName)
        {
            var taskProps = new ConnectToTargetSqlDbTaskProperties
            {
                Input = new ConnectToTargetSqlDbTaskInput(
                    new SqlConnectionInfo
                {
                    DataSource             = "shuhuandmsdbs.database.windows.net",
                    EncryptConnection      = true,
                    TrustServerCertificate = true,
                    UserName       = "******",
                    Password       = "******",
                    Authentication = AuthenticationType.SqlAuthentication,
                }
                    )
            };

            return(client.Tasks.CreateOrUpdate(
                       new ProjectTask(
                           properties: taskProps),
                       resourceGroup.Name,
                       service.Name,
                       dmsProjectName,
                       dmsTaskName));
        }
コード例 #3
0
        public void TestSetup()
        {
            loggerMock          = new Mock <ILogger>();
            migratorFactoryMock = new Mock <ICrmGenericMigratorFactory>();

            systemUnderTest = new DataMigrationService(loggerMock.Object, migratorFactoryMock.Object);
        }
コード例 #4
0
        static void Main(string[] args)
        {
            RemoveDataApp app      = new RemoveDataApp();
            Logger        logger   = app.Logger;
            ExitCode      exitCode = ExitCode.None;

            try
            {
                logger.Info("Application started.");

                CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");

                Options options = new Options();

                Parser.Default.ParseArgumentsStrict(args, options, CommandLineOptions.ArgumentParsingFailed);

                using (IDataMigrationService dataMigrationService = new DataMigrationService())
                {
                    dataMigrationService.RemoveData(options.InputFileName, options.OutputFileName, options.AttributeName, options.AttributeValue);
                    exitCode = ExitCode.Success;
                }
            }
            catch (Exception ex)
            {
                exitCode = new ExceptionHandlingService(ex).GetExitCode();
            }
            finally
            {
                logger.Info(CultureInfo.InvariantCulture, "Application exited with code: {0}", (int)exitCode);
                Environment.Exit((int)exitCode);
            }
        }
コード例 #5
0
        public PSDataMigrationService(DataMigrationService service)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            this.service           = service;
            this.ids               = new DmsResourceIdentifier(service.Id);
            this.ResourceGroupName = ids.ResourceGroupName;
        }
コード例 #6
0
        private ProjectTask CreateDMSSyncTask(MockContext context,
                                              DataMigrationServiceClient client,
                                              ResourceGroup resourceGroup,
                                              DataMigrationService service,
                                              string dmsProjectName,
                                              string dmsTaskName)
        {
            var taskProps = new MigrateSqlServerSqlDbSyncTaskProperties
            {
                Input = new MigrateSqlServerSqlDbSyncTaskInput(
                    new SqlConnectionInfo
                {
                    DataSource             = @"steven-work.redmond.corp.microsoft.com\stevenf16,12345",
                    EncryptConnection      = true,
                    TrustServerCertificate = true,
                    UserName       = "******",
                    Password       = "******",
                    Authentication = AuthenticationType.SqlAuthentication,
                },
                    new SqlConnectionInfo
                {
                    DataSource             = "shuhuandmsdbs.database.windows.net",
                    EncryptConnection      = true,
                    TrustServerCertificate = true,
                    UserName       = "******",
                    Password       = "******",
                    Authentication = AuthenticationType.SqlAuthentication,
                },
                    new List <MigrateSqlServerSqlDbSyncDatabaseInput>
                {
                    new MigrateSqlServerSqlDbSyncDatabaseInput
                    {
                        Name = "JasmineTest",
                        TargetDatabaseName = "JasmineTest",
                        TableMap           = new Dictionary <string, string> {
                            { "dbo.TestTable1", "dbo.TestTable1" }, { "dbo.TestTable2", "dbo.TestTable2" }
                        }
                    }
                })
            };

            return(client.Tasks.CreateOrUpdate(
                       new ProjectTask(
                           properties: taskProps),
                       resourceGroup.Name,
                       service.Name,
                       dmsProjectName,
                       dmsTaskName));
        }
コード例 #7
0
        public DatabaseFixture(LimpingDbContext context, DataMigrationService dataMigrationService)
        {
            _dataMigrationService = dataMigrationService;
            Context = context;

            var database = context.Database;

            _manageDatabase = true;
            if (_manageDatabase)
            {
                database.EnsureDeleted();
            }

            database.EnsureCreated();
        }
コード例 #8
0
        private ProjectTask CreateDMSPGSyncTask(MockContext context,
                                                DataMigrationServiceClient client,
                                                ResourceGroup resourceGroup,
                                                DataMigrationService service,
                                                string dmsProjectName,
                                                string dmsTaskName)
        {
            var taskProps = new MigratePostgreSqlAzureDbForPostgreSqlSyncTaskProperties
            {
                Input = new MigratePostgreSqlAzureDbForPostgreSqlSyncTaskInput(
                    new List <MigratePostgreSqlAzureDbForPostgreSqlSyncDatabaseInput>
                {
                    new MigratePostgreSqlAzureDbForPostgreSqlSyncDatabaseInput
                    {
                        Name = "someSourceDatabaseName",
                        TargetDatabaseName = "someTargetDatabaseName",
                        SelectedTables     = new List <MigratePostgreSqlAzureDbForPostgreSqlSyncDatabaseTableInput>
                        {
                            new MigratePostgreSqlAzureDbForPostgreSqlSyncDatabaseTableInput("public.someTableName")
                        }
                    }
                },
                    new PostgreSqlConnectionInfo
                {
                    ServerName             = @"someTargetServerName",
                    EncryptConnection      = true,
                    TrustServerCertificate = true,
                    UserName = "******",
                    Password = "******"
                },
                    new PostgreSqlConnectionInfo
                {
                    ServerName             = @"someSourceServerName",
                    EncryptConnection      = true,
                    TrustServerCertificate = true,
                    UserName = "******",
                    Password = "******"
                })
            };

            return(client.Tasks.CreateOrUpdate(
                       new ProjectTask(
                           properties: taskProps),
                       resourceGroup.Name,
                       service.Name,
                       dmsProjectName,
                       dmsTaskName));
        }
コード例 #9
0
ファイル: UpdateDataApp.cs プロジェクト: aylosx/xrm-suite
        static void Main(string[] args)
        {
            UpdateDataApp app      = new UpdateDataApp();
            Logger        logger   = app.Logger;
            ExitCode      exitCode = ExitCode.None;

            try
            {
                logger.Info("Application started.");

                CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");

                Options options = new Options();

                Parser.Default.ParseArgumentsStrict(args, options, CommandLineOptions.ArgumentParsingFailed);

                Connection connection = null;

                if (string.IsNullOrWhiteSpace(options.ConnectionString))
                {
                    connection = new Connection(options.AuthorityUrl, options.OrganizationUrl, options.OrganizationUrlSuffix,
                                                options.TenantId, options.ServicePrincipalId, options.ServicePrincipalSecret, options.ConnectionRetries, options.ConnectionTimeout);
                }
                else
                {
                    connection = new Connection(options.ConnectionString, options.ConnectionRetries, options.ConnectionTimeout);
                }

                using (CrmServiceContext organizationServiceContext = new CrmServiceContext(connection.OrganizationService))
                    using (CrmService crmService = new CrmService(organizationServiceContext, connection))
                        using (IDataMigrationService dataMigrationService = new DataMigrationService(organizationServiceContext, crmService))
                        {
                            dataMigrationService.UpdateData(options.EntityName, options.PrimaryKey, options.AttributeName, options.AttributeValue);
                            exitCode = ExitCode.Success;
                        }
            }
            catch (Exception ex)
            {
                exitCode = new ExceptionHandlingService(ex).GetExitCode();
            }
            finally
            {
                logger.Info(CultureInfo.InvariantCulture, "Application exited with code: {0}", (int)exitCode);
                Environment.Exit((int)exitCode);
            }
        }
コード例 #10
0
ファイル: ExportDataApp.cs プロジェクト: aylosx/xrm-suite
        static void Main(string[] args)
        {
            ExportDataApp app      = new ExportDataApp();
            Logger        logger   = app.Logger;
            ExitCode      exitCode = ExitCode.None;

            try
            {
                logger.Info("Application started.");

                CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");

                Options options = new Options();

                Parser.Default.ParseArgumentsStrict(args, options, CommandLineOptions.ArgumentParsingFailed);

                Connection connection = null;

                if (string.IsNullOrWhiteSpace(options.ConnectionString))
                {
                    connection = new Connection(options.AuthorityUrl, options.OrganizationUrl, options.OrganizationUrlSuffix,
                                                options.TenantId, options.ServicePrincipalId, options.ServicePrincipalSecret, options.ConnectionRetries, options.ConnectionTimeout);
                }
                else
                {
                    connection = new Connection(options.ConnectionString, options.ConnectionRetries, options.ConnectionTimeout);
                }

                using (IDataMigrationService dataMigrationService = new DataMigrationService(connection.CrmServiceClient))
                {
                    bool result = dataMigrationService.ExportData(options.SchemaFileName, options.OutputFileName);
                    exitCode = result == true ? ExitCode.Success : ExitCode.ConfigurationDataExportFailed;
                }
            }
            catch (Exception ex)
            {
                exitCode = new ExceptionHandlingService(ex).GetExitCode();
            }
            finally
            {
                logger.Info(CultureInfo.InvariantCulture, "Application exited with code: {0}", (int)exitCode);
                Environment.Exit((int)exitCode);
            }
        }
コード例 #11
0
        private ProjectTask CreateDMSSqlSyncTask(MockContext context,
                                                 DataMigrationServiceClient client,
                                                 ResourceGroup resourceGroup,
                                                 DataMigrationService service,
                                                 string dmsProjectName,
                                                 string dmsTaskName)
        {
            var taskProps = new MigrateSqlServerSqlDbSyncTaskProperties
            {
                Input = new MigrateSqlServerSqlDbSyncTaskInput(
                    new SqlConnectionInfo
                {
                    DataSource = @"someSourceServerName",
                    UserName   = "******",
                    Password   = "******"
                },
                    new SqlConnectionInfo
                {
                    DataSource = @"someTargetServerName",
                    UserName   = "******",
                    Password   = "******"
                },
                    new List <MigrateSqlServerSqlDbSyncDatabaseInput>
                {
                    new MigrateSqlServerSqlDbSyncDatabaseInput
                    {
                        Name = "someSourceDatabaseName",
                        TargetDatabaseName = "someTargetDatabaseName",
                        TableMap           = new Dictionary <string, string> {
                            { "someTableSource", "someTableSource" }
                        }
                    }
                })
            };

            return(client.Tasks.CreateOrUpdate(
                       new ProjectTask(
                           properties: taskProps),
                       resourceGroup.Name,
                       service.Name,
                       dmsProjectName,
                       dmsTaskName));
        }
コード例 #12
0
        private ProjectFile CreateDMSFile(MockContext context,
                                          DataMigrationServiceClient client,
                                          ResourceGroup resourceGroup,
                                          DataMigrationService service,
                                          string dmsProjectName,
                                          string dmsFileName)
        {
            var fileProps = new ProjectFileProperties
            {
                FilePath = "NorthWind.sql"
            };

            return(client.Files.CreateOrUpdate(
                       new ProjectFile {
                Properties = fileProps
            },
                       resourceGroup.Name,
                       service.Name,
                       dmsProjectName,
                       dmsFileName));
        }
コード例 #13
0
        public void ExportDataAsCsv()
        {
            var dataFormat     = DataFormat.Csv;
            var exportSettings = new ExportSettings
            {
                // this is not really unit test but it is the quckest way to get this tested as CrmSchemaConfiguration.ReadFromFile actually looks for the file!
                SchemaPath       = "TestData/BusinessUnitSchema.xml",
                DataFormat       = dataFormat,
                ExportConfigPath = "TestData",
                BatchSize        = 5000,
                SavePath         = "TestData"
            };

            var storeReader = new Mock <IDataStoreReader <Entity, EntityWrapper> >().Object;
            var storeWriter = new Mock <IDataStoreWriter <Entity, EntityWrapper> >().Object;

            var genericCrmDataMigrator = new GenericCrmDataMigrator(loggerMock.Object, storeReader, storeWriter);

            var factoryMock = new Mock <ICrmGenericMigratorFactory>();

            factoryMock.Setup(x => x.GetCrmDataMigrator(
                                  dataFormat,
                                  It.IsAny <ILogger>(),
                                  It.IsAny <EntityRepository>(),
                                  It.IsAny <CrmExporterConfig>(),
                                  It.IsAny <CancellationToken>(),
                                  It.IsAny <CrmSchemaConfiguration>()))
            .Returns(genericCrmDataMigrator)
            .Verifiable();

            var localSystemUnderTest = new DataMigrationService(loggerMock.Object, factoryMock.Object);

            FluentActions.Invoking(() => localSystemUnderTest.ExportData(exportSettings))
            .Should()
            .Throw <NullReferenceException>();

            factoryMock.Verify(x => x.GetCrmDataMigrator(dataFormat, It.IsAny <ILogger>(), It.IsAny <EntityRepository>(), It.IsAny <CrmExporterConfig>(), It.IsAny <CancellationToken>(), It.IsAny <CrmSchemaConfiguration>()), Times.Once);
        }
コード例 #14
0
        static void InsertPlayerStatistic(List <Playerstatistic> playerStatistic, ref int totalMigrated, ref long totalTime)
        {
            try
            {
                var sw = new Stopwatch();
                sw.Start();

                var dataMigrationService = new DataMigrationService();
                dataMigrationService.Store(playerStatistic);

                totalTime += sw.ElapsedMilliseconds;
                Console.WriteLine($"Migrated rows of PlayerStatistic: {playerStatistic.Count} [{sw.ElapsedMilliseconds} ms]");
            }
            catch (Exception e)
            {
                WriteException(e);
                throw new OperationCanceledException("Migration aborted.");
            }

            playerStatistic.Clear();

            GC.Collect();
        }
コード例 #15
0
        /// <summary>
        /// Migrates user data for new versions of the App.
        /// </summary>
        private void MigrateData()
        {
            DataMigrationService dataMigrationService = Mvx.IocConstruct <DataMigrationService>();

            dataMigrationService.MigrateData();
        }
コード例 #16
0
 /// <summary>
 /// Create or update DMS Service Instance
 /// </summary>
 /// <remarks>
 /// The services resource is the top-level resource that represents the
 /// Database Migration Service. The PATCH method updates an existing service.
 /// This method can change the kind, SKU, and network of the service, but if
 /// tasks are currently running (i.e. the service is busy), this will fail with
 /// 400 Bad Request ("ServiceIsBusy").
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='parameters'>
 /// Information about the service
 /// </param>
 /// <param name='groupName'>
 /// Name of the resource group
 /// </param>
 /// <param name='serviceName'>
 /// Name of the service
 /// </param>
 public static DataMigrationService BeginUpdate(this IServicesOperations operations, DataMigrationService parameters, string groupName, string serviceName)
 {
     return(operations.BeginUpdateAsync(parameters, groupName, serviceName).GetAwaiter().GetResult());
 }
コード例 #17
0
 public DatabaseStartup(LimpingDbContext context, IOptions <LimpingConfiguration> configuration, DataMigrationService seedDataService)
 {
     _context         = context;
     _configuration   = configuration;
     _seedDataService = seedDataService;
 }
コード例 #18
0
 /// <summary>
 /// Create or update DMS Instance
 /// </summary>
 /// <remarks>
 /// The services resource is the top-level resource that represents the
 /// Database Migration Service. The PUT method creates a new service or updates
 /// an existing one. When a service is updated, existing child resources (i.e.
 /// tasks) are unaffected. Services currently support a single kind, "vm",
 /// which refers to a VM-based service, although other kinds may be added in
 /// the future. This method can change the kind, SKU, and network of the
 /// service, but if tasks are currently running (i.e. the service is busy),
 /// this will fail with 400 Bad Request ("ServiceIsBusy"). The provider will
 /// reply when successful with 200 OK or 201 Created. Long-running operations
 /// use the provisioningState property.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='parameters'>
 /// Information about the service
 /// </param>
 /// <param name='groupName'>
 /// Name of the resource group
 /// </param>
 /// <param name='serviceName'>
 /// Name of the service
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <DataMigrationService> CreateOrUpdateAsync(this IServicesOperations operations, DataMigrationService parameters, string groupName, string serviceName, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(parameters, groupName, serviceName, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }