init
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Threading;
|
||||
using DTS.Common.Events;
|
||||
using DTS.Common.Interactivity;
|
||||
using Prism.Commands;
|
||||
using Prism.Events;
|
||||
using Prism.Regions;
|
||||
using Unity;
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace DTS.Common.Base
|
||||
{
|
||||
public abstract class BaseViewModel<TModel> : BasePropertyChanged, IBaseViewModel
|
||||
where TModel : class
|
||||
{
|
||||
|
||||
protected IEventAggregator Aggregator { get; private set; }
|
||||
protected IUnityContainer Container { get; private set; }
|
||||
public TModel Model { get; set; }
|
||||
|
||||
protected BaseViewModel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected BaseViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer)
|
||||
{
|
||||
Aggregator = eventAggregator;
|
||||
Container = unityContainer;
|
||||
CreateCommands();
|
||||
}
|
||||
|
||||
|
||||
protected virtual void CreateCommands()
|
||||
{
|
||||
ConfirmationRequest = new InteractionRequest<Confirmation>();
|
||||
CloseCommand = new DelegateCommand<object>(CloseMethod);
|
||||
}
|
||||
|
||||
#region Commands
|
||||
|
||||
/// <summary>
|
||||
/// The interaction request to display the confirmation.
|
||||
/// </summary>
|
||||
public InteractionRequest<Confirmation> ConfirmationRequest { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The delegate command to close object.
|
||||
/// </summary>
|
||||
public DelegateCommand<object> CloseCommand { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// This is an execute method for the <see cref="CloseCommand">CloseCommand</see>.
|
||||
/// </summary>
|
||||
/// <param name="parameter">The parameter to pass to the <see cref="CloseCommand">CloseCommand</see>.</param>
|
||||
protected virtual void CloseMethod(object parameter)
|
||||
{
|
||||
CleanupAtClose();
|
||||
}
|
||||
|
||||
private void CleanupAtClose()
|
||||
{
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
#endregion Commands
|
||||
|
||||
#region Bases Methods
|
||||
|
||||
/// <summary>
|
||||
/// Executes after the viewmodel activated.
|
||||
/// </summary>
|
||||
public virtual void Activated()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Publishes the <see cref="ShowStatus">ShowStatus</see> during the viewmodel initialization.
|
||||
/// </summary>
|
||||
public virtual void Initialize()
|
||||
{
|
||||
Aggregator.GetEvent<ShowStatus>()
|
||||
.Publish(new StatusInfo(StatusInfo.StatusState.Busy, Strings.Strings.Loading));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Publishes the <see cref="ShowStatus">ShowStatus</see> during the viewmodel initialization.
|
||||
/// </summary>
|
||||
/// <param name="parameter">The parameter to be used initialize viewmodel.</param>
|
||||
public virtual void Initialize(object parameter)
|
||||
{
|
||||
Aggregator.GetEvent<ShowStatus>()
|
||||
.Publish(new StatusInfo(StatusInfo.StatusState.Busy, Strings.Strings.Loading));
|
||||
}
|
||||
|
||||
public virtual void Initialize(object parameter, object model)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Publishes the <see cref="ShowStatus">ShowStatus</see> during the viewmodel initialization.
|
||||
/// </summary>
|
||||
public virtual async Task InitializeAsync()
|
||||
{
|
||||
await Dispatcher.CurrentDispatcher.InvokeAsync(() =>
|
||||
{
|
||||
Aggregator.GetEvent<ShowStatus>()
|
||||
.Publish(new StatusInfo(StatusInfo.StatusState.Busy, Strings.Strings.Loading));
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Publishes the <see cref="ShowStatus">ShowStatus</see> during the viewmodel initialization.
|
||||
/// </summary>
|
||||
/// <param name="parameter">The parameter to be used initialize viewmodel.</param>
|
||||
public virtual async Task InitializeAsync(object parameter)
|
||||
{
|
||||
await Dispatcher.CurrentDispatcher.InvokeAsync(() =>
|
||||
{
|
||||
Aggregator.GetEvent<ShowStatus>()
|
||||
.Publish(new StatusInfo(StatusInfo.StatusState.Busy, Strings.Strings.Loading));
|
||||
});
|
||||
}
|
||||
|
||||
#endregion Bases Methods
|
||||
|
||||
public new event PropertyChangedEventHandler PropertyChanged;
|
||||
public bool IsMenuIncluded { get; set; }
|
||||
public bool IsNavigationIncluded { get; set; }
|
||||
public int Percentage { get; set; }
|
||||
public string IsBusyMessage { get; set; }
|
||||
public bool IsBusy { get; set; }
|
||||
|
||||
|
||||
public bool IsDirty { get; set; }
|
||||
/// <summary>
|
||||
/// Sets the Model to null.
|
||||
/// </summary>
|
||||
public virtual void Cleanup()
|
||||
{
|
||||
Model = default(TModel);
|
||||
}
|
||||
|
||||
public Task CleanupAsync()
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user