Exemplo n.º 1
0
 public void Load(XmlItem rootItem)
 {
     Clear();
     for (int i = 0; i < rootItem.Count; i++)
     {
         Add(Converter.FromString(typeof(Stream), Converter.FromXml(rootItem[i].GetProp("Stream"))) as Stream);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Reads the enum property.
        /// </summary>
        /// <param name="name">Name of property.</param>
        /// <param name="typ">Type of property.</param>
        /// <returns>Property value.</returns>
        public object ReadValue(string name, Type typ)
        {
            string propValue = PropValue(name);

            if (propValue == "null")
            {
                return(null);
            }
            return(Converter.FromString(typ, Converter.FromXml(propValue)));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets a property with specified name.
        /// </summary>
        /// <param name="index">The property name.</param>
        /// <returns>The value of property, if found; empty string otherwise.</returns>
        /// <remarks>
        /// This property will return "0" when you request the "Left" property for a node
        /// like <c>&lt;Node Text="" Left="0"/&gt;</c>
        /// </remarks>
        public string GetProp(string index)
        {
            string result = "";
            int    i      = FText.ToUpper().IndexOf(index.ToUpper() + "=\"");

            if (i != -1 && (i == 0 || FText[i - 1] == 32))
            {
                result = FText.Substring(i + index.Length + 2);
                result = Converter.FromXml(result.Substring(0, result.IndexOf("\"")));
            }
            else
            {
                result = "";
            }
            return(result);
        }
Exemplo n.º 4
0
        private bool ReadValue(XmlItem item)
        {
            FastString builder;

            if (Config.IsStringOptimization)
            {
                builder = new FastStringWithPool(stringPool);
            }
            else
            {
                builder = new FastString();
            }
            ReadState state          = ReadState.FindLeft;
            string    lastName       = "</" + this.lastName + ">";
            int       lastNameLength = lastName.Length;

            do
            {
                int c = reader.Read();
                if (c == -1)
                {
                    RaiseException();
                }

                builder.Append((char)c);
                if (state == ReadState.FindLeft)
                {
                    if (c == '<')
                    {
                        symbolInBuffer = '<';
                        return(false);
                    }
                    else if (c != ' ' && c != '\r' && c != '\n' && c != '\t')
                    {
                        state = ReadState.FindCloseItem;
                    }
                }
                else if (state == ReadState.FindCloseItem)
                {
                    if (builder.Length >= lastNameLength)
                    {
                        bool match = true;
                        for (int j = 0; j < lastNameLength; j++)
                        {
                            if (builder[builder.Length - lastNameLength + j] != lastName[j])
                            {
                                match = false;
                                break;
                            }
                        }

                        if (match)
                        {
                            builder.Length -= lastNameLength;
                            item.Value      = Converter.FromXml(builder.ToString());
                            return(true);
                        }
                    }
                }
            }while (true);
        }
Exemplo n.º 5
0
        private ItemState ReadItem(XmlItem item)
        {
            FastString builder;

            if (Config.IsStringOptimization)
            {
                builder = new FastStringWithPool(stringPool);
            }
            else
            {
                builder = new FastString();
            }
            ReadState state   = ReadState.FindLeft;
            int       comment = 0;
            int       i       = 0;
            //string tempAttrName = null;
            //int lc = -1;
            int c = -1;

            // find <
            c = readNextSymbol();
            while (c != -1)
            {
                if (c == '<')
                {
                    break;
                }
                c = readNextSymbol();
            }

            //while not end
            while (state != ReadState.Done && c != -1)
            {
                // find name or comment;
                c = readNextSymbol();
                i = 0;
                while (c != -1)
                {
                    if (i <= comment)
                    {
                        switch (comment)
                        {
                        case 0: if (c == '!')
                            {
                                comment++;
                            }
                            break;

                        case 1: if (c == '-')
                            {
                                comment++;
                            }
                            break;

                        case 2: if (c == '-')
                            {
                                state = ReadState.FindComment;
                            }
                            break;

                        default: comment = -1; break;
                        }
                        if (state == ReadState.FindComment)
                        {
                            break;
                        }
                    }
                    i++;
                    switch (c)
                    {
                    case '>': state = ReadState.Done; break;      //Found name

                    case ' ': state = ReadState.FindRight; break; //Found name

                    case '<': RaiseException(); break;

                    default: builder.Append((char)c); break;
                    }
                    if (state != ReadState.FindLeft)
                    {
                        break;
                    }
                    c = readNextSymbol();
                }
                switch (state)
                {
                case ReadState.FindComment:
                    comment = 0;
                    while (c != -1)
                    {
                        c = readNextSymbol();
                        if (comment > 1)
                        {
                            if (c == '>')
                            {
                                state = ReadState.FindLeft;
                                break;
                            }
                        }
                        else
                        {
                            if (c == '-')
                            {
                                comment++;
                            }
                            else
                            {
                                comment = 0;
                            }
                        }
                    }
                    comment        = 0;
                    builder.Length = 0;
                    while (c != -1)
                    {
                        if (c == '<')
                        {
                            break;
                        }
                        c = readNextSymbol();
                    }
                    break;

                case ReadState.Done:
                    string result = builder.ToString();
                    if (result[0] == '/')
                    {
                        item.Name = result.Substring(1);
                        return(ItemState.End);
                    }
                    if (result[result.Length - 1] == '/')
                    {
                        item.Name = result.Substring(0, result.Length - 1);
                        return(ItemState.Complete);
                    }
                    item.Name = result;
                    return(ItemState.Begin);

                case ReadState.FindRight:
                    if (builder[0] == '/')
                    {
                        builder.Remove(0, 1);
                        item.Name = builder.ToString();
                        return(ItemState.End);
                    }
                    item.Name      = builder.ToString();
                    builder.Length = 0;
                    while (c != -1 && c != '>')
                    {
                        c = readNextSymbol();
                        while (c != -1)
                        {
                            if (c == ' ')
                            {
                                builder.Length = 0;
                                c = readNextSymbol();
                                continue;
                            }
                            if (c == '=' || c == '>')
                            {
                                break;
                            }
                            builder.Append((char)c);
                            c = readNextSymbol();
                        }
                        if (c == '>')
                        {
                            if (builder.Length > 0 && builder[builder.Length - 1] == '/')
                            {
                                return(ItemState.Complete);
                            }
                            return(ItemState.Begin);
                        }
                        c = readNextSymbol();
                        if (c != '"')
                        {
                            continue;
                        }
                        string attrName = builder.ToString();
                        builder.Length = 0;
                        while (c != -1)
                        {
                            c = readNextSymbol();
                            if (c == '"')
                            {
                                break;
                            }
                            builder.Append((char)c);
                        }
                        item.SetProp(attrName, Converter.FromXml(builder.ToString()));
                        builder.Length = 0;
                    }
                    break;
                }
            }


            //just for errors
            return(ItemState.Begin);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Reads the standalone property value.
 /// </summary>
 /// <returns>Property value.</returns>
 public string ReadPropertyValue()
 {
     return(Converter.FromXml(FCurItem.Value));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Reads the string property.
 /// </summary>
 /// <param name="name">Name of property.</param>
 /// <returns>Property value.</returns>
 public string ReadStr(string name)
 {
     return(Converter.FromXml(PropValue(name)));
 }
Exemplo n.º 8
0
        /// <summary>
        /// Reads properties of specified object.
        /// </summary>
        /// <param name="obj">The object to read.</param>
        /// <remarks>
        /// This method reads simple properties like "Text", "Border.Lines" etc. for specified object.
        /// To read nested properties like collections, you should override the <see cref="Base.DeserializeSubItems"/>
        /// method of an object.
        /// </remarks>
        /// <example>This example demonstrates the use of <b>ReadProperties</b>, <b>ReadChildren</b>,
        /// <b>NextItem</b>, <b>Read</b> methods.
        /// <code>
        /// public void Deserialize(FRReader reader)
        /// {
        ///   // read simple properties like "Text", complex properties like "Border.Lines"
        ///   reader.ReadProperties(this);
        ///
        ///   // moves the current reader item
        ///   while (reader.NextItem())
        ///   {
        ///     // read the "Styles" collection
        ///     if (String.Compare(reader.ItemName, "Styles", true) == 0)
        ///       reader.Read(Styles);
        ///     else if (reader.ReadChildren)
        ///     {
        ///       // if read of children is enabled, read them
        ///       Base obj = reader.Read();
        ///       if (obj != null)
        ///          obj.Parent = this;
        ///     }
        ///   }
        /// }
        /// </code>
        /// </example>
        public void ReadProperties(object obj)
        {
            // speed optimization, for use in the preview mode
            if (obj is TextObject && FProps.Count == 1 && FProps[0].Name == "x")
            {
                (obj as TextObject).Text = Converter.FromXml(FProps[0].Value);
                return;
            }

            for (int i = 0; i < FProps.Count; i++)
            {
                string name  = FProps[i].Name;
                string value = FProps[i].Value;

                // check multiple properties like Frame.LeftLine.Typ
                object obj1  = obj;
                int    len   = name.Length;
                int    start = 0;
                int    j     = 0;
                // find '.'
                while (j < len && name[j] != '.')
                {
                    j++;
                }
                if (j < len)
                {
                    while (j < len)
                    {
                        // get subproperty
                        PropertyInfo pi = obj1.GetType().GetProperty(name.Substring(start, j - start));
                        if (pi == null)
                        {
                            break;
                        }
                        obj1 = pi.GetValue(obj1, null);

                        // find next '.'
                        start = j + 1;
                        j++;
                        while (j < len && name[j] != '.')
                        {
                            j++;
                        }
                    }
                    name = name.Substring(start);
                }

                try
                {
                    name = PropName(name);
                    PropertyInfo pi = obj1.GetType().GetProperty(name);
                    if (pi == null)
                    {
                        continue;
                    }

                    if (value == "null")
                    {
                        pi.SetValue(obj1, value, null);
                    }
                    else
                    {
                        if (pi.PropertyType == typeof(string))
                        {
                            pi.SetValue(obj1, Converter.FromXml(value), null);
                        }
                        else if (pi.PropertyType.IsClass && pi.PropertyType.IsSubclassOf(typeof(Base)))
                        {
                            // it's a reference
                            FFixups.Add(new FixupInfo(obj1 as Base, name, Converter.FromXml(value)));
                        }
                        else
                        {
                            pi.SetValue(obj1, Converter.FromString(pi.PropertyType, Converter.FromXml(value)), null);
                        }
                    }
                }
                catch (Exception e)
                {
                    FErrors += e.Message + "\r\n";
                }
            }
        }