internal static Settings FromConfigurationSection(NewRelicConfigurationSection section, ILog log) { var sqlEndpoints = section.SqlServers .Select(s => { var includedDatabaseNames = s.IncludedDatabases.Select(d => d.ToDatabase()).ToArray(); var excludedDatabaseNames = s.ExcludedDatabases.Select(d => d.Name).ToArray(); return ((ISqlEndpoint) new SqlServerEndpoint(s.Name, s.ConnectionString, s.IncludeSystemDatabases, includedDatabaseNames, excludedDatabaseNames)); }) .Union(section.AzureSqlDatabases.Select(s => (ISqlEndpoint) new AzureSqlEndpoint(s.Name, s.ConnectionString))); var service = section.Service; var settings = new Settings(sqlEndpoints.ToArray()) { LicenseKey = service.LicenseKey, PollIntervalSeconds = service.PollIntervalSeconds, }; if (!string.IsNullOrEmpty(service.ServiceName) && Regex.IsMatch(service.ServiceName, "^[a-zA-Z_0-9-]{6,32}$")) { settings.ServiceName = service.ServiceName; } return(settings); }
internal static Settings FromConfigurationSection(NewRelicConfigurationSection section, ILog log) { var sqlEndpoints = section.SqlServers .Select(s => { var includedDatabaseNames = s.IncludedDatabases.Select(d => d.ToDatabase()).ToArray(); var excludedDatabaseNames = s.ExcludedDatabases.Select(d => d.Name).ToArray(); return (ISqlEndpoint) new SqlServerEndpoint(s.Name, s.ConnectionString, s.IncludeSystemDatabases, includedDatabaseNames, excludedDatabaseNames); }) .Union(section.AzureSqlDatabases.Select(s => (ISqlEndpoint) new AzureSqlEndpoint(s.Name, s.ConnectionString))); var service = section.Service; var settings = new Settings(sqlEndpoints.ToArray()) { LicenseKey = service.LicenseKey, PollIntervalSeconds = service.PollIntervalSeconds, }; if (!string.IsNullOrEmpty(service.ServiceName) && Regex.IsMatch(service.ServiceName, "^[a-zA-Z_0-9-]{6,32}$")) { settings.ServiceName = service.ServiceName; } return settings; }
private static IWebProxy GetWebProxy(NewRelicConfigurationSection section, ILog log) { var proxyElement = section.Proxy; if (proxyElement == null || !proxyElement.ElementInformation.IsPresent) return null; Uri uri; if (!Uri.TryCreate(proxyElement.Host, UriKind.RelativeOrAbsolute, out uri)) { log.ErrorFormat("Proxy host '{0}' is not a valid URI, skipping proxy.", proxyElement.Host); return null; } int port; if (!int.TryParse(proxyElement.Port, out port)) { log.ErrorFormat("Unable to parse proxy port from '{0}', skipping proxy. Expecting a number from 1-65535.", proxyElement.Port); return null; } WebProxy webProxy; try { webProxy = new WebProxy(proxyElement.Host, port); } catch (Exception e) { log.ErrorFormat("Proxy settings are invalid. {0}", e.Message); return null; } if ("true".Equals(proxyElement.UseDefaultCredentials, StringComparison.InvariantCultureIgnoreCase)) { webProxy.UseDefaultCredentials = true; webProxy.Credentials = CredentialCache.DefaultCredentials; _ProxyDetails = string.Format("Proxy Server: {0}:{1} with default credentials", proxyElement.Host, port); } else if (!string.IsNullOrEmpty(proxyElement.User)) { if (string.IsNullOrEmpty(proxyElement.Domain)) { webProxy.Credentials = new NetworkCredential(proxyElement.User, proxyElement.Password); _ProxyDetails = string.Format("Proxy Server: {0}@{1}:{2}", proxyElement.User, proxyElement.Host, port); } else { webProxy.Credentials = new NetworkCredential(proxyElement.User, proxyElement.Password, proxyElement.Domain); _ProxyDetails = string.Format("Proxy Server: {0}\\{1}@{2}:{3}", proxyElement.Domain, proxyElement.User, proxyElement.Host, port); } } else { _ProxyDetails = string.Format("Proxy Server: {0}:{1}", proxyElement.Host, port); } return webProxy; }
private static IWebProxy GetWebProxy(NewRelicConfigurationSection section, ILog log) { var proxyElement = section.Proxy; if (proxyElement == null || !proxyElement.ElementInformation.IsPresent) { return(null); } Uri uri; if (!Uri.TryCreate(proxyElement.Host, UriKind.RelativeOrAbsolute, out uri)) { log.ErrorFormat("Proxy host '{0}' is not a valid URI, skipping proxy.", proxyElement.Host); return(null); } int port; if (!int.TryParse(proxyElement.Port, out port)) { log.ErrorFormat("Unable to parse proxy port from '{0}', skipping proxy. Expecting a number from 1-65535.", proxyElement.Port); return(null); } WebProxy webProxy; try { webProxy = new WebProxy(proxyElement.Host, port); } catch (Exception e) { log.ErrorFormat("Proxy settings are invalid. {0}", e.Message); return(null); } if ("true".Equals(proxyElement.UseDefaultCredentials, StringComparison.InvariantCultureIgnoreCase)) { webProxy.UseDefaultCredentials = true; webProxy.Credentials = CredentialCache.DefaultCredentials; _ProxyDetails = string.Format("Proxy Server: {0}:{1} with default credentials", proxyElement.Host, port); } else if (!string.IsNullOrEmpty(proxyElement.User)) { if (string.IsNullOrEmpty(proxyElement.Domain)) { webProxy.Credentials = new NetworkCredential(proxyElement.User, proxyElement.Password); _ProxyDetails = string.Format("Proxy Server: {0}@{1}:{2}", proxyElement.User, proxyElement.Host, port); } else { webProxy.Credentials = new NetworkCredential(proxyElement.User, proxyElement.Password, proxyElement.Domain); _ProxyDetails = string.Format("Proxy Server: {0}\\{1}@{2}:{3}", proxyElement.Domain, proxyElement.User, proxyElement.Host, port); } } else { _ProxyDetails = string.Format("Proxy Server: {0}:{1}", proxyElement.Host, port); } return(webProxy); }