Пример #1
0
        protected virtual void HandleChild(ParseResult result, XElement child)
        {
            switch (child.Name.LocalName.ToLower())
            {
            case "input":

                var input = new Input(Context, SupportedFeatures);
                input.Parse(result, child);

                if (!result.IsOkForRender())
                {
                    return;
                }

                if (Context == NotificationType.Toast)
                {
                    if (Inputs.Count >= 5)
                    {
                        result.AddErrorButRenderAllowed("Toasts can only display up to 5 inputs.", GetErrorPositionInfo(child));
                        return;
                    }
                }

                Inputs.Add(input);
                input.Parent = this;

                break;


            case "action":

                var action = new Action(Context, SupportedFeatures);
                action.Parse(result, child);

                if (!result.IsOkForRender())
                {
                    return;
                }

                if (Context == NotificationType.Toast)
                {
                    if (ActionElements.Count >= 5)
                    {
                        result.AddErrorButRenderAllowed("Toasts can only display up to 5 actions.", GetErrorPositionInfo(child));
                        return;
                    }
                }

                ActionElements.Add(action);
                action.Parent = this;

                break;


            default:
                result.AddWarning($"Invalid child {child.Name.LocalName} under actions element.", GetErrorPositionInfo(child));
                break;
            }
        }
        internal virtual void ParseKnownAttributes(XElement node, AttributesHelper attributes, ParseResult result)
        {
            // id is required
            XAttribute attrId = attributes.PopAttribute(ATTR_ID);

            if (attrId == null)
            {
                result.AddError("id attribute on action element is required.", XmlTemplateParser.GetErrorPositionInfo(node));
                throw new IncompleteElementException();
            }

            this.Id = attrId.Value;


            // arguments is required
            XAttribute attrArguments = attributes.PopAttribute(ATTR_ARGUMENTS);

            if (attrArguments == null)
            {
                result.AddErrorButRenderAllowed("arguments attribute on action element is required.", XmlTemplateParser.GetErrorPositionInfo(node));
                throw new IncompleteElementException();
            }

            this.Arguments = attrArguments.Value;


            // activationType is optional
            ActivationType type;

            if (TryParseEnum(result, attributes, ATTR_ACTIVATIONTYPE, out type))
            {
                this.ActivationType = type;
            }
        }
        internal void ParseActivatableElementAttributes(XElement node, AttributesHelper attributes, ParseResult result)
        {
            IActivatableElement el = this as IActivatableElement;

            // activationType is optional
            ActivationType type;

            if (TryParseEnum(result, attributes, ATTR_ACTIVATIONTYPE, out type))
            {
                el.ActivationType = type;
            }


            // arguments is required
            XAttribute attrArguments = attributes.PopAttribute(ATTR_ARGUMENTS);

            if (attrArguments == null)
            {
                // If we're in an activation type that requires attributes
                if (el.ActivationType != ActivationType.None)
                {
                    result.AddErrorButRenderAllowed("arguments attribute is required.", XmlTemplateParser.GetErrorPositionInfo(node));
                    throw new IncompleteElementException();
                }
            }

            else
            {
                el.Arguments = attrArguments.Value;
            }
        }
        protected void HandleChild(ParseResult result, XElement child, string baseUri, bool addImageQuery)
        {
            switch (child.Name.LocalName.ToLower())
            {
            case "text":

                AdaptiveTextField text = new AdaptiveTextField(Context, SupportedFeatures);
                text.Parse(result, child, false);

                if (!result.IsOkForRender())
                {
                    throw new IncompleteElementException();
                }

                if (text != null)
                {
                    this.Add(text);
                }

                break;



            case "image":

                AdaptiveImage image = new AdaptiveImage(Context, SupportedFeatures);
                image.Parse(result, child, baseUri, addImageQuery);

                if (!result.IsOkForRender())
                {
                    throw new IncompleteElementException();
                }

                if (image != null)
                {
                    if (image.Placement != Placement.Inline)
                    {
                        result.AddErrorButRenderAllowed("You cannot place a non-inline image element inside a subgroup.", GetErrorPositionInfo(child));
                    }

                    this.Add(image);
                }

                break;



            default:
                result.AddWarning($"Invalid child \"{child.Name.LocalName}\" under subgroup element. It will be ignored.", GetErrorPositionInfo(child));
                break;
            }
        }
Пример #5
0
        internal virtual void ParseKnownAttributes(XElement node, AttributesHelper attributes, ParseResult result)
        {
            // target is required
            XAttribute attrTarget = attributes.PopAttribute(ATTR_TARGET);

            if (attrTarget == null)
            {
                result.AddError($"{ATTR_TARGET} attribute on {ELEMENT_NAME} element is required.", XmlTemplateParser.GetErrorPositionInfo(node));
                throw new IncompleteElementException();
            }

            this.Target = attrTarget.Value;


            // property is required
            SetterProperties property;

            if (TryParseEnum(result, attributes, ATTR_PROPERTY, out property))
            {
                this.Property = property;
            }
            else
            {
                result.AddErrorButRenderAllowed($"{ATTR_PROPERTY} attribute on {ELEMENT_NAME} element is required.", XmlTemplateParser.GetErrorPositionInfo(node));
                throw new IncompleteElementException();
            }


            // value is required
            XAttribute attrValue = attributes.PopAttribute(ATTR_VALUE);

            if (attrValue == null)
            {
                result.AddErrorButRenderAllowed($"{ATTR_VALUE} attribute on {ELEMENT_NAME} element is required.", XmlTemplateParser.GetErrorPositionInfo(node));
                throw new IncompleteElementException();
            }

            this.Value = attrValue.Value;
        }
Пример #6
0
        protected virtual void ParseKnownAttributes(XElement node, AttributesHelper attributes, ParseResult result)
        {
            // id is required
            XAttribute attrId = attributes.PopAttribute(ATTR_ID);

            if (attrId == null)
            {
                result.AddError("id attribute on input element is required.", XmlTemplateParser.GetErrorPositionInfo(node));
                throw new IncompleteElementException();
            }

            // type is required
            InputType type;

            if (!TryParseEnum(result, attributes, ATTR_TYPE, out type))
            {
                result.AddErrorButRenderAllowed("type attribute on input element is required.", XmlTemplateParser.GetErrorPositionInfo(node));
                throw new IncompleteElementException();
            }

            this.Id   = attrId.Value;
            this.Type = type;


            // title is optional
            var attrTitle = attributes.PopAttribute(ATTR_TITLE);

            if (attrTitle != null)
            {
                this.Title = attrTitle.Value;
            }

            // placeHolderContent is optional
            var attrPlaceHolderContent = attributes.PopAttribute(ATTR_PLACEHOLDERCONTENT);

            if (attrPlaceHolderContent != null)
            {
                this.PlaceHolderContent = attrPlaceHolderContent.Value;
            }

            // defaultInput is optional
            var attrDefaultInput = attributes.PopAttribute(ATTR_DEFAULTINPUT);

            if (attrDefaultInput != null)
            {
                this.DefaultInput = attrDefaultInput.Value;
            }
        }
Пример #7
0
        protected virtual void ParseKnownAttributes(XElement node, AttributesHelper attributes, ParseResult result)
        {
            // id is required
            XAttribute attrId = attributes.PopAttribute(ATTR_ID);

            if (attrId == null)
            {
                result.AddError("id attribute on input element is required.", XmlTemplateParser.GetErrorPositionInfo(node));
                throw new IncompleteElementException();
            }

            // type is required
            XAttribute attrContent = attributes.PopAttribute(ATTR_CONTENT);

            if (attrContent == null)
            {
                result.AddErrorButRenderAllowed("content attribute on input element is required.", XmlTemplateParser.GetErrorPositionInfo(node));
                throw new IncompleteElementException();
            }

            this.Id      = attrId.Value;
            this.Content = attrContent.Value;
        }
Пример #8
0
        internal void ParseKnownAttributes(XElement node, AttributesHelper attributes, ParseResult result)
        {
            // We parse title first, and we only completely fail on title, since if id isn't provided,
            // we can at least still render something for the preview (we still display error though).
            // We'll assume that the developer will add the id before they send the toast.

            // title is required
            XAttribute attrTitle = attributes.PopAttribute(ATTR_TITLE);

            if (attrTitle == null)
            {
                result.AddErrorButRenderAllowed("title attribute on header element is required.", XmlTemplateParser.GetErrorPositionInfo(node));

                // We'll fail without a title
                throw new IncompleteElementException();
            }
            else
            {
                if (string.IsNullOrWhiteSpace(attrTitle.Value))
                {
                    result.AddWarning("title attribute in header element must contain a string. The header will be dropped.", XmlTemplateParser.GetErrorPositionInfo(attrTitle));
                    throw new IncompleteElementException();
                }
                else
                {
                    Title = attrTitle.Value;
                }
            }

            // id is required
            XAttribute attrId = attributes.PopAttribute(ATTR_ID);

            if (attrId == null)
            {
                result.AddErrorButRenderAllowed("id attribute on header element is required.", XmlTemplateParser.GetErrorPositionInfo(node));
            }
            else
            {
                if (string.IsNullOrWhiteSpace(attrId.Value))
                {
                    result.AddWarning("id attribute in header element must contain a string. The header will be dropped.", XmlTemplateParser.GetErrorPositionInfo(attrId));
                    throw new IncompleteElementException();
                }
                else
                {
                    Id = attrId.Value;
                }
            }

            // arguments is required
            XAttribute attrArguments = attributes.PopAttribute(ATTR_ARGUMENTS);

            if (attrArguments == null)
            {
                result.AddErrorButRenderAllowed("arguments attribute on header element is required.", XmlTemplateParser.GetErrorPositionInfo(node));
            }
            else
            {
                // Empty string in arguments is allowed
                Arguments = attrArguments.Value;
            }

            // activationType is optional
            ActivationType type;

            if (TryParseEnum(result, attributes, ATTR_ACTIVATIONTYPE, out type))
            {
                ActivationType = type;
            }
        }
Пример #9
0
        private void HandleChild(ParseResult result, XElement child)
        {
            if (child.IsType("visual"))
            {
                if (Visual != null)
                {
                    result.AddWarning("A visual element was already provided. Only the first one will be used.", GetErrorPositionInfo(child));
                    return;
                }

                Visual visual = new Visual(NotificationType.Toast, SupportedFeatures);
                visual.Parse(result, child);

                Visual = visual;
            }

            else if (child.IsType("actions"))
            {
                if (Actions != null)
                {
                    result.AddWarning("An actions element was already provided. Only the first one will be used.", GetErrorPositionInfo(child));
                    return;
                }

                Actions actions = new Actions(NotificationType.Toast, SupportedFeatures);
                actions.Parse(result, child);

                Actions = actions;
            }

            else if (child.IsType("audio"))
            {
                if (Audio != null)
                {
                    result.AddWarning("An audio element was already provided. Only the first one will be used.", GetErrorPositionInfo(child));
                    return;
                }

                Audio audio = new Audio(NotificationType.Toast, SupportedFeatures);
                audio.Parse(result, child);

                Audio = audio;
            }

            else if (SupportedFeatures.ToastHeaders && child.IsType("header"))
            {
                if (Header != null)
                {
                    result.AddErrorButRenderAllowed("A header element was already provided. Only one header is allowed.", GetErrorPositionInfo(child));
                    return;
                }

                Header header = new Header(NotificationType.Toast, SupportedFeatures);
                header.Parse(result, child);

                Header = header;
            }

            else
            {
                result.AddError($"Invalid child {child.Name.LocalName} under toast element.", GetErrorPositionInfo(child));
            }
        }
        internal void ParseKnownAttributes(XElement node, AttributesHelper attributes, ParseResult result)
        {
            // title is optional
            string bindingTitle;

            TryPopAttributeValueWithBinding(result, attributes, ATTR_TITLE, out bindingTitle, (val) =>
            {
                Title = val;
            });
            BindingTitle = bindingTitle;

            // valueStringOverride is optional
            string bindingValueStringOverride;

            TryPopAttributeValueWithBinding(result, attributes, ATTR_VALUE_STRING_OVERRIDE, out bindingValueStringOverride, (val) =>
            {
                ValueStringOverride = val;
            });
            BindingValueStringOverride = bindingValueStringOverride;

            // value is required
            string bindingValue;
            bool   hadValue = TryPopAttributeValueWithBinding(result, attributes, ATTR_VALUE, out bindingValue, (val) =>
            {
                if (val == null)
                {
                    throw new ParseErrorException(new ParseError(ParseErrorType.ErrorButRenderAllowed, "progress value wasn't provided.", XmlTemplateParser.GetErrorPositionInfo(node)));
                }

                double value = 0;
                if (val.Equals("indeterminate", StringComparison.CurrentCultureIgnoreCase))
                {
                    IsIndeterminate = true;
                }
                else if (!double.TryParse(val, out value))
                {
                    throw new ParseErrorException(new ParseError(ParseErrorType.ErrorButRenderAllowed, "progress value must be a double between 0.0 and 1.0, or 'indeterminate'.", XmlTemplateParser.GetErrorPositionInfo(node)));
                }
                else
                {
                    if (value < 0 || value > 1)
                    {
                        IsIndeterminate = false;
                        Value           = (value < 0) ? 0 : 1;
                        throw new ParseErrorException(new ParseError(ParseErrorType.ErrorButRenderAllowed, "progress value must be between 0.0 and 1.0, or 'indeterminate'.", XmlTemplateParser.GetErrorPositionInfo(node)));
                    }

                    IsIndeterminate = false;
                    Value           = value;
                }
            });

            if (!hadValue)
            {
                Value = 0;
                result.AddErrorButRenderAllowed("value attribute on progress element is required and must be a double between 0.0 and 1.0, or 'indeterminate'.", XmlTemplateParser.GetErrorPositionInfo(node));
            }

            BindingValue = bindingValue;

            // status is optional
            string bindingStatus;

            TryPopAttributeValueWithBinding(result, attributes, ATTR_STATUS, out bindingStatus, (val) =>
            {
                Status = val;
            });
            BindingStatus = bindingStatus;
        }