public static void ImportData(string connectionString, string schemaPath, string exportFolderPath)
        {
            Console.WriteLine("Import Started");

            var tokenSource   = new CancellationTokenSource();
            var serviceClient = new CrmServiceClient(connectionString);
            var entityRepo    = new EntityRepository(serviceClient, new ServiceRetryExecutor());
            var logger        = new ConsoleLogger();

            if (!Settings.Default.UseCsvImport)
            {
                // Json Import
                var fileImporterJson = new CrmFileDataImporter(logger, entityRepo, GetImportConfig(), tokenSource.Token);
                fileImporterJson.MigrateData();
            }
            else
            {
                //Csv Import
                var schema          = CrmSchemaConfiguration.ReadFromFile(schemaPath);
                var fileImporterCsv = new CrmFileDataImporterCsv(logger, entityRepo, GetImportConfig(), schema, tokenSource.Token);
                fileImporterCsv.MigrateData();
            }

            Console.WriteLine("Import Finished");
        }
Example #2
0
        public void PerformImportAction(string importSchemaFilePath, int maxThreads, bool jsonFormat, Capgemini.DataMigration.Core.ILogger currentLogger, IEntityRepositoryService entityRepositoryService, CrmImportConfig currentImportConfig, CancellationTokenSource tokenSource)
        {
            try
            {
                if (maxThreads > 1)
                {
                    currentLogger.LogInfo($"Starting MultiThreaded Processing, using {maxThreads} threads");
                    var repos       = new List <IEntityRepository>();
                    int threadCount = maxThreads;

                    while (threadCount > 0)
                    {
                        threadCount--;
                        repos.Add(entityRepositoryService.InstantiateEntityRepository(true));
                    }

                    var fileExporter = new CrmFileDataImporter(currentLogger, repos, currentImportConfig, tokenSource.Token);
                    fileExporter.MigrateData();
                }
                else
                {
                    currentLogger.LogInfo("Starting Single Threaded processing, you must set up max threads to more than 1");
                    var entityRepo = entityRepositoryService.InstantiateEntityRepository(false);

                    if (jsonFormat)
                    {
                        var fileExporter = new CrmFileDataImporter(currentLogger, entityRepo, currentImportConfig, tokenSource.Token);
                        fileExporter.MigrateData();
                    }
                    else
                    {
                        var schema       = CrmSchemaConfiguration.ReadFromFile(importSchemaFilePath);
                        var fileExporter = new CrmFileDataImporterCsv(currentLogger, entityRepo, currentImportConfig, schema, tokenSource.Token);
                        fileExporter.MigrateData();
                    }
                }
            }
            catch (Exception ex)
            {
                currentLogger.LogError($"Critical import error, processing stopped: {ex.Message}");
                throw;
            }
        }
Example #3
0
        private static void ImportData(string connectionString, string schemaPath)
        {
            Console.WriteLine("Import Started");

            using (var tokenSource = new CancellationTokenSource())
            {
                using (var serviceClient = new CrmServiceClient(connectionString))
                {
                    var entityRepo  = new EntityRepository(serviceClient, new ServiceRetryExecutor());
                    int threadCount = Settings.Default.ThreadCount;
                    var logger      = new ConsoleLogger();

                    if (threadCount > 1)
                    {
                        List <IEntityRepository> entRepos = new List <IEntityRepository>()
                        {
                            entityRepo
                        };
                        while (threadCount > 1)
                        {
                            threadCount--;
                            var newServiceClient = serviceClient.Clone();
                            if (newServiceClient != null)
                            {
                                entRepos.Add(new EntityRepository(serviceClient.Clone(), new ServiceRetryExecutor()));
                            }
                            else
                            {
                                Console.WriteLine("CrmServiceClient Clone() operation is only supported for OAUTH connections, single thread will be used as clone returned null");
                            }
                        }

                        if (!Settings.Default.UseCsvImport)
                        {
                            // Json Import
                            var fileImporterJson = new CrmFileDataImporter(logger, entRepos, GetImportConfig(), tokenSource.Token);
                            fileImporterJson.MigrateData();
                        }
                        else
                        {
                            // Csv Import
                            var schema          = CrmSchemaConfiguration.ReadFromFile(schemaPath);
                            var fileImporterCsv = new CrmFileDataImporterCsv(logger, entRepos, GetImportConfig(), schema, tokenSource.Token);
                            fileImporterCsv.MigrateData();
                        }
                    }
                    else
                    {
                        if (!Settings.Default.UseCsvImport)
                        {
                            // Json Import
                            var fileImporterJson = new CrmFileDataImporter(logger, entityRepo, GetImportConfig(), tokenSource.Token);
                            fileImporterJson.MigrateData();
                        }
                        else
                        {
                            // Csv Import
                            var schema          = CrmSchemaConfiguration.ReadFromFile(schemaPath);
                            var fileImporterCsv = new CrmFileDataImporterCsv(logger, entityRepo, GetImportConfig(), schema, tokenSource.Token);
                            fileImporterCsv.MigrateData();
                        }
                    }
                }
            }

            Console.WriteLine("Import Finished");
        }