Index: src/Plugins/Wti/Wti.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs =================================================================== diff -u -rab8c3b732c3aaadc8e55be98e132bdaf41110169 -rcc2b9aecfd7eb25353fbf015f23c9f0f69178f3f --- src/Plugins/Wti/Wti.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision ab8c3b732c3aaadc8e55be98e132bdaf41110169) +++ src/Plugins/Wti/Wti.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision cc2b9aecfd7eb25353fbf015f23c9f0f69178f3f) @@ -1,9 +1,12 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.IO; using DelftTools.Shell.Core; +using log4net; + using Wti.Data; using Wti.IO; @@ -90,18 +93,54 @@ public object ImportItem(string path, object target = null) { + var readSurfaceLines = ReadPipingSurfaceLines(path); + + if (!ShouldCancel) + { + AddImportedDataToModel(target, readSurfaceLines); + } + else + { + HandleUserCancellingImport(); + } + + return target; + } + + private void NotifyProgress(string currentStepName, int currentStep, int totalNumberOfSteps) + { + if (ProgressChanged != null) + { + ProgressChanged(currentStepName, currentStep, totalNumberOfSteps); + } + } + + private List ReadPipingSurfaceLines(string path) + { + var stepName = String.Format(ApplicationResources.PipingSurfaceLinesCsvImporter_ReadPipingSurfaceLines_0_, Path.GetFileName(path)); + List readSurfaceLines; using (var reader = new PipingSurfaceLinesCsvReader(path)) { var itemCount = reader.GetSurfaceLinesCount(); + + NotifyProgress(stepName, 0, itemCount); + readSurfaceLines = new List(itemCount); - for (int i = 0; i < itemCount; i++) + for (int i = 0; i < itemCount && !ShouldCancel; i++) { - // TODO: Check ShouldCancel for early abort readSurfaceLines.Add(reader.ReadLine()); + + NotifyProgress(stepName, i+1, itemCount); } } - + return readSurfaceLines; + } + + private void AddImportedDataToModel(object target, List readSurfaceLines) + { + NotifyProgress(ApplicationResources.PipingSurfaceLinesCsvImporter_AddingImportedDataToModel, readSurfaceLines.Count, readSurfaceLines.Count); + var targetCollection = (ICollection)target; foreach (var readSurfaceLine in readSurfaceLines) { @@ -113,8 +152,11 @@ { observableTarget.NotifyObservers(); } + } - return target; + private void HandleUserCancellingImport() + { + LogManager.GetLogger(GetType()).Info(ApplicationResources.PipingSurfaceLinesCsvImporter_ImportItem_ImportCancelled); } } } \ No newline at end of file