Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/14/09 13:49:36 (16 years ago)
Author:
epitzer
Message:

Optionally include necessary assemblies in serial data. (#621)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs

    r1733 r1797  
    161161
    162162    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) {
    163167      string tempfile = Path.GetTempFileName();
    164168      try {
    165         Serialize(obj, File.Create(tempfile), config);
     169        Serialize(obj, File.Create(tempfile), config, includeAssemblies);
    166170        File.Copy(tempfile, filename, true);
    167171        File.Delete(tempfile);
     
    172176    }
    173177
     178
    174179    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) {
    175184      try {
    176185        Serializer serializer = new Serializer(obj, config);
     
    193202          }
    194203          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          }
    195223        }
    196224      } catch (PersistenceException e) {
Note: See TracChangeset for help on using the changeset viewer.