Changeset 7666 for branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/ResourceRegressionInstanceProvider.cs
- Timestamp:
- 03/27/12 16:13:25 (13 years ago)
- 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 2 2 bin 3 3 obj 4 *.user
-
- Property svn:ignore
-
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/ResourceRegressionInstanceProvider.cs
r7664 r7666 23 23 using System.Linq; 24 24 using System.Reflection; 25 using System.Text.RegularExpressions; 26 using ICSharpCode.SharpZipLib.Zip; 25 27 26 28 namespace HeuristicLab.Problems.Instances.Regression { 27 29 public abstract class ResourceRegressionInstanceProvider : RegressionInstanceProvider { 30 31 protected abstract string FileExtension { get; } 32 28 33 public override RegressionData LoadData(IDataDescriptor id) { 29 34 var descriptor = (ResourceRegressionDataDescriptor)id; 30 35 31 RegressionData regData = LoadData(GetTempFileForResource(descriptor. resourceName));36 RegressionData regData = LoadData(GetTempFileForResource(descriptor.ResourceName)); 32 37 regData.Name = descriptor.Name; 33 38 regData.Description = descriptor.Description; … … 36 41 } 37 42 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(); 49 46 } 50 47 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) { 52 61 using (FileStream output = new FileStream(path, FileMode.Create, FileAccess.Write)) { 53 62 int cnt = 0; … … 57 66 } 58 67 } 59 #endregion60 68 } 61 69 }
Note: See TracChangeset
for help on using the changeset viewer.