Exemple #1
0
        private static RompConfigValues MungeConfig(params RompConfigValues[] configs)
        {
            var result = new RompConfigValues();

            foreach (var c in configs)
            {
                result = RompConfigValues.Merge(result, c, false);
            }

            return(result);
        }
Exemple #2
0
        public static void Initialize(ArgList args)
        {
            var configArgs = ParseConfigArguments(args);

            var overridden = MungeConfig(
                configArgs,
                LoadConfigFile(Path.Combine(Environment.CurrentDirectory, "rompconfig.json")),
                LoadConfigFile(Path.Combine(UserConfigPath, "rompconfig.json")),
                LoadConfigFile(Path.Combine(MachineConfigPath, "rompconfig.json"))
                );

            OverriddenValues = overridden;
            Values           = RompConfigValues.Merge(overridden, getDefaults(), true);

            if (CeipEnabled)
            {
                InitializeLoupe();
            }

            RompConfigValues getDefaults()
            {
                // some defaults are dependent on whether running in user mode or not
                var path = overridden.UserMode == true ? UserConfigPath : MachineConfigPath;

                return(new RompConfigValues
                {
                    StoreLogs = true,
                    LogLevel = MessageLevel.Warning,
                    CachePackages = true,
                    UserMode = false,
                    SecureCredentials = false,
                    ExtensionsPath = Path.Combine(path, "extensions"),
                    ExtensionsTempPath = Path.Combine(path, "temp", "extensions"),
                    Rafts = new Dictionary <string, string>()
                });
            }
        }
Exemple #3
0
        private static RompConfigValues ParseConfigArguments(ArgList args)
        {
            var config = new RompConfigValues
            {
                Rafts = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            };

            var properties = typeof(RompConfigValues)
                             .GetProperties()
                             .Where(p => !Attribute.IsDefined(p, typeof(NotCascadedAttribute)))
                             .ToDictionary(p => p.GetCustomAttribute <JsonPropertyAttribute>()?.PropertyName, StringComparer.OrdinalIgnoreCase);

            args.ProcessOptions(
                o =>
            {
                if (string.Equals(o.Key, "log-level", StringComparison.OrdinalIgnoreCase))
                {
                    switch (o.Value?.ToLowerInvariant())
                    {
                    case "debug":
                        config.LogLevel = MessageLevel.Debug;
                        break;

                    case "info":
                    case "information":
                        config.LogLevel = MessageLevel.Information;
                        break;

                    case "warn":
                    case "warning":
                        config.LogLevel = MessageLevel.Warning;
                        break;

                    case "error":
                        config.LogLevel = MessageLevel.Error;
                        break;

                    default:
                        throw new RompException("Invalid log-level; must be debug, info, warn, or error.");
                    }

                    return(true);
                }

                var p = properties.GetValueOrDefault(o.Key);
                if (p != null)
                {
                    try
                    {
                        p.SetValue(config, Convert.ChangeType(o.Value, Nullable.GetUnderlyingType(p.PropertyType) ?? p.PropertyType));
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        throw new RompException($"Invalid argument: {o.Key}={o.Value}: {ex.Message}", ex);
                    }
                }

                return(false);
            }
                );

            return(config);
        }