protected override Unit CalculateWidth(ElementSpecification element)
        {
            if (element.InnerHeight.IsDefined)
                return specification.Source.Width * (element.InnerHeight / specification.Source.Height);

            return element.InnerWidth;
        }
        public void Behave(ElementSpecification element)
        {
            if (element.InnerWidth.IsDefined)
                return;

            element.InnerWidth = CalculateWidth(element);
        }
Beispiel #3
0
        public ElementInsertionCommand(string configurationElementSelector, ElementSpecification elementSpecification)
            : base(configurationElementSelector)
        {
            Arguments.Validation.Constraints
            .IsNotNull(elementSpecification, nameof(elementSpecification))
            .Check();

            ElementSpecification = elementSpecification;
        }
Beispiel #4
0
        internal override ConfigurationCommand Execute(XmlElement configurationElement)
        {
            if (ElementSpecification.Exists(configurationElement))
            {
                throw new InvalidOperationException(
                          $"The configuration element already exists at '{string.Join("/", ConfigurationElementSelector, ElementSpecification.Selector)}'.");
            }
            var undoCommand = ConfigurationCommandFactory.CreateUndoCommandForInsertion(this);

            configurationElement.AppendChild(ElementSpecification.Execute(configurationElement.OwnerDocument));
            return(undoCommand);
        }
Beispiel #5
0
        LayoutedElement LayoutElement(ElementSpecification element)
        {
            var hasDefinedWidth = element.InnerWidth != Unit.Undefined;
            var hasDefinedHeight = element.InnerHeight != Unit.Undefined;

            if (element.Children.Any())
            {
                var verticalSpaceForChildren = hasDefinedWidth ? element.InnerWidth : containerInnerWidth - element.Edge.TotalHorizontal;
                var heightForChildren = hasDefinedHeight ? element.InnerHeight : Unit.Max(containerInnerHeight - element.Edge.TotalVertical, Unit.Zero);
                var lines = new LiningLayouter(verticalSpaceForChildren, heightForChildren).PositionElements(element.Children);
                var children = new Children(lines);

                return new LayoutedElement(element, children)
                {
                    Name = element.Name,
                    ForcedInnerWidth = hasDefinedWidth ? element.InnerWidth : children.OuterWidth,
                    ForcedInnerHeight = element.InnerHeight,
                };
            }

            if (hasDefinedWidth)
            {
                return new LayoutedElement(element, Children.Empty)
                {
                    Name = element.Name,
                    ForcedInnerWidth = element.InnerWidth,
                    ForcedInnerHeight = element.InnerHeight,
                };
            }

            return new LayoutedElement(element, Children.Empty)
            {
                Name = element.Name,
                ForcedInnerWidth = Unit.Undefined,
                ForcedInnerHeight = element.InnerHeight
            };
        }
Beispiel #6
0
        protected override void ValidateAgainstSegmentSpecification(string elementId, int elementNumber, string value)
        {
            if (SegmentSpec != null)
            {
                ElementSpecification spec = SegmentSpec.Elements[elementNumber - 1];
                if (spec != null)
                {
                    if (value.Length == 0 && spec.Required)
                    {
                        throw new ElementValidationException("Element {0} is required.", elementId, value);
                    }
                    if (value.Length > 0)
                    {
                        if (value.Length < spec.MinLength || spec.MaxLength > 0 && value.Length > spec.MaxLength)
                        {
                            throw new ElementValidationException("Element {0} cannot contain the value '{1}' because it must be between {2} and {3} characters in length.",
                                                                 elementId, value, spec.MinLength, spec.MaxLength);
                        }
                    }
                    switch (spec.Type)
                    {
                    case Specification.ElementDataTypeEnum.Numeric:
                        int number;
                        if (!int.TryParse(value, out number))
                        {
                            throw new ElementValidationException("Element {0} cannot contain the value '{1}' because it is constrained to be an implied decimal.",
                                                                 elementId, value);
                        }
                        break;

                    case Specification.ElementDataTypeEnum.Decimal:
                        decimal decNumber;
                        if (!decimal.TryParse(value, out decNumber))
                        {
                            throw new ElementValidationException("Element {0} cannot contain the value '{1}' because it is contrained to be a decimal.",
                                                                 elementId, value);
                        }
                        break;

                    case Specification.ElementDataTypeEnum.Identifier:
                        if (spec.AllowedListInclusive && spec.AllowedIdentifiers.Count > 0)
                        {
                            if (spec.AllowedIdentifiers.FirstOrDefault(ai => ai.ID == value) == null)
                            {
                                string[] ids = new string[spec.AllowedIdentifiers.Count];
                                for (int i = 0; i < spec.AllowedIdentifiers.Count; i++)
                                {
                                    ids[i] = spec.AllowedIdentifiers[i].ID;
                                }

                                string expected = "";
                                if (ids.Length > 1)
                                {
                                    expected  = String.Join(", ", ids, 0, ids.Length - 1);
                                    expected += " or " + ids[ids.Length - 1];
                                }
                                else
                                {
                                    expected = ids[0];
                                }

                                throw new ElementValidationException("Element '{0}' cannot contain the value '{1}'.  Specification restricts this to {2}.", elementId, value, expected);
                            }
                        }
                        break;
                    }
                }
            }
        }
 protected abstract Unit CalculateWidth(ElementSpecification element);
 public void AddChild(ElementSpecification child)
 {
     children.Add(child);
 }
Beispiel #9
0
 LayoutedElement(ElementSpecification specification, IEnumerable<Line> children)
     : this(specification, new Children(children))
 {
 }
Beispiel #10
0
 public LayoutedElement(ElementSpecification specification, Children children)
 {
     this.specification = specification;
     this.children = children;
 }