/// <summary>
 /// Adds a trace to the current value. Useful for tracing the surces and source types
 /// </summary>
 /// <param name="configuration"></param>
 /// <param name="value">the trace value</param>
 /// <param name="sourceType">the optional source type (will ne displayed in brackets before the value)</param>
 /// <returns></returns>
 public static IEnvironmentConfiguration WithTrace(this IEnvironmentConfiguration configuration, string value, string sourceType = null)
 {
     return(configuration.SetValue(Constants.SourceTraceValueKey,
                                   string.IsNullOrEmpty(sourceType?.Trim())
             ? value
             : $"[{sourceType}]{value}"));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a logger to the pipeline
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="loggerFacade">the logger to use</param>
        /// <param name="level">the logging level to use</param>
        /// <returns></returns>
        public static IEnvironmentConfiguration WithLogger(this IEnvironmentConfiguration configuration,
                                                           ILoggerFacade loggerFacade, LogLevel level)
        {
            if (loggerFacade == null)
            {
                throw new ArgumentException("Cannot set a null logger facade", nameof(loggerFacade));
            }

            loggerFacade.LogLevel = level;
            return(configuration.SetValue(typeof(ILoggerFacade).FullName, (ILoggerFacade)loggerFacade));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds the xml file to the configuration. Multiple different files can be added.
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="file">the file to use</param>
        /// <param name="namespaces">The xml namespaces to load</param>
        /// <param name="eagerLoad">if the file should be eagerly loaded rather than lazily loaded</param>
        /// <returns></returns>
        public static IEnvironmentConfiguration WithXmlFile(this IEnvironmentConfiguration configuration, string file,
                                                            IDictionary <string, string> namespaces = null, bool eagerLoad = false)
        {
            XmlFileParser parser = null;

            if (configuration.HasValue(typeof(XmlFileParser).FullName))
            {
                parser = configuration.GetValue <XmlFileParser>(typeof(XmlFileParser).FullName);
            }
            else
            {
                configuration.SetValue(typeof(XmlFileParser).FullName, parser = new XmlFileParser());
            }
            if (parser.Files.Keys.Any(x => String.Equals(x, file, StringComparison.OrdinalIgnoreCase)))
            {
                return(configuration);
            }
            else
            {
                var data = new XmlFileParser.FileDataHolder();
                if (eagerLoad)
                {
                    try
                    {
                        data.ParsedFile = XDocument.Parse(File.ReadAllText(file));
                    }
                    catch
                    {
                        data.ParsingFailed = true;
                    }
                }

                data.Path = file;
                if (namespaces != null && namespaces.Any())
                {
                    foreach (var keyValuePair in namespaces)
                    {
                        data.NamespaceManager.AddNamespace(keyValuePair.Key, keyValuePair.Value);
                    }
                }

                parser.Files.Add(file, data);
            }

            return(configuration);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds the json file to the configuration. Multiple different files can be added.
        /// Use root expression syntax for file selection <example>$(filename).some.path</example>
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="file">the file to use</param>
        /// <param name="eagerLoad">load the file eagerly instead of lazily</param>
        /// <returns></returns>
        public static IEnvironmentConfiguration WithJsonFile(this IEnvironmentConfiguration configuration, string file, bool eagerLoad = false)
        {
            JsonFileParser parser = null;

            if (configuration.HasValue(typeof(JsonFileParser).FullName))
            {
                parser = configuration.GetValue <JsonFileParser>(typeof(JsonFileParser).FullName);
            }
            else
            {
                configuration.SetValue(typeof(JsonFileParser).FullName, parser = new JsonFileParser());
            }
            if (parser.Files.Keys.Any(x => String.Equals(x, file, StringComparison.OrdinalIgnoreCase)))
            {
                return(configuration);
            }
            else
            {
                var data = new JsonFileParser.FileDataHolder();
                if (eagerLoad)
                {
                    try
                    {
                        data.ParsedFile = JsonManager.Parse(File.ReadAllText(file));
                    }
                    catch
                    {
                        data.ParsingFailed = true;
                    }
                }

                data.Path = file;
                parser.Files.Add(file, data);
            }

            return(configuration);
        }
 /// <summary>
 /// Sets the type for the T in the configuration.
 /// This may be accessed with the GetBuildType or with the value of
 /// Abstractions.Constants.SourceRequiredTypeKey
 /// </summary>
 /// <typeparam name="T">the type to set</typeparam>
 /// <param name="configuration"></param>
 public static void SetBuildType <T>(this IEnvironmentConfiguration configuration)
 {
     configuration.SetValue(Constants.SourceRequiredTypeKey, typeof(T));
 }
 /// <summary>
 /// Sets the global description. This value will be used to print out the info/help
 /// </summary>
 /// <param name="configuration">the configuration to modify</param>
 /// <param name="description">the description to set</param>
 /// <returns>the configuration</returns>
 public static IEnvironmentConfiguration WithDescription(this IEnvironmentConfiguration configuration, string description)
 {
     return(configuration.SetValue(Constants.GlobalDescriptionValueKey, description));
 }
 /// <summary>
 /// Clears the environment variable prefix for the source or the environment
 /// </summary>
 /// <param name="configuration"></param>
 /// <param name="prefix"></param>
 /// <returns></returns>
 public static IEnvironmentConfiguration WithNoEnvironmentVariablePrefix(
     this IEnvironmentConfiguration configuration)
 {
     return(configuration.SetValue <string>(Constants.EnvironmentVariablePrefixKey, null));
 }
 /// <summary>
 /// Sets the environment variable prefix to the source or environment
 /// </summary>
 /// <param name="configuration"></param>
 /// <param name="prefix">the prefix to use</param>
 /// <returns></returns>
 public static IEnvironmentConfiguration WithEnvironmentVariablePrefix(
     this IEnvironmentConfiguration configuration, string prefix)
 {
     return(configuration.SetValue(Constants.EnvironmentVariablePrefixKey, prefix));
 }
 /// <summary>
 /// Sets the target for the environment variable resolution
 /// </summary>
 /// <param name="configuration"></param>
 /// <param name="target">the target to use</param>
 public static void SetEnvironmentTarget(this IEnvironmentConfiguration configuration, EnvironmentVariableTarget target)
 {
     configuration.SetValue(Constants.EnvironmentVariableTargetKey, target);
 }