Ejemplo n.º 1
0
 /// <summary>
 /// Saves widget data object hierarchy to an external file whose format is specified
 /// </summary>
 /// <param name="filePath">File path referencing a new file to be created</param>
 /// <param name="format">Specifies the format in which the file is to be written out</param>
 public void Save(string filePath, WidgetDocSaveFormat format)
 {
     using (Stream stream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
     {
         Save(stream, format);
     }
 }
Ejemplo n.º 2
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.º 3
0
 /// <summary>
 /// Loads widget data from an external file whose format must match the specified format that is expected
 /// </summary>
 /// <param name="filePath">Path to the file to be opened</param>
 /// <param name="format">Identifies the expected format of the file being opened</param>
 public void Load(string filePath, WidgetDocSaveFormat format)
 {
     using (Stream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         Load(stream, format);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Saves widget data object hierarchy to a stream using the specified serialization format
        /// </summary>
        /// <param name="stream">Stream object where serialized data is to be written to</param>
        /// <param name="format">Specifies the format in which the file is to be written out</param>
        public void Save(Stream stream, WidgetDocSaveFormat format)
        {
            if (format == WidgetDocSaveFormat.Xml)
            {
                using (XmlTextWriter writer = new XmlTextWriter(stream, Encoding.Unicode))
                {
                    ((IXmlSerializable)_rootNode).WriteXml(writer);
                }
            }
            else if (format == WidgetDocSaveFormat.Binary)
            {
                IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

                formatter.Serialize(stream, _rootNode);
            }
            else
            {
                throw new InvalidOperationException(string.Format("Invalid save mode specified ({0})", (int)format));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Saves widget data object hierarchy to a stream using the specified serialization format
        /// </summary>
        /// <param name="stream">Stream object where serialized data is to be written to</param>
        /// <param name="format">Specifies the format in which the file is to be written out</param>
        public void Save( Stream stream, WidgetDocSaveFormat format )
        {
            if( format == WidgetDocSaveFormat.Xml )
            {
                using( XmlTextWriter writer = new XmlTextWriter( stream, Encoding.Unicode ) )
                {
                    ( (IXmlSerializable)_rootNode ).WriteXml( writer );
                }
            }
            else if( format == WidgetDocSaveFormat.Binary )
            {
                IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

                formatter.Serialize( stream, _rootNode );
            }
            else
            {
                throw new InvalidOperationException( string.Format( "Invalid save mode specified ({0})", (int)format ) );
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Saves widget data object hierarchy to an external file whose format is specified
 /// </summary>
 /// <param name="filePath">File path referencing a new file to be created</param>
 /// <param name="format">Specifies the format in which the file is to be written out</param>
 public void Save( string filePath, WidgetDocSaveFormat format )
 {
     using( Stream stream = new FileStream( filePath, FileMode.Create, FileAccess.Write, FileShare.None ) )
     {
         Save( stream, format );
     }
 }
Ejemplo n.º 7
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.º 8
0
 /// <summary>
 /// Loads widget data from an external file whose format must match the specified format that is expected
 /// </summary>
 /// <param name="filePath">Path to the file to be opened</param>
 /// <param name="format">Identifies the expected format of the file being opened</param>
 public void Load( string filePath, WidgetDocSaveFormat format )
 {
     using( Stream stream = new FileStream( filePath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
     {
         Load( stream, format );
     }
 }