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
{
///
/// Base class used to create ViewModel objects that implement their own commands/verbs/actions.
///
/// Type of the Model object.
public abstract class ViewModelBase : DependencyObject, INotifyPropertyChanged, IViewModel
{
///
/// Gets or sets the Model object.
///
public object Model { get; set; }
///
/// Create new instance of base class used to create ViewModel objects that implement their own commands/verbs/actions.
///
public ViewModelBase()
{
}
///
/// Gets a value indicating whether this object is executing an asynchronous process.
///
public bool IsBusy { get; protected set; }
///
/// Gets a value indicating whether the Model has been changed.
///
public virtual bool IsDirty { get; protected set; }
// Summary:
// Event raised when an error occurs during processing.
///
///
///
public virtual event EventHandler ErrorOccurred;
///
/// Event raised when a property changes.
///
public virtual event PropertyChangedEventHandler PropertyChanged;
///
/// 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.
///
/// A Task that creates the model object.
[DebuggerStepThrough]
protected abstract Task InitializeAsync();
///
/// Creates or retrieves a new instance of the Model by invoking a static factory method.
///
/// Static factory method function.
protected abstract void DoRefresh(Func factoryMethod);
///
/// Raises ErrorOccurred event when an error occurs during processing.
///
///
protected abstract void OnError(Exception error);
///
/// Invoked when the Model changes, allowing event handlers to be unhooked from the old object and hooked on the new object.
///
/// Previous Model reference.
/// New Model reference.
protected abstract void OnModelChanged(T oldValue, T newValue);
///
/// Raise the PropertyChanged event.
///
/// Name of the changed property.
protected abstract void OnPropertyChanged(string propertyName);
}
}