// this method will be used to get the next randomly incremented number
        public static IEnvironmentBuilder Random(this IEnvironmentBuilder builder)
        {
            if (!builder.Configuration.HasValue(SaverKey))
            {
                builder.WithConfiguration(cfg => cfg.SetValue(SaverKey, new NumberSaver()));
            }

            return(builder.WithSource(config =>
            {
                //just a simple logic to increment and save values
                var nextValue = config.GetFactoryValue <int>(RngKey);
                var saver = config.GetValue <NumberSaver>(SaverKey);
                var oldKey = saver.Prev;
                saver.Prev += nextValue;
                return oldKey;
            }, config => config.WithTrace("my random value", "my random source")));
        }
        /// <summary>
        /// Adds the environment variable source to te pipe
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="name">the name of the variable</param>
        /// <param name="configuration">the scoped configuration to add</param>
        /// <returns></returns>
        public static IEnvironmentBuilder WithEnvironmentVariable(this IEnvironmentBuilder builder, string name, Action <IEnvironmentConfiguration> configuration = null)
        {
            if (!builder.Configuration.HasValue(typeof(EnvironmentVariableParser).FullName))
            {
                builder.WithConfiguration(cfg => cfg.SetValue(typeof(EnvironmentVariableParser).FullName,
                                                              new EnvironmentVariableParser()));
            }

            return(builder.WithSource(cfg =>
            {
                var parser = cfg.GetValue <EnvironmentVariableParser>(typeof(EnvironmentVariableParser).FullName);
                var requiredType = cfg.GetBuildType();
                var target = cfg.GetEnvironmentTarget();
                var prefix = cfg.GetEnvironmentVariablePrefix();
                return parser.Value(name, requiredType, target, prefix);
            }, cfg =>
            {
                configuration?.Invoke(cfg);
                cfg.WithTrace(name, "environment");
            }));
        }
 /// <summary>
 /// Adds the common key to the configuration to be consumed by other types
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="key">the key name</param>
 /// <returns></returns>
 public static IEnvironmentBuilder WithCommonKey(this IEnvironmentBuilder builder, string key)
 {
     return(builder.WithConfiguration(cfg => cfg.SetValue(Constants.SourceCommonKeyKey, key)));
 }
 /// <summary>
 /// Sets the scoped description for the current bundle. This value will be used to print out the info for the current bundle.
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="description"></param>
 /// <returns></returns>
 public static IEnvironmentBuilder WithDescription(this IEnvironmentBuilder builder, string description)
 {
     return(builder.WithConfiguration(config =>
                                      config.SetValue(Constants.SourceDescriptionValueKey, description)));
 }
Exemplo n.º 5
0
 public IEnvironmentBuilder WithConfiguration(Action <IEnvironmentConfiguration> configuration)
 {
     _builder.WithConfiguration(configuration);
     return(this);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Logs the fatal message to the logger
 /// </summary>
 /// <param name="configuration"></param>
 /// <param name="message">the message to log</param>
 public static void LogFatal(this IEnvironmentBuilder configuration, object message)
 {
     configuration.WithConfiguration(cfg => cfg.Log(LogLevel.Fatal, message));
 }