/// <summary> /// Parses command string into config node /// </summary> public static Configuration ParseCommand(string command, IEnvironmentVariableResolver resolver = null) { var cfg = LaconicConfiguration.CreateFromString(command); cfg.EnvironmentVarResolver = resolver; return(cfg); }
/// <summary> /// Resolves variable name into its value /// </summary> public string ResolveEnvironmentVar(string name, IEnvironmentVariableResolver resolver = null) { string value; if (resolver != null && resolver.ResolveEnvironmentVariable(name, out value)) { return(value); } resolver = m_EnvironmentVarResolver; if (resolver != null && resolver.ResolveEnvironmentVariable(name, out value)) { return(value); } resolver = ProcesswideEnvironmentVarResolver; if (resolver != null && resolver.ResolveEnvironmentVariable(name, out value)) { return(value); } resolver = OSEnvironmentVariableResolver.Instance; if (resolver != null && resolver.ResolveEnvironmentVariable(name, out value)) { return(value); } return(string.Empty); }
/// <summary> /// Evaluates variables in a context of optional variable resolver and macro runner /// </summary> public static string EvaluateVars(this string line, IEnvironmentVariableResolver envResolver = null, IMacroRunner macroRunner = null) { var config = new MemoryConfiguration(); config.Create(); config.EnvironmentVarResolver = envResolver; config.MacroRunner = macroRunner; return(EvaluateVarsInConfigScope(line, config)); }
/// <summary> /// Resolves variable name into its value /// </summary> public string ResolveEnvironmentVar(string name, IEnvironmentVariableResolver resolver = null) { if (resolver != null) { return(resolver.ResolveEnvironmentVariable(name)); } if (m_EnvironmentVarResolver != null) { return(m_EnvironmentVarResolver.ResolveEnvironmentVariable(name)); } var process = ProcesswideEnvironmentVarResolver; if (process != null) { return(process.ResolveEnvironmentVariable(name)); } return(WindowsEnvironmentVariableResolver.Instance.ResolveEnvironmentVariable(name)); }
/// <summary> /// Evaluates variables in a context of optional configuration supplied as dictionary which is converted to attributes /// </summary> public static string EvaluateVarsInDictionaryScope(this string line, IDictionary <string, object> dict = null, IEnvironmentVariableResolver envResolver = null, IMacroRunner macroRunner = null) { if (dict == null) { return(line.EvaluateVarsInConfigScope(null)); } else { var config = dict.ToConfigAttributes(); config.EnvironmentVarResolver = envResolver; config.MacroRunner = macroRunner; return(line.EvaluateVarsInConfigScope(config)); } }
/// <summary> /// Evaluates variables in a context of optional configuration supplied in XML format /// </summary> public static string EvaluateVarsInXMLConfigScope(this string line, string xmlScope = null, IEnvironmentVariableResolver envResolver = null, IMacroRunner macroRunner = null) { Configuration config = null; if (!string.IsNullOrWhiteSpace(xmlScope)) { config = XMLConfiguration.CreateFromXML(xmlScope); config.EnvironmentVarResolver = envResolver; config.MacroRunner = macroRunner; } return(line.EvaluateVarsInConfigScope(config)); }