﻿/////////////////////////////////////////////////////////////////////////
//                                                                     //
//   ##     ## ##    ##          ######   #######  ######## ########   //
//   ###   ### ##   ##          ##    ## ##     ## ##          ##      //
//   #### #### ##  ##           ##       ##     ## ##          ##      //
//   ## ### ## #####    #######  ######  ##     ## ######      ##      //
//   ##     ## ##  ##                 ## ##     ## ##          ##      //
//   ##     ## ##   ##          ##    ## ##     ## ##          ##      //
//   ##     ## ##    ##          ######   #######  ##          ##      //
//                                                                     //
/////////////////////////////////////////////////////////////////////////
//                                                                     //
//                Copyright © MK-Soft Development 2017                 //
//                                                                     //
//                        Author: Marcel Knorr                         //
//                                                                     //
//*********************************************************************//
//                                                                     //
//                     Cronjobs.NET (Version: 1.2)                     //
//                                                                     //
/////////////////////////////////////////////////////////////////////////

using System;
using System.Threading;
using Cronjobs.NET;

namespace Cronjobs.Test
{
    /// <summary>
    /// A class for testing purposes.
    /// </summary>
    public abstract class Test
    {
        /// <summary>
        /// The <see cref="Test.Main"/> method.
        /// </summary>
        public static void Main()
        {
            //Every 5 seconds (full time)
            Cronjob job1 = new Cronjob("5sec", true);
            job1.AddInterval(new TimeSpan(0, 0, 5));
            job1.Execute += TestMethod1;
            job1.Start();

            //Every second; starting in 30 seconds
            Cronjob job2 = new Cronjob("1sec");
            job2.AddInterval(new TimeSpan(0, 0, 1), DateTime.Now.AddSeconds(30));
            job2.Execute += TestMethod2;
            job2.Start();

            //Once; starting in 40 seconds
            Cronjob job3 = new Cronjob("alarm");
            job3.AddDateTime(DateTime.Now.AddSeconds(40));
            job3.Execute += TestMethod3;
            job3.Start();

            while (true)
            {
                Thread.Sleep(1000000);
            }
        }

        /// <summary>
        /// Gets executed every five seconds.
        /// </summary>
        private static void TestMethod1(object sender, EventArgs e)
        {
            Test.PrintTime();

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Every 5 seconds.");
        }

        /// <summary>
        /// Gets executed every second.
        /// </summary>
        private static void TestMethod2(object sender, EventArgs e)
        {
            Test.PrintTime();

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Every 1 second.");
        }

        /// <summary>
        /// Gets executed once.
        /// </summary>
        private static void TestMethod3(object sender, EventArgs e)
        {
            Test.PrintTime();

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Alarm!");
        }

        /// <summary>
        /// Prints the time on the console.
        /// </summary>
        private static void PrintTime()
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write(DateTime.Now.ToString("[dd.MM.yyyy HH:mm:ss] "));
        }
    }
}