Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17087 for trunk


Ignore:
Timestamp:
07/05/19 14:56:37 (5 years ago)
Author:
abeham
Message:

#2520:

  • fixed loading of samples, removed TODO (due to upgrade of Attic 1.2)
  • corrected check when old persistence should be used to retry download from hive
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Clients.Hive/3.3/HeuristicLab.Clients.Hive-3.3.csproj

    r16658 r17087  
    107107  </PropertyGroup>
    108108  <ItemGroup>
     109    <Reference Include="Google.Protobuf, Version=3.6.1.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL">
     110      <SpecificVersion>False</SpecificVersion>
     111      <HintPath>..\..\bin\Google.Protobuf.dll</HintPath>
     112      <Private>False</Private>
     113    </Reference>
    109114    <Reference Include="System" />
    110115    <Reference Include="System.Configuration" />
  • trunk/HeuristicLab.Clients.Hive/3.3/Plugin.cs.frame

    r16658 r17087  
    4141  [PluginDependency("HeuristicLab.Optimization", "3.3")]
    4242  [PluginDependency("HeuristicLab.Persistence", "3.3")]
     43  [PluginDependency("HeuristicLab.Protobuf", "3.6.1")]
    4344  public class HeuristicLabClientsHivePlugin : PluginBase {
    4445  }
  • trunk/HeuristicLab.Clients.Hive/3.3/Util/PersistenceUtil.cs

    r16565 r17087  
    2323using System.Collections.Generic;
    2424using System.IO;
     25using System.IO.Compression;
     26using Google.Protobuf;
    2527using HEAL.Attic;
    2628using HeuristicLab.Persistence.Default.Xml;
     
    4446      try {
    4547        return (T)ser.Deserialize(sjob);
    46       } catch (Exception) {
    47         // retry with old persistence
    48         using (MemoryStream memStream = new MemoryStream(sjob)) {
    49           return XmlParser.Deserialize<T>(memStream);
     48      } catch (PersistenceException e) {
     49        // Exceptions may arise because data in Hive was uploaded with former XML-based
     50        // persistence or with Attic prior to 1.2.
     51        if (e.InnerException is InvalidDataException) {
     52          // We assume the data was serialized with HEAL.Attic < 1.2 which did not use
     53          // DeflateStream, but as of 1.2 uses DeflateStream by default
     54          var compressedData = Compress(sjob);
     55          try {
     56            // retry with the job's data compressed
     57            return (T)ser.Deserialize(compressedData);
     58          } catch (PersistenceException e2) {
     59            if (e2.InnerException is InvalidProtocolBufferException
     60              || e2.InnerException is InvalidDataException) {
     61              // retry deserialize original bytes with old persistence
     62              return DeserializeWithXmlParser<T>(sjob);
     63            } else throw;
     64          }
    5065        }
     66        if (e.InnerException is InvalidProtocolBufferException) {
     67          // We assume the data was not serialized with HEAL.Attic, but with the former
     68          // XML-based persistence
     69          return DeserializeWithXmlParser<T>(sjob);
     70        } else throw;
     71      }
     72    }
     73
     74    private static byte[] Compress(byte[] sjob) {
     75      using (var memStream = new MemoryStream(sjob.Length)) {
     76        using (var deflateStream = new DeflateStream(memStream, CompressionMode.Compress)) {
     77          deflateStream.Write(sjob, 0, sjob.Length);
     78        }
     79        return memStream.ToArray();
     80      }
     81    }
     82
     83    private static T DeserializeWithXmlParser<T>(byte[] sjob) {
     84      using (MemoryStream memStream = new MemoryStream(sjob)) {
     85        return XmlParser.Deserialize<T>(memStream);
    5186      }
    5287    }
  • trunk/HeuristicLab.Optimizer/3.3/StartPage.cs

    r17022 r17087  
    2323using System.Collections.Generic;
    2424using System.IO;
    25 using System.IO.Compression;
    2625using System.Linq;
    2726using System.Reflection;
     
    120119      using (var stream = assembly.GetManifestResourceStream(name)) {
    121120        var serializer = new ProtoBufSerializer();
    122         // TODO remove deflateStream with next release of HEAL.Attic
    123         using (var deflateStream = new DeflateStream(stream, CompressionMode.Decompress, true)) {
    124           var item = (NamedItem)serializer.Deserialize(deflateStream, false);
    125           OnSampleLoaded(item, group, 1.0 / count);
    126         }
     121        var item = (NamedItem)serializer.Deserialize(stream, false);
     122        OnSampleLoaded(item, group, 1.0 / count);
    127123      }
    128124    }
Note: See TracChangeset for help on using the changeset viewer.