private bool Validate(MovingThreadInfo movingThreadInfo) { bool isValid = movingThreadInfo.HasOutOfTime || (SourceIsEmpty(movingThreadInfo) && ValidateDestination(movingThreadInfo)); return(isValid); }
public void AsyncLoadFiles(MovingThreadInfo movingThreadInfo) { if (timer == null && movingThreadInfo != null && movingThreadInfo.TimeOut >= movingThreadInfo.DueTime && (movingThreadInfo.MovingQueue.Any(x => GetSourceFileNames(x).Any()) || movingThreadInfo.MovingQueue.Any(x => GetDestinationFileNames(x).Any()))) { timer = new Timer(MoveFiles, movingThreadInfo, Timeout.Infinite, Timeout.Infinite); if (oldMovingThreadInfo != movingThreadInfo) { if (oldMovingThreadInfo != null) { oldMovingThreadInfo.Completed -= DisposeTimer; oldMovingThreadInfo.TimeOutIsOver -= DisposeTimer; } oldMovingThreadInfo = movingThreadInfo; movingThreadInfo.Completed += DisposeTimer; movingThreadInfo.TimeOutIsOver += DisposeTimer; } timer.Change(movingThreadInfo.DueTime, movingThreadInfo.Period); } }
public FileService(IJsonService jsonService = null, IImageService imageService = null) { this.jsonService = jsonService ?? new JsonService(); this.imageService = imageService ?? new ImageService(); timer = null; oldMovingThreadInfo = null; }
private void MoveFiles(MovingThreadInfo movingThreadInfo) { if (movingThreadInfo != null) { Stop(); if (movingThreadInfo?.MovingQueue != null && movingThreadInfo.MovingQueue.All(x => !string.IsNullOrWhiteSpace(x.SourcePath)) && movingThreadInfo.MovingQueue.All(x => !string.IsNullOrWhiteSpace(x.DestinationPath))) { movingThreadInfo.MovingQueue.ForEach(x => { x.SourcePath = ValidatePath(x.SourcePath); x.DestinationPath = ValidatePath(x.DestinationPath); }); if (movingThreadInfo.MovingQueue.All(x => PrepareDirectory(x.SourcePath)) && movingThreadInfo.MovingQueue.All(x => PrepareDirectory(x.DestinationPath))) { if (Validate(movingThreadInfo)) { if (!movingThreadInfo.Start.HasValue) { movingThreadInfo.Start = DateTimeOffset.Now; } movingThreadInfo.EndOfProcess(); } else { movingThreadInfo.MovingQueue.ForEach( x => { if (GetFileNames(x.SourcePath, x.SearchPatterns).Length > 0) { if (!movingThreadInfo.Start.HasValue) { movingThreadInfo.Start = DateTimeOffset.Now; } //movingThreadInfo.LastMovingInfo = movingThreadInfo.MovingQueue.Last() == x; movingThreadInfo.MovingInfo = MoveFiles(x.SourcePath, x.DestinationPath, x.SearchPatterns); } }); } } } Start(movingThreadInfo); } }
private void Start(MovingThreadInfo movingThreadInfo) { timer?.Change(movingThreadInfo.DueTime, movingThreadInfo.Period); }
private bool SourceIsEmpty(MovingThreadInfo movingThreadInfo) { bool isEmpty = movingThreadInfo.MovingQueue.All(x => !GetFileNames(x.SourcePath, x.SearchPatterns).Any()); return(isEmpty); }
private bool ValidateDestination(MovingThreadInfo movingThreadInfo) { bool valid = movingThreadInfo.MovingQueue.All(ValidateInputFiles); return(valid); }