Changeset 1733
- Timestamp:
- 05/04/09 16:43:46 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Persistence
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs
r1704 r1733 161 161 162 162 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) { 163 175 try { 164 176 Serializer serializer = new Serializer(obj, config); 165 177 XmlGenerator generator = new XmlGenerator(); 166 178 ILog logger = Logger.GetDefaultLogger(); 167 using (ZipOutputStream zipStream = new ZipOutputStream( File.Create(filename))) {179 using (ZipOutputStream zipStream = new ZipOutputStream(stream)) { 168 180 zipStream.SetLevel(9); 169 181 zipStream.PutNextEntry(new ZipEntry("data.xml")); -
trunk/sources/HeuristicLab.Persistence/UnitTests/UseCases.cs
r1705 r1733 172 172 [Storable] 173 173 public KeyValuePair<List<C>, C> kvpList; 174 } 175 176 public class NonSerializable { 177 int x; 174 178 } 175 179 … … 504 508 } 505 509 510 [TestMethod] 511 public void TestSavingException() { 512 List<int> list = new List<int> { 1, 2, 3 }; 513 XmlGenerator.Serialize(list, tempFile); 514 NonSerializable s = new NonSerializable(); 515 try { 516 XmlGenerator.Serialize(s, tempFile); 517 Assert.Fail("Exception expected"); 518 } catch (PersistenceException) { } 519 List<int> newList = (List<int>)XmlParser.DeSerialize(tempFile); 520 Assert.AreEqual(list[0], newList[0]); 521 Assert.AreEqual(list[1], newList[1]); 522 } 523 506 524 [ClassInitialize] 507 525 public static void Initialize(TestContext testContext) {
Note: See TracChangeset
for help on using the changeset viewer.