This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -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;
}
}
}

View File

@@ -0,0 +1,91 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
// ReSharper disable once CheckNamespace
namespace DTS.Common.Base
{
/// <summary>
/// Base class used to create ViewModel objects that implement their own commands/verbs/actions.
/// </summary>
/// <typeparam name="T">Type of the Model object.</typeparam>
public abstract class ViewModelBase<T> : DependencyObject, INotifyPropertyChanged, IViewModel
{
/// <summary>
/// Gets or sets the Model object.
/// </summary>
public object Model { get; set; }
/// <summary>
/// Create new instance of base class used to create ViewModel objects that implement their own commands/verbs/actions.
/// </summary>
public ViewModelBase()
{
}
/// <summary>
/// Gets a value indicating whether this object is executing an asynchronous process.
/// </summary>
public bool IsBusy { get; protected set; }
/// <summary>
/// Gets a value indicating whether the Model has been changed.
/// </summary>
public virtual bool IsDirty { get; protected set; }
// Summary:
// Event raised when an error occurs during processing.
/// <summary>
///
/// </summary>
public virtual event EventHandler<ErrorEventArgs> ErrorOccurred;
/// <summary>
/// Event raised when a property changes.
/// </summary>
public virtual event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Override this method to implement async initialization of the model object.
/// The result of this method is used to set the Model property of the viewmodel.
/// </summary>
/// <returns>A Task that creates the model object.</returns>
[DebuggerStepThrough]
protected abstract Task<T> InitializeAsync();
/// <summary>
/// Creates or retrieves a new instance of the Model by invoking a static factory method.
/// </summary>
/// <param name="factoryMethod">Static factory method function.</param>
protected abstract void DoRefresh(Func<T> factoryMethod);
/// <summary>
/// Raises ErrorOccurred event when an error occurs during processing.
/// </summary>
/// <param name="error"></param>
protected abstract void OnError(Exception error);
/// <summary>
/// Invoked when the Model changes, allowing event handlers to be unhooked from the old object and hooked on the new object.
/// </summary>
/// <param name="oldValue">Previous Model reference.</param>
/// <param name="newValue">New Model reference.</param>
protected abstract void OnModelChanged(T oldValue, T newValue);
/// <summary>
/// Raise the PropertyChanged event.
/// </summary>
/// <param name="propertyName">Name of the changed property.</param>
protected abstract void OnPropertyChanged(string propertyName);
}
}