Ejemplo n.º 1
0
        /// <summary>
        /// Loads widget data from a stream whose format must match the specified format that is expected.
        /// </summary>
        /// <param name="stream">Stream object which contains serialized data</param>
        /// <param name="format">Identifies the expected format of the stream being read</param>
        public void Load(Stream stream, WidgetDocSaveFormat format)
        {
            WidgetContainerData container = null;

            if (format == WidgetDocSaveFormat.Xml)
            {
                using (XmlTextReader reader = new XmlTextReader(stream))
                {
                    reader.MoveToContent();

                    container = (WidgetContainerData)WidgetData.Create(reader);
                }
            }
            else if (format == WidgetDocSaveFormat.Binary)
            {
                IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

                container = (WidgetContainerData)formatter.Deserialize(stream);
            }
            else
            {
                throw new InvalidOperationException(string.Format("Invalid save mode specified ({0})", (int)format));
            }

            container.PostDeserialize();

            this.Root = container;
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        protected override void DeserializeFromXml(XmlReader reader)
        {
            _containerBounds.Row    = XmlConvert.ToInt32(reader.GetAttribute("firstRow"));
            _containerBounds.Column = XmlConvert.ToInt32(reader.GetAttribute("firstColumn"));

            MatrixSize size = new MatrixSize(
                XmlConvert.ToInt32(reader.GetAttribute("rowCount")),
                XmlConvert.ToInt32(reader.GetAttribute("columnCount")));

            Resize(size, 0);

            if (!reader.Read())
            {
                return;
            }

            while (reader.NodeType != XmlNodeType.EndElement)
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (string.Compare(reader.Name, "Children", true) == 0)
                    {
                        reader.Read();

                        while (reader.NodeType != XmlNodeType.EndElement)
                        {
                            if (reader.NodeType == XmlNodeType.Element)
                            {
                                WidgetData widget = WidgetData.Create(reader);
                                this[widget.Location] = widget;
                            }
                            else
                            {
                                reader.Read();
                            }
                        }

                        reader.ReadEndElement();
                    }
                    else
                    {
                        reader.Skip();
                    }
                }
                else
                {
                    reader.Read();
                }
            }
        }