Exemplo n.º 1
0
        private DataTable GetValuesDataTable(AuditEvent auditEvent, AuditEventType auditEventType)
        {
            DataTable dataTable = new DataTable();

            _ = dataTable.Columns.Add("Item", typeof(String));
            _ = dataTable.Columns.Add("Value", typeof(String));

            // Add standard header
            AddValuesRow(dataTable, "Time", auditEvent.TimeCreated.ToString());
            AddValuesRow(dataTable, "Event ID", auditEvent.ID);
            AddValuesRow(dataTable, "Event", auditEventType.Description);

            // Add other values
            foreach (AuditEventValue auditEventValue in auditEvent.Values)
            {
                AuditEventValueType auditEventValueType = _auditEventValueTypeRepository.GetByID(auditEventValue.TypeID);
                //if (!auditEventValueType.Internal)
                //{
                AuditEventValueConverter auditEventValueConverter = _valueConverters.Find(current => current.Handles(auditEventValue.TypeID));
                if (auditEventValueConverter != null)
                {
                    AddValuesRow(dataTable, auditEventValueType.Description, auditEventValueConverter.ValueConverter.Convert(auditEventValue.Value, auditEventValueType.Type, typeof(String)).ToString());
                }
                else
                {
                    AddValuesRow(dataTable, auditEventValueType.Description, auditEventValue.Value.ToString());
                }
            }
            return(dataTable);
        }
Exemplo n.º 2
0
        public void Insert(AuditEvent auditEvent)
        {
            AuditEventType auditEventType = _auditEventTypeRepository.GetByID(auditEvent.EventTypeID);
            string         message        = auditEventType.Description;

            System.Diagnostics.Debug.WriteLine(string.Format("{0} : {1}", auditEvent.TimeCreated, message));
        }
Exemplo n.º 3
0
        public MailMessage CreateEmail(AuditEvent auditEvent)
        {
            // Determine if we need to generate email
            EmailAuditEventSettings emailAuditEventSettings = _emailAuditEventSettingsList.Find(s => s.EventTypeId == auditEvent.EventTypeID);

            if (!Handles(auditEvent))
            {
                return(null);
            }

            AuditEventType auditEventType = _auditEventTypeRepository.GetByID(auditEvent.EventTypeID);

            MailMessage mail = new MailMessage();

            mail.Subject    = string.Format("{0}", auditEventType.Description);
            mail.Sender     = new MailAddress(emailAuditEventSettings.NotificationSettings.SenderAddress, emailAuditEventSettings.NotificationSettings.SenderAddress);
            mail.From       = new MailAddress(emailAuditEventSettings.NotificationSettings.SenderAddress, emailAuditEventSettings.NotificationSettings.SenderAddress);
            mail.Body       = GetBody(auditEvent, auditEventType);
            mail.IsBodyHtml = mail.Body.ToLower().Contains("<html>") && (mail.Body.ToLower().Contains("<head>") || mail.Body.ToLower().Contains("<head/>"));

            // Set list of recipients
            for (int index = 0; index < emailAuditEventSettings.NotificationSettings.RecipientAddresses.Count; index++)
            {
                mail.To.Add(new MailAddress(emailAuditEventSettings.NotificationSettings.RecipientAddresses[index], emailAuditEventSettings.NotificationSettings.RecipientAddresses[index]));
            }
            return(mail);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns email body. Email has header details (event type, event type etc) and table for each audit event value.
        /// </summary>
        /// <param name="auditEvent"></param>
        /// <returns></returns>
        private string GetBody(AuditEvent auditEvent, AuditEventType auditEventType, Run run, Guid scenarioId, Scenario scenario, string pipelineEvent, AuditEventValueTypeRepository auditEventValueTypeRepository)
        {
            StringBuilder text = new StringBuilder("<table>");
            //text.Append("<tr><th>Item</th><th>Value</th></tr>");
            DataTable valuesDataTable = GetValuesDataTable(auditEvent, run, auditEventType, pipelineEvent, auditEventValueTypeRepository);

            for (int rowIndex = 0; rowIndex < valuesDataTable.Rows.Count; rowIndex++)
            {
                text.Append(string.Format("<tr><td><B>{0}</B></td><td>{1}</td></tr>", valuesDataTable.Rows[rowIndex]["Item"].ToString(), valuesDataTable.Rows[rowIndex]["Value"].ToString()));
            }
            text.Append("</table><BR/>");

            text.Append("<B>Scenario</B><BR/><table>");
            text.Append("<tr><th>Scenario ID</th><th>Passes</th><th>Started</th><th>Completed</th><th>Status</th></tr>");
            foreach (var runScenario in run.Scenarios.Where(s => s.Id == scenarioId))
            {
                string scenarioUrl = string.Format(@"{0}/#/optimizer-report/{1}/{2}", _frontendUrl, run.Id, runScenario.Id);
                text.Append(string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td></tr>", CreateHTMLLink(runScenario.Id.ToString(), scenarioUrl), scenario.Passes.Count,
                                          (runScenario.StartedDateTime == null ? "n/a" : runScenario.StartedDateTime.Value.ToString()),
                                          (runScenario.CompletedDateTime == null ? "n/a" : runScenario.CompletedDateTime.Value.ToString()),
                                          runScenario.Status.ToString()));
            }
            text.Append("</table>");
            return(string.Format("<html><head>{0}</head><body>{1}</body></html>", GetStyle(), text.ToString()));
        }
Exemplo n.º 5
0
        protected DataTable GetValuesDataTable(AuditEvent auditEvent, Run run, AuditEventType auditEventType, string subEvent, AuditEventValueTypeRepository auditEventValueTypeRepository,
                                               List <AuditEventValueConverter> valueConverters)
        {
            DataTable dataTable = new DataTable();

            dataTable.Columns.Add("Item", typeof(String));
            dataTable.Columns.Add("Value", typeof(String));

            //string runUrl = string.Format(@"{0}/#/manage-runs", _frontendUrl);

            // Add standard header
            //AddValuesRow(dataTable, "Time", auditEvent.TimeCreated.ToString());
            //AddValuesRow(dataTable, "Event ID", auditEvent.ID);
            //AddValuesRow(dataTable, "Event", string.IsNullOrEmpty(subEvent) ? auditEventType.Description : string.Format("{0} - {1}", auditEventType.Description, subEvent));

            // Add values from Run ID
            if (run != null)
            {
                AddValuesRow(dataTable, "Run", string.Format("{0} ({1})", run.Description, run.Id.ToString()));
                //AddValuesRow(dataTable, "Description", run.Description);
                //AddValuesRow(dataTable, "Date Range", string.Format("{0} - {1}", run.StartDateTime.ToString(), run.EndDateTime.ToString()));
                //AddValuesRow(dataTable, "Created", run.CreatedDateTime.ToString());
                AddValuesRow(dataTable, "Executed", run.ExecuteStartedDateTime == null ? "n/a" : run.ExecuteStartedDateTime.Value.ToString());
                if (run.CompletedScenarios.Count == run.Scenarios.Count && run.LastScenarioCompletedDateTime != null)
                {
                    AddValuesRow(dataTable, "Completed", run.LastScenarioCompletedDateTime.Value.ToString());
                }
            }

            // Add other values
            HashSet <int> valueTypesDone = new HashSet <int>()
            {
                AuditEventValueTypes.GamePlanRunID, AuditEventValueTypes.GamePlanPipelineEventID, AuditEventValueTypes.GamePlanAutoBookEventID
            };

            foreach (AuditEventValue auditEventValue in auditEvent.Values)
            {
                if (!valueTypesDone.Contains(auditEventValue.TypeID))   // Ignore values done above
                {
                    AuditEventValueType auditEventValueType = auditEventValueTypeRepository.GetByID(auditEventValue.TypeID);
                    if (!auditEventValueType.Internal)
                    {
                        AuditEventValueConverter auditEventValueConverter = valueConverters.Find(current => current.Handles(auditEventValue.TypeID));
                        if (auditEventValueConverter != null)
                        {
                            AddValuesRow(dataTable, auditEventValueType.Description, auditEventValueConverter.ValueConverter.Convert(auditEventValue.Value, auditEventValueType.Type, typeof(String)).ToString());
                        }
                        else
                        {
                            AddValuesRow(dataTable, auditEventValueType.Description, auditEventValue.Value.ToString());
                        }
                    }
                }
            }
            return(dataTable);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns email body. Email has header details (event type, event type etc) and table for each audit event value.
        /// </summary>
        /// <param name="auditEvent"></param>
        /// <returns></returns>
        private string GetBody(AuditEvent auditEvent, AuditEventType auditEventType)
        {
            StringBuilder html = new StringBuilder(string.Format("<html><head>{0}</head><body>", _htmlStyle));

            _ = html.Append("<table>");
            DataTable valuesDataTable = GetValuesDataTable(auditEvent, auditEventType);

            for (int rowIndex = 0; rowIndex < valuesDataTable.Rows.Count; rowIndex++)
            {
                _ = html.Append(string.Format("<tr><td><B>{0}</B></td><td>{1}</td></tr>", valuesDataTable.Rows[rowIndex]["Item"].ToString(), valuesDataTable.Rows[rowIndex]["Value"].ToString()));
            }
            _ = html.Append("</table>");
            _ = html.Append("</body>");
            _ = html.Append("</html>");
            return(html.ToString());
        }
Exemplo n.º 7
0
        public void Insert(AuditEvent auditEvent)
        {
            if (Handles(auditEvent))
            {
                MSTeamsAuditEventSettings auditEventSettings = _msTeamsAuditEventSettings.Find(aes => aes.EventTypeId == auditEvent.EventTypeID);

                //AuditEventTypeRepository auditEventTypeRepository = new AuditEventTypeRepository();

                // Get event type
                AuditEventType auditEventType = _auditEventTypeRepository.GetByID(auditEvent.EventTypeID);

                // Perform action(s)
                if (auditEventSettings.PostMessageSettings != null && auditEventSettings.PostMessageSettings.Enabled)
                {
                    IMSTeamsMessageCreator messageCreator = _msTeamsMessageCreators.Where(ec => ec.Handles(auditEvent)).FirstOrDefault();
                    messageCreator.PostMessage(auditEvent, auditEventType, auditEventSettings.PostMessageSettings);
                }
            }
        }
Exemplo n.º 8
0
        /// <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)
        {
            StringBuilder title = new StringBuilder(auditEventType.Description);

            StringBuilder message = new StringBuilder(auditEventType.Description);

            foreach (AuditEventValue auditEventValue in auditEvent.Values)
            {
                AuditEventValueType auditEventValueType = _auditEventValueTypeRepository.GetByID(auditEventValue.TypeID);
                if (auditEventValueType.Type == typeof(String))
                {
                    _ = message.Append("; ");
                    _ = message.Append(string.Format("{0}={1}", auditEventValueType.Description, auditEventValue.Value.ToString()));
                }
            }

            // Post message
            _msTeamsREST.PostSimpleMessage(postMessageSettings.Url, "", message.ToString());
        }
Exemplo n.º 9
0
        public string Format(AuditEvent auditEvent)
        {
            AuditEventType auditEventType = _auditEventTypeRepository.GetByID(auditEvent.EventTypeID);
            StringBuilder  serialized     = new StringBuilder(string.Format("{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}{6}{0}", _delimiter, auditEvent.ID, auditEvent.TimeCreated.ToString("o"), auditEvent.TenantID, auditEvent.UserID, auditEvent.Source, auditEventType.Description));
            int            valueCount     = 0;

            foreach (AuditEventValue auditEventValue in auditEvent.Values)
            {
                AuditEventValueType auditEventValueType = _auditEventValueTypeRepository.GetByID(auditEventValue.TypeID);
                if (auditEventValueType.Type == typeof(String))
                {
                    valueCount++;
                    if (valueCount > 1)
                    {
                        _ = serialized.Append("; ");
                    }
                    _ = serialized.Append(string.Format("{0}={1}", auditEventValueType.Description, auditEventValue.Value.ToString()));
                }
            }
            return(serialized.ToString());
        }
Exemplo n.º 10
0
        private DataTable GetValuesDataTable(AuditEvent auditEvent, AuditEventType auditEventType, string subEvent, AuditEventValueTypeRepository auditEventValueTypeRepository)
        {
            DataTable dataTable = new DataTable();

            dataTable.Columns.Add("Item", typeof(String));
            dataTable.Columns.Add("Value", typeof(String));

            // Add standard header
            AddValuesRow(dataTable, "Time", auditEvent.TimeCreated.ToString());
            AddValuesRow(dataTable, "Event ID", auditEvent.ID);
            AddValuesRow(dataTable, "Event", string.IsNullOrEmpty(subEvent) ? auditEventType.Description : string.Format("{0} - {1}", auditEventType.Description, subEvent));

            // Add other values
            HashSet <int> valueTypesDone = new HashSet <int>()
            {
                AuditEventValueTypes.GamePlanRunID, AuditEventValueTypes.GamePlanPipelineEventID, AuditEventValueTypes.GamePlanAutoBookEventID
            };

            foreach (AuditEventValue auditEventValue in auditEvent.Values)
            {
                if (!valueTypesDone.Contains(auditEventValue.TypeID))   // Ignore values done above
                {
                    AuditEventValueType auditEventValueType = auditEventValueTypeRepository.GetByID(auditEventValue.TypeID);
                    if (!auditEventValueType.Internal)
                    {
                        AuditEventValueConverter auditEventValueConverter = _valueConverters.Find(current => current.Handles(auditEventValue.TypeID));
                        if (auditEventValueConverter != null)
                        {
                            AddValuesRow(dataTable, auditEventValueType.Description, auditEventValueConverter.ValueConverter.Convert(auditEventValue.Value, auditEventValueType.Type, typeof(String)).ToString());
                        }
                        else
                        {
                            AddValuesRow(dataTable, auditEventValueType.Description, auditEventValue.Value.ToString());
                        }
                    }
                }
            }
            return(dataTable);
        }
Exemplo n.º 11
0
        /// <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());
        }
Exemplo n.º 12
0
        /// <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);
        }
Exemplo n.º 13
0
 public void Update(AuditEventType item) => throw new NotImplementedException();