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; }
private void RunTaskAsync() { try { ProcessedObjects = 0; ObjectsCount = 0; ErrorMap.Clear(); List <string> allLinkedFiles = new List <string>(); foreach (string path in SrcFiles) { if (File.Exists(path)) { List <String> linkedFiles = _support.GetChildFiles(path, TaskType); if (linkedFiles != null && linkedFiles.Count > 0) { var linkedFilesLowercase = (from s in linkedFiles select s.ToLowerInvariant()).ToList(); allLinkedFiles.AddRange(linkedFilesLowercase); } } } List <string> srcFilesClone = new List <string>(SrcFiles); foreach (string srcFile in srcFilesClone) { if (allLinkedFiles.Contains(srcFile.ToLowerInvariant())) { SrcFiles.Remove(srcFile); } } foreach (string path in SrcFiles) { if (Directory.Exists(path)) { List <string> entries = PathUtils.EnumFileSystemEntries(path, "*", SearchOption.AllDirectories); if (entries != null && entries.Count > 0) { ObjectsCount += entries.Count; } } else { ObjectsCount++; } } ObjectsCount += allLinkedFiles.Count; FireTaskProgress(ProgressEventType.Started, string.Empty, UpdateProgressData.Empty); _currentPath = string.Empty; _timer.Start(); try { foreach (string path in SrcFiles) { _currentPath = path; FireTaskProgress(ProgressEventType.Progress, path, UpdateProgressData.Empty); 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.Empty); return; } finally { _timer.Stop(); _currentPath = string.Empty; } } catch (Exception ex) { Logger.LogException(ex); } finally { IsFinished = true; } FireTaskProgress(ProgressEventType.Finished, string.Empty, UpdateProgressData.Empty); _requiresRefresh = _support.RequiresRefresh; _support = null; }