Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/27/12 16:13:25 (13 years ago)
Author:
sforsten
Message:

#1784:

  • deleted obsolete project Problems.Instances.Regression.Views
  • added TrentMcConaghy and Various problem instances (zip file from TrentMcConaghy is rather big)
Location:
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4

    • Property svn:ignore
      •  

        old new  
        22bin
        33obj
         4*.user
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/ResourceRegressionInstanceProvider.cs

    r7664 r7666  
    2323using System.Linq;
    2424using System.Reflection;
     25using System.Text.RegularExpressions;
     26using ICSharpCode.SharpZipLib.Zip;
    2527
    2628namespace HeuristicLab.Problems.Instances.Regression {
    2729  public abstract class ResourceRegressionInstanceProvider : RegressionInstanceProvider {
     30
     31    protected abstract string FileExtension { get; }
     32
    2833    public override RegressionData LoadData(IDataDescriptor id) {
    2934      var descriptor = (ResourceRegressionDataDescriptor)id;
    3035
    31       RegressionData regData = LoadData(GetTempFileForResource(descriptor.resourceName));
     36      RegressionData regData = LoadData(GetTempFileForResource(descriptor.ResourceName));
    3237      regData.Name = descriptor.Name;
    3338      regData.Description = descriptor.Description;
     
    3641    }
    3742
    38     #region Helpers
    39     protected static string GetTempFileForResource(string resourceName) {
    40       Assembly assembly = Assembly.GetExecutingAssembly();
    41       string resource = assembly.GetManifestResourceNames().Where(x => x.EndsWith(resourceName)).First();
    42 
    43       string path = Path.GetTempFileName();
    44 
    45       using (Stream stream = assembly.GetManifestResourceStream(resource)) {
    46         WriteStreamToTempFile(stream, path);
    47       }
    48       return path;
     43    protected virtual string GetResourceName(string fileName) {
     44      return Assembly.GetExecutingAssembly().GetManifestResourceNames()
     45              .Where(x => Regex.Match(x, @".*\.Data\." + fileName).Success).SingleOrDefault();
    4946    }
    5047
    51     private static void WriteStreamToTempFile(Stream stream, string path) {
     48    private string GetTempFileForResource(string resourceName) {
     49      var instanceArchiveName = GetResourceName(FileExtension + @"\.zip");
     50      using (var instancesZipFile = new ZipFile(GetType().Assembly.GetManifestResourceStream(instanceArchiveName))) {
     51        var entry = instancesZipFile.GetEntry(resourceName);
     52        string path = Path.GetTempFileName();
     53        using (var stream = instancesZipFile.GetInputStream(entry)) {
     54          WriteStreamToTempFile(stream, path);
     55        }
     56        return path;
     57      }
     58    }
     59
     60    private void WriteStreamToTempFile(Stream stream, string path) {
    5261      using (FileStream output = new FileStream(path, FileMode.Create, FileAccess.Write)) {
    5362        int cnt = 0;
     
    5766      }
    5867    }
    59     #endregion
    6068  }
    6169}
Note: See TracChangeset for help on using the changeset viewer.