init
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Threading.Tasks;
|
||||
using DTS.Common.Events;
|
||||
using DTS.Common.Interactivity;
|
||||
using DTS.Common.Interface;
|
||||
using ISOSettings.Model;
|
||||
using Prism.Events;
|
||||
using Prism.Regions;
|
||||
using Unity;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace ISOSettings
|
||||
{
|
||||
[Export(typeof(IISOSettingsView))]
|
||||
[PartCreationPolicy(CreationPolicy.Shared)]
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public class ISOSettingsViewModel : IISOSettingsViewModel
|
||||
{
|
||||
public IISOSettingsView View { get; set; }
|
||||
public IISOSettingsModel Model { get; set; }
|
||||
|
||||
private IEventAggregator _eventAggregator { get; set; }
|
||||
private IRegionManager _regionManager;
|
||||
private IUnityContainer UnityContainer { get; set; }
|
||||
|
||||
public InteractionRequest<Notification> NotificationRequest { get; private set; }
|
||||
public InteractionRequest<Confirmation> ConfirmationRequest { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the ISOSettingsViewModel.
|
||||
/// </summary>
|
||||
/// <param name="view">The ISO Settings View.</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 unityContainer.</param>
|
||||
public ISOSettingsViewModel(IISOSettingsView view, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer)
|
||||
{
|
||||
View = view;
|
||||
|
||||
NotificationRequest = new InteractionRequest<Notification>();
|
||||
ConfirmationRequest = new InteractionRequest<Confirmation>();
|
||||
|
||||
_eventAggregator = eventAggregator;
|
||||
UnityContainer = unityContainer;
|
||||
_regionManager = regionManager;
|
||||
_eventAggregator.GetEvent<RaiseNotification>().Subscribe(OnRaiseNotification);
|
||||
_eventAggregator.GetEvent<BusyIndicatorChangeNotification>().Subscribe(OnBusyIndicatorNotification, ThreadOption.PublisherThread, true);
|
||||
Model = new ISOSettingsModel(_eventAggregator);
|
||||
ISOData = Model.LoadData();
|
||||
View.DataContext = ISOData;
|
||||
}
|
||||
|
||||
#region Methods
|
||||
|
||||
public void Cleanup() { }
|
||||
public Task CleanupAsync() { return Task.CompletedTask; }
|
||||
public void Initialize() { }
|
||||
public void Initialize(object parameter) { }
|
||||
public void Initialize(object parameter, object model) { }
|
||||
public Task InitializeAsync() { return Task.CompletedTask; }
|
||||
public Task InitializeAsync(object parameter) { return Task.CompletedTask; }
|
||||
public void Activated() { }
|
||||
|
||||
/// <summary>
|
||||
/// Private Event handler for RaiseNotification event.
|
||||
/// </summary>
|
||||
private void OnBusyIndicatorNotification(bool eventArg)
|
||||
{
|
||||
IsBusy = eventArg;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Private Event handler for RaiseNotification event.
|
||||
/// </summary>
|
||||
private void OnRaiseNotification(NotificationContentEventArgs eventArgsWithTitle)
|
||||
{
|
||||
// The NotificationRequest.Raise triggers the Invoke() method of the PopupWindowAction object to show the NotificationWindow window
|
||||
|
||||
// Notification object expects a NotificationContentEventArgsWithoutTitle object and a Title string.
|
||||
var eventArgsWithoutTitle = new NotificationContentEventArgs(eventArgsWithTitle.Message, "", eventArgsWithTitle.Image, "");
|
||||
|
||||
NotificationRequest.Raise(new Notification { Content = eventArgsWithoutTitle, Title = eventArgsWithTitle.Title });
|
||||
}
|
||||
|
||||
public void SaveData()
|
||||
{
|
||||
Model.SaveData(ISOData);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
private IISOSettingsData _isoData;
|
||||
public IISOSettingsData ISOData { get => _isoData; set { _isoData = value; OnPropertyChanged("ISOData"); } }
|
||||
|
||||
public bool IsDirty { get; private set; }
|
||||
private bool _isBusy = false;
|
||||
public bool IsBusy { get => _isBusy; set { _isBusy = value; OnPropertyChanged("IsBusy"); } }
|
||||
private bool _isMenuIncluded = false;
|
||||
public bool IsMenuIncluded { get => _isMenuIncluded; set { _isMenuIncluded = value; OnPropertyChanged("IsMenuIncluded"); } }
|
||||
private bool _isNavigationIncluded = false;
|
||||
public bool IsNavigationIncluded { get => _isNavigationIncluded; set { _isNavigationIncluded = value; OnPropertyChanged("IsNavigationIncluded"); } }
|
||||
/// <summary>
|
||||
/// Gets the HeaderInfo.
|
||||
/// </summary>
|
||||
public string HeaderInfo => "MainRegion";
|
||||
#endregion Properties
|
||||
|
||||
///<summary>
|
||||
///Occurs when a property value changes.
|
||||
///</summary>
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
public void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
var eventHandler = PropertyChanged;
|
||||
if (eventHandler != null) { eventHandler(this, new PropertyChangedEventArgs(propertyName)); }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user