Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/08/19 00:23:12 (5 years ago)
Author:
mkommend
Message:

#2520: Merged 16584, 16585,16594,16595, 16625, 16658, 16659, 16672, 16707, 16729, 16792, 16796, 16797, 16799, 16819, 16906, 16907, 16908, 16933, 16945, 16992, 16994, 16995, 16996, 16997, 17014, 17015, 17017, 17020, 17021, 17022, 17023, 17024, 17029, 17086, 17087, 17088, 17089 into stable.

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Core

  • stable/HeuristicLab.Core/3.3/PersistenceContentManager.cs

    r17097 r17105  
    2525using HEAL.Attic;
    2626using System;
     27using System.Diagnostics;
    2728
    2829namespace HeuristicLab.Core {
     
    3031    public PersistenceContentManager() : base() { }
    3132
    32     protected override IStorableContent LoadContent(string filename) {
    33       // first try to load using the new persistence format
    34       try {
     33    protected override IStorableContent LoadContent(string filename, out Info info) {
     34      bool useOldPersistence = XmlParser.CanOpen(filename);
     35      IStorableContent content = null;
     36      if (useOldPersistence) {
     37        var sw = new Stopwatch();
     38        sw.Start();
     39        content = XmlParser.Deserialize<IStorableContent>(filename);
     40        sw.Stop();
     41        info = new Info(filename, sw.Elapsed);
     42      } else {
    3543        var ser = new ProtoBufSerializer();
    36         return (IStorableContent)ser.Deserialize(filename);
    37       } catch (Exception) {
    38         // try old format if new format fails
    39         return XmlParser.Deserialize<IStorableContent>(filename);
     44        content = (IStorableContent)ser.Deserialize(filename, out SerializationInfo serInfo);
     45        info = new Info(filename, serInfo);
    4046      }
     47      if (content == null) throw new PersistenceException($"Cannot deserialize root element of {filename}");
     48      return content;
    4149    }
     50
    4251
    4352    protected override void SaveContent(IStorableContent content, string filename, bool compressed, CancellationToken cancellationToken) {
    4453      var ser = new ProtoBufSerializer();
    45       ser.Serialize(content, filename, cancellationToken); 
     54      ser.Serialize(content, filename, cancellationToken);
    4655    }
    4756  }
Note: See TracChangeset for help on using the changeset viewer.