예제 #1
0
        public void RunCleaner()
        {
            //Run unless we need to stop
            while (_stopCleaning == false)
            {
                //Check if cleaner should stop and again ask later
                if (_askLater)
                {
                    Console.WriteLine("Asking later will take " + _config.BreakTime + " minute break!");
                    Thread.Sleep(1000 * 60 * _config.BreakTime);
                    _askLater = false;
                }

                Console.WriteLine("Does anything need to be cleaned?");
                //Search for new files
                SearchForFiles();

                //Run through every item to see if it should be deleted
                List <DeletableItem> deletionList = new List <DeletableItem>();
                bool deletingAFile = false;
                int  combiningTime = 0;

                for (int index = 0; index < _itemsForDeletion.Count; index++)
                {
                    DeletableItem item = _itemsForDeletion[index];
                    Console.WriteLine("Considering " + item);
                    if (item.ShouldBeDeleted(combiningTime) && deletingAFile == false)
                    {
                        Console.WriteLine("Should be deleted!");

                        //Atleast one file must be deleted, so redo the search with a broader time search
                        //to avoid spamming the user
                        deletingAFile = true;
                        combiningTime = _config.CombineTime;
                        //Restart search
                        index = -1;
                        continue;
                    }

                    if (item.ShouldBeDeleted(combiningTime))
                    {
                        deletionList.Add(item);
                    }
                }

                //Clean those files
                Clean(deletionList);


                //Only run every so many seconds
                Console.WriteLine("Waiting on cleaner... " + _itemsForDeletion.Count + " possible files for cleaning");
                Thread.Sleep(CLEANER_RUN_INTERVAL * 1000);
            }

            //Reset lists and whitelist
            _itemsForDeletion = new List <DeletableItem>();
            _whiteList        = new FileWhiteList();
        }
예제 #2
0
        /// <summary>
        /// Creates a blank directory cleaner
        /// </summary>
        public DirectoryCleaner()
        {
            //Establish singleton
            if (Instance == null)
            {
                Instance = this;
            }

            _itemsForDeletion = new List <DeletableItem>();
            _whiteList        = new FileWhiteList();
        }