Changeset 16480 for branches/2520_PersistenceReintegration
- Timestamp:
- 01/02/19 16:07:07 (6 years ago)
- Location:
- branches/2520_PersistenceReintegration
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2520_PersistenceReintegration/HeuristicLab.Clients.Hive/3.3/Util/PersistenceUtil.cs
r16453 r16480 23 23 using System.Collections.Generic; 24 24 using System.IO; 25 using HeuristicLab.Persistence.Core; 26 using HeuristicLab.Persistence.Default.Xml; 25 using HEAL.Fossil; 27 26 28 27 namespace HeuristicLab.Clients.Hive { … … 30 29 public static byte[] Serialize(object obj, out IEnumerable<Type> types) { 31 30 using (MemoryStream memStream = new MemoryStream()) { 32 XmlGenerator.Serialize(obj, memStream, ConfigurationService.Instance.GetConfiguration(new XmlFormat()), false, out types); 33 byte[] jobByteArray = memStream.ToArray(); 34 return jobByteArray; 31 throw new NotImplementedException("Not supported by HEAL.Fossil yet."); // TODO 32 // XmlGenerator.Serialize(obj, memStream, ConfigurationService.Instance.GetConfiguration(new XmlFormat()), false, out types); 33 // byte[] jobByteArray = memStream.ToArray(); 34 // return jobByteArray; 35 35 } 36 36 } 37 37 38 38 public static byte[] Serialize(object obj) { 39 using (MemoryStream memStream = new MemoryStream()) { 40 XmlGenerator.Serialize(obj, memStream); 41 byte[] jobByteArray = memStream.ToArray(); 42 return jobByteArray; 43 } 39 var ser = new ProtoBufSerializer(); 40 return ser.Serialize(obj); 44 41 } 45 42 46 43 public static T Deserialize<T>(byte[] sjob) { 47 using (MemoryStream memStream = new MemoryStream(sjob)) { 48 T job = XmlParser.Deserialize<T>(memStream); 49 return job; 50 } 44 var ser = new ProtoBufSerializer(); 45 return (T)ser.Deserialize(sjob); 51 46 } 52 47 } -
branches/2520_PersistenceReintegration/HeuristicLab.Core.Views/3.3/Clipboard.cs
r16453 r16480 28 28 using System.Threading; 29 29 using System.Windows.Forms; 30 using HEAL.Fossil; 30 31 using HeuristicLab.Common; 31 32 using HeuristicLab.MainForm; … … 156 157 foreach (string filename in items) { 157 158 try { 158 T item = XmlParser.Deserialize<T>(filename); 159 var ser = new ProtoBufSerializer(); 160 T item = (T)ser.Deserialize(filename); 159 161 OnItemLoaded(item, progressBar.Maximum / items.Length); 160 } 161 catch (Exception) { } 162 } catch (Exception) { 163 try { 164 // try old format if protobuf deserialization fails 165 T item = XmlParser.Deserialize<T>(filename); 166 OnItemLoaded(item, progressBar.Maximum / items.Length); 167 } catch (Exception) { } 168 } 162 169 } 163 170 OnAllItemsLoaded(); … … 199 206 i++; 200 207 SetEnabledStateOfContentViews(item, false); 201 XmlGenerator.Serialize(item, ItemsPath + Path.DirectorySeparatorChar + i.ToString("00000000") + ".hl", CompressionLevel.Optimal); 208 var ser = new ProtoBufSerializer(); 209 ser.Serialize(item, ItemsPath + Path.DirectorySeparatorChar + i.ToString("00000000") + ".hl"); 202 210 OnItemSaved(item, progressBar.Maximum / listView.Items.Count); 203 211 } -
branches/2520_PersistenceReintegration/HeuristicLab.Core/3.3/PersistenceContentManager.cs
r16474 r16480 32 32 33 33 protected override IStorableContent LoadContent(string filename) { 34 return XmlParser.Deserialize<IStorableContent>(filename); 34 // first try to load using the new persistence format 35 try { 36 var ser = new ProtoBufSerializer(); 37 return (IStorableContent)ser.Deserialize(filename); 38 } catch (PersistenceException e) { 39 // try old format if new format fails 40 return XmlParser.Deserialize<IStorableContent>(filename); 41 } 35 42 } 36 43 37 44 protected override void SaveContent(IStorableContent content, string filename, bool compressed, CancellationToken cancellationToken) { 38 XmlGenerator.Serialize(content, filename, compressed ? CompressionLevel.Optimal : CompressionLevel.NoCompression, cancellationToken); 45 // XmlGenerator.Serialize(content, filename, compressed ? CompressionLevel.Optimal : CompressionLevel.NoCompression, cancellationToken); 46 // store files with the new persistence format 47 var ser = new ProtoBufSerializer(); 48 ser.Serialize(content, filename); // TODO: support cancellation 39 49 } 40 50 } -
branches/2520_PersistenceReintegration/HeuristicLab.Scripting/3.3/VariableStore.cs
r16462 r16480 81 81 protected T CloneByPersistence<T>(T value) { 82 82 using (var serializerStream = new MemoryStream()) { 83 XmlGenerator.Serialize(value, serializerStream); 83 var serializer = new ProtoBufSerializer(); 84 serializer.Serialize(value, serializerStream, disposeStream: false); 84 85 var bytes = serializerStream.GetBuffer(); 85 86 using (var deserializerStream = new MemoryStream(bytes)) { 86 return XmlParser.Deserialize<T>(deserializerStream);87 return (T)serializer.Deserialize(deserializerStream); 87 88 } 88 89 }
Note: See TracChangeset
for help on using the changeset viewer.