Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/10/14 10:31:41 (9 years ago)
Author:
pfleck
Message:

#2269 Merged trunk. Updated .net version of ALPS plugin.

Location:
branches/ALPS
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/ALPS

  • branches/ALPS/HeuristicLab.Problems.Instances.VehicleRouting/3.4/VRPInstanceProvider.cs

    r11478 r11677  
    2323using System.Collections.Generic;
    2424using System.IO;
     25using System.IO.Compression;
    2526using System.Linq;
    2627using System.Reflection;
    2728using System.Text.RegularExpressions;
    2829using HeuristicLab.Common;
    29 using ICSharpCode.SharpZipLib.Zip;
    3030
    3131namespace HeuristicLab.Problems.Instances.VehicleRouting {
     
    3737      var solutionsArchiveName = GetResourceName(FileName + @"\.opt\.zip");
    3838      if (!String.IsNullOrEmpty(solutionsArchiveName)) {
    39         using (var solutionsZipFile = new ZipInputStream(GetType().Assembly.GetManifestResourceStream(solutionsArchiveName))) {
    40           foreach (var entry in GetZipContents(solutionsZipFile))
    41             solutions.Add(Path.GetFileNameWithoutExtension(entry) + "." + FileName, entry);
     39        using (var solutionsZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(solutionsArchiveName), ZipArchiveMode.Read)) {
     40          foreach (var entry in solutionsZipFile.Entries)
     41            solutions.Add(Path.GetFileNameWithoutExtension(entry.Name) + "." + FileName, entry.Name);
    4242        }
    4343      }
     
    4545      if (String.IsNullOrEmpty(instanceArchiveName)) yield break;
    4646
    47       using (var instanceStream = new ZipInputStream(GetType().Assembly.GetManifestResourceStream(instanceArchiveName))) {
    48         foreach (var entry in GetZipContents(instanceStream).OrderBy(x => x, new NaturalStringComparer())) {
     47      using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) {
     48        foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x, new NaturalStringComparer())) {
    4949          string solutionEntry = Path.GetFileNameWithoutExtension(entry) + "." + FileName;
    5050          yield return new VRPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetInstanceDescription(), entry, solutions.ContainsKey(solutionEntry) ? solutions[solutionEntry] : String.Empty);
     
    5656      var descriptor = (VRPDataDescriptor)id;
    5757      var instanceArchiveName = GetResourceName(FileName + @"\.zip");
    58       using (var instancesZipFile = new ZipFile(GetType().Assembly.GetManifestResourceStream(instanceArchiveName))) {
     58      using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName))) {
    5959        var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier);
    60         var stream = instancesZipFile.GetInputStream(entry);
     60        var stream = entry.Open();
    6161        var instance = LoadData(stream);
    6262        if (string.IsNullOrEmpty(instance.Name)) {
     
    6666        if (!String.IsNullOrEmpty(descriptor.SolutionIdentifier)) {
    6767          var solutionsArchiveName = GetResourceName(FileName + @"\.opt\.zip");
    68           using (var solutionsZipFile = new ZipFile(GetType().Assembly.GetManifestResourceStream(solutionsArchiveName))) {
     68          using (var solutionsZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(solutionsArchiveName))) {
    6969            entry = solutionsZipFile.GetEntry(descriptor.SolutionIdentifier);
    70             stream = solutionsZipFile.GetInputStream(entry);
     70            stream = entry.Open();
    7171            LoadSolution(stream, instance);
    7272          }
     
    130130          LoadSolution(stream, instance);
    131131        }
    132       } catch (Exception) {
     132      }
     133      catch (Exception) {
    133134        // new stream necessary because first try already read from stream
    134135        using (var stream = new FileStream(path, FileMode.Open)) {
     
    149150      return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + ".";
    150151    }
    151 
    152     protected IEnumerable<string> GetZipContents(ZipInputStream zipFile) {
    153       ZipEntry entry;
    154       while ((entry = zipFile.GetNextEntry()) != null) {
    155         yield return entry.Name;
    156       }
    157     }
    158152    #endregion
    159153  }
Note: See TracChangeset for help on using the changeset viewer.