/// <summary> /// Gets the configured Uri for a given configurable setting /// </summary> /// <param name="config">The OverridableConfig object that contains the settings</param> /// <param name="key">The key to seek</param> /// <param name="defaultValue">The default Uri (represented as a string)</param> /// <returns>A valid Uri if possible, null if not</returns> private static Uri GetConfiguredUri(OverridableConfig config, string key, string defaultValue) { string url = config.GetConfigSetting(key, defaultValue); if (!Uri.TryCreate(url, UriKind.Absolute, out Uri uri)) { uri = null; } return(uri); }
/// <summary> /// ctor /// </summary> /// <param name="exceptionReporter">Mechanism for reporting recoverable exceptions from the config</param> public GitHubWrapper(IExceptionReporter exceptionReporter) { const double defaultTimeout = 60.0; OverridableConfig config = new OverridableConfig("GitHubWrapper.settings", exceptionReporter); _productionConfigFileUri = GetConfiguredUri(config, "ProductionConfigFileUrl", DefaultProductionConfigFileUrl); _insiderConfigFileUri = GetConfiguredUri(config, "InsiderConfigFileUrl", DefaultInsiderConfigFileUrl); _canaryConfigFileUri = GetConfiguredUri(config, "CanaryConfigFileUrl", DefaultCanaryConfigFileUrl); string configTimeout = config.GetConfigSetting("TimeoutInSeconds", string.Empty); if (!double.TryParse(configTimeout, NumberStyles.Number, CultureInfo.InvariantCulture, out double timeoutInSeconds) || timeoutInSeconds <= 0) { timeoutInSeconds = defaultTimeout; } _timeout = TimeSpan.FromSeconds(timeoutInSeconds); }