/// <summary> /// Ejecuta un proyecto /// </summary> public async Task <bool> ProcessAsync(JobProjectModel project, CancellationToken cancellationToken) { // Ejecuta el proyecto using (BlockLogModel block = Logger.Default.CreateBlock(LogModel.LogType.Debug, $"Start execute project '{project.Name}'")) { // Indica que por ahora no ha habido errores Errors.Clear(); // Ejecuta los trabajos if (!Validate(project, out string error)) { // Muestra el error block.Error(error); // Añade el error a la colección de errores Errors.Add(error); } else { // Asigna la fecha de inicio de proceso del proyecto project.StartExecution = DateTime.Now; // Ejecuta los pasos foreach (JobStepModel job in project.Jobs) { if (cancellationToken.IsCancellationRequested) { block.Debug($"The job '{job.Name}' is not processed because user canceled the execution"); } else if (!job.Enabled) { block.Debug($"The job '{job.Name}' is not processed because is disabled"); } else if (HasError) { block.Debug($"The job '{job.Name}' is not processed because there is a previous error"); } else { await ExecuteJobAsync(project, job, cancellationToken); } } } } // Devuelve el valor que indica si se ha procesado correctamente return(!HasError); }
/// <summary> /// Copia los archivos de un directorio /// </summary> private void CopyPath(BlockLogModel block, string sourcePath, string targetPath, NormalizedDictionary <object> parameters) { // Log block.Debug($"Copiando '{sourcePath}' a '{targetPath}'"); // Copia los archivos CopyFiles(sourcePath, targetPath, parameters); // Copia recursivamente los directorios foreach (string path in System.IO.Directory.EnumerateDirectories(sourcePath)) { CopyPath(block, path, System.IO.Path.Combine(targetPath, System.IO.Path.GetFileName(path)), parameters); } }
/// <summary> /// Borra los archivos CSV de un directorio /// </summary> private void DeletePathFiles(BlockLogModel block, string path) { if (System.IO.Directory.Exists(path)) { foreach (string fileName in System.IO.Directory.GetFiles(path, "*.csv")) { try { System.IO.File.Delete(fileName); } catch (Exception exception) { block.Debug($"Can't delete the file {fileName}. {exception.Message}"); } } } }
/// <summary> /// Exporta los archivos /// </summary> internal void Export(Models.Deployments.DeploymentModel deployment) { using (BlockLogModel block = Manager.Logger.Default.CreateBlock(LogModel.LogType.Debug, "Comienzo de la copia de directorios")) { (NormalizedDictionary <object> parameters, string error) = GetParameters(deployment.JsonParameters); if (!string.IsNullOrWhiteSpace(error)) { block.Error(error); } else { // Elimina el directorio destino HelperFiles.KillPath(deployment.TargetPath); // Copia los directorios CopyPath(block, deployment.SourcePath, deployment.TargetPath, parameters); // Borra los directorios vacíos HelperFiles.KillEmptyPaths(deployment.TargetPath); // Log block.Debug("Fin de la copia de directorios"); } } }
/// <summary> /// Ejecuta una serie de comandos /// </summary> private async Task <int> ExecuteCommandsAsync(BlockLogModel block, IDbProvider provider, List <SqlSectionModel> commands, ParametersDbCollection parametersDb, TimeSpan timeout, CancellationToken cancellationToken) { int scriptsExecuted = 0; // Ejecuta las consultas foreach (SqlSectionModel command in commands) { if (!cancellationToken.IsCancellationRequested && command.Type == SqlSectionModel.SectionType.Sql) { // Log block.Debug($"Execute: {command.Content}"); // Ejecuta la cadena SQL await provider.ExecuteAsync(provider.SqlHelper.ConvertSqlNoParameters(command.Content, parametersDb), null, CommandType.Text, timeout, cancellationToken); // Indica que se ha ejecutado una sentencia scriptsExecuted++; } } // Devuelve el número de comandos ejecutados return(scriptsExecuted); }
/// <summary> /// Obtiene los comandos para importación de los archivos asociados a las tablas /// </summary> private List <SentenceImportCsv> GetImportFileSentences(BlockLogModel block, ProviderModel provider, SentenceImportCsvSchema sentence) { List <SentenceImportCsv> sentences = new List <SentenceImportCsv>(); // Obtiene las sentencias foreach (TableDbModel table in provider.LoadSchema().Tables) { if (sentence.ExcludeRules.CheckMustExclude(table.Name)) { block.Debug($"Skip table {table.Name} because is excluded"); } else { string fileName = System.IO.Path.Combine(Processor.Manager.Step.Project.GetFullFileName(sentence.Path), $"{table.Name}.csv"); if (System.IO.File.Exists(fileName)) { sentences.Add(CreateSentence(sentence, table)); } } } // Devuelve la colección de instrucciones return(sentences); }