DbScout.Services.CommandLineConfiguration.GetMandatoryConfigValue C# (CSharp) Method

GetMandatoryConfigValue() public method

public GetMandatoryConfigValue ( string key ) : string
key string
return string
        public string GetMandatoryConfigValue(string key)
        {
            if (!GetConfiguration().ContainsKey(key.ToLowerInvariant()))
            {
                throw new Exception($"Configuration error: Missed mandatory parameter {key} in command line!");
            }

            return GetConfiguration()[key.ToLowerInvariant()];
        }

Usage Example

Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            try
            {
                XmlConfigurator.Configure();

                var cfg = new CommandLineConfiguration { CmdLineArgs = args };
                var commandInstance = new CommandFactory()
                    .CreateCommand(cfg.GetMandatoryConfigValue(CommandKey));

                (commandInstance as IConfigurable)?.Configure(cfg);

                Logger.Info($"Executing command {commandInstance.GetType().Name}...");

                commandInstance.Execute();

                Logger.Info($"Command {commandInstance.GetType().Name} executed.");
            }
            catch (Exception e)
            {
                Logger.Error($"Error executing application: {e.Message}");
                var innerException = e.InnerException;
                while (null != innerException)
                {
                    Logger.Error(innerException.Message);
                    innerException = innerException.InnerException;
                }
                Logger.Error($"Stack trace: {e.StackTrace}");
            }
        }