private void RunTaskAsync() { try { ProcessedObjects = 0; ObjectsCount = 0; ErrorMap.Clear(); List<string> toRemove = new List<string>(); foreach (string path in SrcFiles) { FileInfo fi = new FileInfo(path); if (fi.Exists) { List<String> linkedFiles = _support.GetChildFiles(fi, TaskType); if (linkedFiles != null && linkedFiles.Count > 0) toRemove.AddRange(linkedFiles); } } foreach (string dup in toRemove) { SrcFiles.Remove(dup); } foreach (string path in SrcFiles) { if (Directory.Exists(path)) { string[] entries = Directory.GetFileSystemEntries(path, "*", SearchOption.AllDirectories); if (entries != null && entries.Length > 0) { ObjectsCount += entries.Length; } } else { ObjectsCount++; } } FireTaskProgress(ProgressEventType.Started, string.Empty, UpdateProgressData.Default); _currentPath = string.Empty; _timer.Start(); try { foreach (string path in SrcFiles) { _currentPath = path; FireTaskProgress(ProgressEventType.Progress, path, UpdateProgressData.Default); switch (TaskType) { case FileTaskType.Copy: CopyObject(path); break; case FileTaskType.Move: MoveObject(path); break; case FileTaskType.Delete: DeleteObject(path); break; } } } catch (TaskInterruptedException) { FireTaskProgress(ProgressEventType.Aborted, string.Empty, UpdateProgressData.Default); return; } finally { _timer.Stop(); _currentPath = string.Empty; } } catch (Exception ex) { Logger.LogException(ex); } finally { IsFinished = true; } FireTaskProgress(ProgressEventType.Finished, string.Empty, UpdateProgressData.Default); _requiresRefresh = _support.RequiresRefresh; _support = null; }
public BaseFileTask(FileTaskType type, List<string> srcFiles, string srcFolder) { this.TaskType = type; this.ErrorMap = new Dictionary<string, string>(); this.SrcFiles = srcFiles; this.SrcFolder = srcFolder; _timer = new System.Timers.Timer(500); _timer.AutoReset = true; _timer.Elapsed += new System.Timers.ElapsedEventHandler(_timer_Elapsed); _support = InitSupport(); this.IsFinished = false; }