Exemplo n.º 1
0
        /// <summary>
        /// Initializes an instance of Screen in XElement format with specified contents and attributes.
        /// </summary>
        /// <param name="screen">System.Xml.Linq.Screen</param>
        /// <returns>RippleDictionary.Screen</returns>
        private static XElement GetXElementScreen(Screen screen)
        {
            List<XElement> eScreenContents = new List<XElement>();
            XElement eScreenContent = null;
            XAttribute eType, eId, eHeader, eContent, eLoopVideo;

            foreach (var screenContent in screen.ScreenContents)
            {
                eType = new XAttribute(XMLElementsAndAttributes.Type, screenContent.Value.Type.ToString());
                eId = new XAttribute(XMLElementsAndAttributes.Id, screenContent.Value.Id);
                eHeader = new XAttribute(XMLElementsAndAttributes.Header, screenContent.Value.Header);
                eContent = new XAttribute(XMLElementsAndAttributes.Content, screenContent.Value.Content);
                if (screenContent.Value.LoopVideo != null)
                {
                    eLoopVideo = new XAttribute(XMLElementsAndAttributes.LoopVideo, screenContent.Value.LoopVideo);
                }
                else
                {
                    eLoopVideo = null;
                }

                eScreenContent = new XElement(XMLElementsAndAttributes.ScreenContent, eType, eId, eHeader, eContent, eLoopVideo);

                eScreenContents.Add(eScreenContent);
            }
            return new XElement(XMLElementsAndAttributes.Screen, eScreenContents);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the Screen tag from the Ripple XML.
        /// </summary>
        /// <param name="xml"></param>
        /// <returns>RippleDictionary.Screen</returns>
        /// <exception cref="System.NullReferenceException
        ///     System.ArgumentNullException
        ///     RippleDictionary.TypeNotKnownException
        ///     RippleDictionary.UnparseableXMLException" />
        public static Screen GetScreenFromXML(string xml)
        {
            Screen screen = null;
            XDocument xdoc = XDocument.Load(GenerateRippleDictionaryStreamFromXML(xml));

            foreach (var xel in xdoc.Root.Elements())
            {
                if (xel.Name == XMLElementsAndAttributes.Screen)
                {
                    
                    string type, id, header, content;
                    Dictionary<string, ScreenContent> screenContents = new Dictionary<string, ScreenContent>();
                    ScreenContent screenContent;
                    foreach (var tagContent in xel.Elements())
                    {
                        if (tagContent.Name == XMLElementsAndAttributes.ScreenContent)
                        {
                            type = tagContent.Attribute(XMLElementsAndAttributes.Type).Value;
                            id = tagContent.Attribute(XMLElementsAndAttributes.Id).Value;
                            header = tagContent.Attribute(XMLElementsAndAttributes.Header).Value;
                            content = tagContent.Attribute(XMLElementsAndAttributes.Content).Value;
                            var loopVideoObj = tagContent.Attribute(XMLElementsAndAttributes.LoopVideo);
                            bool loopVideo = loopVideoObj != null ? (loopVideoObj.Value.ToLower() == "true" ? (bool)true : (loopVideoObj.Value.ToLower() == "false" ? (bool)false : false)) : false;

                            screenContent = new ScreenContent(GetType(type), id, header, content, loopVideo);
                            screenContents.Add(screenContent.Id, screenContent);
                        }
                    }

                    screen = new Screen(screenContents); 
                    
                }
                else
                {
                    continue;
                }
            }

            return screen;
        }