public static string GetBatchFileTemplate(EnumImportType enumImportType) { var batchFileName = string.Empty; switch (enumImportType) { case EnumImportType.Coverholder: case EnumImportType.Binder: batchFileName = "BatchFileTemplate.bat"; break; default: break; } return(batchFileName); }
public static string GetConfigTemplate(EnumImportType enumImportType) { var configName = string.Empty; switch (enumImportType) { case EnumImportType.Coverholder: configName = "Coverholder.config.template"; break; case EnumImportType.Binder: configName = "Binder.config.template"; break; default: break; } return(configName); }
public bool Import(CSVModel csvModel, EnumImportType enumImportType) { //create file var key = $"{csvModel.LegalName}_{csvModel.InternalRef}"; var currentFolderPath = Path.Combine(_env.ContentRootPath, _appSettings.Value.CSVFolderName, key); if (!Directory.Exists(currentFolderPath)) { Directory.CreateDirectory(currentFolderPath); } //create CSV file var csvFilePath = FileHelper.CreateCSV(currentFolderPath, csvModel, key); if (string.IsNullOrEmpty(csvFilePath)) { throw new Exception($"{enumImportType.ToString()} csv file not created for {key}"); } //create config template file var configTemplateFileName = ImportType.GetConfigTemplate(enumImportType); if (string.IsNullOrEmpty(configTemplateFileName)) { throw new Exception($"{enumImportType.ToString()} config template not configured."); } var configTemplatePath = ConfigTemplateHelper.Create(_env.ContentRootPath, currentFolderPath, _appSettings.Value.ConfigTemplateFolderName, configTemplateFileName, csvFilePath); if (string.IsNullOrEmpty(configTemplatePath)) { throw new Exception($"{enumImportType.ToString()} config template not created for {key}"); } //create batch file var batchFileTemplateName = ImportType.GetBatchFileTemplate(enumImportType); if (string.IsNullOrEmpty(batchFileTemplateName)) { throw new Exception($"{enumImportType.ToString()} batch file template not configured."); } var templateFilePath = Path.Combine(_env.ContentRootPath, _appSettings.Value.BatchFileTemplateFolderName, batchFileTemplateName); if (!File.Exists(templateFilePath)) { throw new Exception($"Batch file template {batchFileTemplateName} does not exists."); } var batchFilePath = BatchFileTemplateHelper.Create(currentFolderPath, templateFilePath, enumImportType.ToString(), _appSettings.Value.TaskRunnerPath, configTemplatePath); if (string.IsNullOrEmpty(configTemplatePath)) { throw new Exception($"{enumImportType.ToString()} batch file template not created for {key}"); } //Execute batch file return(true); }