Exemple #1
0
        public static KeyBinding Deserialize(XmlNode node)
        {
            var key = XmlHelper.GetAttribute(node, "Key", null);

            if (key == null)
            {
                return(null);
            }
            SpeccyKey keyValue;

            if (!Enum.TryParse <SpeccyKey>(key, true, out keyValue))
            {
                Logger.Warn("KeyBinding: Skipped unknown Key value: {0}", key);
                return(null);
            }
            var conditions = new List <IKeyCondition>();
            var keySrc     = XmlHelper.GetAttribute(node, "Condition", null);

            if (keySrc != null)
            {
                Key keySrcValue;
                if (!Enum.TryParse <Key>(keySrc, true, out keySrcValue))
                {
                    Logger.Warn("KeyBinding: Skipped unknown Condition value: {0}", keySrc);
                    return(null);
                }
                conditions.Add(new KeyCondition(keySrcValue));
            }
            else
            {
                foreach (XmlNode subNode in XmlHelper.SelectNodes(node, "Condition"))
                {
                    var condition = KeyCondition.Deserialize(subNode);
                    if (condition != null)
                    {
                        conditions.Add(condition);
                    }
                }
                foreach (XmlNode subNode in XmlHelper.SelectNodes(node, "MultiCondition"))
                {
                    var condition = KeyMultiCondition.Deserialize(subNode);
                    if (condition != null)
                    {
                        conditions.Add(condition);
                    }
                }
            }
            return(new KeyBinding(keyValue, conditions.ToArray()));
        }
Exemple #2
0
        public static KeyMultiCondition Deserialize(XmlNode node)
        {
            var conditions = new List <IKeyCondition>();

            foreach (XmlNode subNode in XmlHelper.SelectNodes(node, "Condition"))
            {
                var condition = KeyCondition.Deserialize(subNode);
                if (condition != null)
                {
                    conditions.Add(condition);
                }
            }
            foreach (XmlNode subNode in XmlHelper.SelectNodes(node, "MultiCondition"))
            {
                var condition = KeyMultiCondition.Deserialize(subNode);
                if (condition != null)
                {
                    conditions.Add(condition);
                }
            }
            return(new KeyMultiCondition(conditions.ToArray()));
        }