WriteLineColor() public static method

Writes a line to the console in a specific color.
public static WriteLineColor ( string message, ConsoleColor, backgroundColor, ConsoleColor, foregroundColor ) : void
message string The message to write.
backgroundColor ConsoleColor, The background color.
foregroundColor ConsoleColor, The foreground color.
return void
Example #1
0
    private IDictionary <string, string> ParseConfigFile(
        IDictionary <string, string> envResult,
        IDictionary <string, string> argsResult)
    {
        var key            = ConfigKeys.ConfigJsonLocationKey;
        var configJsonPath = argsResult.CaseInsensitiveSearch(key);

        if (string.IsNullOrWhiteSpace(configJsonPath))
        {
            configJsonPath = envResult.CaseInsensitiveSearch(key);
        }

        if (string.IsNullOrWhiteSpace(configJsonPath))
        {
            return(new Dictionary <string, string>());
        }

        // Read the settings from a given file if the correct config key is set.
        if (!_fileService.FileExists(configJsonPath))
        {
            throw new FileNotFoundException($"File '{configJsonPath}' not found.");
        }

        ConsoleHelpers.WriteLineColor($"Reading configuration from '{configJsonPath}'.", ConsoleColor.Green,
                                      ConsoleColor.Black);
        var config = _fileService.ReadAllText(configJsonPath);

        return(JsonConvert.DeserializeObject <Dictionary <string, string> >(config));
    }
        private IDictionary <string, string> DetermineBaseArgsDictionary(IEnumerable <string> args)
        {
            var argsDictionary = args.Parse();
            var key            = ConfigKeys.ConfigJsonLocationKey.ToLower();

            if (!argsDictionary.TryGetValue(key, out var configJsonPath))
            {
                var envVars = _envService.GetEnvironmentVariables();
                configJsonPath = envVars?.FirstOrDefault(v => v.Key.Equals(key, StringComparison.OrdinalIgnoreCase))
                                 .Value;
                if (string.IsNullOrWhiteSpace(configJsonPath))
                {
                    return(argsDictionary);
                }
            }

            // Read the settings from a given file if the correct config key is set
            if (!_fileService.FileExists(configJsonPath))
            {
                throw new FileNotFoundException($"File '{configJsonPath}' not found.");
            }

            ConsoleHelpers.WriteLineColor($"Reading configuration from '{configJsonPath}'.", ConsoleColor.Green,
                                          ConsoleColor.Black);
            var config = _fileService.ReadAllText(configJsonPath);

            argsDictionary = JsonConvert.DeserializeObject <Dictionary <string, string> >(config);

            return(argsDictionary);
        }