private Hashtable LoadTemplates() { var templates = new Hashtable(); var physicalPath = HostingEnvironment.MapPath( $"{_configuration.GetConfig().EmailTemplatesLocation}{TemplateFileName}"); FileInfo fileInfo; try { fileInfo = new FileInfo(physicalPath); } catch { throw new FileNotFoundException("No email templates found."); } var reader = fileInfo.OpenRead(); var document = new XmlDocument(); document.Load(reader); reader.Close(); foreach (XmlNode node in document.GetElementsByTagName("email")) { var template = new EmailTemplate(node); templates.Add(template.EmailType, template); } return(templates); }
private static DirectoryEntry CreateDirectoryEntry() { var config = ConfigurationSettings.GetConfig(); var ldapConnection = new DirectoryEntry(config.LdapDomain, config.LdapDomainUser, config.LdapDomainPassword, AuthenticationTypes.None) { Path = config.LdapConnectionPath }; return(ldapConnection); }
public void Start() { if (CurrentJobs.Count != 0) { return; } var configuration = _configuration.GetConfig(); if (!configuration.DisableBackgroundThreads) { var jobs = configuration.Jobs.Items; foreach (JobItemConfigurationElement job in jobs) { var type = Type.GetType(job.Type); if (type != null) { if (!CurrentJobs.Contains(job.Name)) { var newJob = new Job(type, job); CurrentJobs[job.Name] = newJob; if (!configuration.Jobs.SingleThread || !job.SingleThread) { newJob.InitializeTimer(); } } } } if (configuration.Jobs.SingleThread) { try { _interval = configuration.Jobs.Minutes * 60000; } catch { _interval = 15 * 60000; } _singleTimer = new Timer(Callback, null, _interval, _interval); } } }
public static MvcHtmlString ApplicationName(this HtmlHelper html) { var value = Configuration.GetConfig().ApplicationName; return(new MvcHtmlString(value)); }
public static MvcHtmlString Resource(this HtmlHelper html, string name, bool defaultOnly) { return(Resource(html, name, Configuration.GetConfig().ResourcesFile, false)); }
public void SendQueuedEmails(int failureInterval, int maxNumberOfTries) { var configuration = _configuration.GetConfig(); var emails = _queueService.Dequeue(); var failure = new List <EmailQueueItem>(); var smtp = new SmtpClient(configuration.SmtpServer, configuration.SmtpServerPort); if (!string.IsNullOrEmpty(configuration.SmtpServerUsername) && !string.IsNullOrEmpty(configuration.SmtpServerPassword)) { smtp.Credentials = new NetworkCredential(configuration.SmtpServerUsername, configuration.SmtpServerPassword); } var connectionLimit = configuration.SmtpServerConnectionLimit; var sentCount = 0; var totalSent = 0; foreach (var item in emails) { try { var message = CreateEmailMessageFromQueue(item); message.Headers.Add("X-EB-EmailID", item.Id.ToString()); message.Headers.Add("X-EB-Attempts", (item.NumberOfTries + 1).ToString()); message.Headers.Add("X-EB-AppDomain", AppDomain.CurrentDomain.FriendlyName); message.BodyEncoding = Encoding.UTF8; // Replace any LF characters with CR LF message.Body = message.Body.Replace("\r", string.Empty); message.Body = message.Body.Replace("\n", "\r\n"); smtp.Send(message); _queueService.Delete(item.Id); if (connectionLimit != -1 && ++sentCount >= connectionLimit) { Thread.Sleep(new TimeSpan(0, 0, 0, 15, 0)); sentCount = 0; } } catch (Exception) { failure.Add(item); } ++totalSent; } if (failure.Count > 0) { foreach (var fail in failure) { _queueService.QueueSendingFailure(fail.Id, failureInterval, maxNumberOfTries); } } if (totalSent > 0 || failure.Count > 0) { var infoLog = $"Email Queue:\n Messages Sent: {totalSent}\nMessages Failed: {failure.Count}"; } }