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
        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. Found '" + children[i].Name +
                                            "' where 'key' was expected.");
                    }
                    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 "real":
            {
                float f;
                if (float.TryParse(GetText(xml), out f))
                {
                    return(new PlistElementReal(f));
                }
                return(null);
            }

            case "date":
            {
                DateTime date;
                if (DateTime.TryParse(GetText(xml), out date))
                {
                    return(new PlistElementDate(date.ToUniversalTime()));
                }
                return(null);
            }

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

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

            default:
                return(null);
            }
        }
Esempio n. 3
0
 public PlistDocument()
 {
     root    = new PlistElementDict();
     version = "1.0";
 }
Esempio n. 4
0
        public void AddMaps(MapsOptions options)
        {
            var bundleArr =
                (GetOrCreateInfoDoc().root[MapsInfo.BundleKey] ??
                 (GetOrCreateInfoDoc().root[MapsInfo.BundleKey] = new PlistElementArray())) as PlistElementArray;

            bundleArr.values.Add(new PlistElementDict());
            PlistElementDict bundleDic = GetOrCreateUniqueDictElementInArray(bundleArr);

            bundleDic[MapsInfo.BundleNameKey] = new PlistElementString(MapsInfo.BundleNameValue);
            var bundleTypeArr =
                (bundleDic[MapsInfo.BundleTypeKey] ?? (bundleDic[MapsInfo.BundleTypeKey] = new PlistElementArray())) as
                PlistElementArray;

            GetOrCreateStringElementInArray(bundleTypeArr, MapsInfo.BundleTypeValue);

            var optionArr = (GetOrCreateInfoDoc().root[MapsInfo.ModeKey] ??
                             (GetOrCreateInfoDoc().root[MapsInfo.ModeKey] = new PlistElementArray())) as
                            PlistElementArray;

            if ((options & MapsOptions.Airplane) == MapsOptions.Airplane)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModePlaneValue);
            }

            if ((options & MapsOptions.Bike) == MapsOptions.Bike)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModeBikeValue);
            }

            if ((options & MapsOptions.Bus) == MapsOptions.Bus)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModeBusValue);
            }

            if ((options & MapsOptions.Car) == MapsOptions.Car)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModeCarValue);
            }

            if ((options & MapsOptions.Ferry) == MapsOptions.Ferry)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModeFerryValue);
            }

            if ((options & MapsOptions.Other) == MapsOptions.Other)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModeOtherValue);
            }

            if ((options & MapsOptions.Pedestrian) == MapsOptions.Pedestrian)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModePedestrianValue);
            }

            if ((options & MapsOptions.RideSharing) == MapsOptions.RideSharing)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModeRideShareValue);
            }

            if ((options & MapsOptions.StreetCar) == MapsOptions.StreetCar)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModeStreetCarValue);
            }

            if ((options & MapsOptions.Subway) == MapsOptions.Subway)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModeSubwayValue);
            }

            if ((options & MapsOptions.Taxi) == MapsOptions.Taxi)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModeTaxiValue);
            }

            if ((options & MapsOptions.Train) == MapsOptions.Train)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModeTrainValue);
            }

            project.AddCapability(m_TargetGuid, PBXCapabilityType.Maps);
        }