Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/11/19 20:59:44 (5 years ago)
Author:
gkronber
Message:

#2994: merged r16944:16997 from trunk to branch

Location:
branches/2994-AutoDiffForIntervals
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2994-AutoDiffForIntervals

  • branches/2994-AutoDiffForIntervals/HeuristicLab.Core

  • branches/2994-AutoDiffForIntervals/HeuristicLab.Core/3.3/PersistenceContentManager.cs

    r16943 r17005  
    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       var ser = new ProtoBufSerializer();
    35       try {
    36         return (IStorableContent)ser.Deserialize(filename, out SerializationInfo info);
    37       } catch (Exception e) {
    38         try {
    39           // try old format if new format fails
    40           return XmlParser.Deserialize<IStorableContent>(filename);
    41         } catch (Exception e2) {
    42           throw new AggregateException($"Cannot open file {filename}", e, e2);
    43         }
     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 {
     43        var ser = new ProtoBufSerializer();
     44        content = (IStorableContent)ser.Deserialize(filename, out SerializationInfo serInfo);
     45        info = new Info(filename, serInfo);
    4446      }
     47      if (content == null) throw new PersistenceException($"Cannot deserialize root element of {filename}");
     48      return content;
    4549    }
     50
    4651
    4752    protected override void SaveContent(IStorableContent content, string filename, bool compressed, CancellationToken cancellationToken) {
Note: See TracChangeset for help on using the changeset viewer.