init
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user