Exemple #1
0
        internal virtual void ParseKnownAttributes(XElement node, AttributesHelper attributes, ParseResult result, string baseUri, bool addImageQuery)
        {
            // src is required
            XAttribute attrSrc = attributes.PopAttribute(ATTR_IMAGE_SRC);

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

            this.Src = XmlTemplateParser.ConstructUri(attrSrc.Value, baseUri, addImageQuery);



            // alt is optional, I don't use it right now either
            attributes.PopAttribute(ATTR_IMAGE_ALT);


            // hint-crop is optional
            HintCrop hintCrop;

            if (TryParseEnum(result, attributes, ATTR_IMAGE_HINT_CROP, out hintCrop))
            {
                this.HintCrop = hintCrop;
            }
        }
Exemple #2
0
        internal virtual void ParseKnownAttributes(XElement node, AttributesHelper attributes, ParseResult result)
        {
            // src is optional
            var srcAttr = attributes.PopAttribute(ATTR_SRC);

            if (srcAttr != null)
            {
                Uri srcUri;
                if (Uri.TryCreate(srcAttr.Value, UriKind.RelativeOrAbsolute, out srcUri))
                {
                    Src = srcUri;
                }
                else
                {
                    result.AddWarning("Audio src value must be a valid Uri.", XmlTemplateParser.GetErrorPositionInfo(node));
                }
            }

            // loop is optional, must be bool
            bool boolean;

            if (TryParse(result, attributes, ATTR_LOOP, out boolean))
            {
                Loop = boolean;
            }

            if (TryParse(result, attributes, ATTR_SILENT, out boolean))
            {
                Silent = boolean;
            }
        }
        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;
            }
        }
Exemple #4
0
        internal 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();
            }

            this.Id = attrId.Value;
        }
Exemple #5
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;
            }
        }
        internal virtual void ParseKnownAttributes(XElement node, AttributesHelper attributes, ParseResult result)
        {
            // content is required
            XAttribute attrContent = attributes.PopAttribute(ATTR_CONTENT);

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

            this.Content = attrContent.Value;

            // parse activationType, arguments, state
            base.ParseActivatableElementAttributes(node, attributes, result);


            // imageUri is optional
            var attrImageUri = attributes.PopAttribute(ATTR_IMAGEURI);

            if (attrImageUri != null)
            {
                this.ImageUri = attrImageUri.Value;
            }

            // inputId is optional
            var attrInputId = attributes.PopAttribute(ATTR_HINT_INPUTID);

            if (attrInputId != null)
            {
                this.InputId = attrInputId.Value;
            }

            ActionPlacement placement;

            if (TryParseEnum(result, attributes, ATTR_PLACEMENT, out placement))
            {
                this.Placement = placement;
            }
        }
        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;
        }
Exemple #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;
            }
        }
        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;
        }
        internal void ParseKnownAttributes(XElement node, AttributesHelper attributes, ParseResult result, string baseUri, bool addImageQuery)
        {
            // AddImageQuery is optional
            {
                bool val;
                if (TryParse(result, attributes, ATTR_IMAGE_ADDIMAGEQUERY, out val))
                {
                    addImageQuery = val; // Overwrite cascaded value if it was specified
                    AddImageQuery = val;
                }
            }

            // src is required
            XAttribute attrSrc = attributes.PopAttribute(ATTR_IMAGE_SRC);

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

            this.Src = XmlTemplateParser.ConstructUri(attrSrc.Value, baseUri, addImageQuery);



            // alt is optional, I don't use it right now
            var altAttr = attributes.PopAttribute(ATTR_IMAGE_ALT);

            if (altAttr != null)
            {
                AlternateText = altAttr.Value;
            }

            // placement defaults to inline
            Placement placement;

            if (TryParseEnum(result, attributes, ATTR_IMAGE_PLACEMENT, out placement))
            {
                this.Placement = placement;
            }

            switch (placement)
            {
            case Placement.Background:

                if (SupportedFeatures.CropCircleOnBackgroundImage)
                {
                    HandleHintCrop(result, attributes);
                }

                if (SupportedFeatures.OverlayForBothBackgroundAndPeek)
                {
                    HandleHintOverlay(result, attributes);
                }

                break;

            case Placement.Peek:

                if (SupportedFeatures.CropCircleOnPeekImage)
                {
                    HandleHintCrop(result, attributes);
                }

                if (SupportedFeatures.OverlayForBothBackgroundAndPeek)
                {
                    HandleHintOverlay(result, attributes);
                }

                break;

            case Placement.Hero:
#if EXPERIMENTAL
                if (Context == NotificationType.NewsFeed)
                {
                    HintHeroHeight heroHeight;
                    if (TryParseEnum(result, attributes, "hint-heroHeight", out heroHeight))
                    {
                        this.HintHeroHeight = heroHeight;
                    }
                }
#endif
                break;

#if EXPERIMENTAL
            case Placement.HeroLogo:
                // No additional properties supported on hero logo
                break;
#endif

            default:
                HandleHintCrop(result, attributes);

                // These only apply to tiles, and only to inline images
                if (Context != NotificationType.Toast ||
                    SupportedFeatures.AdaptiveToasts
                    )
                {
                    // hint-removeMargin is optional
                    bool hintRemoveMargin;
                    if (TryParse(result, attributes, ATTR_IMAGE_HINT_REMOVE_MARGIN, out hintRemoveMargin))
                    {
                        this.HintRemoveMargin = hintRemoveMargin;
                    }

                    // hint-align is optional
                    HintImageAlign hintAlign;
                    if (TryParseEnum(result, attributes, ATTR_IMAGE_HINT_ALIGN, out hintAlign))
                    {
                        this.HintAlign = hintAlign;
                    }
                }

                break;
            }
        }
Exemple #11
0
 internal static ErrorPositionInfo GetErrorPositionInfo(XObject node)
 {
     return(XmlTemplateParser.GetErrorPositionInfo(node));
 }
        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;
            }
        }
Exemple #13
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;
        }