public static AppConfiguration GetConfig() { SendFromConfigSection sendFromSection = (ConfigurationManager.GetSection("sendFrom") as SendFromConfigSection); if (sendFromSection == null) { return null; } AppConfiguration config = new AppConfiguration { DeviceEHConnectionString = ConfigurationManager.AppSettings.Get("Microsoft.ServiceBus.EventHubConnectionString"), DeviceEHName = ConfigurationManager.AppSettings.Get("Microsoft.ServiceBus.EventHubToMonitor"), NotificationService = ConfigurationManager.AppSettings.Get("NotificationService"), EmailServiceUserName = ConfigurationManager.AppSettings.Get("SenderUserName"), EmailServicePassword = ConfigurationManager.AppSettings.Get("SenderPassword"), SmtpHost = ConfigurationManager.AppSettings.Get("SmtpHost"), SmtpEnableSSL = ConfigurationManager.AppSettings.Get("SmtpEnableSSL").ToLowerInvariant() == "true", MessageFromAddress = sendFromSection.Address, MessageFromName = sendFromSection.DisplayName, MessageSubject = sendFromSection.Subject, SendToList = ConfigurationLoader.GetSendToList(), ConsumerGroupPrefix = ConfigurationManager.AppSettings.Get("ConsumerGroupPrefix"), }; return config; }
private static void StartHost(string consumerGroupSuffix) { Trace.WriteLine("Starting Worker..."); #if DEBUG_LOG RoleEnvironment.TraceSource.TraceInformation("Starting Worker..."); #endif _Config = ConfigurationLoader.GetConfig(); if (_Config == null) { return; } _Config.ConsumerGroupPrefix += consumerGroupSuffix; _NotificationService = (NotificationServiceType)Enum.Parse(typeof(NotificationServiceType), _Config.NotificationService); var credentials = new NetworkCredential(_Config.EmailServiceUserName, _Config.EmailServicePassword); PrepareMailAddressInstances(); switch (_NotificationService) { case NotificationServiceType.Smtp: { _SmtpClient = new SmtpClient { Port = _Config.SmtpEnableSSL ? 587 : 25, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, EnableSsl = false, Host = _Config.SmtpHost, Credentials = credentials }; } break; case NotificationServiceType.SendGridWeb: { _SendGridTransportWeb = new Web(credentials); } break; case NotificationServiceType.Twilio: case NotificationServiceType.TwilioCall: { string ACCOUNT_SID = _Config.EmailServiceUserName; string AUTH_TOKEN = _Config.EmailServicePassword; _TwilioRestClient = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN); } break; } _EventHubReader = new EventHubReader(_Config.ConsumerGroupPrefix, OnMessage); Process(); }
public static AppConfiguration GetConfig(ILogger logger) { AppConfiguration config = new AppConfiguration { CredentialToUse = new NetworkCredential(CloudConfigurationManager.GetSetting("UserName"), CloudConfigurationManager.GetSetting("Password")), UseXml = ReadConfigValue("SendJson", "[Send Xml if 'false', otherwise Json]").ToLowerInvariant().Contains("false"), XmlTemplate = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).GetSection("MergeToXML").SectionInformation.GetRawXml(), ServiceBusConnectionString = ReadConfigValue("Microsoft.ServiceBus.ServiceBusConnectionString", "[Service Bus connection string]"), EventHubName = ReadConfigValue("Microsoft.ServiceBus.EventHubToUse", "[event hub name]"), MessageSubject = ReadConfigValue("MessageSubject", "[Message subject]"), MessageDeviceId = ReadConfigValue("MessageDeviceId", "[Message device Id]"), MessageDeviceDisplayName = ReadConfigValue("MessageDeviceDisplayName", "[Message device name]") }; if (!int.TryParse(ReadConfigValue("SleepTimeMs", "[Sleep time]"), out config.SleepTimeMs)) { logger.LogInfo("Incorrect SleepTimeMs value, using default..."); //default sleep time interval is 10 sec config.SleepTimeMs = 10000; } return config; }