public void AddRange(params EmailAuditEventSettings[] models) => _emailAuditEventSettingsRepository.AddRange(new List <EmailAuditEventSettings>(models));
Exemple #2
0
        /// <summary>
        /// Configures an audit event
        /// </summary>
        /// <param name="eventTypeId"></param>
        /// <param name="auditEventSettingsRepositories"></param>
        private void ConfigureAuditEvent(int eventTypeId, Dictionary <Type, object> auditEventSettingsRepositories,
                                         bool csvEvent, bool emailEvent, bool msTeamsEvent, bool sqlEvent, bool httpEvent, bool textFileEvent,
                                         string msTeamsUrl, List <string> emailRecipientAddresses)
        {
            // Get audit event settings repositories
            IMSTeamsAuditEventSettingsRepository  msTeamsAuditEventSettingsRepository  = auditEventSettingsRepositories.ContainsKey(typeof(IMSTeamsAuditEventSettingsRepository)) ? (IMSTeamsAuditEventSettingsRepository)auditEventSettingsRepositories[typeof(IMSTeamsAuditEventSettingsRepository)] : null;
            IEmailAuditEventSettingsRepository    emailAuditEventSettingsRepository    = auditEventSettingsRepositories.ContainsKey(typeof(IEmailAuditEventSettingsRepository)) ? (IEmailAuditEventSettingsRepository)auditEventSettingsRepositories[typeof(IEmailAuditEventSettingsRepository)] : null;
            ICSVAuditEventSettingsRepository      csvAuditEventSettingsRepository      = auditEventSettingsRepositories.ContainsKey(typeof(ICSVAuditEventSettingsRepository)) ? (ICSVAuditEventSettingsRepository)auditEventSettingsRepositories[typeof(ICSVAuditEventSettingsRepository)] : null;
            ISQLAuditEventSettingsRepository      sqlAuditEventSettingsRepository      = auditEventSettingsRepositories.ContainsKey(typeof(ISQLAuditEventSettingsRepository)) ? (ISQLAuditEventSettingsRepository)auditEventSettingsRepositories[typeof(ISQLAuditEventSettingsRepository)] : null;
            IHTTPAuditEventSettingsRepository     httpAuditEventSettingsRepository     = auditEventSettingsRepositories.ContainsKey(typeof(IHTTPAuditEventSettingsRepository)) ? (IHTTPAuditEventSettingsRepository)auditEventSettingsRepositories[typeof(IHTTPAuditEventSettingsRepository)] : null;
            ITextFileAuditEventSettingsRepository textFileAuditEventSettingsRepository = auditEventSettingsRepositories.ContainsKey(typeof(ITextFileAuditEventSettingsRepository)) ? (ITextFileAuditEventSettingsRepository)auditEventSettingsRepositories[typeof(ITextFileAuditEventSettingsRepository)] : null;

            // Configure CSV
            if (csvAuditEventSettingsRepository != null)
            {
                CSVAuditEventSettings csvAuditEventSettings = new CSVAuditEventSettings()
                {
                    EventTypeId = eventTypeId,
                    Enabled     = csvEvent
                };
                csvAuditEventSettingsRepository.Insert(new List <CSVAuditEventSettings>()
                {
                    csvAuditEventSettings
                });
            }

            // Configure email
            if (emailAuditEventSettingsRepository != null)
            {
                EmailAuditEventSettings emailAuditEventSettings = new EmailAuditEventSettings()
                {
                    EventTypeId          = eventTypeId,
                    EmailCreatorId       = "Default",
                    NotificationSettings = new EmailNotificationSettings()
                    {
                        Enabled            = emailEvent,
                        SenderAddress      = "*****@*****.**",
                        RecipientAddresses = emailRecipientAddresses
                    }
                };
                emailAuditEventSettingsRepository.AddRange(new List <EmailAuditEventSettings>()
                {
                    emailAuditEventSettings
                });
            }

            // Configure MS Teams notification
            if (msTeamsAuditEventSettingsRepository != null)
            {
                MSTeamsAuditEventSettings msTeamsAuditEventSettings = new MSTeamsAuditEventSettings()
                {
                    EventTypeId         = eventTypeId,
                    MessageCreatorId    = "Basic",
                    PostMessageSettings = new MSTeamsPostMessageSettings()
                    {
                        Enabled = msTeamsEvent,
                        Url     = msTeamsUrl
                    }
                };
                msTeamsAuditEventSettingsRepository.Insert(new List <MSTeamsAuditEventSettings>()
                {
                    msTeamsAuditEventSettings
                });
            }

            // Configure SQL
            if (sqlAuditEventSettingsRepository != null)
            {
                SQLAuditEventSettings sqlAuditEventSettings = new SQLAuditEventSettings()
                {
                    EventTypeId      = eventTypeId,
                    Enabled          = sqlEvent,
                    ConnectionString = ""    // TODO: Set this
                };
                sqlAuditEventSettingsRepository.Insert(new List <SQLAuditEventSettings>()
                {
                    sqlAuditEventSettings
                });
            }

            // Configure HTTP
            if (httpAuditEventSettingsRepository != null)
            {
                HTTPAuditEventSettings httpAuditEventSettings = new HTTPAuditEventSettings()
                {
                    EventTypeId     = eventTypeId,
                    Enabled         = httpEvent,
                    RequestSettings = new HTTPRequestSettings()
                    {
                        Method          = "POST",
                        URL             = @"http:\\myserver\event",
                        ContentTemplate = "{event_json}",
                        Headers         = new Dictionary <string, string>()
                        {
                        }
                    },
                    ResponseSettings = new HTTPResponseSettings()
                    {
                        SuccessStatusCodes = new List <System.Net.HttpStatusCode>()
                        {
                            System.Net.HttpStatusCode.OK
                        }
                    }
                };
                httpAuditEventSettingsRepository.Insert(new List <HTTPAuditEventSettings>()
                {
                    httpAuditEventSettings
                });
            }

            // Configure text file
            if (textFileAuditEventSettingsRepository != null)
            {
                TextFileAuditEventSettings textFileAuditEventSettings = new TextFileAuditEventSettings()
                {
                    EventTypeId = eventTypeId,
                    Enabled     = textFileEvent,
                    FormatterId = "Basic"
                };
                textFileAuditEventSettingsRepository.Insert(new List <TextFileAuditEventSettings>()
                {
                    textFileAuditEventSettings
                });
            }
        }