public bool Execute(ISessionContext context) { _context = context; _logger = context.GetLogger(); _options = context.Options; IFileTransfer input = null; _fileTransferService = context.GetContainer().GetInstanceOf <IFileService> (); _deleteSourceFile = _options.Get <bool> ("deleteSourceFile", false); _retryCount = _options.Get <int> ("retryCount", 2); _retryWait = TimeSpan.FromMilliseconds(_options.Get <int> ("retryWaitMs", 250)); try { var searchPath = _options.Get("inputPath", _options.Get("searchPath", "")); if (String.IsNullOrEmpty(searchPath)) { throw new ArgumentNullException("inputPath"); } if (String.IsNullOrEmpty(_options.Get("outputPath", ""))) { throw new ArgumentNullException("outputPath"); } _maxFilesCount = _options.Get("maxFileCount", _maxFilesCount); if (_maxFilesCount <= 0) { _maxFilesCount = Int32.MaxValue; } // prepare paths input = _fileTransferService.Open(searchPath, _options); if (!input.IsOpened()) { throw new Exception(String.Format("Invalid inputPath, {0}: {1}", input.LastError ?? "", searchPath)); } // try move files ParallelTasks <FileTransferInfo> .Process(input.ListFiles().Take(_maxFilesCount), 0, _options.Get("maxConcurrency", 2), f => MoveFileInternal(f, searchPath)); if (!String.IsNullOrEmpty(input.LastError)) { _logger.Warn(input.LastError); } if (_filesCount > 0) { _logger.Success("Done"); return(true); } else { _logger.Debug("No Files Found on: " + searchPath); return(true); } } catch (Exception ex) { context.Error = ex.Message; _logger.Error(ex); return(false); } finally { if (input != null) { input.Dispose(); } } }