private async Task InsertDiagnosticSqlIntoDetails(RuleBO rule, RuleExecutionLog ruleExecutionLog, string connectionString, List <UserParamBO> sqlParams, string tableName, int maxNumberResults) { string sqlToRun = Utils.GenerateSqlWithTop(rule.DiagnosticSql, maxNumberResults.ToString()); string columnsSchema = string.Empty; var listColumnsFromDestination = await _edFiRuleExecutionLogDetailQueries.GetColumnsByTableAsync(tableName, "destination"); using (var conn = new SqlConnection(connectionString)) { await conn.OpenAsync(); using (var cmd = new SqlCommand(sqlToRun, conn)) { AddParameters(sqlToRun, cmd, sqlParams); var reader = await cmd.ExecuteReaderAsync(); Dictionary <string, string> listColumns = new Dictionary <string, string>(); listColumnsFromDestination.ForEach(rec => listColumns.Add(rec.Name, rec.Type)); DataTable tableToInsert = Utils.GetTableForSqlBulk(ruleExecutionLog.Id, reader, listColumns, out columnsSchema); if (tableToInsert != null && tableToInsert.Rows.Count > 0) { if (ruleExecutionLog != null) { ruleExecutionLog.DetailsSchema = columnsSchema; await _ruleExecutionLogCommands.UpdateAsync(ruleExecutionLog); } await _edFiRuleExecutionLogDetailCommands.ExecuteSqlBulkCopy(tableToInsert, $"[destination].[{tableName}]"); } } } }
public static string GetExecutionLogXml(RuleExecutionLog executionLog) { var sw = new StringWriter(); var xw = new XmlTextWriter(sw); using (xw) { xw.WriteStartElement("ExecutionLog"); foreach (var message in executionLog.AllMessages) { xw.WriteElementString("ExecutionMessage", message.Description); } xw.WriteEndElement(); return(sw.ToString()); } }
public string Save(string year, string jurisdiction, string returnType, Guid?locatorId, EfileSchemaType schemaType, EvaluationRequest evaluationRequest, string status, string DiagnosticInfo = null, string Id = null) { //_context.StartEventLog("Save start"); _logger.Info("RuleExecutionLogService Save method start"); try { RuleExecutionLog LogInformation = null; if (string.IsNullOrEmpty(Id)) { LogInformation = new RuleExecutionLog(); LogInformation.Locator = new Locator(); LogInformation.Locator.Id = (Guid)locatorId; LogInformation.Id = Guid.NewGuid(); LogInformation.StartTime = DateTime.Now; LogInformation.Status = status; LogInformation.SchemaType = schemaType; LogInformation.EvaluationRequest = evaluationRequest; LogInformation.Endtime = DateTime.Now; // LogInformation.Jurisdiction = jurisdiction; _repository.Insert <RuleExecutionLog>(LogInformation); } else { LogInformation = _repository.Get <RuleExecutionLog>(new Guid(Id)); if (LogInformation != null) { LogInformation.Endtime = DateTime.Now; LogInformation.DiagnosticInfo = DiagnosticInfo; LogInformation.Status = status; LogInformation.EvaluationRequest = evaluationRequest; _repository.Merge <RuleExecutionLog>(LogInformation); } } Id = (LogInformation != null) ? LogInformation.Id.ToString() : null; } catch (Exception ex) { _logger.Error("Error in RuleExecutionLogService Save Method ", ex); } _logger.Info("RuleExecutionLogService Save method End"); //_context.EndEventLog(); return(Id); }
public async Task <RuleTestResult> ExecuteRuleByEnvironmentIdAsync(Guid ruleId, DatabaseEnvironmentBO databaseEnvironment) { int?ruleDetailsDestinationId = null; var rule = await _ruleService.GetAsync(ruleId); var executionLogs = await _ruleExecutionLogQueries.GetByRuleIdAsync(ruleId); var connectionString = databaseEnvironment.GetConnectionString(); var stopWatch = System.Diagnostics.Stopwatch.StartNew(); RuleTestResult testResult = await ExecuteRuleAsync(rule, connectionString, databaseEnvironment.UserParams, databaseEnvironment.TimeoutInMinutes); var containerParent = await _collectionQueries.GetAsync(rule.ContainerId); if (containerParent.ParentContainerId != null) { var collectionParent = await _collectionQueries.GetAsync(containerParent.ParentContainerId.Value); ruleDetailsDestinationId = collectionParent.RuleDetailsDestinationId; } RuleExecutionLog ruleExecutionLog = new RuleExecutionLog() { Id = 0, Evaluation = testResult.Evaluation, RuleId = ruleId, StatusId = (int)testResult.Status, Result = testResult.Result, Response = testResult.Evaluation ? "Ok" : testResult.ErrorMessage, DatabaseEnvironmentId = databaseEnvironment.Id, ExecutedSql = testResult.ExecutedSql, DiagnosticSql = rule.DiagnosticSql, RuleDetailsDestinationId = ruleDetailsDestinationId }; if (ruleExecutionLog.RuleDetailsDestinationId == null || ruleExecutionLog.RuleDetailsDestinationId.Value == 0) { ruleExecutionLog.RuleDetailsDestinationId = null; } testResult.LastExecuted = executionLogs.Any() ? executionLogs.FirstOrDefault().ExecutionDate : (DateTime?)null; ruleExecutionLog.ExecutionTimeMs = stopWatch.ElapsedMilliseconds; ruleExecutionLog.Result = testResult.Result; var newRuleExecutionLog = await _ruleExecutionLogCommands.AddAsync(ruleExecutionLog); testResult.TestResults = await _ruleService.GetTopResults(ruleId, databaseEnvironment.Id); if (!testResult.Evaluation) { testResult.DiagnosticSql = rule.DiagnosticSql; } try { //Validate if the rule is going to any queue table if (ruleDetailsDestinationId != null && ruleDetailsDestinationId.Value > 0) { var existCatalog = await _catalogQueries.GetAsync(ruleDetailsDestinationId.Value); if (existCatalog != null) { int maxNumberResults = databaseEnvironment.MaxNumberResults.Value; if (rule.MaxNumberResults != null) { maxNumberResults = rule.MaxNumberResults.Value; } await InsertDiagnosticSqlIntoDetails(rule, newRuleExecutionLog, connectionString, databaseEnvironment.UserParams, existCatalog.Name, maxNumberResults); } } } catch (Exception ex) { newRuleExecutionLog.Result = -1; newRuleExecutionLog.Response = ex.Message; await _ruleExecutionLogCommands.UpdateAsync(newRuleExecutionLog); } return(testResult); }
public InRuleResponse PaymentAllocationRules(InRuleRequest request) { ServiceData myServiceData = new ServiceData(); var response = new InRuleResponse(); var ruleAppNotifications = string.Empty; try { if (Settings.Default.IsHardCoded) { XmlSerializer reader = new XmlSerializer(typeof(InRuleResponse)); using ( StreamReader file = new StreamReader(Settings.Default.RuleAppDirectory + "InRuleResponse.xml")) { response = (InRuleResponse)reader.Deserialize(file); file.Close(); } } else { var ruleApp = new FileSystemRuleApplicationReference(Settings.Default.RuleAppDirectory + Settings.Default.RuleAppObject); using (var session = new RuleSession(ruleApp)) { var objectEntityState = Util.DeserializeFromXml <PaymentAllocationRoot>("<" + Settings.Default.TopEntityName + ">" + request.RuleDataXML + "</" + Settings.Default.TopEntityName + ">"); objectEntityState.RuleEvaluationDate = request.RuleInfo.RuleEvaluationDate; var rootEntity = session.CreateEntity(Settings.Default.TopEntityName, objectEntityState); if (Settings.Default.UseLog) { session.Settings.LogOptions = EngineLogOptions.Execution | EngineLogOptions.RuleTrace; } else { session.Settings.LogOptions = EngineLogOptions.None; } RuleExecutionLog executionLog = rootEntity.ExecuteRuleSet(request.RuleInfo.RuleName, Settings.Default.PerformPreValidation, Settings.Default.PerformPostValidation); if (Settings.Default.UseLog) { string logMessages = string.Empty; foreach (TextFeedbackLogMessage logMessage in executionLog.TextFeedbackMessages) { logMessages += logMessage.Description + "\r\n"; } if (executionLog.HasNotifications) { foreach (var notification in session.GetNotifications()) { ruleAppNotifications += notification.Message + "\r\n"; } } } response.RuleInfo = request.RuleInfo; response.RuleInfo.ErrorDetails = objectEntityState.ErrorDetails; response.RuleInfo.Status = objectEntityState.ErrorDetails.Count > 0 ? "Failure" : "Success"; response.RuleResult = Util.GetRuleResultXml(objectEntityState.Payments); } } Util.SerializeToXmlFile(response, Settings.Default.RuleAppDirectory + @"\InRuleResponse.xml"); } catch (System.Exception ex) { myServiceData.Result = false; myServiceData.ErrorMessage = "PaymentAllocationRules call failed"; myServiceData.ErrorDetails = ex.ToString(); throw new FaultException <ServiceData>(myServiceData, ex.ToString()); } return(response); }