/// <summary> /// Posts message to MS Teams channel /// </summary> /// <param name="auditEvent"></param> /// <param name="auditEventType"></param> /// <param name="postMessageSettings"></param> public void PostMessage(AuditEvent auditEvent, AuditEventType auditEventType, MSTeamsPostMessageSettings postMessageSettings) { AuditEventValueTypeRepository auditEventValueTypeRepository = new AuditEventValueTypeRepository(); //Get Message value AuditEventValue auditEventValueMessage = auditEvent.GetValueByValueTypeId(AuditEventValueTypes.Message); AuditEventValue auditEventValueRunId = auditEvent.GetValueByValueTypeId(AuditEventValueTypes.GamePlanRunID); AuditEventValue auditEventValueScenarioId = auditEvent.GetValueByValueTypeId(AuditEventValueTypes.GamePlanScenarioID); AuditEventValue auditEventValueAutoBookId = auditEvent.GetValueByValueTypeId(AuditEventValueTypes.GamePlanAutoBookID); AuditEventValue auditEventValuePipelineErrorMessage = auditEvent.GetValueByValueTypeId(AuditEventValueTypes.GamePlanPipelineEventErrorMessage); // Determine if sub event is set string subEvent = ""; foreach (int valueTypeId in new int[] { AuditEventValueTypes.GamePlanPipelineEventID, AuditEventValueTypes.GamePlanAutoBookEventID }) { subEvent = GetValueDescription(auditEvent, valueTypeId, auditEventValueTypeRepository, _valueConverters); if (!String.IsNullOrEmpty(subEvent)) { break; } } StringBuilder title = new StringBuilder(auditEventType.Description); if (!String.IsNullOrEmpty(subEvent)) { title.Append(string.Format(" - {0}", subEvent)); } // Set Run/Scenario details Run run = null; StringBuilder message = new StringBuilder(title.ToString()); if (auditEventValueRunId != null || auditEventValueScenarioId != null) { using (var scope = _repositoryFactory.BeginRepositoryScope()) { var runRepository = scope.CreateRepository <IRunRepository>(); run = (auditEventValueRunId != null ? runRepository.Find((Guid)auditEventValueRunId.Value) : runRepository.FindByScenarioId((Guid)auditEventValueScenarioId.Value)); message.Append(message.Length == 0 ? "" : "; "); message.Append(string.Format("Description: {0}; Run ID: {1}", run.Description, MSTeamsMessageFormatter.FormatHyperlink(run.Id.ToString(), WebLinkFactory.GetRunDetailsURL(_frontendUrl, run.Id)))); if (auditEventValueScenarioId != null) { message.Append(message.Length == 0 ? "" : "; "); message.Append(string.Format("Scenario ID: {0}", MSTeamsMessageFormatter.FormatHyperlink(auditEventValueScenarioId.Value.ToString(), WebLinkFactory.GetOptimiserReportURL(_frontendUrl, run.Id, (Guid)auditEventValueScenarioId.Value)))); } } } // Set AutoBook details if (auditEventValueAutoBookId != null) { message.Append(message.Length == 0 ? "" : "; "); message.Append(string.Format("AutoBook ID: {0}", MSTeamsMessageFormatter.FormatHyperlink(auditEventValueAutoBookId.Value.ToString(), WebLinkFactory.GetAutoBookURL(_frontendUrl, (Guid)auditEventValueAutoBookId.Value)))); } // Set pipeline error if (auditEventValuePipelineErrorMessage != null) { message.Append(message.Length == 0 ? "" : "; "); message.Append(string.Format("Error: {0}", auditEventValuePipelineErrorMessage.Value.ToString())); } // Set message if (auditEventValueMessage != null) { message.Append(message.Length == 0 ? "" : "; "); message.Append(string.Format("Message: {0}", auditEventValueMessage.Value.ToString())); } // Post message _msTeamsREST.PostSimpleMessage(postMessageSettings.Url, "", message.ToString()); }
/// <summary> /// Posts message to MS Teams channel /// </summary> /// <param name="auditEvent"></param> /// <param name="auditEventType"></param> /// <param name="postMessageSettings"></param> public void PostMessage(AuditEvent auditEvent, AuditEventType auditEventType, MSTeamsPostMessageSettings postMessageSettings) { AuditEventValueTypeRepository auditEventValueTypeRepository = new AuditEventValueTypeRepository(); //Get Message value AuditEventValue auditEventValueMessage = auditEvent.GetValueByValueTypeId(AuditEventValueTypes.Message); AuditEventValue auditEventValueRunId = auditEvent.GetValueByValueTypeId(AuditEventValueTypes.GamePlanRunID); AuditEventValue auditEventValueScenarioId = auditEvent.GetValueByValueTypeId(AuditEventValueTypes.GamePlanScenarioID); AuditEventValue auditEventValueAutoBookId = auditEvent.GetValueByValueTypeId(AuditEventValueTypes.GamePlanAutoBookID); // Determine if sub event is set string subEvent = ""; foreach (int valueTypeId in new int[] { AuditEventValueTypes.GamePlanPipelineEventID, AuditEventValueTypes.GamePlanAutoBookEventID }) { subEvent = GetValueDescription(auditEvent, valueTypeId, auditEventValueTypeRepository, _valueConverters); if (!String.IsNullOrEmpty(subEvent)) { break; } } List <string> detailsTextList = new List <string>(); List <string> detailsUrlList = new List <string>(); StringBuilder title = new StringBuilder(auditEventType.Description); if (!String.IsNullOrEmpty(subEvent)) { title.Append(string.Format(" - {0}", subEvent)); } // Set Run/Scenario details Run run = null; StringBuilder message = new StringBuilder(""); if (auditEventValueRunId != null || auditEventValueScenarioId != null) { using (var scope = _repositoryFactory.BeginRepositoryScope()) { var runRepository = scope.CreateRepository <IRunRepository>(); run = (auditEventValueRunId != null ? runRepository.Find((Guid)auditEventValueRunId.Value) : runRepository.FindByScenarioId((Guid)auditEventValueScenarioId.Value)); if (auditEventValueScenarioId == null) { // Set URL detailsUrlList.Add(WebLinkFactory.GetRunDetailsURL(_frontendUrl, run.Id)); detailsTextList.Add("Run Details"); } else { detailsUrlList.Add(WebLinkFactory.GetRunDetailsURL(_frontendUrl, run.Id)); detailsTextList.Add("Run Details"); // Set URL detailsUrlList.Add(WebLinkFactory.GetOptimiserReportURL(_frontendUrl, run.Id, (Guid)auditEventValueScenarioId.Value)); detailsTextList.Add("Scenario Details"); } } } // Set AutoBook details if (auditEventValueAutoBookId != null) { detailsUrlList.Add(WebLinkFactory.GetAutoBookURL(_frontendUrl, (Guid)auditEventValueAutoBookId.Value)); detailsTextList.Add("AutoBook Details"); } DataTable dataTable = GetValuesDataTable(auditEvent, run, auditEventType, subEvent, auditEventValueTypeRepository, _valueConverters); foreach (DataRow dataRow in dataTable.Rows) { message.Append(message.Length == 0 ? "" : "; "); //message.Append(message.Length == 0 ? "" : "<BR/>"); message.Append(string.Format("{0}: {1}", dataRow[0].ToString(), dataRow[1].ToString())); } // Post message _msTeamsREST.PostMessageCard(postMessageSettings.Url, "Title", title.ToString(), message.ToString(), detailsTextList, detailsUrlList); }