コード例 #1
0
        protected override void Validate()
        {
            var fields  = GetAllFields().ToArray();
            var names   = new HashSet <string>(fields.Select(f => f.Name).Distinct());
            var aliases = new HashSet <string>(fields.Select(f => f.Alias));

            ValidateVersion(names, aliases);
            ValidateFilter(names, aliases);
            ValidateOrder(names, aliases);

            foreach (var field in GetAllOutputFields().Where(f => f.Sortable == "true" && !string.IsNullOrEmpty(f.SortField)))
            {
                if (GetField(field.SortField) == null)
                {
                    Error($"Can't find sort field {field.SortField} defined in field {field.Alias}.");
                }
            }

            // Paging Madness
            if (Page > 0)
            {
                if (PageSizes.Any())
                {
                    if (PageSizes.All(ps => ps.Size != PageSize))
                    {
                        var first = PageSizes.First().Size;
                        Warn($"The entity {Name} has an invalid PageSize of {PageSize}. Set to {first}.");
                        PageSize = first;
                    }
                }
                else
                {
                    if (PageSize > 0)
                    {
                        PageSizes.Add(new PageSize {
                            Size = PageSize
                        });
                    }
                    else
                    {
                        PageSizes.Add(new PageSize {
                            Size = 25
                        });
                        PageSizes.Add(new PageSize {
                            Size = 50
                        });
                        PageSizes.Add(new PageSize {
                            Size = 100
                        });
                        if (PageSize != 25 && PageSize != 50 && PageSize != 100)
                        {
                            PageSize = 25;
                        }
                    }
                }
            }
            else
            {
                if (PageSize > 0)
                {
                    PageSize = 0;
                }
            }
        }
コード例 #2
0
ファイル: Entity.cs プロジェクト: jeason0813/Transformalize
        protected override void Validate()
        {
            // if validation has been defined, check to see if corresponding valid and message fields are present and create them if not
            var calculatedKeys = new HashSet <string>(CalculatedFields.Select(f => f.Alias ?? f.Name).Distinct(), StringComparer.OrdinalIgnoreCase);

            if (Fields.Any(f => f.Validators.Any()))
            {
                foreach (var field in Fields.Where(f => f.Validators.Any()))
                {
                    if (!calculatedKeys.Contains(field.ValidField))
                    {
                        CalculatedFields.Add(new Field {
                            Name         = field.ValidField,
                            Alias        = field.ValidField,
                            Input        = false,
                            Type         = "bool",
                            Default      = "true",
                            IsCalculated = true
                        });
                    }

                    if (!calculatedKeys.Contains(field.MessageField))
                    {
                        CalculatedFields.Add(new Field {
                            Name = field.MessageField, Alias = field.MessageField, Length = "255", Default = "", IsCalculated = true, Input = false
                        });
                    }
                }
                // create an entity-wide valid field if necessary
                if (ValidField == string.Empty)
                {
                    var valid = Alias + "Valid";
                    if (!CalculatedFields.Any(f => f.Name.Equals(valid)))
                    {
                        var add = new Field {
                            Name = valid, Alias = valid, Type = "bool", ValidField = valid, Input = false, IsCalculated = true
                        };
                        add.Validators.Add(new Operation {
                            Method     = "all",
                            Operator   = "equals",
                            Value      = "true",
                            Parameters = GetAllFields().Where(f => f.ValidField != string.Empty).Select(f => f.ValidField).Distinct().Select(n => new Parameter {
                                Field = n
                            }).ToList()
                        });
                        CalculatedFields.Add(add);
                        ValidField = valid;
                    }
                }
            }

            var fields  = GetAllFields().ToArray();
            var names   = new HashSet <string>(fields.Select(f => f.Name).Distinct());
            var aliases = new HashSet <string>(fields.Select(f => f.Alias));

            ValidateVersion(names, aliases);
            ValidateFilter(names, aliases);
            ValidateOrder(names, aliases);

            foreach (var field in GetAllOutputFields().Where(f => f.Sortable == "true" && !string.IsNullOrEmpty(f.SortField)))
            {
                if (GetField(field.SortField) == null)
                {
                    Error($"Can't find sort field {field.SortField} defined in field {field.Alias}.");
                }
            }

            // Paging Madness
            if (Page > 0)
            {
                if (PageSizes.Any())
                {
                    if (PageSizes.All(ps => ps.Size != PageSize))
                    {
                        var first = PageSizes.First().Size;
                        Warn($"The entity {Name} has an invalid PageSize of {PageSize}. Set to {first}.");
                        PageSize = first;
                    }
                }
                else
                {
                    if (PageSize > 0)
                    {
                        PageSizes.Add(new PageSize {
                            Size = PageSize
                        });
                    }
                    else
                    {
                        PageSizes.Add(new PageSize {
                            Size = 25
                        });
                        PageSizes.Add(new PageSize {
                            Size = 50
                        });
                        PageSizes.Add(new PageSize {
                            Size = 100
                        });
                        if (PageSize != 25 && PageSize != 50 && PageSize != 100)
                        {
                            PageSize = 25;
                        }
                    }
                }
            }
            else
            {
                if (PageSize > 0)
                {
                    PageSize = 0;
                }
            }
        }