コード例 #1
0
        /// <summary>
        /// Initializes an instance of Floor in XElement format with specified contents and attributes.
        /// </summary>
        /// <param name="floor">RippleDictionary.Floor</param>
        /// <returns>System.Xml.Linq.XElement</returns>
        private static XElement GetXElementFloor(Floor floor)
        {
            XElement eStart = GetXElementStart(floor.Start);

            XElement eTransition = new XElement(XMLElementsAndAttributes.Transition,
                new XAttribute(XMLElementsAndAttributes.Music, floor.Transition.Music),
                new XAttribute(XMLElementsAndAttributes.Animation, floor.Transition.Animation)
                );

            XElement eLockingPeriod = new XElement(XMLElementsAndAttributes.LockingPeriod, floor.LockingPeriod.ToString());

            XElement eSystemAutoLockPeriod = new XElement(XMLElementsAndAttributes.SystemAutoLockPeriod, floor.SystemAutoLockPeriod.ToString());

            XElement eUpperTile = new XElement(XMLElementsAndAttributes.UpperTile,
                new XAttribute(XMLElementsAndAttributes.Id, floor.UpperTile.Id),
                new XAttribute(XMLElementsAndAttributes.Name, floor.UpperTile.Name),
                new XAttribute(XMLElementsAndAttributes.TileType, floor.UpperTile.TileType),
                new XAttribute(XMLElementsAndAttributes.Content, floor.UpperTile.Content),
                new XAttribute(XMLElementsAndAttributes.CorrespondingScreenContentType, floor.UpperTile.CorrespondingScreenContentType),
                new XAttribute(XMLElementsAndAttributes.Color, floor.UpperTile.Color),               
                new XAttribute(XMLElementsAndAttributes.Style, GenerateStringValue(floor.UpperTile.Style)),
                new XAttribute(XMLElementsAndAttributes.Coordinate, GenerateStringValue(floor.UpperTile.Coordinate)),
                new XAttribute(XMLElementsAndAttributes.Action, floor.UpperTile.Action),
                new XAttribute(XMLElementsAndAttributes.ActionURI, floor.UpperTile.ActionURI)
                );

            XElement eTiles = new XElement(XMLElementsAndAttributes.Tiles, GetXElementTiles(floor.Tiles));

            return new XElement(XMLElementsAndAttributes.Floor, new XElement(XMLElementsAndAttributes.SetupID, floor.SetupID), eStart, eTransition, eLockingPeriod, eSystemAutoLockPeriod, eUpperTile, eTiles);
        }
コード例 #2
0
ファイル: Dictionary.cs プロジェクト: guozanhua/kinect-ripple
        /// <summary>
        /// Gets the Floor tag from the Ripple XML.
        /// </summary>
        /// <param name="xml"></param>
        /// <returns>RippleDictionary.Floor</returns>
        /// <exception cref="System.NullReferenceException
        ///     System.ArgumentNullException
        ///     System.FormatException
        ///     System.OverflowException
        ///     RippleDictionary.UndefinedUnlockException
        ///     RippleDictionary.TileTypeNotKnownException
        ///     RippleDictionary.InvalidStyleException
        ///     RippleDictionary.InvalidCoordinateException
        ///     RippleDictionary.TypeNotKnownException
        ///     RippleDictionary.ActionNotKnownException
        ///     RippleDictionary.UnparseableXMLException" />
        public static Floor GetFloorFromXML(string xml)
        {
            Floor floor = null;

            XDocument xdoc = XDocument.Load(GenerateRippleDictionaryStreamFromXML(xml));

            foreach (var xel in xdoc.Root.Elements())
            {
                if (xel.Name == XMLElementsAndAttributes.Floor)
                {
                    Start start = null;
                    Transition transition = null;
                    Tile upperTile = null;
                    Dictionary<string, Tile> tiles = new Dictionary<string, Tile>();
                    double lockingPeriod = 0.0;
                    int systemAutoLockPeriod = 0;
                    String setupID = String.Empty;

                    foreach (var tagContent in xel.Elements())
                    {
                        if (tagContent.Name == XMLElementsAndAttributes.Start)
                        {
                            Animation animation;
                            Unlock unlock;
                            int introVideoWaitPeriod;

                            GetStartContent(tagContent, out animation, out unlock, out introVideoWaitPeriod);

                            start = new Start(animation, unlock, introVideoWaitPeriod);
                        }
                        else if (tagContent.Name == XMLElementsAndAttributes.Transition)
                        {
                            string music = tagContent.Attribute(XMLElementsAndAttributes.Music).Value;
                            string animation = tagContent.Attribute(XMLElementsAndAttributes.Animation).Value;

                            transition = new Transition(music, animation);
                        }
                        else if (tagContent.Name == XMLElementsAndAttributes.Tiles)
                        {
                            tiles = GetTilesDictionaryFromTag(tagContent);
                        }
                        else if (tagContent.Name == XMLElementsAndAttributes.UpperTile)
                        {
                            string id = tagContent.Attribute(XMLElementsAndAttributes.Id).Value;
                            string name = tagContent.Attribute(XMLElementsAndAttributes.Name).Value;
                            string tileType = tagContent.Attribute(XMLElementsAndAttributes.TileType).Value;
                            string content = tagContent.Attribute(XMLElementsAndAttributes.Content).Value;
                            string color = tagContent.Attribute(XMLElementsAndAttributes.Color).Value;
                            string action = tagContent.Attribute(XMLElementsAndAttributes.Action).Value;
                            var actionURIObj = tagContent.Attribute(XMLElementsAndAttributes.ActionURI);
                            string actionURI = actionURIObj != null ? actionURIObj.Value : null;
                            string style = tagContent.Attribute(XMLElementsAndAttributes.Style).Value;
                            string coordinate = tagContent.Attribute(XMLElementsAndAttributes.Coordinate).Value;
                            var correspondingScreenContentTypeObj = tagContent.Attribute(XMLElementsAndAttributes.CorrespondingScreenContentType);
                            string correspondingScreenContentType = correspondingScreenContentTypeObj != null ? correspondingScreenContentTypeObj.Value : null;

                            upperTile = new Tile(id, name, GetTileType(tileType), color, GetStyle(style), GetCoordinate(coordinate), GetAction(action), actionURI, content, GetType(correspondingScreenContentType), null);
                        }
                        else if (tagContent.Name == XMLElementsAndAttributes.LockingPeriod)
	                    {
		                    lockingPeriod = Convert.ToDouble(tagContent.Value);
	                    }
                        else if (tagContent.Name == XMLElementsAndAttributes.SystemAutoLockPeriod)
                        {
                            systemAutoLockPeriod = Convert.ToInt32(tagContent.Value);
                        }
                        else if (tagContent.Name == XMLElementsAndAttributes.SetupID)
                        {
                            setupID = tagContent.Value;
                        }
                    }

                    floor = new Floor(start, transition, tiles, lockingPeriod, systemAutoLockPeriod, setupID, upperTile);
                }
                else
                {
                    continue;
                }
            }

            return floor;
        }