﻿// Copyright (c) 2018 Nikolay Zahariev <zahasoft.com>. Licensed under the MIT License.

namespace Zahasoft.Ashot
{
    using System;
    using System.Drawing;
    using System.Threading;

    public class AutoShotService : IAutoShotService
    {
        bool on;

        public void Start(int seconds = 60)
        {
            on = true;

            while (on)
            {
                MakeScreenShot();
                Thread.Sleep(seconds * 1000);
            }
        }

        public void Stop()
        {
            on = false;
        }

        void MakeScreenShot()
        {
            var screenshot = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
            Graphics graphics = Graphics.FromImage(screenshot as Image);
            graphics.CopyFromScreen(0, 0, 0, 0, screenshot.Size);
            DateTime date = DateTime.Now;
            screenshot.Save(string.Format(@"C:\{0}-{1}-{2}-{3}-{4}.jpg", date.Year, date.Month, date.Day, date.Hour, date.Minute));
        }
    }
}
