internal static ObjectGroup Load(XmlReader reader)
        {
            var         result = new ObjectGroup();
            CultureInfo ci     = (CultureInfo)CultureInfo.CurrentCulture.Clone();

            ci.NumberFormat.CurrencyDecimalSeparator = ".";

            if (reader.GetAttribute("name") != null)
            {
                result.Name = reader.GetAttribute("name");
            }
            if (reader.GetAttribute("width") != null)
            {
                result.Width = int.Parse(reader.GetAttribute("width"));
            }
            if (reader.GetAttribute("height") != null)
            {
                result.Height = int.Parse(reader.GetAttribute("height"));
            }
            if (reader.GetAttribute("x") != null)
            {
                result.X = int.Parse(reader.GetAttribute("x"));
            }
            if (reader.GetAttribute("y") != null)
            {
                result.Y = int.Parse(reader.GetAttribute("y"));
            }
            if (reader.GetAttribute("opacity") != null)
            {
                result.Opacity = float.Parse(reader.GetAttribute("opacity"), NumberStyles.Any, ci);
            }

            while (!reader.EOF)
            {
                var name = reader.Name;

                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (name)
                    {
                    case "object":
                    {
                        using (var st = reader.ReadSubtree())
                        {
                            st.Read();
                            var objects = Object.Load(st);
                            if (!result.Objects.ContainsKey(objects.Name))
                            {
                                result.Objects.Add(objects.Name, objects);
                            }
                            else
                            {
                                int count = result.Objects.Keys.Count((item) => item.Equals(objects.Name));
                                result.Objects.Add(string.Format("{0}{1}", objects.Name, count), objects);
                            }
                        }
                    }
                    break;

                    case "properties":
                    {
                        using (var st = reader.ReadSubtree())
                        {
                            while (!st.EOF)
                            {
                                switch (st.NodeType)
                                {
                                case XmlNodeType.Element:
                                    if (st.Name == "property")
                                    {
                                        if (st.GetAttribute("name") != null)
                                        {
                                            result.Properties.Add(st.GetAttribute("name"), st.GetAttribute("value"));
                                        }
                                    }

                                    break;

                                case XmlNodeType.EndElement:
                                    break;
                                }

                                st.Read();
                            }
                        }
                    }
                    break;
                    }

                    break;

                case XmlNodeType.EndElement:
                    break;
                }

                reader.Read();
            }

            return(result);
        }
Beispiel #2
0
        internal static ObjectGroup Load(XmlReader reader)
        {
            var result = new ObjectGroup();

            if (reader.GetAttribute("name") != null)
            {
                result.Name = reader.GetAttribute("name");
            }
            if (reader.GetAttribute("width") != null)
            {
                result.Width = int.Parse(reader.GetAttribute("width"));
            }
            if (reader.GetAttribute("height") != null)
            {
                result.Height = int.Parse(reader.GetAttribute("height"));
            }
            if (reader.GetAttribute("x") != null)
            {
                result.X = int.Parse(reader.GetAttribute("x"));
            }
            if (reader.GetAttribute("y") != null)
            {
                result.Y = int.Parse(reader.GetAttribute("y"));
            }
            if (reader.GetAttribute("opacity") != null)
            {
                result.Opacity = float.Parse(reader.GetAttribute("opacity"));
            }

            while (!reader.EOF)
            {
                var name = reader.Name;

                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (name)
                    {
                    case "object":
                    {
                        using (var st = reader.ReadSubtree())
                        {
                            st.Read();
                            var objects = Object.Load(st);
                            if (result.Objects.ContainsKey(objects.Name))
                            {
                                result.Objects[objects.Name].Add(objects);
                            }
                            else
                            {
                                List <Object> list = new List <Object>();
                                list.Add(objects);
                                result.Objects.Add(objects.Name, list);
                            }
                        }
                    } break;

                    case "properties":
                    {
                        using (var st = reader.ReadSubtree())
                        {
                            while (!st.EOF)
                            {
                                switch (st.NodeType)
                                {
                                case XmlNodeType.Element:
                                    if (st.Name == "property")
                                    {
                                        //st.Read();
                                        if (st.GetAttribute("name") != null)
                                        {
                                            result.Properties.Add(st.GetAttribute("name"), st.GetAttribute("value"));
                                        }
                                    }

                                    break;

                                case XmlNodeType.EndElement:
                                    break;
                                }

                                st.Read();
                            }
                        }
                    } break;
                    }

                    break;

                case XmlNodeType.EndElement:
                    break;
                }

                reader.Read();
            }

            return(result);
        }