2017-10-06 00:52:26 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
|
2020-12-07 14:29:45 -08:00
|
|
|
|
using SabreTools.Logging;
|
2017-10-06 00:52:26 -07:00
|
|
|
|
|
2017-10-06 20:46:43 -07:00
|
|
|
|
namespace SabreTools.Library.Tools
|
2017-10-06 00:52:26 -07:00
|
|
|
|
{
|
2019-02-08 21:03:28 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Stopwatch class for keeping track of duration in the code
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class InternalStopwatch
|
|
|
|
|
|
{
|
|
|
|
|
|
private string _subject;
|
|
|
|
|
|
private DateTime _startTime;
|
2020-10-07 16:37:10 -07:00
|
|
|
|
private readonly Logger _logger;
|
2017-10-06 00:52:26 -07:00
|
|
|
|
|
2019-02-08 21:03:28 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Constructor that initalizes the stopwatch
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public InternalStopwatch()
|
|
|
|
|
|
{
|
2020-06-10 22:37:19 -07:00
|
|
|
|
_subject = string.Empty;
|
2020-10-07 16:37:10 -07:00
|
|
|
|
_logger = new Logger(this);
|
2019-02-08 21:03:28 -08:00
|
|
|
|
}
|
2017-10-06 00:52:26 -07:00
|
|
|
|
|
2019-02-08 21:03:28 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Constructor that initalizes the stopwatch with a subject and starts immediately
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="subject">Subject of the stopwatch</param>
|
|
|
|
|
|
public InternalStopwatch(string subject)
|
|
|
|
|
|
{
|
|
|
|
|
|
_subject = subject;
|
2020-10-07 16:37:10 -07:00
|
|
|
|
_logger = new Logger(this);
|
2019-02-08 21:03:28 -08:00
|
|
|
|
Start();
|
|
|
|
|
|
}
|
2017-10-06 00:52:26 -07:00
|
|
|
|
|
2019-02-08 21:03:28 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Start the stopwatch and display subject text
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
_startTime = DateTime.Now;
|
2020-10-07 15:42:30 -07:00
|
|
|
|
_logger.User($"{_subject}...");
|
2019-02-08 21:03:28 -08:00
|
|
|
|
}
|
2017-10-06 00:52:26 -07:00
|
|
|
|
|
2019-02-08 21:03:28 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Start the stopwatch and display subject text
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="subject">Text to show on stopwatch start</param>
|
|
|
|
|
|
public void Start(string subject)
|
|
|
|
|
|
{
|
|
|
|
|
|
_subject = subject;
|
|
|
|
|
|
Start();
|
|
|
|
|
|
}
|
2017-10-06 00:52:26 -07:00
|
|
|
|
|
2019-02-08 21:03:28 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// End the stopwatch and display subject text
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void Stop()
|
|
|
|
|
|
{
|
2020-10-07 15:42:30 -07:00
|
|
|
|
_logger.User($"{_subject} completed in {DateTime.Now.Subtract(_startTime):G}");
|
2019-02-08 21:03:28 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-06 00:52:26 -07:00
|
|
|
|
}
|