public static T Build <T>(JObject obj, IConfigVariables enviromentVariables) where T : class { IncludeSubConfigs(obj); Transform(obj, enviromentVariables); return(obj.ToObject <T>()); }
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); } } }
public LinkableConfigVariables(IConfigVariables underlying) { this.underlying = underlying; if (underlying == null) { throw new ArgumentNullException(nameof(underlying)); } }
/// <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)); }
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(); }
/// <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; }
/// <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; }
public App(IConfigVariables env) : base(env) { Configure(() => { AppConfig .RegisterCommonServices() .UseCommands(c => { c.RegisterCommandsFromAssembly(GetType().Assembly); }); }); Configure(() => { AppConfig.AddAppRunnerAfter(() => { Container = AppConfig.SetupAutofacContainer(); }); }); }
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)); } }
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; }
public CommandRunContext(IConfigVariables vars, TextWriter info, TextWriter error) { Vars = vars; Info = info; Error = error; }
public App(IConfigVariables env) : base(env) { Configure(Prepare); }
/// <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); }
public ValueResolver(IConfigVariables vars, string key) { this.vars = vars; this.originKey = key; }
public ConfigVariablesBuilder Add(IConfigVariables configVariables) { return(AddBuilder(new GenericConfigVariablesBulider(() => configVariables))); }