using System;
using SabreTools.Library.Data;
namespace SabreTools.Library.Tools
{
///
/// Stopwatch class for keeping track of duration in the code
///
public class InternalStopwatch
{
private string _subject;
private DateTime _startTime;
///
/// Constructor that initalizes the stopwatch
///
public InternalStopwatch()
{
_subject = "";
}
///
/// Constructor that initalizes the stopwatch with a subject and starts immediately
///
/// Subject of the stopwatch
public InternalStopwatch(string subject)
{
_subject = subject;
Start();
}
///
/// Constructor that initalizes the stopwatch with a subject and starts immediately
///
/// Subject of the stopwatch
/// Parameters to format the string
public InternalStopwatch(string subject, params object[] more)
{
_subject = string.Format(subject, more);
Start();
}
///
/// Start the stopwatch and display subject text
///
public void Start()
{
_startTime = DateTime.Now;
Globals.Logger.User("{0}...", _subject);
}
///
/// Start the stopwatch and display subject text
///
/// Text to show on stopwatch start
public void Start(string subject)
{
_subject = subject;
Start();
}
///
/// Start the stopwatch and display subject text
///
/// Text to show on stopwatch start
/// Parameters to format the string
public void Start(string subject, params object[] more)
{
_subject = string.Format(subject, more);
Start();
}
///
/// End the stopwatch and display subject text
///
public void Stop()
{
Globals.Logger.User("{0} completed in {1}", _subject, DateTime.Now.Subtract(_startTime).ToString(@"hh\:mm\:ss\.fffff"));
}
}
}