Exemple #1
0
 public MediaItem(MediaItem source)
     : base(source)
 {
     _itemId       = source._itemId;
     _itemPath     = source._itemPath;
     _altText      = source._altText;
     _itemType     = source._itemType;
     _itemUnit     = source._itemUnit;
     _itemWidth    = source._itemWidth;
     _itemHeight   = source._itemHeight;
     _useMap       = source._useMap;
     _imageMap     = source._imageMap;
     _resolveLinks = source._resolveLinks;
 }
Exemple #2
0
        /// <summary>
        /// This reads and sets its state or attributes stored in a <c>XML</c> format
        /// with the given reader.
        /// </summary>
        /// <param name="reader">
        /// The reader with which the <c>XML</c> attributes of this object are accessed.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If the <paramref name="reader"/> is <see langword="null"/>.
        /// </exception>
        public override void ReadXml(XmlReader reader)
        {
            BuildExceptions.NotNull(reader, "reader");

            Debug.Assert(reader.NodeType == XmlNodeType.Element);
            if (reader.NodeType != XmlNodeType.Element)
            {
                return;
            }
            if (!String.Equals(reader.Name, TagName,
                               StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            _itemId = reader.GetAttribute("id");
            string nodeText = reader.GetAttribute("type");

            if (!String.IsNullOrEmpty(nodeText))
            {
                _itemType = MediaItemType.None;

                switch (nodeText.ToLower())
                {
                case "image":
                    _itemType = MediaItemType.Image;
                    break;

                case "video":
                    _itemType = MediaItemType.Video;
                    break;

                case "flash":
                    _itemType = MediaItemType.Flash;
                    break;

                case "silverlight":
                    _itemType = MediaItemType.Silverlight;
                    break;

                case "youtube":
                    _itemType = MediaItemType.YouTube;
                    break;

                case "pdf":
                    _itemType = MediaItemType.Pdf;
                    break;

                case "xps":
                    _itemType = MediaItemType.Xps;
                    break;
                }
            }
            nodeText = reader.GetAttribute("width");
            if (!String.IsNullOrEmpty(nodeText))
            {
                _itemWidth = Convert.ToInt32(nodeText);
            }
            nodeText = reader.GetAttribute("height");
            if (!String.IsNullOrEmpty(nodeText))
            {
                _itemHeight = Convert.ToInt32(nodeText);
            }
            nodeText = reader.GetAttribute("unit");
            if (!String.IsNullOrEmpty(nodeText))
            {
                _itemUnit = MediaSizeUnit.None;

                switch (nodeText.ToLower())
                {
                case "pixel":
                    _itemUnit = MediaSizeUnit.Pixel;
                    break;

                case "point":
                    _itemUnit = MediaSizeUnit.Point;
                    break;

                case "percent":
                    _itemUnit = MediaSizeUnit.Percent;
                    break;

                case "em":
                    _itemUnit = MediaSizeUnit.Em;
                    break;

                case "pica":
                    _itemUnit = MediaSizeUnit.Pica;
                    break;

                case "ex":
                    _itemUnit = MediaSizeUnit.Ex;
                    break;
                }
            }

            if (reader.IsEmptyElement)
            {
                return;
            }

            XmlNodeType nodeType = XmlNodeType.None;

            while (reader.Read())
            {
                nodeText = reader.Name;
                nodeType = reader.NodeType;

                if (nodeType == XmlNodeType.Element)
                {
                    if (String.Equals(reader.Name, "image",
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        if (_itemType == MediaItemType.YouTube)
                        {
                            _itemName = reader.GetAttribute("file");
                        }
                        else
                        {
                            _itemPath = new BuildFilePath(reader.GetAttribute("file"));
                        }
                        _useMap  = reader.GetAttribute("usemap");
                        nodeText = reader.GetAttribute("resolveMapLinks");
                        if (!String.IsNullOrEmpty(nodeText))
                        {
                            _resolveLinks = Convert.ToBoolean(nodeText);
                        }
                    }
                    else if (String.Equals(reader.Name, "altText",
                                           StringComparison.OrdinalIgnoreCase))
                    {
                        _altText = reader.ReadString();
                    }
                    else if (String.Equals(reader.Name, "map",
                                           StringComparison.OrdinalIgnoreCase))
                    {
                        _imageMap = new MediaImageMap();
                        _imageMap.ReadXml(reader);
                    }
                }
                else if (nodeType == XmlNodeType.EndElement)
                {
                    if (String.Equals(reader.Name, "item",
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                }
            }
        }