- Timestamp:
- 05/11/19 14:38:47 (6 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Core/3.3/PersistenceContentManager.cs
r16933 r16945 31 31 32 32 protected override IStorableContent LoadContent(string filename) { 33 // first try to load using the new persistence format 33 bool useOldPersistence = XmlParser.CanOpen(filename); 34 if (useOldPersistence) return XmlParser.Deserialize<IStorableContent>(filename); 35 34 36 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 } 44 } 37 return (IStorableContent)ser.Deserialize(filename, out SerializationInfo info); 45 38 } 46 39 -
trunk/HeuristicLab.Persistence/3.3/Default/Xml/XmlParser.cs
r16565 r16945 288 288 } 289 289 } 290 291 /// <summary> 292 /// Checks if the given file can be opened as <see cref="ZipArchive" />. 293 /// </summary> 294 /// <param name="filename">The filename.</param> 295 /// <returns><see langword="true" /> if the file can be opened as <see cref="ZipArchive" />; otherwise, <see langword="false" />.</returns> 296 public static bool CanOpen(string filename) { 297 try { 298 using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) { 299 using (ZipArchive zip = new ZipArchive(fs)) { 300 return true; 301 } 302 } 303 } catch (InvalidDataException) { 304 return false; 305 } 306 } 290 307 } 291 308 }
Note: See TracChangeset
for help on using the changeset viewer.