Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/04/09 16:43:46 (15 years ago)
Author:
epitzer
Message:

Added Serialization to stream. Do not overwrite file if serialization fails. (#603)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs

    r1704 r1733  
    161161
    162162    public static void Serialize(object obj, string filename, Configuration config) {
     163      string tempfile = Path.GetTempFileName();
     164      try {
     165        Serialize(obj, File.Create(tempfile), config);
     166        File.Copy(tempfile, filename, true);
     167        File.Delete(tempfile);
     168      } catch (Exception x) {
     169        Logger.Warn("Exception caught, no data has been written.");
     170        throw;
     171      }
     172    }
     173
     174    public static void Serialize(object obj, Stream stream, Configuration config) {
    163175      try {
    164176        Serializer serializer = new Serializer(obj, config);
    165177        XmlGenerator generator = new XmlGenerator();
    166178        ILog logger = Logger.GetDefaultLogger();
    167         using (ZipOutputStream zipStream = new ZipOutputStream(File.Create(filename))) {
     179        using (ZipOutputStream zipStream = new ZipOutputStream(stream)) {
    168180          zipStream.SetLevel(9);
    169181          zipStream.PutNextEntry(new ZipEntry("data.xml"));
Note: See TracChangeset for help on using the changeset viewer.