Пример #1
0
        public void TestBackup()
        {
            //Arrange so that the empty folder is empty
            int expected = 4;

            archivingManager.DeleteArchivedLogs(config.LOG_BACKUP_DIRECTORY);

            //Act
            archivingManager.BackupLogs();
            int actual = System.IO.Directory.GetFiles(config.LOG_BACKUP_DIRECTORY).Length;

            //clear backup logs after actual is set
            archivingManager.DeleteArchivedLogs(config.LOG_BACKUP_DIRECTORY);

            //Assert
            Assert.AreEqual(expected, actual);
        }
Пример #2
0
        /// <summary>
        /// Executable Program that backs up logs and archives logs whenever it is called.
        /// </summary>
        static void Main(string[] args)
        {
            //TimeSpan of 2 hours for the archive retry
            TimeSpan ts = new TimeSpan(2, 0, 0);
            //New instance of ArchiveManager
            ArchivingManager archivingManager = new ArchivingManager();

            //Backup the logs
            archivingManager.BackupLogs();

            //Archive logs older than 2 years
            bool archived = false;

            archived = archivingManager.ArchiveLogs();
            //Extract the log specified
            //  //bool unarchived = archivingManager.ReverseArchive("05-01-2019");

            //If logs fail to archive 1-3 times wait 2 hours then try again
            if (!archived && tries < 3)
            {
                try
                {
                    System.Threading.Tasks.Task task = System.Threading.Tasks.Task.Delay(ts).ContinueWith(t => archivingManager.ArchiveLogs());
                    task.Wait();
                }
                catch (Exception e)
                {
                    Console.Write("2 Hour wait for re-archive has failed.");
                }
            }
            //Otherwise, stop archiving and email a system administrator
            else if (!archived && tries >= 3)
            {
                /*using (TaskService task = new TaskService())
                 * {
                 *
                 *  Microsoft.Win32.TaskScheduler.Task td = task.FindTask("LogArchiver");
                 *  td.Definition.Settings.Enabled = false;
                 *  Console.WriteLine("Email a System Administrator");
                 *  tries = 0;
                 * }*/
                new ServiceLayer.EmailService().SendMail("*****@*****.**", "Notification from CheckIt", "Archiving is screwed up.");
                tries = 0;
            }
        }