Esempio n. 1
0
        public void ReadFromString(string text)
        {
            XDocument doc = ParseXmlNoDtd(text);
            version = (string) doc.Root.Attribute("version");
            XElement xml = doc.XPathSelectElement("plist/dict");

            var dict = ReadElement(xml);
            if (dict == null)
                throw new Exception("Error parsing plist file");
            root = dict as PlistElementDict;
            if (root == null)
                throw new Exception("Malformed plist file");
        }
Esempio n. 2
0
        public void ReadFromString(string text)
        {
            XDocument doc = ParseXmlNoDtd(text);

            version = (string)doc.Root.Attribute("version");
            XElement xml = doc.XPathSelectElement("plist/dict");

            var dict = ReadElement(xml);

            if (dict == null)
            {
                throw new Exception("Error parsing plist file");
            }
            root = dict as PlistElementDict;
            if (root == null)
            {
                throw new Exception("Malformed plist file");
            }
        }
Esempio n. 3
0
        private static PlistElement ReadElement(XElement xml)
        {
            switch (xml.Name.LocalName)
            {
            case "dict":
            {
                List <XElement> children = xml.Elements().ToList();
                var             el       = new PlistElementDict();

                if (children.Count % 2 == 1)
                {
                    throw new Exception("Malformed plist file");
                }

                for (int i = 0; i < children.Count - 1; i++)
                {
                    if (children[i].Name != "key")
                    {
                        throw new Exception("Malformed plist file");
                    }
                    string key      = GetText(children[i]).Trim();
                    var    newChild = ReadElement(children[i + 1]);
                    if (newChild != null)
                    {
                        i++;
                        el[key] = newChild;
                    }
                }
                return(el);
            }

            case "array":
            {
                List <XElement> children = xml.Elements().ToList();
                var             el       = new PlistElementArray();

                foreach (var childXml in children)
                {
                    var newChild = ReadElement(childXml);
                    if (newChild != null)
                    {
                        el.values.Add(newChild);
                    }
                }
                return(el);
            }

            case "string":
                return(new PlistElementString(GetText(xml)));

            case "integer":
            {
                int r;
                if (int.TryParse(GetText(xml), out r))
                {
                    return(new PlistElementInteger(r));
                }
                return(null);
            }

            case "true":
                return(new PlistElementBoolean(true));

            case "false":
                return(new PlistElementBoolean(false));

            default:
                return(null);
            }
        }
Esempio n. 4
0
 public PlistDocument()
 {
     root    = new PlistElementDict();
     version = "1.0";
 }
 public PlistElementDict CreateDict(string key)
 {
     var v = new PlistElementDict();
     values[key] = v;
     return v;
 }
        private static PlistElement ReadElement(XElement xml)
        {
            switch (xml.Name.LocalName)
            {
                case "dict":
                {
                    List<XElement> children = xml.Elements().ToList();
                    var el = new PlistElementDict();

                    if (children.Count % 2 == 1)
                        throw new Exception("Malformed plist file");

                    for (int i = 0; i < children.Count - 1; i++)
                    {
                        if (children[i].Name != "key")
                            throw new Exception("Malformed plist file");
                        string key = GetText(children[i]).Trim();
                        var newChild = ReadElement(children[i+1]);
                        if (newChild != null)
                        {
                            i++;
                            el[key] = newChild;
                        }
                    }
                    return el;
                }
                case "array":
                {
                    List<XElement> children = xml.Elements().ToList();
                    var el = new PlistElementArray();

                    foreach (var childXml in children)
                    {
                        var newChild = ReadElement(childXml);
                        if (newChild != null)
                            el.values.Add(newChild);
                    }
                    return el;
                }
                case "string":
                    return new PlistElementString(GetText(xml));
                case "integer":
                {
                    int r;
                    if (int.TryParse(GetText(xml), out r))
                        return new PlistElementInteger(r);
                    return null;
                }
                case "true":
                    return new PlistElementBoolean(true);
                case "false":
                    return new PlistElementBoolean(false);
                default:
                    return null;
            }
        }
 public PlistDocument()
 {
     root = new PlistElementDict();
     version = "1.0";
 }
 public PlistElementDict AddDict()
 {
     var v = new PlistElementDict();
     values.Add(v);
     return v;
 }
Esempio n. 9
0
        private static void PreparePlist(string buildPath)
        {
            Dictionary<string, PlistElementDict> kitsDict = new Dictionary<string, PlistElementDict>();
            PlistElementDict twitterDict = new PlistElementDict ();

            twitterDict.SetString("consumerKey", consumerKey);
            twitterDict.SetString("consumerSecret", consumerSecret);
            kitsDict.Add("Twitter", twitterDict);
            AddFabricKitsToPlist(buildPath, kitsDict);
        }