コード例 #1
0
ファイル: ChartScript.cs プロジェクト: mapacheL/extensions
        protected override string ChildPropertyValidation(ModifiableEntity sender, System.Reflection.PropertyInfo pi)
        {
            var column = sender as ChartScriptColumnEntity;
            if (column != null && pi.Name == nameof(column.IsGroupKey))
            {
                if (column.IsGroupKey)
                {
                    if (!ChartUtils.Flag(ChartColumnType.Groupable, column.ColumnType))
                        return "{0} can not be true for {1}".FormatWith(pi.NiceName(), column.ColumnType.NiceToString());
                }
            }

            var param = sender as ChartScriptParameterEntity;
            if (param != null && pi.Name == nameof(param.ColumnIndex))
            {
                if (param.ColumnIndex == null && param.ShouldHaveColumnIndex())
                    return ValidationMessage._0IsNecessary.NiceToString(pi.NiceName());

                if (param.ColumnIndex.HasValue && !(0 <= param.ColumnIndex && param.ColumnIndex < this.Columns.Count))
                    return ValidationMessage._0HasToBeBetween1And2.NiceToString(pi.NiceName(), 0, this.Columns.Count);
            }

            return base.ChildPropertyValidation(sender, pi);
        }
コード例 #2
0
        protected override string PropertyValidation(System.Reflection.PropertyInfo pi)
        {
            if (pi.Is(() => GroupBy))
            {
                if (GroupBy == GroupByChart.Always || GroupBy == GroupByChart.Optional)
                {
                    if (!Columns.Any(a => a.IsGroupKey))
                        return "{0} {1} requires some key columns".FormatWith(pi.NiceName(), groupBy.NiceToString());
                }
                else
                {
                    if (Columns.Any(a => a.IsGroupKey))
                        return "{0} {1} should not have key".FormatWith(pi.NiceName(), groupBy.NiceToString());
                }
            }

            if (pi.Is(() => Script))
            {
                if (!Regex.IsMatch(Script, @"function\s+DrawChart\s*\(\s*chart\s*,\s*data\s*\)", RegexOptions.Singleline))
                {
                    return "{0} should be a definition of function DrawChart(chart, data)".FormatWith(pi.NiceName());
                }
            }

            return base.PropertyValidation(pi);
        }