112 lines
2.5 KiB
C#
112 lines
2.5 KiB
C#
using Microsoft.Practices.Prism.ViewModel;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace DTS.Common.BusyIndicatorManager
|
|
{
|
|
public class BusyIndicatorManager : NotificationObject
|
|
{
|
|
#region Membervariables
|
|
|
|
private Dictionary<int, string> busyParameters;
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
private BusyIndicatorManager()
|
|
{
|
|
_isBusy = false;
|
|
_message = string.Empty;
|
|
busyParameters = new Dictionary<int, string>();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Singleton Implementation
|
|
|
|
private static BusyIndicatorManager _instance;
|
|
private static readonly object SyncRoot = new object();
|
|
|
|
public static BusyIndicatorManager Instance
|
|
{
|
|
get
|
|
{
|
|
lock (SyncRoot)
|
|
{
|
|
return _instance ?? (_instance = new BusyIndicatorManager());
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Public Properties
|
|
|
|
private bool _isBusy;
|
|
|
|
public bool IsBusy
|
|
{
|
|
get => _isBusy;
|
|
private set
|
|
{
|
|
_isBusy = value;
|
|
RaisePropertyChanged("IsBusy");
|
|
}
|
|
}
|
|
|
|
private string _message;
|
|
|
|
public string Message
|
|
{
|
|
get => _message;
|
|
private set
|
|
{
|
|
_message = value;
|
|
RaisePropertyChanged("Message");
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Public Methods
|
|
|
|
public void ShowBusy(int id, string busyMessage)
|
|
{
|
|
if (!busyParameters.ContainsKey(id))
|
|
{
|
|
busyParameters.Add(id, busyMessage);
|
|
IsBusy = true;
|
|
Message = busyMessage;
|
|
}
|
|
else
|
|
{
|
|
busyParameters[id] = busyMessage;
|
|
IsBusy = true;
|
|
Message = busyMessage;
|
|
}
|
|
}
|
|
|
|
public void CloseBusy(int id)
|
|
{
|
|
if (busyParameters.ContainsKey(id))
|
|
busyParameters.Remove(id);
|
|
|
|
if (busyParameters.Count == 0)
|
|
{
|
|
IsBusy = false;
|
|
Message = string.Empty;
|
|
}
|
|
else
|
|
{
|
|
IsBusy = true;
|
|
Message = busyParameters.Last().Value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
|