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;
            }
        }
        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;
            }
        }