using System.ComponentModel.Composition; using System.Threading.Tasks; using DTS.Common.Base; using DTS.Common.Events; using DTS.Common.Interactivity; using DTS.Common.Interface; using Prism.Events; using Prism.Regions; using Unity; namespace PowerAndBattery { [Export(typeof(IPowerAndBatteryView))] [PartCreationPolicy(CreationPolicy.Shared)] public class PowerAndBatteryViewModel : BasePropertyChanged, IPowerAndBatteryViewModel { public IPowerAndBatteryView View { get; private set; } private IEventAggregator _eventAggregator { get; set; } private IRegionManager _regionManager; private IUnityContainer UnityContainer { get; set; } public InteractionRequest NotificationRequest { get; private set; } public InteractionRequest ConfirmationRequest { get; private set; } /// /// Creates a new instance of the TechnologyDomainEditViewModel. /// /// The ShellView View. /// The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed. /// The EventAggregator which allows different components to publish/subscribe to events without being coupled to each other. /// The unityContainer. public PowerAndBatteryViewModel(IPowerAndBatteryView view, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer) //: base(regionManager, eventAggregator, unityContainer) { View = view; View.DataContext = this; NotificationRequest = new InteractionRequest(); ConfirmationRequest = new InteractionRequest(); _eventAggregator = eventAggregator; UnityContainer = unityContainer; _regionManager = regionManager; _eventAggregator.GetEvent().Subscribe(OnRaiseNotification); _eventAggregator.GetEvent().Subscribe(OnBusyIndicatorNotification, ThreadOption.PublisherThread, true); } #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() { } /// /// Private Event handler for RaiseNotification event. /// private void OnBusyIndicatorNotification(bool eventArg) { IsBusy = eventArg; } /// /// Private Event handler for RaiseNotification event. /// private void OnRaiseNotification(NotificationContentEventArgs eventArgsWithTitle) { // The NotificationRequest.Raise triggers the Invoke() method of the .Infrastructure.PopupWindowAction object // to show the .Infrastructure.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 }); } #endregion #region Properties public bool IsDirty { get; private set; } private bool _isBusy = false; public bool IsBusy { get => _isBusy; set => SetProperty(ref _isBusy, value, "IsBusy"); } private bool _isMenuIncluded = false; public bool IsMenuIncluded { get => _isMenuIncluded; set => SetProperty(ref _isMenuIncluded, value, "IsMenuIncluded"); } private bool _isNavigationIncluded = false; public bool IsNavigationIncluded { get => _isNavigationIncluded; set => SetProperty(ref _isNavigationIncluded, value, "IsNavigationIncluded"); } /// /// Gets the HeaderInfo. /// public string HeaderInfo => "MainRegion"; #endregion Properties } }