using DTS.Common.Base; using DTS.Common.Events; using DTS.Common.Interactivity; using DTS.Common.Interface; using Prism.Events; using Prism.Regions; using System; using System.Threading.Tasks; using Unity; namespace DTS.Viewer.PSDReportSettings { public class PSDReportSettingsViewModel : BaseViewModel, IPSDReportSettingsViewModel { public IBaseView View { get; set; } //public bool Standalone { get; set; } public IBaseViewModel Parent { get; set; } private IPSDReportSettingsModel _model; public new IPSDReportSettingsModel Model { get => _model; set { _model = value; OnPropertyChanged("Model"); } } private IEventAggregator _eventAggregator { get; set; } private IUnityContainer _unityContainer { get; set; } public InteractionRequest NotificationRequest { get; private set; } public new InteractionRequest ConfirmationRequest { get; private set; } /// /// Creates a new instance of the MainViewModel. /// /// 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 Unity container. public PSDReportSettingsViewModel(IPSDReportSettingsView 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; } #region Methods public override void Initialize() { } public override void Initialize(object parameter) { Parent = (IBaseViewModel)parameter; Subscribe(); Model = _unityContainer.Resolve(); Model.Parent = this; //View.DataContext = Model; } private void Subscribe() { //_eventAggregator.GetEvent().Subscribe(OnCursorsAlailableChanged); _eventAggregator.GetEvent().Subscribe(OnGraphSelectedChannelsChanged); _eventAggregator.GetEvent().Subscribe(OnGraphCleared); _eventAggregator.GetEvent().Subscribe(OnChartAxisChanged); } private void OnChartAxisChanged(ChartAxisChangedEventArg arg) { if (arg?.ParentVM != Parent) return; switch (arg.Axis) { case "Y": //Model.MinFixedY = args.MinValue; //Model.MaxFixedY = args.MaxValue; break; case "X": Model.CanPublishChanges = false; Model.DataStart = arg.MinValue; Model.DataEnd = arg.MaxValue; Model.CanPublishChanges = true; PublishChanges(); break; } //throw new NotImplementedException(); } private void OnGraphCleared(GraphClearNotificationArg obj) { //Graph's been cleared. Init our settings Model.ReadData = false; PublishChanges(); } private void OnGraphSelectedChannelsChanged(GraphSelectedChannelsNotificationArg arg) { if (Parent != arg?.ParentVM) return; var channels = arg.SelectedChannels; Model.Parent = this; //PublishChanges(); } /// /// 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 void PublishChanges() { _eventAggregator.GetEvent().Publish(new PSDReportSettingsChangedEventArg() { Model = Model, ParentVM = Parent }); } #endregion } }