/// <summary> /// Carga los datos de un paso /// </summary> private JobStepModel LoadStep(MLNode rootML, JobProjectModel project, JobStepModel parent) { JobStepModel step = new JobStepModel(project, parent); // Asigna las propiedades básicas step.Name = rootML.Nodes[TagName].Value.TrimIgnoreNull(); step.Description = rootML.Nodes[TagDescription].Value.TrimIgnoreNull(); step.ScriptFileName = rootML.Attributes[TagScript].Value.TrimIgnoreNull(); step.Target = rootML.Attributes[TagTarget].Value.TrimIgnoreNull(); step.ProcessorKey = rootML.Attributes[TagProcessor].Value.TrimIgnoreNull(); step.StartWithPreviousError = rootML.Attributes[TagStartWithPreviousError].Value.GetBool(false); step.Enabled = rootML.Attributes[TagEnabled].Value.GetBool(true); step.Parallel = rootML.Attributes[TagParallel].Value.GetBool(false); // Carga los pasos step.Steps.AddRange(LoadSteps(rootML, project, step)); // Carga el contexto foreach (MLNode nodeML in rootML.Nodes) { if (nodeML.Name == JobContextRepository.TagContext) { step.Context = new JobContextRepository().LoadContext(rootML, nodeML.Attributes[TagProcessor].Value.TrimIgnoreNull()); } } // Carga los parámetros step.Context.Parameters.AddRange(new JobParameterRepository().LoadParameters(rootML)); // Devuelve los datos del paso return(step); }
/// <summary> /// Comprueba los datos /// </summary> protected override string Validate(JobProjectModel project) { string error = string.Empty; // Comprueba el contenido if (string.IsNullOrWhiteSpace(Path)) { error = "Path can't be empty"; } // Comprueba el bloque if if (IfSentences.Count > 0) { foreach (BaseSentence sentence in IfSentences) { if (!sentence.ValidateData(project, out string errorSentence)) { error += Environment.NewLine + errorSentence; } } } // Comprueba el bloque else if (ElseSentences.Count > 0) { foreach (BaseSentence sentence in ElseSentences) { if (!sentence.ValidateData(project, out string errorSentence)) { error += Environment.NewLine + errorSentence; } } } // Devuelve el error return(error); }
/// <summary> /// Comprueba los datos de la sentencia /// </summary> protected override string Validate(JobProjectModel project) { if (Sentences.Count == 0) { return($"There's no {nameof(Sentences)} defined"); } else { return(string.Empty); } }
/// <summary> /// Comprueba los datos de la sentencia /// </summary> protected override string Validate(JobProjectModel project) { if (string.IsNullOrWhiteSpace(Process)) { return($"Process is undefined"); } else { return(string.Empty); } }
/// <summary> /// Comprueba los datos /// </summary> protected override string Validate(JobProjectModel project) { if (string.IsNullOrWhiteSpace(Message)) { return($"{nameof(Message)} undefined"); } else { return(string.Empty); } }
/// <summary> /// Comprueba los datos /// </summary> protected override string Validate(JobProjectModel project) { if (string.IsNullOrWhiteSpace(FileNameSource)) { return($"{nameof(FileNameSource)} is undefined"); } else if (string.IsNullOrWhiteSpace(FileNameTarget)) { return($"{nameof(FileNameTarget)} is undefined"); } else { return(string.Empty); } }
/// <summary> /// Graba un archivo con los datos de un proyecto /// </summary> internal void Save(JobProjectModel project, string fileName) { MLFile fileML = new MLFile(); MLNode rootML = fileML.Nodes.Add(TagRoot); // Añade los nodos básicos rootML.Nodes.Add(TagName, project.Name); rootML.Nodes.Add(TagDescription, project.Description); // Añade los nodos de contexto rootML.Nodes.AddRange(new JobContextRepository().GetContextNodes(project.Contexts)); // Añade los nodos de trabajo rootML.Nodes.AddRange(GetStepNodes(project.Jobs)); // Graba el archivo new LibMarkupLanguage.Services.XML.XMLWriter().Save(fileName, fileML); }
/// <summary> /// Comprueba los datos de la sentencia /// </summary> protected override string Validate(JobProjectModel project) { if (string.IsNullOrWhiteSpace(FileName) && string.IsNullOrWhiteSpace(Content)) { return($"{nameof(FileName)} and {nameof(Content)} are empty"); } else if (!string.IsNullOrWhiteSpace(FileName) && !System.IO.File.Exists(project.GetFullFileName(FileName))) { return($"Cant find the file {FileName}"); } else { return(string.Empty); } }
/// <summary> /// Comprueba los datos de la sentencia /// </summary> protected override string Validate(JobProjectModel project) { if (Method == MethodType.Unkwnown) { return($"{nameof(Method)} is undefined"); } else if (string.IsNullOrWhiteSpace(EndPoint)) { return($"{nameof(EndPoint)} is undefined"); } else { return(string.Empty); } }
/// <summary> /// Carga una serie de pasos /// </summary> private List <JobStepModel> LoadSteps(MLNode rootML, JobProjectModel project, JobStepModel parent) { List <JobStepModel> steps = new List <JobStepModel>(); // Carga los pasos foreach (MLNode nodeML in rootML.Nodes) { if (nodeML.Name == TagStep) { steps.Add(LoadStep(nodeML, project, parent)); } } // Devuelve la colección de pasos return(steps); }
/// <summary> /// Obtiene los contextos que se asocian al trabajo /// </summary> private List <JobContextModel> GetContexts(JobProjectModel project, JobStepModel job) { List <JobContextModel> contexts = new List <JobContextModel>(); // Obtiene los contextos asociados foreach (JobContextModel context in project.Contexts) { if (context.ProcessorKey.Equals(JobProjectModel.GlobalContext, StringComparison.CurrentCultureIgnoreCase) || context.ProcessorKey.Equals(job.ProcessorKey, StringComparison.CurrentCultureIgnoreCase)) { contexts.Add(context); } } // Devuelve la colección de contextos return(contexts); }
/// <summary> /// Obtiene las conexiones de un contexto /// </summary> private NormalizedDictionary <DataBaseConnectionModel> GetConnections(JobProjectModel project, JobContextModel context) { NormalizedDictionary <DataBaseConnectionModel> connections = new NormalizedDictionary <DataBaseConnectionModel>(); // Obtiene las conexiones del árbol foreach (LibDataStructures.Trees.TreeNodeModel node in context.Tree.Nodes) { if (node.Id.EqualsIgnoreCase("Connection")) { DataBaseConnectionModel connection = GetConnection(project, node); connections.Add(connection.GlobalId, connection); } } // Devuelve la lista de conexiones return(connections); }
/// <summary> /// Ejecuta un <see cref="JobModel"/> /// </summary> private async Task ExecuteJobAsync(JobProjectModel project, JobStepModel job, CancellationToken cancellationToken) { using (BlockLogModel block = Logger.Default.CreateBlock(LogModel.LogType.Debug, $"Start execute '{job.Name}'")) { IJobProcesor processor = GetProcessor(job); // Comprueba los datos antes de continuar if (processor == null) { block.Error($"Can't execute '{job.Name}' because can't find a procssor for '{job.ProcessorKey}'"); } else { try { List <JobContextModel> contexts = GetContexts(project, job); // Cambia el nombre de archivo job.ScriptFileName = project.GetFullFileName(job.ScriptFileName, contexts); // Procesa el archivo if (string.IsNullOrWhiteSpace(job.ScriptFileName) || !System.IO.File.Exists(job.ScriptFileName)) { block.Error($"Cant find the file '{job.ScriptFileName}'"); Errors.Add($"Cant find the file '{job.ScriptFileName}'"); } else { bool processed = await processor.ProcessAsync(contexts, job, cancellationToken); // Añade los errores de procesamiento if (!processed) { block.Error($"Error when execute '{job.Name}'{Environment.NewLine}{GetError(processor.Errors)}"); Errors.Add($"Error when execute '{job.Name}'"); Errors.AddRange(processor.Errors); } } } catch (Exception exception) { block.Error($"Error when execute '{job.Name}'", exception); } } } }
/// <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> /// Comprueba los datos /// </summary> protected override string Validate(JobProjectModel project) { if (string.IsNullOrEmpty(Path)) { return($"{nameof(Path)} is undefined"); } else if (Source == FileType.Unknown) { return($"{nameof(Source)} is undefined"); } else if (Target == FileType.Unknown) { return($"{nameof(Target)} is undefined"); } else { return(string.Empty); } }
/// <summary> /// Valida los datos del proyecto /// </summary> private bool Validate(JobProjectModel project, out string error) { List <Core.Models.Errors.ErrorModel> errors = project.Validate(); // Inicializa los argumentos de salida error = string.Empty; // Valida el proyecto if (errors.Count > 0) { // Inicializa el error error = "Error when validate the project"; // Añade los errores foreach (Core.Models.Errors.ErrorModel innerError in errors) { error += Environment.NewLine + $"\t{innerError.ToString()}"; } } // Devuelve el valor que indica si la validación es correcta return(string.IsNullOrWhiteSpace(error)); }
/// <summary> /// Carga los datos de un <see cref="JobProjectModel"/> /// </summary> internal JobProjectModel Load(string fileName) { JobProjectModel project = new JobProjectModel(System.IO.Path.GetDirectoryName(fileName)); // Carga los datos del archivo if (System.IO.File.Exists(fileName)) { MLFile fileML = new LibMarkupLanguage.Services.XML.XMLParser().Load(fileName); // Obtiene los nodos if (fileML != null) { foreach (MLNode rootML in fileML.Nodes) { if (rootML.Name == TagRoot) { // Asigna el nombre del proyecto project.Name = rootML.Nodes[TagName].Value.TrimIgnoreNull(); project.Description = rootML.Nodes[TagDescription].Value.TrimIgnoreNull(); // Carga los contextos project.Contexts.AddRange(new JobContextRepository().LoadContexts(rootML)); // Carga los trabajos foreach (MLNode nodeML in rootML.Nodes) { switch (nodeML.Name) { case TagStep: project.Jobs.Add(LoadStep(nodeML, project, null)); break; } } } } } } // Asigna el directorio de trabajo del contexto project.ContextWorkPath = project.ProjectWorkPath; // Devuelve los datos del proyecto return(project); }
/// <summary> /// Obtiene la conexión asociada a un nodo /// </summary> private DataBaseConnectionModel GetConnection(JobProjectModel project, LibDataStructures.Trees.TreeNodeModel node) { DataBaseConnectionModel connection = new DataBaseConnectionModel(); // Asigna las propiedades básicas a la conexión connection.Type = node.Attributes["Type"].GetValueString(); connection.GlobalId = node.Attributes["Key"].GetValueString(); // Asigna el resto de propiedades foreach (LibDataStructures.Trees.TreeNodeModel child in node.Nodes) { if (!string.IsNullOrWhiteSpace(child.Id)) { string value = child.Value?.ToString(); if (child.Id.Equals("Name", StringComparison.CurrentCultureIgnoreCase)) { connection.Name = value; } else if (child.Id.Equals("Description", StringComparison.CurrentCultureIgnoreCase)) { connection.Description = value; } else // Parámetros correspondientes a la conexión { // Si el parámetro identifica un nombre de archivo, le añade el directorio if (child.Id.EqualsIgnoreCase("FileName") && !System.IO.File.Exists(value)) { value = project.GetFullFileName(value); } // Añade un parámetro a la conexión connection.Parameters.Add(child.Id, value); } } } // Devuelve la conexión return(connection); }
public ErrorModel(JobProjectModel project, Jobs.JobStepModel step, string message) { Project = project; Step = step; Message = message; }
/// <summary> /// Añade un error a la colección /// </summary> public void Add(JobProjectModel project, Jobs.JobStepModel step, string message) { Add(new ErrorModel(project, step, message)); }
public JobStepModel(JobProjectModel project, JobStepModel parent = null) { Project = project; Parent = parent; }
/// <summary> /// Graba un archivo de proyecto /// </summary> public void Save(JobProjectModel project, string fileName) { new Repository.JobProjectRepository().Save(project, fileName); }