JD2022-TU1/main/tools/framework/JD.Statistics/Statistic.cs

68 lines
No EOL
1.5 KiB
C#

using System;
namespace JD.Statistics
{
public abstract class Statistic : IDisposable
{
#region Variables
private bool m_isDisposed;
#endregion
#region Constructor
public Statistic()
{
Id = Guid.NewGuid().ToString();
}
public virtual void Dispose()
{
if (IsRelevant)
{
RelevantStatisticEnded?.Invoke(null, new StatisticsEventArgs(this));
}
m_isDisposed = true;
}
#endregion
#region Properties
public bool IsDisposed
{
get { return m_isDisposed; }
}
public virtual bool IsRelevant
{
get { return true; }
}
/// <summary>
/// The identifier of the statistic will be used on the backend (typically, a guid)
/// </summary>
public string Id { get; set; }
#endregion
#region Methods
/// <summary>
/// Normally, statistics are posted to the server on disposal. When using the send now method, stats are sent earlier. This can also be used to update the same statistic over and over.
/// </summary>
public void SendNow()
{
RelevantStatisticEnded?.Invoke(this, new StatisticsEventArgs(this));
}
#endregion
#region Events
public static event EventHandler<StatisticsEventArgs> RelevantStatisticEnded;
#endregion
}
}