private void OnProgress(ProgressEventArgs e) { if (this.Progress != null) { this.Progress(this, e); } }
/// <summary> /// Imports the files. /// </summary> /// <param name="settings">The settings.</param> /// <param name="files">The files.</param> public void ImportFiles(CsvSettings settings, IEnumerable files) { // calculate count int count = 0; foreach (string f in files) { count += 1; } ProgressEventArgs progressEA = new ProgressEventArgs(0, count); using (Database db = this.OpenDB(settings)) { if (settings.CreateTable) { progressEA.Message = "Creating data table..."; this.OnProgress(progressEA); this.CreateTable(settings, db); progressEA.Message = "Table created!"; this.OnProgress(progressEA); progressEA.Message = null; if (progressEA.Cancel) { this.OnDone(true); return; } } foreach (string f in files) { try { this.ImportFile(settings, db, f); progressEA.Value += 1; progressEA.Message = string.Format("{0} / {1}", progressEA.Value, progressEA.MaxValue); this.OnProgress(progressEA); if (progressEA.Cancel) { this.OnDone(true); return; } } catch (Exception ex) { this.OnWorkerError(new CsvException("Error importing file: " + f, ex)); } } } this.OnDone(false); }