protected override Property SetSubprop(Property baseProp, string subpropName, Property subProp)
        {
            LengthRange val = baseProp.GetLengthRange();

            val.SetComponent(subpropName, subProp, false);
            return(baseProp);
        }
        public override Property ConvertProperty(Property p, PropertyList pList, FObj fo)
        {
            if (p is LengthRangeProperty)
            {
                return(p);
            }
            if (!(p is EnumProperty))
            {
                p = m_shorthandMaker.ConvertProperty(p, pList, fo);
            }
            if (p != null)
            {
                Property    prop = MakeCompound(pList, fo);
                LengthRange pval = prop.GetLengthRange();

                pval.SetComponent("minimum", p, false);
                pval.SetComponent("optimum", p, false);
                pval.SetComponent("maximum", p, false);
                return(prop);
            }
            else
            {
                return(null);
            }
        }
예제 #3
0
        /// <summary>Indicates whether the current object is equal to another object of the same type.</summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>true if the current object is equal to the <paramref name="other">other</paramref> parameter; otherwise, false.</returns>
        public bool Equals(OasSchema other)
        {
            if (other is null) return false;
            if (ReferenceEquals(this, other)) return true;

            if (JsonType != other.JsonType) return false;
            if (Format != other.Format) return false;
            if (Options != other.Options) return false;
            if (!NumberRange.Equals(other.NumberRange)) return false;
            if (!ItemsRange.Equals(other.ItemsRange)) return false;
            if (!LengthRange.Equals(other.LengthRange)) return false;
            if (!PropertiesRange.Equals(other.PropertiesRange)) return false;
            if (!ExternalDocumentation.Equals(other.ExternalDocumentation)) return false;
            if (!StringComparer.Ordinal.Equals(Title, other.Title)) return false;
            if (!StringComparer.Ordinal.Equals(Description, other.Description)) return false;
            if (!StringComparer.Ordinal.Equals(Pattern, other.Pattern)) return false;
            if (!Enum.NullableSetEquals(other.Enum)) return false;
            if (!AllOf.NullableSetEquals(other.AllOf)) return false;
            if (!OneOf.NullableSetEquals(other.OneOf)) return false;
            if (!AnyOf.NullableSetEquals(other.AnyOf)) return false;
            if (!Not.NullableSetEquals(other.Not)) return false;
            if (Items != other.Items) return false;
            if (!Properties.NullableDictionaryEquals(other.Properties)) return false;
            if (!AdditionalProperties.NullableDictionaryEquals(other.AdditionalProperties)) return false;

            return true;
        }
예제 #4
0
        /// <summary>Returns the hash code for this instance.</summary>
        /// <returns>A 32-bit signed integer that is the hash code for this instance.</returns>
        public override int GetHashCode()
        {
            unchecked
            {
                var hc = 17L;

                hc = (hc * 23) + JsonType.GetHashCode();
                hc = (hc * 23) + Options.GetHashCode();
                hc = (hc * 23) + NumberRange.GetHashCode();
                hc = (hc * 23) + ItemsRange.GetHashCode();
                hc = (hc * 23) + LengthRange.GetHashCode();
                hc = (hc * 23) + PropertiesRange.GetHashCode();
                if (ExternalDocumentation != null)
                {
                    hc = (hc * 23) + ExternalDocumentation.GetHashCode();
                }
                if (Title != null)
                {
                    hc = (hc * 23) + StringComparer.Ordinal.GetHashCode(Title);
                }
                if (Format != null)
                {
                    hc = (hc * 23) + StringComparer.Ordinal.GetHashCode(Format);
                }
                if (Description != null)
                {
                    hc = (hc * 23) + StringComparer.Ordinal.GetHashCode(Description);
                }
                if (Pattern != null)
                {
                    hc = (hc * 23) + StringComparer.Ordinal.GetHashCode(Pattern);
                }
                hc = (hc * 23) + Enum.Count;
                hc = (hc * 23) + AllOf.Count;
                hc = (hc * 23) + OneOf.Count;
                hc = (hc * 23) + AnyOf.Count;
                hc = (hc * 23) + Not.Count;
                hc = (hc * 23) + Items.GetHashCode();
                hc = (hc * 23) + Properties.Count;
                hc = (hc * 23) + AdditionalProperties.Count;

                return(((int)(hc >> 32)) ^ (int)hc);
            }
        }
        protected override Property MakeCompound(PropertyList pList, FObj fo)
        {
            LengthRange p = new LengthRange();
            Property    subProp;

            subProp = GetSubpropMaker("minimum").Make(pList,
                                                      GetDefaultForMinimum(), fo);
            p.SetComponent("minimum", subProp, true);

            subProp = GetSubpropMaker("optimum").Make(pList,
                                                      GetDefaultForOptimum(), fo);
            p.SetComponent("optimum", subProp, true);

            subProp = GetSubpropMaker("maximum").Make(pList,
                                                      GetDefaultForMaximum(), fo);
            p.SetComponent("maximum", subProp, true);

            return(new LengthRangeProperty(p));
        }
예제 #6
0
        public override Status Layout(Area area)
        {
            if (this.marker == MarkerBreakAfter)
            {
                return(new Status(Status.OK));
            }

            if (this.marker == MarkerStart)
            {
                AccessibilityProps    mAccProps = propMgr.GetAccessibilityProps();
                AuralProps            mAurProps = propMgr.GetAuralProps();
                BorderAndPadding      bap       = propMgr.GetBorderAndPadding();
                BackgroundProps       bProps    = propMgr.GetBackgroundProps();
                MarginProps           mProps    = propMgr.GetMarginProps();
                RelativePositionProps mRelProps = propMgr.GetRelativePositionProps();

                this.breakBefore = this.properties.GetProperty("break-before").GetEnum();
                this.breakAfter  = this.properties.GetProperty("break-after").GetEnum();
                this.spaceBefore =
                    this.properties.GetProperty("space-before.optimum").GetLength().MValue();
                this.spaceAfter =
                    this.properties.GetProperty("space-after.optimum").GetLength().MValue();
                this.ipd =
                    this.properties.GetProperty("inline-progression-dimension").
                    GetLengthRange();
                this.height      = this.properties.GetProperty("height").GetLength().MValue();
                this.bAutoLayout = (this.properties.GetProperty("table-layout").GetEnum() ==
                                    TableLayout.AUTO);

                this.id = this.properties.GetProperty("id").GetString();

                this.omitHeaderAtBreak =
                    this.properties.GetProperty("table-omit-header-at-break").GetEnum()
                    == TableOmitHeaderAtBreak.TRUE;
                this.omitFooterAtBreak =
                    this.properties.GetProperty("table-omit-footer-at-break").GetEnum()
                    == TableOmitFooterAtBreak.TRUE;

                if (area is BlockArea)
                {
                    area.end();
                }
                if (this.areaContainer
                    == null)
                {
                    area.getIDReferences().CreateID(id);
                }

                this.marker = 0;

                if (breakBefore == BreakBefore.PAGE)
                {
                    return(new Status(Status.FORCE_PAGE_BREAK));
                }

                if (breakBefore == BreakBefore.ODD_PAGE)
                {
                    return(new Status(Status.FORCE_PAGE_BREAK_ODD));
                }

                if (breakBefore == BreakBefore.EVEN_PAGE)
                {
                    return(new Status(Status.FORCE_PAGE_BREAK_EVEN));
                }
            }

            if ((spaceBefore != 0) && (this.marker == 0))
            {
                area.addDisplaySpace(spaceBefore);
            }

            if (marker == 0 && areaContainer == null)
            {
                area.getIDReferences().ConfigureID(id, area);
            }

            int spaceLeft = area.spaceLeft();

            this.areaContainer =
                new AreaContainer(propMgr.GetFontState(area.getFontInfo()), 0, 0,
                                  area.getAllocationWidth(), area.spaceLeft(),
                                  Position.STATIC);

            areaContainer.foCreator = this;
            areaContainer.setPage(area.getPage());
            areaContainer.setParent(area);
            areaContainer.setBackground(propMgr.GetBackgroundProps());
            areaContainer.setBorderAndPadding(propMgr.GetBorderAndPadding());
            areaContainer.start();

            areaContainer.setAbsoluteHeight(area.getAbsoluteHeight());
            areaContainer.setIDReferences(area.getIDReferences());

            bool addedHeader = false;
            bool addedFooter = false;
            int  numChildren = this.children.Count;

            if (columns.Count == 0)
            {
                FindColumns(areaContainer);
                if (this.bAutoLayout)
                {
                    FonetDriver.ActiveDriver.FireFonetWarning(
                        "table-layout=auto is not supported, using fixed!");
                }
                this.contentWidth =
                    CalcFixedColumnWidths(areaContainer.getAllocationWidth());
            }
            areaContainer.setAllocationWidth(this.contentWidth);
            layoutColumns(areaContainer);

            for (int i = this.marker; i < numChildren; i++)
            {
                FONode fo = (FONode)children[i];
                if (fo is TableHeader)
                {
                    if (columns.Count == 0)
                    {
                        FonetDriver.ActiveDriver.FireFonetWarning(
                            "Current implementation of tables requires a table-column for each column, indicating column-width");
                        return(new Status(Status.OK));
                    }
                    tableHeader = (TableHeader)fo;
                    tableHeader.SetColumns(columns);
                }
                else if (fo is TableFooter)
                {
                    if (columns.Count == 0)
                    {
                        FonetDriver.ActiveDriver.FireFonetWarning(
                            "Current implementation of tables requires a table-column for each column, indicating column-width");
                        return(new Status(Status.OK));
                    }
                    tableFooter = (TableFooter)fo;
                    tableFooter.SetColumns(columns);
                }
                else if (fo is TableBody)
                {
                    if (columns.Count == 0)
                    {
                        FonetDriver.ActiveDriver.FireFonetWarning(
                            "Current implementation of tables requires a table-column for each column, indicating column-width");
                        return(new Status(Status.OK));
                    }
                    Status status;
                    if (tableHeader != null && !addedHeader)
                    {
                        if ((status =
                                 tableHeader.Layout(areaContainer)).isIncomplete())
                        {
                            tableHeader.ResetMarker();
                            return(new Status(Status.AREA_FULL_NONE));
                        }
                        addedHeader = true;
                        tableHeader.ResetMarker();
                        area.setMaxHeight(area.getMaxHeight() - spaceLeft
                                          + this.areaContainer.getMaxHeight());
                    }
                    if (tableFooter != null && !this.omitFooterAtBreak &&
                        !addedFooter)
                    {
                        if ((status =
                                 tableFooter.Layout(areaContainer)).isIncomplete())
                        {
                            return(new Status(Status.AREA_FULL_NONE));
                        }
                        addedFooter = true;
                        tableFooter.ResetMarker();
                    }
                    fo.SetWidows(widows);
                    fo.SetOrphans(orphans);
                    ((TableBody)fo).SetColumns(columns);

                    if ((status = fo.Layout(areaContainer)).isIncomplete())
                    {
                        this.marker = i;
                        if (bodyCount == 0 &&
                            status.getCode() == Status.AREA_FULL_NONE)
                        {
                            if (tableHeader != null)
                            {
                                tableHeader.RemoveLayout(areaContainer);
                            }
                            if (tableFooter != null)
                            {
                                tableFooter.RemoveLayout(areaContainer);
                            }
                            ResetMarker();
                        }
                        if (areaContainer.getContentHeight() > 0)
                        {
                            area.addChild(areaContainer);
                            area.increaseHeight(areaContainer.GetHeight());
                            if (this.omitHeaderAtBreak)
                            {
                                tableHeader = null;
                            }
                            if (tableFooter != null && !this.omitFooterAtBreak)
                            {
                                ((TableBody)fo).SetYPosition(tableFooter.GetYPosition());
                                tableFooter.SetYPosition(tableFooter.GetYPosition()
                                                         + ((TableBody)fo).GetHeight());
                            }
                            SetupColumnHeights();
                            status = new Status(Status.AREA_FULL_SOME);
                        }
                        return(status);
                    }
                    else
                    {
                        bodyCount++;
                    }
                    area.setMaxHeight(area.getMaxHeight() - spaceLeft
                                      + this.areaContainer.getMaxHeight());
                    if (tableFooter != null && !this.omitFooterAtBreak)
                    {
                        ((TableBody)fo).SetYPosition(tableFooter.GetYPosition());
                        tableFooter.SetYPosition(tableFooter.GetYPosition()
                                                 + ((TableBody)fo).GetHeight());
                    }
                }
            }

            if (tableFooter != null && this.omitFooterAtBreak)
            {
                if (tableFooter.Layout(areaContainer).isIncomplete())
                {
                    FonetDriver.ActiveDriver.FireFonetWarning(
                        "Footer could not fit on page, moving last body row to next page");
                    area.addChild(areaContainer);
                    area.increaseHeight(areaContainer.GetHeight());
                    if (this.omitHeaderAtBreak)
                    {
                        tableHeader = null;
                    }
                    tableFooter.RemoveLayout(areaContainer);
                    tableFooter.ResetMarker();
                    return(new Status(Status.AREA_FULL_SOME));
                }
            }

            if (height != 0)
            {
                areaContainer.SetHeight(height);
            }

            SetupColumnHeights();

            areaContainer.end();
            area.addChild(areaContainer);

            area.increaseHeight(areaContainer.GetHeight());

            if (spaceAfter != 0)
            {
                area.addDisplaySpace(spaceAfter);
            }

            if (area is BlockArea)
            {
                area.start();
            }

            if (breakAfter == BreakAfter.PAGE)
            {
                this.marker = MarkerBreakAfter;
                return(new Status(Status.FORCE_PAGE_BREAK));
            }

            if (breakAfter == BreakAfter.ODD_PAGE)
            {
                this.marker = MarkerBreakAfter;
                return(new Status(Status.FORCE_PAGE_BREAK_ODD));
            }

            if (breakAfter == BreakAfter.EVEN_PAGE)
            {
                this.marker = MarkerBreakAfter;
                return(new Status(Status.FORCE_PAGE_BREAK_EVEN));
            }

            return(new Status(Status.OK));
        }
예제 #7
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            //类型
            var valueType     = validationContext.ObjectType.GetProperty(validationContext.MemberName).PropertyType;
            var valueBaseType = valueType.BaseType;

            //验证的属性
            string valName = validationContext.MemberName;
            //消息中的字段名称
            string valDisplayName = valName;
            //必填
            bool valRequired = false;

            var fsColumnAttr = validationContext.ObjectType.GetProperty(valName).CustomAttributes.ToList().Where(p => p.AttributeType == typeof(Model.FsColumnAttribute)).FirstOrDefault();

            if (fsColumnAttr != null) //FreeSQL实体类
            {
                var attrCount = fsColumnAttr.ConstructorArguments.Count;
                if (attrCount > 0)
                {
                    valDisplayName = fsColumnAttr.ConstructorArguments[0].Value.ObjToString();               //取是否必填
                }
                if (attrCount > 1)
                {
                    valRequired = fsColumnAttr.ConstructorArguments[1].Value.ObjToBool();
                }
            }
            else
            {
                //ViewModel  DTO实体类
                valRequired = Required;
                if (!string.IsNullOrWhiteSpace(DisplayName))
                {
                    valDisplayName = DisplayName;
                }
            }

            if (VerRequired)
            {
                valRequired = VerRequired;
            }

            string inputText = value == null ? "" : Convert.ToString(value);

            if (valRequired)
            {
                if (string.IsNullOrEmpty(inputText))
                {
                    return(new ValidationResult($"{valDisplayName}不能为空", new[] { valName }));
                }
            }

            //枚举类型
            if (typeof(Enum) == valueBaseType)
            {
                if (!Enum.IsDefined(valueType, value))
                {
                    return(new ValidationResult($"{valDisplayName}的值不在枚举限定范围内", new[] { valName }));
                }
            }

            if (string.IsNullOrWhiteSpace(inputText))
            {
                return(ValidationResult.Success);
            }

            //验证时间
            if (typeof(DateTime) == valueType)
            {
                if (value.ObjToDate() == DateTime.MinValue)
                {
                    return(new ValidationResult($"缺少{valDisplayName}", new[] { valName }));
                }
            }

            //验证长度范围
            if (!string.IsNullOrWhiteSpace(LengthRange))
            {
                var arr = LengthRange.SplitString("-");
                var ipnutTextByteLength = inputText.ByteLength();
                if (arr.Length == 2)
                {
                    if (ipnutTextByteLength < arr[0].ObjToInt() || ipnutTextByteLength > arr[1].ObjToInt())
                    {
                        return(new ValidationResult($"{valDisplayName}长度范围在{LengthRange}之间", new[] { valName }));
                    }
                }
                else
                {
                    var tempLength = LengthRange.ObjToInt(0);
                    if (tempLength <= 0)
                    {
                        return(new ValidationResult($"{valDisplayName}LengthRange属性值有误", new[] { valName }));
                    }
                    else
                    {
                        if (ipnutTextByteLength != tempLength)
                        {
                            return(new ValidationResult($"{valDisplayName}长度为{tempLength}个字符", new[] { valName }));
                        }
                    }
                }
            }

            switch (ValidateType)
            {
            case ValidateType.None:
                break;

            case ValidateType.Email:
                if (!Common.Helper.ValidateHelper.IsEmail(inputText))
                {
                    return(new ValidationResult($"{valDisplayName}内容不是合法的邮箱", new[] { valName }));
                }
                break;

            case ValidateType.Date:
                inputText = inputText.Split(' ')[0].Replace("/", "-");
                if (!Common.Helper.ValidateHelper.IsDate(inputText))
                {
                    return(new ValidationResult($"{valDisplayName}内容不是合法的日期", new[] { valName }));
                }
                break;

            case ValidateType.DateYear:
                if (!Common.Helper.ValidateHelper.IsDateYear(inputText))
                {
                    return(new ValidationResult($"{valDisplayName}内容不是合法的年份", new[] { valName }));
                }
                break;

            case ValidateType.DateMonth:
                if (!Common.Helper.ValidateHelper.IsDateMonth(inputText))
                {
                    return(new ValidationResult($"{valDisplayName}内容不是合法的月份", new[] { valName }));
                }
                break;

            case ValidateType.DateTime:
                inputText = inputText.Replace("/", "-").Replace(" 0:", " 00:");
                if (!Common.Helper.ValidateHelper.IsDateTime(inputText))
                {
                    return(new ValidationResult($"{valDisplayName}内容不是合法的时间日期", new[] { valName }));
                }
                break;

            case ValidateType.Number:
                if (!Common.Helper.ValidateHelper.IsNumeric(inputText))
                {
                    return(new ValidationResult($"{valDisplayName}内容不是合法的数字", new[] { valName }));
                }
                break;

            case ValidateType.Money:
                if (!Common.Helper.ValidateHelper.IsMoney(inputText))
                {
                    return(new ValidationResult($"{valDisplayName}内容不是合法的非负金额", new[] { valName }));
                }
                break;

            case ValidateType.MoneyIncloudMinus:
                if (!Common.Helper.ValidateHelper.IsMoneyIncloudMinus(inputText))
                {
                    return(new ValidationResult($"{valDisplayName}内容不是合法的金额", new[] { valName }));
                }
                break;

            case ValidateType.IdNo:
                if (!Common.Helper.ValidateHelper.IsIdCard(inputText))
                {
                    return(new ValidationResult($"{valDisplayName}内容不是合法的身份证号码", new[] { valName }));
                }
                break;

            case ValidateType.CellPhone:
                if (!Common.Helper.ValidateHelper.IsCellPhone(inputText))
                {
                    return(new ValidationResult($"{valDisplayName}内容不是合法的手机号", new[] { valName }));
                }
                break;

            case ValidateType.WebURL:
                if (!Common.Helper.ValidateHelper.IsWebUrl(inputText))
                {
                    return(new ValidationResult($"{valDisplayName}内容不是合法的网址", new[] { valName }));
                }
                break;

            case ValidateType.AccountName:
                if (!Common.Helper.ValidateHelper.IsAccountName(inputText))
                {
                    return(new ValidationResult($"{valDisplayName}只能由数字、字母、下划线组成", new[] { valName }));
                }
                break;

            default:
                break;
            }
            if (!string.IsNullOrWhiteSpace(NumberRange))
            {
                var arr = NumberRange.SplitString("-");
                if (arr.Length != 2)
                {
                    return(new ValidationResult($"{valDisplayName}LengthRange属性值有误", new[] { valName }));
                }
                var inputTextDecimal = inputText.ObjToDecimal(0);
                if (inputTextDecimal < arr[0].ObjToDecimal(0) || inputTextDecimal > arr[1].ObjToDecimal(0))
                {
                    return(new ValidationResult($"{valDisplayName}值范围在{NumberRange}之间", new[] { valName }));
                }
            }

            return(ValidationResult.Success);
        }
        public override Property GetSubpropValue(Property baseProp, string subpropName)
        {
            LengthRange val = baseProp.GetLengthRange();

            return(val.GetComponent(subpropName));
        }
예제 #9
0
 public LengthRangeProperty(LengthRange lengthRange)
 {
     this.lengthRange = lengthRange;
 }