Example #1
0
        private bool Validate(MovingThreadInfo movingThreadInfo)
        {
            bool isValid = movingThreadInfo.HasOutOfTime ||
                           (SourceIsEmpty(movingThreadInfo) && ValidateDestination(movingThreadInfo));

            return(isValid);
        }
Example #2
0
        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);
            }
        }
Example #3
0
 public FileService(IJsonService jsonService = null, IImageService imageService = null)
 {
     this.jsonService    = jsonService ?? new JsonService();
     this.imageService   = imageService ?? new ImageService();
     timer               = null;
     oldMovingThreadInfo = null;
 }
Example #4
0
        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);
            }
        }
Example #5
0
 private void Start(MovingThreadInfo movingThreadInfo)
 {
     timer?.Change(movingThreadInfo.DueTime, movingThreadInfo.Period);
 }
Example #6
0
        private bool SourceIsEmpty(MovingThreadInfo movingThreadInfo)
        {
            bool isEmpty = movingThreadInfo.MovingQueue.All(x => !GetFileNames(x.SourcePath, x.SearchPatterns).Any());

            return(isEmpty);
        }
Example #7
0
        private bool ValidateDestination(MovingThreadInfo movingThreadInfo)
        {
            bool valid = movingThreadInfo.MovingQueue.All(ValidateInputFiles);

            return(valid);
        }