Changeset 1892 for trunk/sources/HeuristicLab.Persistence/3.3/Default
- Timestamp:
- 05/25/09 18:03:39 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs
r1823 r1892 157 157 158 158 public static void Serialize(object o, string filename) { 159 Serialize(o, filename, ConfigurationService.Instance.GetDefaultConfig(new XmlFormat())); 159 Serialize(o, filename, ConfigurationService.Instance.GetDefaultConfig(new XmlFormat()), false, 5); 160 } 161 162 public static void Serialize(object o, string filename, int compression) { 163 Serialize(o, filename, ConfigurationService.Instance.GetConfiguration(new XmlFormat()), false, compression); 160 164 } 161 165 162 166 public static void Serialize(object obj, string filename, Configuration config) { 163 Serialize(obj, filename, config, false); 164 } 165 166 public static void Serialize(object obj, string filename, Configuration config, bool includeAssemblies) { 167 string tempfile = Path.GetTempFileName(); 167 Serialize(obj, filename, config, false, 5); 168 } 169 170 public static void Serialize(object obj, string filename, Configuration config, bool includeAssemblies, int compression) { 168 171 try { 169 Serialize(obj, File.Create(tempfile), config, includeAssemblies); 172 string tempfile = Path.GetTempFileName(); 173 DateTime start = DateTime.Now; 174 Serialize(obj, File.Create(tempfile), config, includeAssemblies, compression); 175 Logger.Info(String.Format("serialization took {0} seconds with compression level {1}", 176 (DateTime.Now - start).TotalSeconds, compression)); 170 177 File.Copy(tempfile, filename, true); 171 178 File.Delete(tempfile); … … 180 187 Serialize(obj, stream, config, false); 181 188 } 182 189 183 190 public static void Serialize(object obj, Stream stream, Configuration config, bool includeAssemblies) { 191 Serialize(obj, stream, config, includeAssemblies, 9); 192 } 193 194 public static void Serialize(object obj, Stream stream, Configuration config, bool includeAssemblies, int compression) { 184 195 try { 185 196 Serializer serializer = new Serializer(obj, config); 186 197 XmlGenerator generator = new XmlGenerator(); 187 ILog logger = Logger.GetDefaultLogger();188 198 using (ZipOutputStream zipStream = new ZipOutputStream(stream)) { 189 zipStream.SetLevel( 9);199 zipStream.SetLevel(compression); 190 200 zipStream.PutNextEntry(new ZipEntry("data.xml")); 191 201 StreamWriter writer = new StreamWriter(zipStream); … … 193 203 string line = generator.Format(token); 194 204 writer.Write(line); 195 logger.Debug(line.TrimEnd());196 205 } 197 206 writer.Flush(); … … 199 208 foreach (string line in generator.Format(serializer.TypeCache)) { 200 209 writer.Write(line); 201 logger.Debug(line.TrimEnd());202 210 } 203 211 writer.Flush(); … … 226 234 } catch (Exception e) { 227 235 throw new PersistenceException("Unexpected exception during Serialization.", e); 228 } 236 } 229 237 } 230 238 }
Note: See TracChangeset
for help on using the changeset viewer.