Changeset 13414
- Timestamp:
- 11/29/15 16:59:52 (9 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis.Views/3.3/RegressionInstanceProviderView.cs
r12012 r13414 22 22 using System; 23 23 using System.IO; 24 using System.Threading.Tasks; 24 25 using System.Windows.Forms; 25 26 using HeuristicLab.MainForm; … … 44 45 if (importTypeDialog.ShowDialog() == DialogResult.OK) { 45 46 IRegressionProblemData instance = null; 46 try { 47 instance = Content.ImportData(importTypeDialog.Path, importTypeDialog.ImportType, importTypeDialog.CSVFormat); 48 } catch (IOException ex) { 49 ErrorWhileParsing(ex); 50 return; 51 } 52 try { 53 GenericConsumer.Load(instance); 54 instancesComboBox.SelectedIndex = -1; 55 } catch (IOException ex) { 56 ErrorWhileLoading(ex, importTypeDialog.Path); 57 } 47 48 Task.Factory.StartNew(() => { 49 var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm; 50 // lock active view and show progress bar 51 IContentView activeView = (IContentView)MainFormManager.MainForm.ActiveView; 52 53 try { 54 var progress = mainForm.AddOperationProgressToContent(activeView.Content, "Loading problem instance."); 55 56 Content.ProgressChanged += (o, args) => { progress.ProgressValue = args.ProgressPercentage / 100.0; }; 57 58 instance = Content.ImportData(importTypeDialog.Path, importTypeDialog.ImportType, importTypeDialog.CSVFormat); 59 } catch (IOException ex) { 60 ErrorWhileParsing(ex); 61 mainForm.RemoveOperationProgressFromContent(activeView.Content); 62 return; 63 } 64 try { 65 GenericConsumer.Load(instance); 66 instancesComboBox.SelectedIndex = -1; 67 } catch (IOException ex) { 68 ErrorWhileLoading(ex, importTypeDialog.Path); 69 } finally { 70 mainForm.RemoveOperationProgressFromContent(activeView.Content); 71 } 72 }); 58 73 } 59 74 } -
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/DataAnalysisInstanceProvider.cs
r12012 r13414 23 23 using System.Collections; 24 24 using System.Collections.Generic; 25 using System.ComponentModel; 26 using System.Drawing; 25 27 using System.Globalization; 26 28 using System.IO; … … 35 37 where ImportType : DataAnalysisImportType { 36 38 39 public event ProgressChangedEventHandler ProgressChanged; 37 40 38 41 public TData ImportData(string path, ImportType type, DataAnalysisCSVFormat csvFormat) { 39 42 TableFileParser csvFileParser = new TableFileParser(); 43 long fileSize = new FileInfo(path).Length; 44 csvFileParser.ProgressChanged += (sender, e) => { 45 OnProgressChanged(e / (double)fileSize); 46 }; 40 47 csvFileParser.Parse(path, csvFormat.NumberFormatInfo, csvFormat.DateTimeFormatInfo, csvFormat.Separator, csvFormat.VariableNamesAvailable); 41 48 return ImportData(path, type, csvFileParser); 49 } 50 51 protected virtual void OnProgressChanged(double d) { 52 var handler = ProgressChanged; 53 if (handler != null) 54 handler(this, new ProgressChangedEventArgs((int)(100*d), null)); 42 55 } 43 56 -
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/TableFileParser.cs
r13413 r13414 30 30 31 31 namespace HeuristicLab.Problems.Instances.DataAnalysis { 32 public class TableFileParser {32 public class TableFileParser : Progress<long> { // reports the number of bytes read 33 33 private const int BUFFER_SIZE = 65536; 34 34 // char used to symbolize whitespaces (no missing values can be handled with whitespaces) … … 310 310 private set { currentLine = value; } 311 311 } 312 public long BytesRead { 313 get; 314 private set; 315 } 316 312 317 313 318 public Tokenizer(StreamReader reader, NumberFormatInfo numberFormatInfo, DateTimeFormatInfo dateTimeFormatInfo, char separator) { … … 322 327 if (!reader.EndOfStream) { 323 328 CurrentLine = reader.ReadLine(); 329 try { 330 BytesRead = reader.BaseStream.Position; 331 } catch (IOException) { 332 BytesRead += CurrentLine.Length + 2; // guess 333 } catch (NotSupportedException) { 334 BytesRead += CurrentLine.Length + 2; 335 } 324 336 int i = 0; 325 337 foreach (var tok in Split(CurrentLine)) { … … 449 461 rowValues.Add(row); 450 462 } 463 464 OnReport(tokenizer.BytesRead); 451 465 } 452 466 }
Note: See TracChangeset
for help on using the changeset viewer.