using System; using System.ComponentModel; using System.ComponentModel.Composition; using System.Linq; using System.Threading.Tasks; using DTS.Common.Events; using DTS.Common.Interface; using Microsoft.Practices.Prism.Events; using Microsoft.Practices.Prism.Interactivity.InteractionRequest; using Microsoft.Practices.Prism.Regions; using Microsoft.Practices.Unity; using PedestrianAndHeadReports.Classes; using System.Collections.Generic; using DTS.Slice.Control; // ReSharper disable CheckNamespace // ReSharper disable MemberCanBePrivate.Global // ReSharper disable InconsistentNaming namespace PedestrianAndHeadReports { /// /// this class handles DB import/export functionality /// (note that since a lot of of DataPRO objects still live in the datapro project it's functionality is limited to the xml string going back and forth right now) /// [Export(typeof(ITRLReportInputView))] [Export(typeof(ITRLReportOutputView))] [PartCreationPolicy(CreationPolicy.Shared)] public class TRLReportViewModel : ITRLReportViewModel { public ITRLReportInputView InputView { get; set; } public ITRLReportOutputView OutputView { 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 TechnologyDomainEditViewModel. /// /// /// /// 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 TRLReportViewModel(ITRLReportInputView inputView, ITRLReportOutputView outputView, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer, DTS.Serialization.Test test) { Test = test; AvailableTimeUnits = new[] {ConstantsAndEnums.TimeUnits.Seconds, ConstantsAndEnums.TimeUnits.MilliSeconds}; SelectedTimeUnits = ConstantsAndEnums.TimeUnits.Seconds; AvailableAccelerationUnits = new[] { DTS.SensorDB.MeasurementUnitList.GetMeasurementUnit("m/sec^2"), DTS.SensorDB.MeasurementUnitList.GetMeasurementUnit("g") }; SelectedAccelerationUnit = AvailableAccelerationUnits[0]; PopulateChannels(); InputView = inputView; OutputView = outputView; inputView.DataContext = this; outputView.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 private void PopulateChannels() { var accelerationChannels = new List(); var bendChannels = new List(); var sheerChannels = new List(); var unitBending = DTS.SensorDB.MeasurementUnitList.GetMeasurementUnit("deg"); var unitSheering = DTS.SensorDB.MeasurementUnitList.GetMeasurementUnit("deg"); foreach (var ch in Test.Channels) { if (!(ch.emc is Event.Module.AnalogInputChannel emc)) { continue; } accelerationChannels.AddRange(from unit in AvailableAccelerationUnits where unit.UnitMatches(emc.EngineeringUnits) select emc); if (unitBending.UnitMatches(emc.EngineeringUnits)) { bendChannels.Add(emc); } if (unitSheering.UnitMatches(emc.EngineeringUnits)) { sheerChannels.Add(emc); } } AccelerationChannels = accelerationChannels.ToArray(); AvailableBendingChannels = bendChannels.ToArray(); AvailableShearChannels = sheerChannels.ToArray(); } public void Cleanup() { } public Task CleanupAsync() { return null; } public void Initialize() { } public void Initialize(object parameter) { } public void Initialize(object parameter, object model) { } public Task InitializeAsync() { return null; } public Task InitializeAsync(object parameter) { return null; } 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 PopupWindowAction object to show the NotificationWindow window // Notification object expects a NotificationContentEventArgsWithoutTitle object and a Title string. var eventArgsWithoutTitle = new NotificationContentEventArgs(eventArgsWithTitle.Message, "", eventArgsWithTitle.Image, string.Empty); 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 { _isBusy = value; OnPropertyChanged("IsBusy"); } } private bool _isMenuIncluded = false; public bool IsMenuIncluded { get => _isMenuIncluded; set { _isMenuIncluded = value; OnPropertyChanged("IsMenuIncluded"); } } private bool _isNavigationIncluded = false; public bool IsNavigationIncluded { get => _isNavigationIncluded; set { _isNavigationIncluded = value; OnPropertyChanged("IsNavigationIncluded"); } } /// /// Gets the HeaderInfo. /// public string HeaderInfo => "MainRegion"; #endregion Properties #region Commands /*/// /// browse to a file to import, should be xml, maybe needs a few other criteria /// private DelegateCommand _importBrowseCommand; public DelegateCommand ImportBrowseCommand { get { return _importBrowseCommand ?? ( _importBrowseCommand = new DelegateCommand(ImportBrowseMethod)); } } private void ImportBrowseMethod() { using (var dlg = new System.Windows.Forms.OpenFileDialog()) { dlg.CheckFileExists = true; dlg.CheckPathExists = true; dlg.Filter = Resources.StringResources.ImportFileBrowse_Filter; dlg.FilterIndex = 0; if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ImportFileName = dlg.FileName; } } }*/ #endregion #region properties public DTS.Serialization.Test Test { get; set; } public enum Tags { TestNumber, DateTimeText, CarName, Model, TestTemperature, MeasurementPoint, CrashVelocity, ImpactorID, AvailableImpactorTypes, SelectedImpactor, ImpactorWeight, Examiner, Reserved1, Reserved2, AvailableCFCs, SelectedCFC, AvailableAccelerationUnits, SelectedAccelerationUnit, AvailableBendingAngleUnits, SelectedBendingAngleUnit, AvailableShearAngleUnits, SelectedShearAngleUnit, AvailableTimeUnits, SelectedTimeUnits, AccelerationChannels, SelectedAccelerationChannel, AvailableBendingChannels, SelectedBendingChannel, AvailableShearChannels, SelectedShearChannel } public string TestNumber { get; set; } private DateTime _dateTime = DateTime.Now; public string DateTimeText { get => _dateTime.ToString(System.Globalization.CultureInfo.CurrentCulture); set => _dateTime = DateTime.Parse(value); } public string CarName { get; set; } public string Model { get; set; } public string TestTemperature { get; set; } public string MeasurementPoint { get; set; } public string CrashVelocity { get; set; } public string ImpactorID { get; set; } public string[] AvailableImpactorTypes => throw new NotImplementedException(); public string SelectedImpactor{get;set;} public string ImpactorWeight{get;set;} public string Examiner{get;set;} public string Reserved1{get;set;} public string Reserved2{get;set;} public DTS.SensorDB.FilterClass[] AvailableCFCs => throw new NotImplementedException(); public DTS.SensorDB.FilterClass SelectedCFC{get;set;} public DTS.SensorDB.MeasurementUnit[] AvailableAccelerationUnits { get; set; } public DTS.SensorDB.MeasurementUnit SelectedAccelerationUnit { get; set; } public ConstantsAndEnums.TimeUnits[] AvailableTimeUnits { get; set; } public ConstantsAndEnums.TimeUnits SelectedTimeUnits{get;set;} public Event.Module.AnalogInputChannel[] AccelerationChannels { get; set; } public Event.Module.Channel SelectedAccelerationChannel{get;set;} public Event.Module.AnalogInputChannel[] AvailableBendingChannels { get; set; } public Event.Module.Channel SelectedBendingChannel { get; set; } public Event.Module.AnalogInputChannel[] AvailableShearChannels { get; set; } public Event.Module.Channel SelectedShearChannel { get; set; } #endregion /// ///Occurs when a property value changes. /// public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } }