Пример #1
0
        void IViewModel.OnSelectProperty(IPropertyListItem property)
        {
            var prop = property as PropertyInfo;

            selectedProperty = prop != null ? new SelectedProperty(prop.Object, prop.PropertyKey) : null;
            changeNotification.Post();
        }
Пример #2
0
        /// <summary>
        /// Hidden constructor. For Read() only usage.
        /// </summary>
        private PropertyList(IPropertyListItem root, Version version)
        {
            if (root == null)
                throw new ArgumentNullException("root");
            if (version == null)
                throw new ArgumentNullException("version");

            Root = root;
            Version = version;
        }
Пример #3
0
        /// <summary>
        /// Writes given property list into a designated output.
        /// </summary>
        public static void Write(StringBuilder output, Boolean indented, IPropertyListItem root)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            using (XmlWriter writer = XmlWriter.Create(output, CreateWriteSettings(indented)))
            {
                Write(writer, root);
            }
        }
Пример #4
0
        private IPropertyListItem Add(IPropertyListItem item)
        {
            if (_items.ContainsKey(item.Key))
            {
                _items[item.Key] = item;
            }
            else
            {
                _items.Add(item.Key, item);
            }

            return(item);
        }
Пример #5
0
        /// <summary>
        /// Hidden constructor. For Read() only usage.
        /// </summary>
        private PropertyList(IPropertyListItem root, Version version)
        {
            if (root == null)
            {
                throw new ArgumentNullException("root");
            }
            if (version == null)
            {
                throw new ArgumentNullException("version");
            }

            Root    = root;
            Version = version;
        }
Пример #6
0
        /// <summary>
        /// Writes given property list into a designated output.
        /// </summary>
        public static void Write(XmlWriter writer, IPropertyListItem root)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            writer.WriteStartDocument();
            writer.WriteDocType("plist", "-//Apple Computer//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);
            writer.WriteStartElement("plist");
            writer.WriteAttributeString("version", "1.0");
            WriteItem(writer, root);
            writer.WriteEndElement();
            writer.WriteEndDocument();
        }
Пример #7
0
 private IPropertyListItem Add(IPropertyListItem item)
 {
     _items.Add(item);
     return item;
 }
        private IPropertyListItem Add(IPropertyListItem item)
        {
            if (_items.ContainsKey(item.Key))
                _items[item.Key] = item;
            else
                _items.Add(item.Key, item);

            return item;
        }
Пример #9
0
        private static void WriteItem(XmlWriter writer, IPropertyListItem item)
        {
            switch (item.Type)
            {
                case PropertyListItemTypes.Dictionary:
                    writer.WriteStartElement("dict");
                    foreach (KeyValuePair<string, IPropertyListItem> childItem in item.DictionaryItems)
                    {
                        writer.WriteStartElement("key");
                        writer.WriteString(childItem.Key);
                        writer.WriteEndElement();
                        WriteItem(writer, childItem.Value);
                    }
                    writer.WriteEndElement();
                    break;

                case PropertyListItemTypes.Array:
                    writer.WriteStartElement("array");
                    foreach (IPropertyListItem childItem in item.ArrayItems)
                        WriteItem(writer, childItem);
                    writer.WriteEndElement();
                    break;

                case PropertyListItemTypes.Binary:
                    writer.WriteStartElement("data");
                    writer.WriteBase64(item.BinaryValue, 0, item.BinaryValue.Length);
                    writer.WriteEndElement();
                    break;

                case PropertyListItemTypes.Boolean:
                    if (item.BooleanValue)
                        writer.WriteStartElement("true");
                    else
                        writer.WriteStartElement("false");
                    writer.WriteEndElement();
                    break;

                case PropertyListItemTypes.DateTime:
                    writer.WriteStartElement("date");
                    writer.WriteString(item.DateTimeValue.ToString("s", CultureInfo.InvariantCulture));
                    writer.WriteEndElement();
                    break;

                case PropertyListItemTypes.String:
                    writer.WriteStartElement("string");
                    writer.WriteString(item.StringValue);
                    writer.WriteEndElement();
                    break;

                case PropertyListItemTypes.FloatingNumber:
                    writer.WriteStartElement("real");
                    writer.WriteString(item.StringValue);
                    writer.WriteEndElement();
                    break;

                case PropertyListItemTypes.IntegerNumber:
                    writer.WriteStartElement("integer");
                    writer.WriteString(item.StringValue);
                    writer.WriteEndElement();
                    break;

                default:
                    throw new InvalidOperationException("Serialization action not defined for given item type (" + item.Type + ")!");
            }
        }
Пример #10
0
        /// <summary>
        /// Writes given property list into a designated output.
        /// </summary>
        public static void Write(XmlWriter writer, IPropertyListItem root)
        {
            if (writer == null)
                throw new ArgumentNullException("writer");

            writer.WriteStartDocument();
            writer.WriteDocType("plist", "-//Apple Computer//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);
            writer.WriteStartElement("plist");
            writer.WriteAttributeString("version", "1.0");
            WriteItem(writer, root);
            writer.WriteEndElement();
            writer.WriteEndDocument();
        }
Пример #11
0
        /// <summary>
        /// Writes given property list into a designated output.
        /// </summary>
        public static void Write(StringBuilder output, Boolean indented, IPropertyListItem root)
        {
            if (output == null)
                throw new ArgumentNullException("output");

            using (XmlWriter writer = XmlWriter.Create(output, CreateWriteSettings(indented)))
            {
                Write(writer, root);
            }
        }
Пример #12
0
        private static void WriteItem(XmlWriter writer, IPropertyListItem item)
        {
            switch (item.Type)
            {
            case PropertyListItemTypes.Dictionary:
                writer.WriteStartElement("dict");
                foreach (KeyValuePair <string, IPropertyListItem> childItem in item.DictionaryItems)
                {
                    writer.WriteStartElement("key");
                    writer.WriteString(childItem.Key);
                    writer.WriteEndElement();
                    WriteItem(writer, childItem.Value);
                }
                writer.WriteEndElement();
                break;

            case PropertyListItemTypes.Array:
                writer.WriteStartElement("array");
                foreach (IPropertyListItem childItem in item.ArrayItems)
                {
                    WriteItem(writer, childItem);
                }
                writer.WriteEndElement();
                break;

            case PropertyListItemTypes.Binary:
                writer.WriteStartElement("data");
                writer.WriteBase64(item.BinaryValue, 0, item.BinaryValue.Length);
                writer.WriteEndElement();
                break;

            case PropertyListItemTypes.Boolean:
                if (item.BooleanValue)
                {
                    writer.WriteStartElement("true");
                }
                else
                {
                    writer.WriteStartElement("false");
                }
                writer.WriteEndElement();
                break;

            case PropertyListItemTypes.DateTime:
                writer.WriteStartElement("date");
                writer.WriteString(item.DateTimeValue.ToString("s", CultureInfo.InvariantCulture));
                writer.WriteEndElement();
                break;

            case PropertyListItemTypes.String:
                writer.WriteStartElement("string");
                writer.WriteString(item.StringValue);
                writer.WriteEndElement();
                break;

            case PropertyListItemTypes.FloatingNumber:
                writer.WriteStartElement("real");
                writer.WriteString(item.StringValue);
                writer.WriteEndElement();
                break;

            case PropertyListItemTypes.IntegerNumber:
                writer.WriteStartElement("integer");
                writer.WriteString(item.StringValue);
                writer.WriteEndElement();
                break;

            default:
                throw new InvalidOperationException("Serialization action not defined for given item type (" + item.Type + ")!");
            }
        }
Пример #13
0
        /// <summary>
        /// Reads the texts and interprets as PList definition.
        /// </summary>
        public static PropertyList Read(TextReader text)
        {
            try
            {
                XmlReaderSettings settings = new XmlReaderSettings();

#if NET_2_COMPATIBLE && !PocketPC && !WINDOWS_PHONE
                // obsolete, but will cause an exception at start-up if not set to false (crazy!)
                settings.ProhibitDtd = false;
#endif

#if !NET_2_COMPATIBLE
                settings.DtdProcessing = DtdProcessing.Ignore;
#endif
                settings.IgnoreComments = true;
                settings.IgnoreProcessingInstructions = true;
                settings.IgnoreWhitespace             = true;

                Version           resultVersion = null;
                IPropertyListItem result        = null;
                int    intNumber;
                double doubleNumber;
                string key = null;
                Stack <IPropertyListItem> items = new Stack <IPropertyListItem>();

                using (XmlReader reader = XmlReader.Create(text, settings))
                {
                    while (reader.Read())
                    {
                        switch (reader.NodeType)
                        {
                        case XmlNodeType.Element:
                            if (reader.Name == "plist")
                            {
                                if (resultVersion != null)
                                {
                                    throw new FormatException("Secondary plist definition not expected");
                                }

                                if (reader.MoveToAttribute("version"))
                                {
                                    if (reader.ReadAttributeValue())
                                    {
                                        resultVersion = new Version(reader.Value);
                                    }
                                }
                                break;
                            }

                            if (reader.Name == "key")
                            {
                                if (key != null)
                                {
                                    throw new FormatException("Two keys in a row are not expected");
                                }

                                if (reader.Read())
                                {
                                    key = reader.Value;
                                }
                                break;
                            }

                            if (reader.Name == "dict")
                            {
                                if (key == null)
                                {
                                    if (result == null)
                                    {
                                        result = new PropertyListDictionary(null);
                                        if (!reader.IsEmptyElement)
                                        {
                                            items.Push(result);
                                        }
                                        break;
                                    }
                                    if (items.Peek().Type != PropertyListItemTypes.Array)
                                    {
                                        throw new FormatException("Found dictionary definition without key name");
                                    }
                                }

                                // add new dictionary to the top collection:
                                var newDictionary = items.Peek().AddNewDictionary(key);
                                if (!reader.IsEmptyElement)
                                {
                                    items.Push(newDictionary);
                                }
                                key = null;
                                break;
                            }

                            if (reader.Name == "array")
                            {
                                if (key == null)
                                {
                                    if (result == null)
                                    {
                                        result = new PropertyListArray(null);
                                        if (!reader.IsEmptyElement)
                                        {
                                            items.Push(result);
                                        }
                                        break;
                                    }
                                    if (items.Peek().Type != PropertyListItemTypes.Array)
                                    {
                                        throw new FormatException("Found array definition without key name");
                                    }
                                }

                                // add new array to the top collection:
                                var newArray = items.Peek().AddNewArray(key);
                                if (!reader.IsEmptyElement)
                                {
                                    items.Push(newArray);
                                }
                                key = null;
                                break;
                            }

                            if (reader.Name == "string")
                            {
                                if (key == null && items.Peek().Type == PropertyListItemTypes.Dictionary)
                                {
                                    throw new FormatException("Found string definition without key name");
                                }

                                if (reader.Read())
                                {
                                    items.Peek().Add(key, reader.Value);
                                }
                                key = null;
                                break;
                            }

                            if (reader.Name == "integer")
                            {
                                if (key == null && items.Peek().Type == PropertyListItemTypes.Dictionary)
                                {
                                    throw new FormatException("Found integer definition without key name");
                                }

                                if (reader.Read())
                                {
                                    if (NumericHelper.TryParseInt32(reader.Value, out intNumber))
                                    {
                                        items.Peek().Add(key, intNumber);
                                    }
                                    else
                                    {
                                        throw new FormatException("Can not parse number: '" + reader.Value + "'");
                                    }
                                }
                                key = null;
                                break;
                            }

                            if (reader.Name == "real")
                            {
                                if (key == null && items.Peek().Type == PropertyListItemTypes.Dictionary)
                                {
                                    throw new FormatException("Found real definition without key name");
                                }

                                if (reader.Read())
                                {
                                    if (NumericHelper.TryParseDouble(reader.Value, NumberStyles.Float, out doubleNumber))
                                    {
                                        items.Peek().Add(key, doubleNumber);
                                    }
                                    else
                                    {
                                        throw new FormatException("Can not parse number: '" + reader.Value + "'");
                                    }
                                }
                                key = null;
                                break;
                            }

                            if (reader.Name == "true")
                            {
                                if (key == null && items.Peek().Type == PropertyListItemTypes.Dictionary)
                                {
                                    throw new FormatException("Found boolean definition without key name");
                                }

                                items.Peek().Add(key, true);
                                key = null;
                                break;
                            }

                            if (reader.Name == "false")
                            {
                                if (key == null && items.Peek().Type == PropertyListItemTypes.Dictionary)
                                {
                                    throw new FormatException("Found boolean definition without key name");
                                }

                                items.Peek().Add(key, false);
                                key = null;
                                break;
                            }

                            if (reader.Name == "date")
                            {
                                if (key == null && items.Peek().Type == PropertyListItemTypes.Dictionary)
                                {
                                    throw new FormatException("Found date definition without key name");
                                }

                                if (reader.Read())
                                {
                                    items.Peek().Add(key, DateTime.Parse(reader.Value, CultureInfo.InvariantCulture));
                                }
                                key = null;
                                break;
                            }

                            if (reader.Name == "data")
                            {
                                if (key == null && items.Peek().Type == PropertyListItemTypes.Dictionary)
                                {
                                    throw new FormatException("Found data definition without key name");
                                }

                                if (reader.Read())
                                {
                                    items.Peek().Add(key, Convert.FromBase64String(reader.Value));
                                }
                                key = null;
                                break;
                            }

                            break;

                        case XmlNodeType.EndElement:
                            if (EndElement(items, reader.Name, "dict", PropertyListItemTypes.Dictionary))
                            {
                                break;
                            }
                            if (EndElement(items, reader.Name, "array", PropertyListItemTypes.Array))
                            {
                                break;
                            }
                            break;
                        }
                    }
                }

                if (items.Count > 0)
                {
                    throw new FormatException("Not all items have been closed");
                }

                return(new PropertyList(result, resultVersion));
            }
            catch (Exception ex)
            {
                DebugLog.WriteCoreException(ex);
                throw;
            }
        }
Пример #14
0
 private IPropertyListItem Add(IPropertyListItem item)
 {
     _items.Add(item);
     return(item);
 }
Пример #15
0
 void IViewModel.OnPropertyCellClicked(IPropertyListItem property)
 {
     HandlePropertyCellClick(property as PropertyInfo);
 }