protected override void ProcessRecord()
        {
            base.ProcessRecord();
            var logger = new CmdletLoggerPS(this, TreatWarningsAsErrors);

            try
            {
                logger.Info("About to start exporting data from Dynamics365");
                var manager = new Dynamics365DataManager();

                var cancellationTokenSource = new CancellationTokenSource();

                var exportConfig = new CrmExporterConfig();
                if (!string.IsNullOrWhiteSpace(ConfigFilePath))
                {
                    if (!File.Exists(ConfigFilePath))
                    {
                        WriteWarning($"Export config file path does not exist, will be ignored {ConfigFilePath}");
                    }
                    else
                    {
                        exportConfig = CrmExporterConfig.GetConfiguration(ConfigFilePath);
                    }
                }

                PopulateConfiguration(exportConfig);

                if (!Directory.Exists(JsonFolderPath))
                {
                    WriteWarning($"JsonFolderPath {JsonFolderPath} does not exist, cannot continue!");
                    throw new DirectoryNotFoundException($"JsonFolderPath {JsonFolderPath} does not exist, cannot continue!");
                }
                else
                {
                    foreach (var file in Directory.GetFiles(JsonFolderPath, $"{exportConfig.FilePrefix}_*.csv"))
                    {
                        WriteVerbose($"Delete Csv file {file}");
                        File.Delete(file);
                    }

                    foreach (var file in Directory.GetFiles(JsonFolderPath, $"{exportConfig.FilePrefix}_*.json"))
                    {
                        WriteVerbose($"Delete Json file {file}");
                        File.Delete(file);
                    }
                }

                manager.StartSingleThreadedExport(exportConfig, logger, cancellationTokenSource, ConnectionString);
                logger.Info("Export has finished");
            }
            catch (Exception exception)
            {
                var errorMessage = $"Dynamics365 data export failed: {exception.Message}";
                logger.Verbose(errorMessage);
                logger.Error(errorMessage);
                throw;
            }
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            var logger = new CmdletLogger(TreatWarningsAsErrors);

            try
            {
                logger.LogInfo("About to start importing data from Dynamics365");
                var manager = new Dynamics365DataManager();

                var cancellationTokenSource = new CancellationTokenSource();

                var importConfig = new CrmImportConfig();
                if (!string.IsNullOrWhiteSpace(ConfigFilePath))
                {
                    if (!File.Exists(ConfigFilePath))
                    {
                        WriteWarning($"Import config file path does not exist, will be ignored {ConfigFilePath}");
                    }
                    else
                    {
                        importConfig = CrmImportConfig.GetConfiguration(ConfigFilePath);
                    }
                }

                PopulateConfigFile(importConfig);

                if (!Directory.Exists(JsonFolderPath))
                {
                    WriteWarning($"JsonFolderPath {JsonFolderPath} does not exist, cannot continue!");
                    throw new DirectoryNotFoundException($"JsonFolderPath {JsonFolderPath} does not exist, cannot continue!");
                }

                CrmSchemaConfiguration schemaConfig = null;

                if (CsvImport)
                {
                    if (string.IsNullOrWhiteSpace(SchemaFilePath))
                    {
                        throw new ConfigurationException("Schema file is required for CSV Import!");
                    }

                    schemaConfig = CrmSchemaConfiguration.ReadFromFile(SchemaFilePath);
                    logger.LogInfo("Using Csv import");
                }
                else
                {
                    logger.LogInfo("Using JSon import");
                }

                if (MaxThreads > 1)
                {
                    var result = manager.StartImport(importConfig, logger, cancellationTokenSource, ConnectionString, MaxThreads, CsvImport, schemaConfig)
                                 .ContinueWith(a =>
                    {
                        logger.LogInfo("Dynamics365 data import completed successfully.");
                    },
                                               cancellationTokenSource.Token);

                    result.Wait(cancellationTokenSource.Token);
                }
                else
                {
                    manager.StartSingleThreadedImport(importConfig, new CmdletLoggerPS(this, TreatWarningsAsErrors), cancellationTokenSource, ConnectionString, CsvImport, schemaConfig);
                }
            }
            catch (Exception exception)
            {
                var errorMessage = $"Dynamics365 data import failed: {exception.Message}";
                logger.LogVerbose(errorMessage);
                logger.LogError(errorMessage);
                throw;
            }
        }