Changeset 1734
- Timestamp:
- 05/04/09 16:50:34 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/3.3/PersistenceManager.cs
r1667 r1734 28 28 using HeuristicLab.PluginInfrastructure; 29 29 using HeuristicLab.Persistence.Default.Xml; 30 using HeuristicLab.Persistence.Core; 30 31 31 32 namespace HeuristicLab.Core { … … 51 52 /// <param name="stream">The (file) stream where the object should be saved.</param> 52 53 public static void Save(IStorable instance, Stream stream) { 53 string tempfile = Path.GetTempFileName(); 54 XmlGenerator.Serialize(instance, tempfile); 55 Stream reader = new FileStream(tempfile, FileMode.Open); 56 byte[] buffer = new byte[1024]; 57 int bytesRead = 0; 58 do { 59 bytesRead = reader.Read(buffer, 0, buffer.Length); 60 stream.Write(buffer, 0, bytesRead); 61 } while (bytesRead > 0); 62 reader.Close(); 63 stream.Close(); 64 File.Delete(tempfile); 54 XmlGenerator.Serialize(instance, stream, ConfigurationService.Instance.GetConfiguration(new XmlFormat())); 65 55 } 66 56 /// <summary> … … 72 62 /// <returns>The loaded object.</returns> 73 63 public static IStorable Load(string filename) { 74 return (IStorable)XmlParser.De Serialize(filename);64 return (IStorable)XmlParser.Deserialize(filename); 75 65 } 76 66 /// <summary> … … 82 72 /// <returns>The loaded object.</returns> 83 73 public static IStorable Load(Stream stream) { 84 string tempfile = Path.GetTempFileName(); 85 Stream writer = new FileStream(tempfile, FileMode.CreateNew); 86 byte[] buffer = new byte[1024]; 87 int bytesRead = 0; 88 do { 89 bytesRead = stream.Read(buffer, 0, buffer.Length); 90 writer.Write(buffer, 0, bytesRead); 91 } while (bytesRead > 0); 92 stream.Close(); 93 writer.Close(); 94 object o = XmlParser.DeSerialize(tempfile); 95 File.Delete(tempfile); 96 return (IStorable)o; 74 return (IStorable)XmlParser.Deserialize(stream); 97 75 } 98 76 -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlParser.cs
r1703 r1734 122 122 } 123 123 124 public static object DeSerialize(string filename) { 125 try { 126 ZipFile zipFile = new ZipFile(filename); 124 public static object Deserialize(string filename) { 125 return Deserialize(new ZipFile(filename)); 126 } 127 128 public static object Deserialize(Stream stream) { 129 return Deserialize(new ZipFile(stream)); 130 } 131 132 private static object Deserialize(ZipFile zipFile) { 133 try { 127 134 Deserializer deSerializer = new Deserializer( 128 135 ParseTypeCache( -
trunk/sources/HeuristicLab.Persistence/UnitTests/UseCases.cs
r1733 r1734 219 219 r.uninitialized = null; 220 220 XmlGenerator.Serialize(r, tempFile); 221 Root newR = (Root)XmlParser.De Serialize(tempFile);221 Root newR = (Root)XmlParser.Deserialize(tempFile); 222 222 Assert.AreEqual( 223 223 DebugStringGenerator.Serialize(r), … … 283 283 c.kvpList = new KeyValuePair<List<C>, C>(new List<C> { c }, c); 284 284 XmlGenerator.Serialize(cs, tempFile); 285 object o = XmlParser.De Serialize(tempFile);285 object o = XmlParser.Deserialize(tempFile); 286 286 Assert.AreEqual( 287 287 DebugStringGenerator.Serialize(cs), … … 315 315 arrayListArray[2].Add(a); 316 316 XmlGenerator.Serialize(arrayListArray, tempFile); 317 object o = XmlParser.De Serialize(tempFile);317 object o = XmlParser.Deserialize(tempFile); 318 318 Assert.AreEqual( 319 319 DebugStringGenerator.Serialize(arrayListArray), … … 330 330 Manager m = new Manager(); 331 331 XmlGenerator.Serialize(m, tempFile); 332 Manager newM = (Manager)XmlParser.De Serialize(tempFile);332 Manager newM = (Manager)XmlParser.Deserialize(tempFile); 333 333 Assert.AreNotEqual( 334 334 DebugStringGenerator.Serialize(m), … … 344 344 PrimitivesTest sdt = new PrimitivesTest(); 345 345 XmlGenerator.Serialize(sdt, tempFile); 346 object o = XmlParser.De Serialize(tempFile);346 object o = XmlParser.Deserialize(tempFile); 347 347 Assert.AreEqual( 348 348 DebugStringGenerator.Serialize(sdt), … … 357 357 }; 358 358 XmlGenerator.Serialize(mDimString, tempFile); 359 object o = XmlParser.De Serialize(tempFile);359 object o = XmlParser.Deserialize(tempFile); 360 360 Assert.AreEqual( 361 361 DebugStringGenerator.Serialize(mDimString), … … 372 372 NestedType t = new NestedType(); 373 373 XmlGenerator.Serialize(t, tempFile); 374 object o = XmlParser.De Serialize(tempFile);374 object o = XmlParser.Deserialize(tempFile); 375 375 Assert.AreEqual( 376 376 DebugStringGenerator.Serialize(t), … … 383 383 string[] strings = { "ora", "et", "labora" }; 384 384 XmlGenerator.Serialize(strings, tempFile); 385 object o = XmlParser.De Serialize(tempFile);385 object o = XmlParser.Deserialize(tempFile); 386 386 Assert.AreEqual( 387 387 DebugStringGenerator.Serialize(strings), … … 400 400 public void PrimitiveRoot() { 401 401 XmlGenerator.Serialize(12.3f, tempFile); 402 object o = XmlParser.De Serialize(tempFile);402 object o = XmlParser.Deserialize(tempFile); 403 403 Assert.AreEqual( 404 404 DebugStringGenerator.Serialize(12.3f), … … 456 456 new StorableDecomposer(), 457 457 new Number2StringDecomposer() })); 458 object o = XmlParser.De Serialize(tempFile);458 object o = XmlParser.Deserialize(tempFile); 459 459 Assert.AreEqual( 460 460 DebugStringGenerator.Serialize(sdt), … … 467 467 et.OnChange += (o) => o; 468 468 XmlGenerator.Serialize(et, tempFile); 469 EventTest newEt = (EventTest)XmlParser.De Serialize(tempFile);469 EventTest newEt = (EventTest)XmlParser.Deserialize(tempFile); 470 470 } 471 471 … … 477 477 et.trickyEnum = TrickyEnum.two | TrickyEnum.one; 478 478 XmlGenerator.Serialize(et, tempFile); 479 EnumTest newEt = (EnumTest)XmlParser.De Serialize(tempFile);479 EnumTest newEt = (EnumTest)XmlParser.Deserialize(tempFile); 480 480 Assert.AreEqual(et.simpleEnum, SimpleEnum.two); 481 481 Assert.AreEqual(et.complexEnum, ComplexEnum.three); … … 491 491 Assert.AreNotSame(ints[0], ints[1]); 492 492 XmlGenerator.Serialize(ints, tempFile); 493 List<IntWrapper> newInts = (List<IntWrapper>)XmlParser.De Serialize(tempFile);493 List<IntWrapper> newInts = (List<IntWrapper>)XmlParser.Deserialize(tempFile); 494 494 Assert.AreEqual(newInts[0].Value, 1); 495 495 Assert.AreEqual(newInts[1].Value, 1); … … 517 517 Assert.Fail("Exception expected"); 518 518 } catch (PersistenceException) { } 519 List<int> newList = (List<int>)XmlParser.De Serialize(tempFile);519 List<int> newList = (List<int>)XmlParser.Deserialize(tempFile); 520 520 Assert.AreEqual(list[0], newList[0]); 521 521 Assert.AreEqual(list[1], newList[1]);
Note: See TracChangeset
for help on using the changeset viewer.