init
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
using DTS.Common.Base;
|
||||
using DTS.Common.Events;
|
||||
using DTS.Common.Interactivity;
|
||||
using DTS.Common.Interface;
|
||||
using DTS.Common.Utils;
|
||||
using Prism.Commands;
|
||||
using Prism.Events;
|
||||
using Prism.Regions;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
using Unity;
|
||||
|
||||
namespace DTS.Viewer.PSDReportResults
|
||||
{
|
||||
public class PSDReportResultsViewModel : BaseViewModel<IPSDReportResultsViewModel>, IPSDReportResultsViewModel
|
||||
{
|
||||
#region properties / fields
|
||||
public IBaseView View { get; set; }
|
||||
public IBaseViewModel Parent { get; set; }
|
||||
public ObservableCollection<IChannelGRMSSummary> Results { get; set; }
|
||||
private string Directory { get; set; }
|
||||
private IEventAggregator _eventAggregator { get; set; }
|
||||
private new IRegionManager _regionManager { get; set; }
|
||||
private IUnityContainer _unityContainer { get; set; }
|
||||
|
||||
public InteractionRequest<Notification> NotificationRequest { get; private set; }
|
||||
public new InteractionRequest<Confirmation> ConfirmationRequest { get; private set; }
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the MainViewModel.
|
||||
/// </summary>
|
||||
|
||||
/// <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 Unity container.</param>
|
||||
public PSDReportResultsViewModel(IPSDReportSettingsView 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;
|
||||
_regionManager = regionManager;
|
||||
}
|
||||
|
||||
public override void Initialize(object parameter)
|
||||
{
|
||||
Parent = (IBaseViewModel)parameter;
|
||||
Results = new ObservableCollection<IChannelGRMSSummary>();
|
||||
Subscribe();
|
||||
}
|
||||
|
||||
private void Subscribe()
|
||||
{
|
||||
_eventAggregator.GetEvent<PSDReportGRMSValuesUpdatedEvent>().Subscribe(OnGRMSValuesUpdated, ThreadOption.UIThread);
|
||||
_eventAggregator.GetEvent<GraphSelectedChannelsNotification>().Subscribe(OnGraphSelectedChannelsChanged);
|
||||
}
|
||||
|
||||
private void OnGRMSValuesUpdated(PSDReportGRMSValuesUpdatedEventArg arg)
|
||||
{
|
||||
if (Parent != arg.ParentVM) return;
|
||||
Results.Clear();
|
||||
foreach (var val in arg.Values)
|
||||
{
|
||||
Results.Add(val);
|
||||
}
|
||||
}
|
||||
private void OnGraphSelectedChannelsChanged(GraphSelectedChannelsNotificationArg arg)
|
||||
{
|
||||
if (Parent != arg?.ParentVM) return;
|
||||
var channels = arg?.SelectedChannels ?? new System.Collections.Generic.List<ITestChannel>();
|
||||
|
||||
Directory = channels.Count > 0 ? channels[0].BinaryFilePath.ReplaceLast("Binary", "Reports") : string.Empty;
|
||||
}
|
||||
|
||||
private DelegateCommand _exportToPDFCommand;
|
||||
public DelegateCommand ExportToPDFCommand => _exportToPDFCommand ?? (_exportToPDFCommand = new DelegateCommand(ExportToPDFMethod));
|
||||
private void ExportToPDFMethod()
|
||||
{
|
||||
_eventAggregator.GetEvent<SaveReportToPDFRequestedEvent>().Publish(new SaveReportToPDFRequestedEventArgs() { Directory = Directory, ParentVM = Parent });
|
||||
}
|
||||
|
||||
private DelegateCommand _exportToCSVCommand;
|
||||
public DelegateCommand ExportToCSVCommand => _exportToCSVCommand ?? (_exportToCSVCommand = new DelegateCommand(ExportToCSVMethod));
|
||||
|
||||
private void ExportToCSVMethod()
|
||||
{
|
||||
_eventAggregator.GetEvent<SaveReportToCSVRequestedEvent>().Publish(new SaveReportToCSVRequestedEventArgs() { Directory = Directory, ParentVM = Parent });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user