Beispiel #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public ServiceDependencies()
        {
            // $hack(jefflill): This screams for dependency injection.

            var textLogger = new TextLogger(LogManager.Default);

            // Parse: NEON_SERVICE_DEPENDENCIES_URIS

            var urisVar = Environment.GetEnvironmentVariable("NEON_SERVICE_DEPENDENCIES_URIS");

            if (!string.IsNullOrEmpty(urisVar))
            {
                var uris = urisVar.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var item in uris)
                {
                    var uriString = item.Trim();

                    if (string.IsNullOrEmpty(uriString))
                    {
                        continue;
                    }

                    if (Uri.TryCreate(uriString, UriKind.Absolute, out var uri))
                    {
                        Uris.Add(uri);
                    }
                    else
                    {
                        textLogger.LogWarn($"Service Dependency: [{uriString}] is not a valid URI and will be ignored.");
                    }
                }
            }

            // Parse: NEON_SERVICE_DEPENDENCIES_DISABLE_DNS_CHECK

            var disableDnsCheckVar = Environment.GetEnvironmentVariable("NEON_SERVICE_DEPENDENCIES_DISABLE_DNS_CHECK");

            if (!string.IsNullOrEmpty(disableDnsCheckVar))
            {
                if (NeonHelper.TryParseBool(disableDnsCheckVar, out var disableDnsCheck))
                {
                    DisableDnsCheck = disableDnsCheck;
                }
                else
                {
                    textLogger.LogWarn($"Service Dependency: [NEON_SERVICE_DEPENDENCIES_DISABLE_DNS_CHECK={disableDnsCheckVar}] is not a valid and will be ignored.");
                }
            }

            // Parse: NEON_SERVICE_DEPENDENCIES_TIMEOUT_SECONDS

            var timeoutSecondsVar = Environment.GetEnvironmentVariable("NEON_SERVICE_DEPENDENCIES_TIMEOUT_SECONDS");

            if (!string.IsNullOrEmpty(timeoutSecondsVar))
            {
                if (double.TryParse(timeoutSecondsVar, out var timeoutSeconds) && timeoutSeconds >= 0)
                {
                    Timeout = TimeSpan.FromSeconds(timeoutSeconds);
                }
                else
                {
                    textLogger.LogWarn($"Service Dependency: [NEON_SERVICE_DEPENDENCIES_TIMEOUT_SECONDS={timeoutSecondsVar}] is not a valid and will be ignored.");
                }
            }

            // Parse: NEON_SERVICE_DEPENDENCIES_WAIT_SECONDS

            var waitSecondsVar = Environment.GetEnvironmentVariable("NEON_SERVICE_DEPENDENCIES_WAIT_SECONDS");

            if (!string.IsNullOrEmpty(waitSecondsVar))
            {
                if (double.TryParse(waitSecondsVar, out var waitSeconds) && waitSeconds >= 0)
                {
                    Wait = TimeSpan.FromSeconds(waitSeconds);
                }
                else
                {
                    textLogger.LogWarn($"Service Dependency: [NEON_SERVICE_DEPENDENCIES_WAIT_SECONDS={waitSecondsVar}] is not a valid and will be ignored.");
                }
            }
        }