Пример #1
0
        public PythonAppConfigSection([NotNull] PythonAppConfigParams configParams, KeyValuePair <string, IniFileSection> pair, [CanBeNull] IniFileSection values)
            : base(pair.Value
                   .Where(x => !x.Key.StartsWith("__HINT"))
                   .Select(x => PythonAppConfigValue.Create(configParams, x,
                                                            pair.Value.Commentaries?.GetValueOrDefault(x.Key)?.Split('\n')[0],
                                                            values?.GetValueOrDefault(x.Key), values != null)).NonNull())
        {
            Key        = pair.Key;
            HintTop    = PrepareHint(pair.Value.GetNonEmpty("__HINT_TOP"));
            HintBottom = PrepareHint(pair.Value.GetNonEmpty("__HINT_BOTTOM"));

            var commentary = pair.Value.Commentary?.Split('\n')[0].Trim();

            if (commentary == @"hidden")
            {
                DisplayName = @"hidden";
            }
            else
            {
                var name = commentary ?? PythonAppConfig.ConvertKeyToName(pair.Key);

                var match = SectionName.Match(name);
                if (match.Success && match.Groups[2].Success && match.Groups[2].Length > 50)
                {
                    name    = PythonAppConfig.CapitalizeFirst(match.Groups[1].Value).Trim();
                    ToolTip = PythonAppConfig.CapitalizeFirst(match.Groups[2].Value).Trim();
                }

                DisplayName = PythonAppConfig.CapitalizeFirst(name);
            }
        }
Пример #2
0
        public PythonAppConfigSection(KeyValuePair <string, IniFileSection> pair, [CanBeNull] IniFileSection values)
            : base(pair.Value.Select(x => PythonAppConfigValue.Create(x,
                                                                      pair.Value.Commentaries?.GetValueOrDefault(x.Key), values?.GetValueOrDefault(x.Key), values != null)))
        {
            Key = pair.Key;

            var commentary = pair.Value.Commentary;

            DisplayName = commentary?.Trim() ?? PythonAppConfig.ConvertKeyToName(pair.Key);
        }
Пример #3
0
        public static PythonAppConfigValue Create(KeyValuePair <string, string> pair, [CanBeNull] string commentary, [CanBeNull] string actualValue,
                                                  bool isResetable)
        {
            string name = null, toolTip = null;
            Func <IPythonAppConfigValueProvider, bool> isEnabledTest = null;
            var result = CreateInner(pair, commentary, ref name, ref toolTip, ref isEnabledTest);

            if (string.IsNullOrEmpty(name))
            {
                name = PythonAppConfig.ConvertKeyToName(pair.Key);
            }

            result.Set(pair.Key, actualValue ?? pair.Value, name, toolTip, isEnabledTest, isResetable ? pair.Value : null);
            return(result);
        }
Пример #4
0
 public PythonAppConfigProvider([NotNull] PythonAppConfig root)
 {
     _root  = root;
     _flags = root.ConfigParams.Flags;
 }
Пример #5
0
        private static PythonAppConfigValue CreateInner(KeyValuePair <string, string> pair, [CanBeNull] string commentary, [CanBeNull] ref string name,
                                                        [CanBeNull] ref string toolTip, [CanBeNull] ref Func <IPythonAppConfigValueProvider, bool> isEnabledTest)
        {
            var value = pair.Value;

            if (commentary != null)
            {
                var match = ValueCommentaryRegex.Match(commentary);
                if (match.Success)
                {
                    name    = PythonAppConfig.CapitalizeFirst(match.Groups[1].Value.TrimEnd());
                    toolTip = match.Groups[2].Success ? PythonAppConfig.CapitalizeFirst(match.Groups[2].Value.Replace(@"; ", ";\n")) : null;

                    if (name.Length > 50 && toolTip == null)
                    {
                        toolTip = name;
                        name    = null;
                    }

                    if (match.Groups[3].Success)
                    {
                        var description = match.Groups[3].Value.Trim();

                        var dependent = DependentRegex.Match(description);
                        if (dependent.Success)
                        {
                            description   = dependent.Groups[1].Value;
                            isEnabledTest = CreateDisabledFunc(dependent.Groups[4].Value.Trim(), dependent.Groups[2].Success);
                        }

                        if (NumberRegex.IsMatch(description))
                        {
                            return(new PythonAppConfigNumberValue());
                        }

                        var boolean = BooleanRegex.Match(description);
                        if (boolean.Success)
                        {
                            return(new PythonAppConfigBoolValue(boolean.Groups[1].Value, boolean.Groups[2].Value));
                        }

                        var range = RangeRegex.Match(description);
                        if (range.Success)
                        {
                            return(new PythonAppConfigRangeValue(FlexibleParser.TryParseDouble(range.Groups[1].Value) ?? 0d,
                                                                 FlexibleParser.TryParseDouble(range.Groups[3].Value) ?? 100d, range.Groups[2].Success ? range.Groups[2].Value : null));
                        }

                        var file = FileRegex.Match(description);
                        if (file.Success)
                        {
                            return(new PythonAppConfigFileValue(file.Groups[1].Success, file.Groups[2].Success ? file.Groups[2].Value : null));
                        }

                        if (description.IndexOf(',') != -1)
                        {
                            var options = OptionsRegex.Matches(description).Cast <Match>()
                                          .Select(x => (x.Groups[1].Success ? x.Groups[1].Value : x.Groups[2].Value).Trim()).ToArray();
                            if (options.Length > 0)
                            {
                                return(new PythonAppConfigOptionsValue(options.Select(x => {
                                    var m = OptionValueRegex.Match(x);
                                    return m.Success ? new SettingEntry(m.Groups[2].Value.TrimStart(), m.Groups[1].Value.TrimEnd()) : new SettingEntry(x, x);
                                }).ToArray()));
                            }
                        }
                    }
                }
            }

            switch (value)
            {
            case "True":
            case "False":
                return(new PythonAppConfigBoolValue());

            case "true":
            case "false":
                return(new PythonAppConfigBoolValue("true", "false"));

            case "TRUE":
            case "FALSE":
                return(new PythonAppConfigBoolValue("TRUE", "FALSE"));

            case "On":
            case "Off":
                return(new PythonAppConfigBoolValue("On", "Off"));

            case "on":
            case "off":
                return(new PythonAppConfigBoolValue("on", "off"));

            case "ON":
            case "OFF":
                return(new PythonAppConfigBoolValue("ON", "OFF"));
            }

            return(new PythonAppConfigValue());
        }