Exemplo n.º 1
0
 /// <summary>
 /// Write the data to a stream
 /// </summary>
 /// <param name="serializationStream">Stream to read the data from</param>
 /// <param name="objectData">List of <see cref="SerializationInfo"/> objects to write</param>
 public void Write(Stream serializationStream, List <SerializationInfo> objectData)
 {
     using (var xmlWrtier = XmlDictionaryWriter.CreateBinaryWriter(serializationStream, null, null, false))
     {
         DataContractSerializer dataContractSerializer = CslaReaderWriterFactory.GetDataContractSerializer();
         dataContractSerializer.WriteObject(xmlWrtier, objectData);
         xmlWrtier.Flush();
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Read the data from a stream and produce list of <see cref="SerializationInfo"/> objects
        /// </summary>
        /// <param name="serializationStream">Stream to read the data from</param>
        /// <returns>List of SerializationInfo objects</returns>
        public List <SerializationInfo> Read(Stream serializationStream)
        {
            List <SerializationInfo> returnValue = null;

            using (var xmlReader = XmlReader.Create(serializationStream))
            {
                DataContractSerializer dataContractSerializer = CslaReaderWriterFactory.GetDataContractSerializer();
                returnValue = (List <SerializationInfo>)dataContractSerializer.ReadObject(xmlReader);
            }
            return(returnValue);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Deserialize an object from XML.
        /// </summary>
        /// <param name="serializationStream">
        /// Stream containing the serialized XML
        /// data.
        /// </param>
        /// <returns></returns>
        public object Deserialize(Stream serializationStream)
        {
            if (serializationStream == null)
            {
                return(null);
            }

            ICslaReader reader = CslaReaderWriterFactory.GetCslaReader();
            var         data   = reader.Read(serializationStream);

            return(DeserializeAsDTO(data));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Write the data to a stream
 /// </summary>
 /// <param name="serializationStream">Stream to read the data from</param>
 /// <param name="objectData">List of <see cref="SerializationInfo"/> objects to write</param>
 public void Write(Stream serializationStream, List <SerializationInfo> objectData)
 {
     using (var xmlWrtier = XmlWriter.Create(serializationStream, new XmlWriterSettings()
     {
         CloseOutput = false
     }))
     {
         DataContractSerializer dataContractSerializer = CslaReaderWriterFactory.GetDataContractSerializer();
         dataContractSerializer.WriteObject(xmlWrtier, objectData);
         xmlWrtier.Flush();
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Deserialize an object from XML.
        /// </summary>
        /// <param name="buffer">
        /// Stream containing the serialized XML
        /// data.
        /// </param>
        /// <returns></returns>
        object ISerializationFormatter.Deserialize(byte[] buffer)
        {
            if (buffer.Length == 0)
            {
                return(null);
            }
            using var serializationStream = new MemoryStream(buffer);
            ICslaReader reader = CslaReaderWriterFactory.GetCslaReader(ApplicationContext);
            var         data   = reader.Read(serializationStream);

            return(DeserializeAsDTO(data));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Serialize an object graph into XML.
        /// </summary>
        /// <param name="serializationStream">
        /// Stream to which the serialized data
        /// will be written.
        /// </param>
        /// <param name="graph">
        /// Root object of the object graph
        /// to serialize.
        /// </param>
        public void Serialize(Stream serializationStream, object graph)
        {
            ICslaWriter writer = CslaReaderWriterFactory.GetCslaWriter();

            writer.Write(serializationStream, SerializeToDTO(graph));
        }