Changeset 1797 for trunk/sources/HeuristicLab.Persistence/3.3/Default
- Timestamp:
- 05/14/09 13:49:36 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs
r1733 r1797 161 161 162 162 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) { 163 167 string tempfile = Path.GetTempFileName(); 164 168 try { 165 Serialize(obj, File.Create(tempfile), config );169 Serialize(obj, File.Create(tempfile), config, includeAssemblies); 166 170 File.Copy(tempfile, filename, true); 167 171 File.Delete(tempfile); … … 172 176 } 173 177 178 174 179 public static void Serialize(object obj, Stream stream, Configuration config) { 180 Serialize(obj, stream, config, false); 181 } 182 183 public static void Serialize(object obj, Stream stream, Configuration config, bool includeAssemblies) { 175 184 try { 176 185 Serializer serializer = new Serializer(obj, config); … … 193 202 } 194 203 writer.Flush(); 204 if (includeAssemblies) { 205 foreach (string name in serializer.RequiredFiles) { 206 Uri uri = new Uri(name); 207 if (!uri.IsFile) { 208 Logger.Warn("cannot read non-local files"); 209 continue; 210 } 211 zipStream.PutNextEntry(new ZipEntry(Path.GetFileName(uri.PathAndQuery))); 212 FileStream reader = File.OpenRead(uri.PathAndQuery); 213 byte[] buffer = new byte[1024 * 1024]; 214 while (true) { 215 int bytesRead = reader.Read(buffer, 0, 1024 * 1024); 216 if (bytesRead == 0) 217 break; 218 zipStream.Write(buffer, 0, bytesRead); 219 } 220 writer.Flush(); 221 } 222 } 195 223 } 196 224 } catch (PersistenceException e) {
Note: See TracChangeset
for help on using the changeset viewer.