示例#1
0
 public static T Build <T>(JObject obj, IConfigVariables enviromentVariables)
     where T : class
 {
     IncludeSubConfigs(obj);
     Transform(obj, enviromentVariables);
     return(obj.ToObject <T>());
 }
示例#2
0
 private static void Transform(JObject obj, IConfigVariables enviromentVariables)
 {
     foreach (var item in obj)
     {
         if (item.Value?.Type == JTokenType.Object)
         {
             Transform((JObject)item.Value, enviromentVariables);
         }
         else if (item.Value?.Type == JTokenType.Array)
         {
             foreach (var arrayItem in item.Value)
             {
                 if (arrayItem is JObject)
                 {
                     Transform((JObject)arrayItem, enviromentVariables);
                 }
                 else
                 {
                     EnvVariableSubstitution(arrayItem, enviromentVariables);
                 }
             }
         }
         else
         {
             EnvVariableSubstitution(item.Value, enviromentVariables);
         }
     }
 }
示例#3
0
 public LinkableConfigVariables(IConfigVariables underlying)
 {
     this.underlying = underlying;
     if (underlying == null)
     {
         throw new ArgumentNullException(nameof(underlying));
     }
 }
示例#4
0
        /// <summary>
        /// Creates new AppSetup instance with a given <para>env</para> ConfigVariables
        /// </summary>
        /// <param name="env">IConfigVariables instance</param>
        protected AppSetup(IConfigVariables env)
        {
            if (env == null)
            {
                throw new ArgumentNullException(nameof(env));
            }

            Env       = env;
            appConfig = new AppConfig();
            appConfig.SetConfigVariables(env);
        }
        /// <summary>
        /// Returns new IConfigVariables instance which is prefixing all variable accessors
        /// with a given <para>prefix</para>
        /// </summary>
        /// <param name="vars">IConfigVariables instance</param>
        /// <param name="prefix">prefix string</param>
        /// <returns>new IConfigVariables instance</returns>
        public static IConfigVariables WithPrefix(this IConfigVariables vars, string prefix)
        {
            if (vars == null)
            {
                throw new ArgumentNullException(nameof(vars));
            }
            if (prefix == null)
            {
                throw new ArgumentNullException(nameof(prefix));
            }

            return(new ConfigVariablesWrapper(vars, prefix));
        }
示例#6
0
        public CommandRunner(
            ICommandRepository commandRepository,
            IConfigVariables vars,
            ICommandRunnerOutput output
            )
        {
            this.output          = output;
            this.vars            = vars;
            this.commandsLookups = commandRepository.GetCommands()
                                   .ToLookup(x => x.Definition().Name, StringComparer.CurrentCultureIgnoreCase);

            this.commands = commandRepository.GetCommands();
        }
示例#7
0
        /// <summary>
        /// Set Config Variables to <para>appConfig</para> using ConfigVariables predefined key
        /// </summary>
        /// <param name="appConfig">AppConfig instance</param>
        /// <param name="configVariables">IConfigVariables instance</param>
        public static void SetConfigVariables(this IAppConfig appConfig,
                                              IConfigVariables configVariables)
        {
            if (appConfig == null)
            {
                throw new ArgumentNullException(nameof(appConfig));
            }
            if (configVariables == null)
            {
                throw new ArgumentNullException(nameof(configVariables));
            }

            appConfig[ConfigVariablesKey] = configVariables;
        }
示例#8
0
        /// <summary>
        /// Creates new ConfigVariablesWrapper instance for underlying <para>configVariables</para> with
        /// given <para>prefix</para>
        /// </summary>
        /// <param name="configVariables">configVariables instance</param>
        /// <param name="prefix">prefix string</param>
        public ConfigVariablesWrapper(IConfigVariables configVariables, string prefix = "")
        {
            if (configVariables == null)
            {
                throw new ArgumentNullException(nameof(configVariables));
            }

            if (prefix == null)
            {
                throw new ArgumentNullException(nameof(prefix));
            }

            _configVariables = configVariables;
            _prefix          = prefix;
        }
示例#9
0
        public App(IConfigVariables env) : base(env)
        {
            Configure(() =>
            {
                AppConfig
                .RegisterCommonServices()
                .UseCommands(c =>
                {
                    c.RegisterCommandsFromAssembly(GetType().Assembly);
                });
            });

            Configure(() =>
            {
                AppConfig.AddAppRunnerAfter(() =>
                {
                    Container = AppConfig.SetupAutofacContainer();
                });
            });
        }
示例#10
0
        private static void EnvVariableSubstitution(JToken item, IConfigVariables enviromentVariables)
        {
            if (item?.Type != JTokenType.String)
            {
                return;
            }
            var val = item.Value <string>();

            if (_envVariableRegex.IsMatch(val))
            {
                foreach (Match match in _envVariableRegex.Matches(val))
                {
                    if (match != null)
                    {
                        var envName  = match.Groups[0].Value;
                        var envValue = enviromentVariables.GetEnviromentVariable(match.Groups[1].Value);
                        val = val.Replace(envName, envValue);
                    }
                }
                item.Replace(JToken.FromObject(val));
            }
        }
示例#11
0
        private static IOutput ResolveConsoleOutput(IConfigVariables env)
        {
            var type = env["Confifu:Samples:Library:OutputType"];

            if (type == null)
            {
                return(null);
            }

            switch (type.ToLower())
            {
            case "console":
                return(new ConsoleOutput());

            case "file":
            {
                var file = env["Confifu:Samples:Library:OutputFile"];
                return(new FileOutput(file));
            }

            default:
                return(null);
            }
        }
 public GuardianApiHttpService(RestClient restClient, IConfigVariables configVariables)
 {
     _restClient      = restClient;
     _configVariables = configVariables;
 }
示例#13
0
 public CommandRunContext(IConfigVariables vars, TextWriter info, TextWriter error)
 {
     Vars  = vars;
     Info  = info;
     Error = error;
 }
示例#14
0
 public App(IConfigVariables env) : base(env)
 {
     Configure(Prepare);
 }
示例#15
0
 /// <summary>
 /// Sets to IAppConfig instance ConfigVariables and returns the given instance
 /// </summary>
 /// <param name="appConfig">AppConfig instance</param>
 /// <param name="configVariables">ConfigVariables instance</param>
 /// <returns>Given IAppConfig instance</returns>
 public static IAppConfig WithConfigVariables(this IAppConfig appConfig, IConfigVariables configVariables)
 {
     appConfig.SetConfigVariables(configVariables);
     return(appConfig);
 }
示例#16
0
 public ValueResolver(IConfigVariables vars, string key)
 {
     this.vars      = vars;
     this.originKey = key;
 }
示例#17
0
 public ConfigVariablesBuilder Add(IConfigVariables configVariables)
 {
     return(AddBuilder(new GenericConfigVariablesBulider(() => configVariables)));
 }