2010-10-08 06:35:04 +03:00
|
|
|
using System;
|
|
|
|
using NLog;
|
|
|
|
|
2010-10-21 04:49:23 +03:00
|
|
|
namespace NzbDrone.Core.Model.Notification
|
2010-10-08 06:35:04 +03:00
|
|
|
{
|
|
|
|
public class ProgressNotification : IDisposable
|
|
|
|
{
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
public ProgressNotification(string title)
|
|
|
|
{
|
|
|
|
Title = title;
|
2010-10-12 05:49:27 +03:00
|
|
|
CurrentStatus = String.Empty;
|
2010-10-08 06:35:04 +03:00
|
|
|
Id = Guid.NewGuid();
|
|
|
|
ProgressMax = 100;
|
|
|
|
ProgressValue = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the unique id.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The Id.</value>
|
|
|
|
public Guid Id { get; private set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the title for this notification.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The title.</value>
|
|
|
|
public String Title { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 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.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The current status.</value>
|
|
|
|
public String CurrentStatus { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the completion status in percent.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The percent complete.</value>
|
|
|
|
public int PercentComplete
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return Convert.ToInt32(Convert.ToDouble(ProgressValue) / Convert.ToDouble(ProgressMax) * 100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the total number of items that need to be completed
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The progress max.</value>
|
|
|
|
public int ProgressMax { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the number of items successfully completed.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The progress value.</value>
|
|
|
|
public int ProgressValue { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the status.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The status.</value>
|
2010-10-21 04:49:23 +03:00
|
|
|
public ProgressNotificationStatus Status { get; set; }
|
2010-10-08 06:35:04 +03:00
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
2010-10-21 04:49:23 +03:00
|
|
|
if (Status == ProgressNotificationStatus.InProgress)
|
2010-10-08 06:35:04 +03:00
|
|
|
{
|
2010-10-24 20:35:58 +03:00
|
|
|
Logger.Warn("Background task '{0}' was unexpectedly abandoned.", Title);
|
2010-10-21 04:49:23 +03:00
|
|
|
Status = ProgressNotificationStatus.Failed;
|
2010-10-08 06:35:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|