using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Threading.Tasks; using DTS.Common.Base; using DTS.Common.Classes.TestMetadata; using DTS.Common.Events; using DTS.Common.Interface; using DTS.Common.Interface.TestDefinition; using DTS.Viewer.TestSummaryList.Model; using Microsoft.Practices.Prism.Events; using Microsoft.Practices.Prism.Interactivity.InteractionRequest; using Microsoft.Practices.Prism.Regions; using Microsoft.Practices.Unity; // ReSharper disable ConvertToAutoProperty namespace DTS.Viewer.TestSummaryList.ViewModel { public class TestSummaryViewModel : BaseViewModel, ITestSummaryListViewModel { public ITestSummaryListView TestSummaryListView { get; private set; } private IBaseWindowModel Parent { get; 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 TechnologyDoFrontEditViewModel. /// /// The TestListView 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 TestSummaryViewModel(ITestSummaryListView view, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer) : base(regionManager, eventAggregator, unityContainer) { TestSummaryListView = view; TestSummaryListView.DataContext = this; NotificationRequest = new InteractionRequest(); ConfirmationRequest = new InteractionRequest(); _eventAggregator = eventAggregator; UnityContainer = unityContainer; _regionManager = regionManager; _eventAggregator.GetEvent().Subscribe(OnRaiseNotification); _eventAggregator.GetEvent().Subscribe(OnDataFolderChanged); } #region Methods public override void Initialize() { } public override void Initialize(object parameter) { Parent = (IBaseWindowModel)parameter; } private void OnDataFolderChanged(string path) { if (String.IsNullOrEmpty(path)) return; IsBusy = true; _eventAggregator.GetEvent().Publish(new StatusInfo(StatusInfo.StatusState.Busy, "Please wait...")); var td = new TestSummaryModel { Parent = this, _eventAggregator = _eventAggregator }; td.GetTestSummary(path); } /// /// Private Event handler for RaiseNotification event. /// private void OnRaiseNotification(NotificationContentEventArgs eventArgsWithTitle) { // Notification object expects a NotificationContentEventArgsWithoutTitle object and a Title string. var eventArgsWithoutTitle = new NotificationContentEventArgs(eventArgsWithTitle.Message, eventArgsWithTitle.MessageDetails, eventArgsWithTitle.Image); NotificationRequest.Raise(new Notification { Content = eventArgsWithoutTitle, Title = eventArgsWithTitle.Title }); } public override void Activated() { throw new NotImplementedException(); } public override void Cleanup() { throw new NotImplementedException(); } public new Task CleanupAsync() { throw new NotImplementedException(); } public override Task InitializeAsync() { throw new NotImplementedException(); } public override Task InitializeAsync(object parameter) { throw new NotImplementedException(); } public void PublishSelectedTestSummaryList() { _eventAggregator.GetEvent().Publish(SelectedTestSummaryList); _eventAggregator.GetEvent().Publish(SelectedTestSummaryList.Count); } #endregion #region ContextRegion public object ContextNavigationRegion { get => ((TestSummaryView)TestSummaryListView).TestListRegion.Content; set { ((TestSummaryView)TestSummaryListView).TestListRegion.Content = value; OnPropertyChanged("ContextNavigationRegion"); } } #endregion #region Properties private TestSummary _selectedTestSummary = new TestSummary(); public TestSummary SelectedTestSummary { get => _selectedTestSummary; set { _selectedTestSummary = value; OnPropertyChanged("SelectedTestSummary"); } } private List _selectedTestSummaryList = new List(); public List SelectedTestSummaryList { get => _selectedTestSummaryList; set { _selectedTestSummaryList = value; OnPropertyChanged("SelectedTestSummaryList"); } } private ObservableCollection _testSummaryList = new ObservableCollection(); public ObservableCollection TestSummaryList { get => _testSummaryList; set { _testSummaryList = value; OnPropertyChanged("TestSummaryList"); } } /// ///Occurs when a property value changes. /// public new event PropertyChangedEventHandler PropertyChanged; private new void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } /// /// Gets the HeaderInfo. /// public string HeaderInfo => "TestSummaryRegion"; private bool _isBusy = false; public new bool IsBusy { get => _isBusy; set { _isBusy = value; OnPropertyChanged("IsBusy"); } } private bool _isDirty; public new bool IsDirty { get => _isDirty; set => _isDirty = value; } private bool _isNavigationIncluded; public new bool IsNavigationIncluded { get => _isNavigationIncluded; set => _isNavigationIncluded = value; } #endregion } }