private void AddWorkThread(DistributionWork work) { try { switch (work.Type) { case ActionType.Distribute: { var sourceFiles = work.Application.Sources .Select(source => new { Source = source, FullPath = Path.Combine(work.Group.Path, source.Path.Trim(Path.DirectorySeparatorChar)) }) .Select(x => new { x.Source, Files = FileSystemHandler.IsFile(x.FullPath) ? new List <DistributionFile>() { new DistributionFile(x.Source.Path) } : FileSystemHandler.GetFileSystemEntries(x.FullPath, x.Source.Filter, x.Source.Recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly) .Where(entry => !entry.IsFolder) .Select(entry => new DistributionFile(Path.Combine(x.Source.Path, entry.Name))) .ToList() }) .ToList(); IEnumerable <DistributionFile> inclusiveSourceFiles = sourceFiles.Where(x => x.Source.Inclusive).SelectMany(x => x.Files); IEnumerable <DistributionFile> exclusiveSourceFiles = sourceFiles.Where(x => !x.Source.Inclusive).SelectMany(x => x.Files); work.Files = inclusiveSourceFiles.Except(exclusiveSourceFiles, new DistributionFileEqualityComparer()).ToList(); } break; } Logger.Add(LogType.Verbose, $"Adding distribution work to queue: destination machine = {work.DestinationMachine}, files = {work.Files.Count}"); lock (_pendingDistributionWork) _pendingDistributionWork.Add(work); } catch (ThreadAbortException) { } catch (Exception ex) { Logger.Add("An unexpected error occurred while preparing to add distribution work, aborting..", ex); } }
public void AddWork(DistributionWork work) { Task.Run(() => AddWorkThread(work)); }