/// <summary> /// Carga los datos de un método /// </summary> private CallApiMethodSentence LoadMethod(MLNode rootML) { CallApiMethodSentence sentence = new CallApiMethodSentence(); // Asigna las propiedades AssignDefaultProperties(sentence, rootML); sentence.EndPoint = rootML.Attributes[TagEndPoint].Value.TrimIgnoreNull(); sentence.Method = rootML.Attributes[TagType].Value.GetEnum(CallApiMethodSentence.MethodType.Unkwnown); sentence.Body = rootML.Nodes[TagBody].Value.TrimIgnoreNull(); // Obtiene los resultados foreach (MLNode nodeML in rootML.Nodes) { if (nodeML.Name == TagResult) { sentence.Results.Add(LoadResult(nodeML)); } } // Devuelve la sentencia return(sentence); }
/// <summary> /// Obtiene las sentencias que se deben ejecutar al encontrar un resultado /// </summary> private List <BaseSentence> GetContinuation(CallApiMethodSentence method, int result) { // Obtiene el grupo de sentencias que tiene que tratar el resultado foreach (CallApiResultSentence apiResult in method.Results) { if (apiResult.ResultFrom >= result && apiResult.ResultTo <= result) { return(apiResult.Sentences); } } // Si no ha encontrado nada, busca un resultado que tenga tanto FROM como TO a 0 foreach (CallApiResultSentence apiResult in method.Results) { if (apiResult.ResultFrom == 0 && apiResult.ResultTo == 0) { return(apiResult.Sentences); } } // Si ha llegado hasta aquí, es porque no ha encontrado nada a ejecutar return(new List <BaseSentence>()); }
/// <summary> /// Ejecuta el método /// </summary> private async Task <List <BaseSentence> > ExecuteMethodAsync(BlockLogModel block, CallApiMethodSentence method, HttpClientManager client, CancellationToken cancellationToken) { List <BaseSentence> sentences = new List <BaseSentence>(); int result = -1; // Ejecuta el método switch (method.Method) { case CallApiMethodSentence.MethodType.Post: result = await client.PostAsync(method.EndPoint, TransformVariables(method.Body), cancellationToken); break; } // Trata el resultado if (result == -1) { Errors.Add($"Error when call {method.EndPoint}: {method.Method.ToString()}"); } else { sentences = GetContinuation(method, result); } // Devuelve la lista de sentencias return(sentences); }