Exemplo n.º 1
0
        /// <summary>
        /// Fills the object data.
        /// </summary>
        /// <param name="xml">The XML.</param>
        protected override void FillObjectData(XElement xml)
        {
            base.FillObjectData(xml);

            this.Event =xml.GetValue( nodeName_Event);
            this.EventKey =xml.GetValue( nodeName_EventKey);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Fills the object data.
        /// </summary>
        /// <param name="xml">The XML.</param>
        protected override void FillObjectData(XElement xml)
        {
            base.FillObjectData(xml);

            this.Url = xml.GetValue(nodeName_Url);
            this.Title = xml.GetValue(nodeName_Title);
            this.Description = xml.GetValue(nodeName_Description);
        }
Exemplo n.º 3
0
        public static Argument FromXml(XElement container)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            return new Argument
            {
                Name = container.GetValue(uPnpNamespaces.svc + "name"),
                Direction = container.GetValue(uPnpNamespaces.svc + "direction"),
                RelatedStateVariable = container.GetValue(uPnpNamespaces.svc + "relatedStateVariable")                
            };
        }
Exemplo n.º 4
0
        public MetaListItemInfo(XElement node)
        {
            if (node == null)
                throw new ArgumentNullException("node");

            _path = node.GetValue("id");
            _parent = node.GetValue("parent_id");
            _modified = node.GetValue("updated_time");
            _isDir = node.GetValue("type") == "folder";

            Title = node.GetValue("name");
            Notes = GetRelativeTime(_modified);
            Icon = ThemeData.GetImage(_isDir
                ? "folder" : "entry");
        }
Exemplo n.º 5
0
        public static bool MakeReportNode(XElement source, bool? compatibleValue=false)
        {
            if ((source.GetValue("Compatible")!=null && compatibleValue==null) ||
                (source.GetValue("Compatible") == compatibleValue.ToString().ToLowerInvariant()))
            {
                source.Elements().Where(e => e.Name != "Parameter" && e.Name != "Accessor").Remove();
                return true;
            }

            if (!source.HasElements)
                return false;

            source.Elements().Where(e => !MakeReportNode(e,compatibleValue)).Remove();
            return source.HasElements;
        }
Exemplo n.º 6
0
        public static uBaseObject Create(XElement container)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            return new uBaseObject
            {
                Id = container.GetAttributeValue(uPnpNamespaces.Id),
                ParentId = container.GetAttributeValue(uPnpNamespaces.ParentId),
                Title = container.GetValue(uPnpNamespaces.title),
                IconUrl = container.GetValue(uPnpNamespaces.Artwork),
                UpnpClass = container.GetValue(uPnpNamespaces.uClass)
            };
        }
Exemplo n.º 7
0
        //One generic compatibility check for all. Needed for reports and stuff
        public static bool AreCompatible(XElement first, XElement second)
        {
            //get method parameters
            IEnumerable<string> params1 = first.Elements("Parameter").Select(m => m.Attribute("Type").Value).ToArray();
            IEnumerable<string> params2 = second.Elements("Parameter").Select(m => m.Attribute("Type").Value).ToArray();

            //TODO: optimization?
            return
                //whatever: check tag names
                first.Name.LocalName == second.Name.LocalName &&
                //whatever: check names
                first.GetValue("Name") == second.GetValue("Name") &&
                //whatever: static or not
                first.GetValue("Static") == second.GetValue("Static") &&
                //classes: path
                first.GetValue("Path") == second.GetValue("Path") &&
                //classes: abstract or not
                first.GetValue("Abstract") == second.GetValue("Abstract") &&
                //fields&properties: check type
                first.GetValue("Type") == second.GetValue("Type") &&
                //methods: check return type
                first.GetValue("ReturnType") == second.GetValue("ReturnType") &&
                //enums: check value
                first.GetValue("Value") == second.GetValue("Value") &&
                //methods: check parameters
                Enumerable.SequenceEqual(params1, params2) &&
                //Check properties Accessors
                first.Elements("Accessor").All(m => second.Elements("Accessor").Any(n => AreCompatible(m, n)));
        }
Exemplo n.º 8
0
        public void Empty_value_returns_default_type()
        {
            var element = new XElement("foo", "");

            int expected = 0;
            var actual = element.GetValue<int>();

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 9
0
        public void Value_of_element_is_returned_of_type_according_to_generic_invocation()
        {
            var element = new XElement("foo", "42");

            double expected = 42;
            var actual = element.GetValue<double>();

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 10
0
        public static uBaseObject Create(XElement container)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            return new uBaseObject
            {
                Id = container.Attribute(uPnpNamespaces.Id).Value,
                ParentId = container.Attribute(uPnpNamespaces.ParentId).Value,
                Title = container.GetValue(uPnpNamespaces.title),
                IconUrl = container.GetValue(uPnpNamespaces.Artwork),
                SecondText = "",
                Url = container.GetValue(uPnpNamespaces.Res),
                ProtocolInfo = GetProtocolInfo(container),
                MetaData = container.ToString()
            };
        }
Exemplo n.º 11
0
        public static StateVariable FromXml(XElement container)
        {
            var allowedValues = new List<string>();
            var element = container.Descendants(uPnpNamespaces.svc + "allowedValueList")
                .FirstOrDefault();
            
            if (element != null)
            {
                var values = element.Descendants(uPnpNamespaces.svc + "allowedValue");

                allowedValues.AddRange(values.Select(child => child.Value));
            }

            return new StateVariable
            {
                Name = container.GetValue(uPnpNamespaces.svc + "name"),
                DataType = container.GetValue(uPnpNamespaces.svc + "dataType"),
                AllowedValues = allowedValues
            };
        }
Exemplo n.º 12
0
        public MetaListItemInfo(XElement node)
        {
            if (node == null)
                throw new ArgumentNullException("node");

            _path = node.GetValue("id");
            _parent = node.GetValue("parent_id");
            _modified = node.GetValue("updated_time");
            var type = node.GetValue("type");
            if(string.IsNullOrEmpty(type))
            {
                type = "file";
            }
            _isDir = "folder|album".Contains(type); // Show folder icon in case of folder/album
            int.TryParse(node.GetValue("size"), out _size);

            Title = node.GetValue("name") ?? "";
            Notes = GetRelativeTime(_modified);
            string iconStr = "";
            iconStr = Title.EndsWith(".kdbx",StringComparison.InvariantCultureIgnoreCase) // If its keepass database
                ? "keepasslogo"
                : (_isDir
                    ? "folder"
                    : "entry");

            Icon = ThemeData.GetImage(iconStr);
        }
Exemplo n.º 13
0
        public static void ApplyPatch(XElement source, XElement patch)
        {
            if (patch == null)
                return;

            source.SetAttributeValue("Compatible", patch.GetValue("Compatible"));

            foreach (XElement element in source.Elements().ExceptAccessorsAndParameters())
            {
                ApplyPatch(element, patch.Elements(element.Name.LocalName).
                                        ExceptAccessorsAndParameters().SingleOrDefault(e => Check.AreCompatible(element, e)));

            }
        }
Exemplo n.º 14
0
        public static ServiceAction FromXml(XElement container)
        {
            var argumentList = new List<Argument>();

            foreach (var arg in container.Descendants(uPnpNamespaces.svc + "argument"))
            {
                argumentList.Add(Argument.FromXml(arg));
            }
            
            return new ServiceAction
            {
                Name = container.GetValue(uPnpNamespaces.svc + "name"),

                ArgumentList = argumentList
            };
        }
Exemplo n.º 15
0
        public MetaListItemInfo(XElement node)
        {
            if (node == null)
                throw new ArgumentNullException("node");

            _path = node.GetValue("id");
            _parent = node.GetValue("parent_id");
            _modified = node.GetValue("updated_time");
            _isDir = "folder|album".Contains(node.GetValue("type")); // Show folder icon in case of folder/album
            int.TryParse(node.GetValue("size"), out _size);

            Title = node.GetValue("name");
            Notes = GetRelativeTime(_modified);
            string iconStr = "";
            iconStr = Title.EndsWith(".kdbx") // If its keepass database
                ? "keepasslogo"
                : (_isDir
                    ? "folder"
                    : "entry");

            Icon = ThemeData.GetImage(iconStr);
        }
        public void can_get_value_without_default_from_xnode()
        {
            var node = new XElement(
                "parent",
                new XElement("id", 21));

            var value = node.GetValue<int>("id");

            Expect(value, Is.EqualTo(21));
        }
Exemplo n.º 17
0
        public static Effect LoadEffectAction(XElement node)
        {
            Effect effect = e => { };

            switch (node.Name.LocalName)
            {
                case "Call":
                    effect = GetLateBoundEffect(node.Value);
                    break;

                case "Spawn":
                    effect = LoadSpawnEffect(node);
                    break;

                case "Remove":
                    effect = entity => { entity.Remove(); };
                    break;

                case "Die":
                    effect = entity => { entity.Die(); };
                    break;

                case "AddInventory":
                    string itemName = node.RequireAttribute("item").Value;
                    int quantity = node.TryAttribute<int>("quantity", 1);

                    effect = entity =>
                    {
                        Game.CurrentGame.Player.CollectItem(itemName, quantity);
                    };
                    break;

                case "RemoveInventory":
                    string itemNameUse = node.RequireAttribute("item").Value;
                    int quantityUse = node.TryAttribute<int>("quantity", 1);

                    effect = entity =>
                    {
                        Game.CurrentGame.Player.UseItem(itemNameUse, quantityUse);
                    };
                    break;

                case "UnlockWeapon":
                    string weaponName = node.RequireAttribute("name").Value;

                    effect = entity =>
                    {
                        Game.CurrentGame.Player.UnlockWeapon(weaponName);
                    };
                    break;

                case "DefeatBoss":
                    string name = node.RequireAttribute("name").Value;

                    effect = entity =>
                    {
                        Game.CurrentGame.Player.DefeatBoss(name);
                    };
                    break;

                case "Lives":
                    int add = int.Parse(node.RequireAttribute("add").Value);
                    effect = entity =>
                    {
                        Game.CurrentGame.Player.Lives += add;
                    };
                    break;

                case "GravityFlip":
                    bool flip = node.GetValue<bool>();
                    effect = entity => { entity.Container.IsGravityFlipped = flip; };
                    break;

                case "Func":
                    effect = entity => { };
                    string[] statements = node.Value.Split(';');
                    foreach (string st in statements.Where(st => !string.IsNullOrEmpty(st.Trim())))
                    {
                        LambdaExpression lambda = System.Linq.Dynamic.DynamicExpression.ParseLambda(
                            new[] { posParam, moveParam, sprParam, inputParam, collParam, ladderParam, timerParam, healthParam, stateParam, weaponParam, playerParam },
                            typeof(SplitEffect),
                            null,
                            st,
                            dirDict);
                        effect += CloseEffect((SplitEffect)lambda.Compile());
                    }
                    break;

                case "Trigger":
                    string conditionString;
                    if (node.Attribute("condition") != null) conditionString = node.RequireAttribute("condition").Value;
                    else conditionString = node.Element("Condition").Value;

                    Condition condition = ParseCondition(conditionString);
                    Effect triggerEffect = LoadTriggerEffect(node.Element("Effect"));
                    effect += (e) =>
                    {
                        if (condition(e)) triggerEffect(e);
                    };
                    break;

                case "Pause":
                    effect = entity => { entity.Paused = true; };
                    break;

                case "Unpause":
                    effect = entity => { entity.Paused = false; };
                    break;

                case "Next":
                    var transfer = GameXmlReader.LoadHandlerTransfer(node);
                    effect = e => { Game.CurrentGame.ProcessHandler(transfer); };
                    break;

                case "Palette":
                    var paletteName = node.RequireAttribute("name").Value;
                    var paletteIndex = node.GetAttribute<int>("index");
                    effect = e =>
                    {
                        var palette = PaletteSystem.Get(paletteName);
                        if (palette != null)
                        {
                            palette.CurrentIndex = paletteIndex;
                        }
                    };
                    break;

                case "Delay":
                    var delayFrames = node.GetAttribute<int>("frames");
                    var delayEffect = LoadEffect(node);
                    effect = e =>
                    {
                        Engine.Instance.DelayedCall(() => delayEffect(e), null, delayFrames);
                    };
                    break;

                case "SetVar":
                    var varname = node.RequireAttribute("name").Value;
                    var value = node.RequireAttribute("value").Value;
                    effect = e =>
                    {
                        Game.CurrentGame.Player.SetVar(varname, value);
                    };
                    break;

                default:
                    effect = GameEntity.ParseComponentEffect(node);
                    break;
            }
            return effect;
        }
Exemplo n.º 18
0
Arquivo: Device.cs Projeto: Cyrre/Emby
        private static uBaseObject CreateUBaseObject(XElement container, string trackUri)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            var url = container.GetValue(uPnpNamespaces.Res);

            if (string.IsNullOrWhiteSpace(url))
            {
                url = trackUri;
            }

            return new uBaseObject
            {
                Id = container.GetAttributeValue(uPnpNamespaces.Id),
                ParentId = container.GetAttributeValue(uPnpNamespaces.ParentId),
                Title = container.GetValue(uPnpNamespaces.title),
                IconUrl = container.GetValue(uPnpNamespaces.Artwork),
                SecondText = "",
                Url = url,
                ProtocolInfo = GetProtocolInfo(container),
                MetaData = container.ToString()
            };
        }
Exemplo n.º 19
0
		private static bool UseLatLon(XElement crsElement)
		{
			bool useLatLon = false;
			string crs = crsElement.GetValue();
			if (crs != null && crs.Contains("EPSG:")) // else if SR is defined by CRS:84, CRS:83 or CRS:27 --> use x,y
			{
				var sref = GetSpatialReference(crsElement);
				if (sref != null)
					useLatLon = UseLatLon(sref.WKID);
			}
			return useLatLon;
		}
Exemplo n.º 20
0
        ApplicationModel ApplicationFromXml(XElement xml)
        {
            ApplicationModel application = new ApplicationModel()
            {
                Title = xml.GetValue("Title"),
                FilePath = xml.GetValue("FilePath"),
                RunArguments = xml.GetValue("RunArguments"),
                Tab = xml.GetValue("Tab"),
                ImagePath = xml.GetValue("ImagePath"),
                IsSteamApp = xml.GetValue<bool>("IsSteamApp", false),
                SteamAppNumber = xml.GetValue<int>("SteamAppNumber", 0),
                Installed = xml.GetValue<bool>("Installed", false),
                Installer = xml.GetValue("Installer"),
                InstallArguments = xml.GetValue("InstallArguments"),
                Uninstaller = xml.GetValue("Uninstaller"),
                UninstallArguments = xml.GetValue("UninstallArguments")
            };

            return application;
        }
Exemplo n.º 21
0
        /// <summary>
        /// Converts the automatic music object.
        /// </summary>
        /// <param name="xml">The XML.</param>
        /// <returns>MusicObject.</returns>
        public static MusicObject ConvertToMusicObject(XElement xml)
        {
            MusicObject result = null;

            if (xml != null && xml.Name.LocalName == nodeName_Music)
            {
                result = new MusicObject();

                result.HQMusicUrl = xml.GetValue(nodeName_HQMusicUrl);
                result.MusicUrl = xml.GetValue(nodeName_MusicUrl);
                result.Title = xml.GetValue(nodeName_Title);
                result.Description = xml.GetValue(nodeName_Description);
            }

            return result;
        }
Exemplo n.º 22
0
        /// <summary>
        /// Converts the message.
        /// </summary>
        /// <param name="xElement">The executable element.</param>
        /// <returns>Message.</returns>
        public static Message ConvertMessage(XElement xElement)
        {
            Message message = null;

            if (xElement != null && xElement.Name.LocalName == nodeName_Xml)
            {
                string type = xElement.GetValue(nodeName_MessageType);

                if (!string.IsNullOrWhiteSpace(type))
                {
                    MessageType messageType;
                    if (Enum.TryParse<MessageType>(type, true, out messageType))
                    {
                        switch (messageType)
                        {
                            case MessageType.Text:
                                message = new ContentMessage();
                                break;
                            case MessageType.Event:
                                message = new EventMessage();
                                break;
                            case MessageType.Location:
                                message = new GeographyMessage();
                                break;
                            default:
                                break;
                        }

                        if (message != null)
                        {
                            message.FillObjectData(xElement);
                        }
                    }
                }
            }

            return message;
        }
        /// <summary>
        /// Fills the object data.
        /// </summary>
        /// <param name="xml">The XML.</param>
        protected override void FillObjectData(XElement xml)
        {
            base.FillObjectData(xml);

            this.Label =xml.GetValue( nodeName_Label);
            this.Latitude =xml.GetValue( nodeName_Latitude).ToDouble();
            this.Longitude =xml.GetValue( nodeName_Longitude).ToDouble();
            this.Scale =xml.GetValue( nodeName_Scale).ToInt32();
        }
Exemplo n.º 24
0
        public void TestGetValue()
        {
            var element = new XElement(ELEMENT_NAME);
            Assert.AreEqual(String.Empty, element.GetValue());

            element.Add(new XElement(SUB_ELEMENT_NAME));
            Assert.AreEqual(String.Empty, element.GetValue());

            Assert.AreEqual(CONTENT_SAMPLE, new XElement(ELEMENT_NAME, CONTENT_SAMPLE).GetValue());
            Assert.AreEqual(CONTENT_SAMPLE + DATE_STRING_SAMPLE + UnitTestHelper.SAMPLE_STRING,
                new XElement(ELEMENT_NAME, CONTENT_SAMPLE,
                new XElement(SUB_ELEMENT_NAME, DATE_STRING_SAMPLE), UnitTestHelper.SAMPLE_STRING).GetValue());
        }
Exemplo n.º 25
0
 /// <summary>
 /// Fills the basic information.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="xElement">The executable element.</param>
 protected static void FillBasicInformation(Message message, XElement xElement)
 {
     if (message != null && xElement != null)
     {
         message.FromUserName = xElement.GetValue(nodeName_FromUserName);
         message.ToUserName = xElement.GetValue(nodeName_ToUserName);
         message.MessageId = xElement.GetValue(nodeName_MessageId).DBToLong();
         message.CreatedStamp = xElement.GetValue(nodeName_CreatedStamp).DBToLong().ToDateTime();
     }
 }
Exemplo n.º 26
0
        TabModel TabFromXml(XElement xml)
        {
            string title = xml.GetValue("Title");
            bool isExpanded = xml.GetValue<bool>("IsExpanded", false);

            return new TabModel(title, isExpanded);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Fills the object data.
        /// </summary>
        /// <param name="xml">The XML.</param>
        protected override void FillObjectData(XElement xml)
        {
            base.FillObjectData(xml);

            this.ImageUrl =xml.GetValue( nodeName_ImageUrl);
        }
 public IEffectPartInfo Load(XElement partNode)
 {
     return new GravityFlipEffectPartInfo() {
         Flipped = partNode.GetValue<bool>()
     };
 }