Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/02/16 08:15:07 (8 years ago)
Author:
gkronber
Message:

#2071: merged r13411,r13413,r13414,r13415,r13419,r13440,r13441,r13442,r13445,r13447,r13525,r13526,r13529,r13584,r13901,r13925 from trunk to stable

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.Instances.DataAnalysis

  • stable/HeuristicLab.Problems.Instances.DataAnalysis/3.3/DataAnalysisInstanceProvider.cs

    r12009 r13974  
    2323using System.Collections;
    2424using System.Collections.Generic;
     25using System.ComponentModel;
    2526using System.Globalization;
    2627using System.IO;
     
    3536    where ImportType : DataAnalysisImportType {
    3637
     38    public event ProgressChangedEventHandler ProgressChanged;
    3739
    3840    public TData ImportData(string path, ImportType type, DataAnalysisCSVFormat csvFormat) {
    3941      TableFileParser csvFileParser = new TableFileParser();
     42      long fileSize = new FileInfo(path).Length;
     43      csvFileParser.ProgressChanged += (sender, e) => {
     44        OnProgressChanged(e / (double)fileSize);
     45      };
    4046      csvFileParser.Parse(path, csvFormat.NumberFormatInfo, csvFormat.DateTimeFormatInfo, csvFormat.Separator, csvFormat.VariableNamesAvailable);
    4147      return ImportData(path, type, csvFileParser);
     48    }
     49
     50    protected virtual void OnProgressChanged(double d) {
     51      var handler = ProgressChanged;
     52      if (handler != null)
     53        handler(this, new ProgressChangedEventArgs((int)(100 * d), null));
    4254    }
    4355
     
    89101        strBuilder.AppendLine();
    90102      }
    91 
    92       using (var writer = new StreamWriter(path)) {
    93         writer.Write(strBuilder);
     103      using (var fileStream = new FileStream(path, FileMode.Create)) {
     104        Encoding encoding = Encoding.GetEncoding(Encoding.Default.CodePage,
     105          new EncoderReplacementFallback("*"),
     106          new DecoderReplacementFallback("*"));
     107        using (var writer = new StreamWriter(fileStream, encoding)) {
     108          writer.Write(strBuilder);
     109        }
    94110      }
    95111    }
Note: See TracChangeset for help on using the changeset viewer.