420 lines
17 KiB
C#
420 lines
17 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Collections.ObjectModel;
|
|||
|
|
using System.Collections.Specialized;
|
|||
|
|
using System.ComponentModel;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using System.Windows.Threading;
|
|||
|
|
using DTS.Common.Base;
|
|||
|
|
using DTS.Common.Classes.Viewer.TestMetadata;
|
|||
|
|
using DTS.Common.Events;
|
|||
|
|
using DTS.Common.Interactivity;
|
|||
|
|
using DTS.Common.Interface;
|
|||
|
|
using DTS.Common.Interface.TestDefinition;
|
|||
|
|
using DTS.Viewer.TestSummaryList.Model;
|
|||
|
|
using DTS.Viewer.TestSummaryList.Resources;
|
|||
|
|
using Prism.Commands;
|
|||
|
|
using Prism.Events;
|
|||
|
|
using Prism.Regions;
|
|||
|
|
using Unity;
|
|||
|
|
|
|||
|
|
|
|||
|
|
namespace DTS.Viewer.TestSummaryList.ViewModel
|
|||
|
|
{
|
|||
|
|
public class TestSummaryViewListModel : BaseViewModel<ITestSummaryListViewModel>, ITestSummaryListViewModel
|
|||
|
|
{
|
|||
|
|
public IFilterView FilterView { get; private set; }
|
|||
|
|
public ITestSummaryListView View { get; set; }
|
|||
|
|
internal IBaseViewModel Parent { get; set; }
|
|||
|
|
private IEventAggregator _eventAggregator { get; set; }
|
|||
|
|
|
|||
|
|
private IUnityContainer _unityContainer { get; set; }
|
|||
|
|
public InteractionRequest<Notification> NotificationRequest { get; private set; }
|
|||
|
|
public new InteractionRequest<Confirmation> ConfirmationRequest { get; private set; }
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Creates a new instance of the TestSummaryViewListModel.
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="view">The TestSummaryList View interface.</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 TestSummaryViewListModel(ITestSummaryListView view, IRegionManager regionManager, IEventAggregator eventAggregator,
|
|||
|
|
IUnityContainer unityContainer)
|
|||
|
|
: base(regionManager, eventAggregator, unityContainer)
|
|||
|
|
{
|
|||
|
|
View = view;
|
|||
|
|
View.DataContext = this;
|
|||
|
|
NotificationRequest = new InteractionRequest<Notification>();
|
|||
|
|
ConfirmationRequest = new InteractionRequest<Confirmation>();
|
|||
|
|
|
|||
|
|
_eventAggregator = eventAggregator;
|
|||
|
|
_unityContainer = unityContainer;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#region Methods
|
|||
|
|
|
|||
|
|
public override void Initialize()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override void Initialize(object parameter)
|
|||
|
|
{
|
|||
|
|
Parent = (IBaseViewModel)parameter;
|
|||
|
|
|
|||
|
|
FilterView = GetFilterView(this);
|
|||
|
|
TestSummaryList.CollectionChanged += TestSummaryList_CollectionChanged;
|
|||
|
|
FilteredTestSummaryList.CollectionChanged += TestSummaryList_CollectionChanged;
|
|||
|
|
Subscribe();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Subscribe()
|
|||
|
|
{
|
|||
|
|
_eventAggregator.GetEvent<RaiseNotification>().Subscribe(OnRaiseNotification);
|
|||
|
|
_eventAggregator.GetEvent<DataFolderChangedEvent>().Subscribe(OnDataFolderChanged);
|
|||
|
|
_eventAggregator.GetEvent<FilterParameterChangedEvent>().Subscribe(OnFilterChanged);
|
|||
|
|
_eventAggregator.GetEvent<RefreshTestRequestEvent>().Subscribe(OnRefreshTestRequest);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void OnFilterChanged(FilterParameterArgs args)
|
|||
|
|
{
|
|||
|
|
if (((IFilterViewModel)FilterView.DataContext).Parent == this)
|
|||
|
|
{
|
|||
|
|
FilteredTestSummaryList = string.IsNullOrEmpty(args.Param) ? new ObservableCollection<ITestSummary>(TestSummaryList)
|
|||
|
|
: new ObservableCollection<ITestSummary>((from x in TestSummaryList where x.SetupName.ToLower().Contains(args.Param.ToLower()) || x.Id.ToLower().Contains(args.Param.ToLower()) || x.Description.ToLower().Contains(args.Param.ToLower()) select x).ToList());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private void OnDataFolderChanged(DataFolderSelectionArg arg)
|
|||
|
|
{
|
|||
|
|
if (Parent != arg.ParentVM) return;
|
|||
|
|
var path = arg.Path;
|
|||
|
|
var file = arg.File;
|
|||
|
|
|
|||
|
|
if (string.IsNullOrEmpty(path) && string.IsNullOrEmpty(file)) return;
|
|||
|
|
if (!string.IsNullOrEmpty(path) && string.IsNullOrEmpty(file)) { Cleanup(); }
|
|||
|
|
|
|||
|
|
_selectedDataFolder = path;
|
|||
|
|
_selectedDataFile = file;
|
|||
|
|
|
|||
|
|
IsBusy = true;
|
|||
|
|
_eventAggregator.GetEvent<BusyIndicatorChangeNotification>().Publish(true);
|
|||
|
|
|
|||
|
|
var td = new TestSummaryModel { Parent = this, _eventAggregator = _eventAggregator };
|
|||
|
|
td.GetTestSummary(path, file, arg.SetSelected, arg.SelectAll);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Private Event handler for RaiseNotification event.
|
|||
|
|
/// </summary>
|
|||
|
|
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()
|
|||
|
|
{
|
|||
|
|
var fp = new FilterParameterArgs
|
|||
|
|
{
|
|||
|
|
Param = string.Empty,
|
|||
|
|
Requester = this
|
|||
|
|
};
|
|||
|
|
_eventAggregator.GetEvent<FilterParameterChangedEvent>().Publish(fp);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override void Cleanup()
|
|||
|
|
{
|
|||
|
|
TestSummaryList.Clear();
|
|||
|
|
SelectedTestSummaryList.Clear();
|
|||
|
|
FilteredTestSummaryList.Clear();
|
|||
|
|
SelectedTestSummary = new TestSummary();
|
|||
|
|
PublishSelectedTestSummaryList();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void PublishSelectedTestSummaryList()
|
|||
|
|
{
|
|||
|
|
_eventAggregator.GetEvent<TestSummaryChangeNotification>().Publish(new TestSummaryChangeNotificationArg { SummaryList = SelectedTestSummaryList, ParentVM = Parent, TotalSummaryCount = TestSummaryList.Count });
|
|||
|
|
_eventAggregator.GetEvent<TestSummaryCountNotification>().Publish(new TestSummaryCountNotificationArg { SummaryCount = SelectedTestSummaryList.Count, ParentVM = Parent });
|
|||
|
|
_eventAggregator.GetEvent<ResetZoomChangedEvent>().Publish(true);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region ContextRegion
|
|||
|
|
public object ContextNavigationRegion
|
|||
|
|
{
|
|||
|
|
get => ((TestSummaryListView)View).TestListRegion.DataContext;
|
|||
|
|
set { ((TestSummaryListView)View).TestListRegion.DataContext = value; OnPropertyChanged("ContextNavigationRegion"); }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private IFilterView GetFilterView(IBaseViewModel parent)
|
|||
|
|
{
|
|||
|
|
var view = _unityContainer.Resolve<IFilterView>();
|
|||
|
|
var viewModel = _unityContainer.Resolve<IFilterViewModel>();
|
|||
|
|
view.DataContext = viewModel;
|
|||
|
|
viewModel.Initialize(parent);
|
|||
|
|
return view;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region Properties
|
|||
|
|
|
|||
|
|
private bool _isFilterEnabled = false;
|
|||
|
|
public bool IsFilterEnabled { get => _isFilterEnabled; set { _isFilterEnabled = value; OnPropertyChanged("IsFilterEnabled"); } }
|
|||
|
|
|
|||
|
|
private TestSummary _selectedTestSummary = new TestSummary();
|
|||
|
|
public TestSummary SelectedTestSummary
|
|||
|
|
{
|
|||
|
|
get => _selectedTestSummary;
|
|||
|
|
set { _selectedTestSummary = value; OnPropertyChanged("SelectedTestSummary"); }
|
|||
|
|
}
|
|||
|
|
private List<ITestSummary> _selectedTestSummaryList = new List<ITestSummary>();
|
|||
|
|
public List<ITestSummary> SelectedTestSummaryList
|
|||
|
|
{
|
|||
|
|
get => _selectedTestSummaryList;
|
|||
|
|
set { _selectedTestSummaryList = value; OnPropertyChanged("SelectedTestSummaryList"); }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private ObservableCollection<ITestSummary> _testSummaryList = new ObservableCollection<ITestSummary>();
|
|||
|
|
public ObservableCollection<ITestSummary> TestSummaryList
|
|||
|
|
{
|
|||
|
|
get => _testSummaryList;
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
_testSummaryList = value;
|
|||
|
|
IsFilterEnabled = _testSummaryList.Count > 0;
|
|||
|
|
FilteredTestSummaryList = new ObservableCollection<ITestSummary>(_testSummaryList);
|
|||
|
|
OnPropertyChanged("TestSummaryList");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public void TestSummaryList_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
|||
|
|
{
|
|||
|
|
if (e.OldItems != null)
|
|||
|
|
{
|
|||
|
|
foreach (INotifyPropertyChanged item in e.OldItems)
|
|||
|
|
item.PropertyChanged -= TestSummaryList_PropertyChanged;
|
|||
|
|
}
|
|||
|
|
if (e.NewItems != null)
|
|||
|
|
{
|
|||
|
|
foreach (INotifyPropertyChanged item in e.NewItems)
|
|||
|
|
item.PropertyChanged += TestSummaryList_PropertyChanged;
|
|||
|
|
}
|
|||
|
|
IsFilterEnabled = _testSummaryList.Count > 0;
|
|||
|
|
FilteredTestSummaryList = new ObservableCollection<ITestSummary>(_testSummaryList);
|
|||
|
|
SortTestSummaryList();
|
|||
|
|
}
|
|||
|
|
private void TestSummaryList_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
|||
|
|
{
|
|||
|
|
if (e.PropertyName == "TestSummaryList")
|
|||
|
|
{
|
|||
|
|
IsFilterEnabled = _testSummaryList.Count > 0;
|
|||
|
|
FilteredTestSummaryList = new ObservableCollection<ITestSummary>(_testSummaryList);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private ObservableCollection<ITestSummary> _filteredTestSummaryList = new ObservableCollection<ITestSummary>();
|
|||
|
|
public ObservableCollection<ITestSummary> FilteredTestSummaryList
|
|||
|
|
{
|
|||
|
|
get => _filteredTestSummaryList;
|
|||
|
|
set { _filteredTestSummaryList = value; OnPropertyChanged("FilteredTestSummaryList"); }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
///<summary>
|
|||
|
|
///Occurs when a property value changes.
|
|||
|
|
///</summary>
|
|||
|
|
public new event PropertyChangedEventHandler PropertyChanged;
|
|||
|
|
private new void OnPropertyChanged(string propertyName)
|
|||
|
|
{
|
|||
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Gets the HeaderInfo.
|
|||
|
|
/// </summary>
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private string _selectedDataFolder = string.Empty;
|
|||
|
|
public string SelectedDataFolder
|
|||
|
|
{
|
|||
|
|
get => _selectedDataFolder;
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(value)) return;
|
|||
|
|
|
|||
|
|
_selectedDataFolder = value; _eventAggregator.GetEvent<DataFolderChangedEvent>().Publish(new DataFolderSelectionArg { Path = _selectedDataFolder, File = string.Empty, SelectAll = false, ParentVM = Parent }); OnPropertyChanged("SelectedDataFolder");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private string _selectedDataFile = string.Empty;
|
|||
|
|
public string SelectedDataFile
|
|||
|
|
{
|
|||
|
|
get => _selectedDataFile;
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(value)) return;
|
|||
|
|
_selectedDataFile = value; _eventAggregator.GetEvent<DataFolderChangedEvent>().Publish(new DataFolderSelectionArg { Path = string.Empty, File = _selectedDataFile, SelectAll = false, ParentVM = Parent }); OnPropertyChanged("SelectedDataFile");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region Commands
|
|||
|
|
private DelegateCommand _refreshDataFolderCommand;
|
|||
|
|
public DelegateCommand RefreshDataFolderCommand => _refreshDataFolderCommand ?? (_refreshDataFolderCommand = new DelegateCommand(RefreshDataFolder));
|
|||
|
|
|
|||
|
|
|
|||
|
|
private DelegateCommand _selectDataFolderCommand;
|
|||
|
|
public DelegateCommand SelectDataFolderCommand => _selectDataFolderCommand ?? (_selectDataFolderCommand = new DelegateCommand(SelectDataFolder));
|
|||
|
|
|
|||
|
|
private void RefreshDataFolder()
|
|||
|
|
{
|
|||
|
|
Dispatcher.CurrentDispatcher.Invoke(() =>
|
|||
|
|
{
|
|||
|
|
_eventAggregator.GetEvent<DataFolderChangedEvent>().Publish(new DataFolderSelectionArg { Path = _selectedDataFolder, File = string.Empty, SelectAll = false, ParentVM = Parent });
|
|||
|
|
}, DispatcherPriority.Background);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void SelectDataFolder()
|
|||
|
|
{
|
|||
|
|
const string fileExt = "DTS Files (*.dts)|*.dts";
|
|||
|
|
var fileDialog = new System.Windows.Forms.OpenFileDialog { Filter = fileExt };
|
|||
|
|
var result = fileDialog.ShowDialog();
|
|||
|
|
if (result == System.Windows.Forms.DialogResult.OK)
|
|||
|
|
{
|
|||
|
|
//16158 Browse button on View Data tab not functiona
|
|||
|
|
//((IViewerMainViewModel) Parent).SelectAndIncludeDataFile(fileDialog.FileName);
|
|||
|
|
_eventAggregator.GetEvent<DataFileSelectedEvent>().Publish(new DataFileSelectionArg { File = fileDialog.FileName, ParentVM = Parent });
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void OnRefreshTestRequest(string file)
|
|||
|
|
{
|
|||
|
|
var td = new TestSummaryModel { Parent = this, _eventAggregator = _eventAggregator };
|
|||
|
|
td.GetTestSummary(string.Empty, file);
|
|||
|
|
}
|
|||
|
|
#endregion Commands
|
|||
|
|
|
|||
|
|
public enum SortableAttribute
|
|||
|
|
{
|
|||
|
|
TimeStampDescending,
|
|||
|
|
Timestamp,
|
|||
|
|
FileDateDescending,
|
|||
|
|
FileDate,
|
|||
|
|
IdDescending,
|
|||
|
|
Id,
|
|||
|
|
TestSetupDescending,
|
|||
|
|
TestSetup
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public List<string> SortableAttributes
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
var rv = new List<string>();
|
|||
|
|
foreach (var sortableAttribute in Enum.GetValues(typeof(SortableAttribute)).Cast<SortableAttribute>().ToList())
|
|||
|
|
{
|
|||
|
|
rv.Add(new SortableAttributeHelper(sortableAttribute).ToString());
|
|||
|
|
}
|
|||
|
|
return rv;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private int _selctedSortIndex = (int)SortableAttribute.TimeStampDescending;
|
|||
|
|
public int SelectedSortIndex
|
|||
|
|
{
|
|||
|
|
get => _selctedSortIndex;
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
_selctedSortIndex = value;
|
|||
|
|
SortTestSummaryList();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void SortTestSummaryList()
|
|||
|
|
{
|
|||
|
|
var rv = new ITestSummary[FilteredTestSummaryList.Count];
|
|||
|
|
switch ((SortableAttribute)_selctedSortIndex)
|
|||
|
|
{
|
|||
|
|
default:
|
|||
|
|
case SortableAttribute.TimeStampDescending:
|
|||
|
|
FilteredTestSummaryList.OrderByDescending(x => x.TimeStamp.Ticks).ToList().CopyTo(rv);
|
|||
|
|
break;
|
|||
|
|
case SortableAttribute.Timestamp:
|
|||
|
|
FilteredTestSummaryList.OrderBy(x => x.TimeStamp.Ticks).ToList().CopyTo(rv);
|
|||
|
|
break;
|
|||
|
|
case SortableAttribute.FileDateDescending:
|
|||
|
|
FilteredTestSummaryList.OrderByDescending(x => x.FileDate.Ticks).ToList().CopyTo(rv);
|
|||
|
|
break;
|
|||
|
|
case SortableAttribute.FileDate:
|
|||
|
|
FilteredTestSummaryList.OrderBy(x => x.FileDate.Ticks).ToList().CopyTo(rv);
|
|||
|
|
break;
|
|||
|
|
case SortableAttribute.IdDescending:
|
|||
|
|
FilteredTestSummaryList.OrderByDescending(x => x.Id).ToList().CopyTo(rv);
|
|||
|
|
break;
|
|||
|
|
case SortableAttribute.Id:
|
|||
|
|
FilteredTestSummaryList.OrderBy(x => x.Id).ToList().CopyTo(rv);
|
|||
|
|
break;
|
|||
|
|
case SortableAttribute.TestSetupDescending:
|
|||
|
|
FilteredTestSummaryList.OrderByDescending(x => x.SetupName).ToList().CopyTo(rv);
|
|||
|
|
break;
|
|||
|
|
case SortableAttribute.TestSetup:
|
|||
|
|
FilteredTestSummaryList.OrderBy(x => x.SetupName).ToList().CopyTo(rv);
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
FilteredTestSummaryList.Clear();
|
|||
|
|
foreach (var testSummary in rv)
|
|||
|
|
{
|
|||
|
|
FilteredTestSummaryList.Add(testSummary);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public class SortableAttributeHelper
|
|||
|
|
{
|
|||
|
|
public SortableAttributeHelper(SortableAttribute attribute)
|
|||
|
|
{
|
|||
|
|
_attribute = attribute;
|
|||
|
|
}
|
|||
|
|
private SortableAttribute _attribute;
|
|||
|
|
public SortableAttribute Attribute
|
|||
|
|
{
|
|||
|
|
get => _attribute;
|
|||
|
|
set => _attribute = value;
|
|||
|
|
}
|
|||
|
|
public override string ToString()
|
|||
|
|
{
|
|||
|
|
return StringResources.ResourceManager.GetString(_attribute.ToString()) ?? _attribute.ToString();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|