2010-10-08 05:35:04 +02:00
|
|
|
using System;
|
|
|
|
using NLog;
|
|
|
|
|
2010-10-21 03:49:23 +02:00
|
|
|
namespace NzbDrone.Core.Model.Notification
|
2010-10-08 05:35:04 +02:00
|
|
|
{
|
|
|
|
public class ProgressNotification : IDisposable
|
|
|
|
{
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
public ProgressNotification(string title)
|
|
|
|
{
|
|
|
|
Title = title;
|
2011-04-24 07:48:12 +02:00
|
|
|
CurrentMessage = String.Empty;
|
2010-10-08 05:35:04 +02:00
|
|
|
Id = Guid.NewGuid();
|
|
|
|
ProgressMax = 100;
|
|
|
|
ProgressValue = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2011-04-10 04:44:01 +02:00
|
|
|
/// Gets or sets the unique id.
|
2010-10-08 05:35:04 +02:00
|
|
|
/// </summary>
|
|
|
|
/// <value>The Id.</value>
|
|
|
|
public Guid Id { get; private set; }
|
|
|
|
|
|
|
|
/// <summary>
|
2011-04-10 04:44:01 +02:00
|
|
|
/// Gets or sets the title for this notification.
|
2010-10-08 05:35:04 +02:00
|
|
|
/// </summary>
|
|
|
|
/// <value>The title.</value>
|
2011-07-02 10:56:58 +02:00
|
|
|
public String Title { get; private set; }
|
2010-10-08 05:35:04 +02:00
|
|
|
|
|
|
|
/// <summary>
|
2011-04-10 04:44:01 +02:00
|
|
|
/// Gets or sets the current status of this task. this field could be use to show the currently processing item in a long running task.
|
2010-10-08 05:35:04 +02:00
|
|
|
/// </summary>
|
|
|
|
/// <value>The current status.</value>
|
2011-04-24 07:48:12 +02:00
|
|
|
public String CurrentMessage { get; set; }
|
2010-10-08 05:35:04 +02:00
|
|
|
|
|
|
|
/// <summary>
|
2011-04-10 04:44:01 +02:00
|
|
|
/// Gets or sets the completion status in percent.
|
2010-10-08 05:35:04 +02:00
|
|
|
/// </summary>
|
|
|
|
/// <value>The percent complete.</value>
|
|
|
|
public int PercentComplete
|
|
|
|
{
|
2011-04-24 06:06:34 +02:00
|
|
|
get { return Convert.ToInt32(Convert.ToDouble(ProgressValue) / Convert.ToDouble(ProgressMax) * 100); }
|
2010-10-08 05:35:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2011-04-10 04:44:01 +02:00
|
|
|
/// Gets or sets the total number of items that need to be completed
|
2010-10-08 05:35:04 +02:00
|
|
|
/// </summary>
|
|
|
|
/// <value>The progress max.</value>
|
|
|
|
public int ProgressMax { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
2011-04-10 04:44:01 +02:00
|
|
|
/// Gets or sets the number of items successfully completed.
|
2010-10-08 05:35:04 +02:00
|
|
|
/// </summary>
|
|
|
|
/// <value>The progress value.</value>
|
|
|
|
public int ProgressValue { get; set; }
|
|
|
|
|
2011-04-24 06:06:34 +02:00
|
|
|
private ProgressNotificationStatus _status;
|
|
|
|
|
2010-10-08 05:35:04 +02:00
|
|
|
/// <summary>
|
2011-04-10 04:44:01 +02:00
|
|
|
/// Gets or sets the status.
|
2010-10-08 05:35:04 +02:00
|
|
|
/// </summary>
|
|
|
|
/// <value>The status.</value>
|
2011-04-24 06:06:34 +02:00
|
|
|
public ProgressNotificationStatus Status
|
|
|
|
{
|
|
|
|
get { return _status; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value != ProgressNotificationStatus.InProgress)
|
|
|
|
{
|
|
|
|
CompletedTime = DateTime.Now;
|
|
|
|
}
|
|
|
|
_status = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the completed time.
|
|
|
|
/// </summary>
|
2011-11-21 05:43:16 +01:00
|
|
|
public Nullable<DateTime> CompletedTime { get; private set; }
|
2010-10-08 05:35:04 +02:00
|
|
|
|
2011-04-10 04:44:01 +02:00
|
|
|
#region IDisposable Members
|
|
|
|
|
2010-10-08 05:35:04 +02:00
|
|
|
public void Dispose()
|
|
|
|
{
|
2010-10-21 03:49:23 +02:00
|
|
|
if (Status == ProgressNotificationStatus.InProgress)
|
2010-10-08 05:35:04 +02:00
|
|
|
{
|
2010-10-24 19:35:58 +02:00
|
|
|
Logger.Warn("Background task '{0}' was unexpectedly abandoned.", Title);
|
2010-10-21 03:49:23 +02:00
|
|
|
Status = ProgressNotificationStatus.Failed;
|
2010-10-08 05:35:04 +02:00
|
|
|
}
|
|
|
|
}
|
2011-04-10 04:44:01 +02:00
|
|
|
|
|
|
|
#endregion
|
2010-10-08 05:35:04 +02:00
|
|
|
}
|
|
|
|
}
|