136 lines
5.9 KiB
Plaintext
136 lines
5.9 KiB
Plaintext
|
|
using System;
|
||
|
|
using System.ComponentModel;
|
||
|
|
using System.Threading.Tasks;
|
||
|
|
using System.Windows;
|
||
|
|
using System.Windows.Media;
|
||
|
|
using DTS.Common.Base;
|
||
|
|
using DTS.Common.Classes;
|
||
|
|
using DTS.Common.Events;
|
||
|
|
using DTS.Common.Interactivity;
|
||
|
|
using DTS.Common.Interface;
|
||
|
|
using Prism.Events;
|
||
|
|
using Prism.Regions;
|
||
|
|
using Unity;
|
||
|
|
|
||
|
|
namespace DTS.StatusAndProgressBar
|
||
|
|
{
|
||
|
|
public class StatusAndProgressBarViewModel : BaseViewModel<IStatusAndProgressBarViewModel>, IStatusAndProgressBarViewModel
|
||
|
|
{
|
||
|
|
public IBaseView View { get; set; }
|
||
|
|
public IBaseViewModel Parent { get; set; }
|
||
|
|
private IEventAggregator _eventAggregator { get; set; }
|
||
|
|
private IUnityContainer _unityContainer { get; set; }
|
||
|
|
|
||
|
|
public InteractionRequest<Notification> NotificationRequest { get; private set; }
|
||
|
|
public new InteractionRequest<Confirmation> ConfirmationRequest { get; private set; }
|
||
|
|
/// <summary>
|
||
|
|
/// Creates a new instance of the FilterViewModel.
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="view">The StatusAndProgressBar View interface.</param>
|
||
|
|
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
|
||
|
|
/// <param name="eventAggregator">The EventAggregator which allows different components to publish/subscribe to events without being coupled to each other.</param>
|
||
|
|
/// <param name="unityContainer">The Unity container.</param>
|
||
|
|
public StatusAndProgressBarViewModel(IStatusAndProgressBarView view, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer)
|
||
|
|
: base(regionManager, eventAggregator, unityContainer)
|
||
|
|
{
|
||
|
|
View = view;
|
||
|
|
View.DataContext = this;
|
||
|
|
|
||
|
|
NotificationRequest = new InteractionRequest<Notification>();
|
||
|
|
ConfirmationRequest = new InteractionRequest<Confirmation>();
|
||
|
|
|
||
|
|
_eventAggregator = eventAggregator;
|
||
|
|
_unityContainer = unityContainer;
|
||
|
|
_searchButtonVisability = false;
|
||
|
|
_eventAggregator.GetEvent<StatusAndProgressBarEvent>().Subscribe(OnUpdate, ThreadOption.PublisherThread, true);
|
||
|
|
}
|
||
|
|
|
||
|
|
#region Properties
|
||
|
|
public string ProgressBarName { get; set; }
|
||
|
|
public new bool IsMenuIncluded { get; set; }
|
||
|
|
public new bool IsNavigationIncluded { get; set; }
|
||
|
|
public new bool IsBusy { get; set; }
|
||
|
|
public new bool IsDirty { get; }
|
||
|
|
public object ContextSearchRegion { get; set; }
|
||
|
|
|
||
|
|
private bool _searchButtonVisability = false;
|
||
|
|
public bool SearchButtonVisability { get => _searchButtonVisability; set { _searchButtonVisability = value; OnPropertyChanged("SearchButtonVisability"); } }
|
||
|
|
private Visibility _alertVisibility = Visibility.Hidden;
|
||
|
|
public Visibility AlertVisibility
|
||
|
|
{
|
||
|
|
get => _alertVisibility;
|
||
|
|
set => SetProperty(ref _alertVisibility, value, "AlertVisibility");
|
||
|
|
}
|
||
|
|
private string _aggregateStatusText = "---";
|
||
|
|
public string AggregateStatusText { get => _aggregateStatusText; set { _aggregateStatusText = value; OnPropertyChanged("AggregateStatusText"); } }
|
||
|
|
|
||
|
|
private Color _aggregateStatusColor = Colors.AliceBlue;
|
||
|
|
public Color AggregateStatusColor { get => _aggregateStatusColor; set { _aggregateStatusColor = value; OnPropertyChanged("AggregateStatusColor"); } }
|
||
|
|
private Visibility _progressBarVisibility = Visibility.Hidden;
|
||
|
|
public Visibility ProgressBarVisibility { get => _progressBarVisibility; set { _progressBarVisibility = value; OnPropertyChanged("ProgressBarVisibility"); } }
|
||
|
|
|
||
|
|
private int _progressBarValue;
|
||
|
|
public int ProgressBarValue { get => _progressBarValue; set { _progressBarValue = value; OnPropertyChanged("ProgressBarValue"); } }
|
||
|
|
|
||
|
|
public new event PropertyChangedEventHandler PropertyChanged;
|
||
|
|
///<summary>
|
||
|
|
///Occurs when a property value changes.
|
||
|
|
///</summary>
|
||
|
|
private new void OnPropertyChanged(string propertyName)
|
||
|
|
{
|
||
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||
|
|
}
|
||
|
|
#endregion Properties
|
||
|
|
|
||
|
|
#region Methods
|
||
|
|
|
||
|
|
public override void Initialize()
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void Initialize(object parameter)
|
||
|
|
{
|
||
|
|
Parent = (IBaseViewModel)parameter;
|
||
|
|
_eventAggregator.GetEvent<ProgressBarEvent>().Subscribe(OnProgressBarEvent, ThreadOption.UIThread);
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnProgressBarEvent(ProgressBarEventArg arg)
|
||
|
|
{
|
||
|
|
if (arg.ProgressBarName != ProgressBarName) { return; }
|
||
|
|
AggregateStatusColor = arg.ProgressBarColor;
|
||
|
|
AggregateStatusText = arg.ProgressBarText;
|
||
|
|
ProgressBarVisibility = arg.ProgressBarVisibility;
|
||
|
|
if (!double.IsNaN(arg.ProgressBarPercentage))
|
||
|
|
{
|
||
|
|
ProgressBarValue = Convert.ToInt32(arg.ProgressBarPercentage);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
public override void Activated()
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public override void Cleanup()
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
private void OnUpdate(StatusAndProgressBarEventArgs args)
|
||
|
|
{
|
||
|
|
//Since there may be multiple instances of this control, don't do anything if
|
||
|
|
//the requester is not our parent because it's just a waste of time and resources
|
||
|
|
if (args.Requester != Parent) return;
|
||
|
|
AggregateStatusText = args.StatusText;
|
||
|
|
if (!string.IsNullOrWhiteSpace(args.ErrorText))
|
||
|
|
{
|
||
|
|
AggregateStatusText += " - " + args.ErrorText;
|
||
|
|
}
|
||
|
|
AggregateStatusColor = args.StatusColor;
|
||
|
|
ProgressBarVisibility = args.ProgressBarVisibility;
|
||
|
|
ProgressBarValue = (int)args.ProgressValue;
|
||
|
|
}
|
||
|
|
#endregion Methods
|
||
|
|
}
|
||
|
|
}
|