From 24149160c17fabe143f143de2796f9485d64410b Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 21 Aug 2018 18:39:38 +0300 Subject: Tech Board Module seems to be working good !! --- .../ViewModels/MachineTechViewVM.cs | 151 ++++++++++++--------- 1 file changed, 84 insertions(+), 67 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs index 333e43187..8b331b5f5 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs @@ -94,7 +94,7 @@ namespace Tango.MachineStudio.Technician.ViewModels /// /// Gets or sets the db adapter. /// - public ObservablesEntitiesAdapter Adapter { get; set; } + public ObservablesStaticCollections Adapter { get; set; } /// /// Gets or sets the application manager. @@ -241,7 +241,7 @@ namespace Tango.MachineStudio.Technician.ViewModels ApplicationManager = applicationManager; ApplicationManager.ConnectedMachineChanged += ApplicationManager_ConnectedMachineChanged; - Adapter = ObservablesEntitiesAdapter.Instance; + Adapter = ObservablesStaticCollections.Instance; Elements = new ObservableCollection(); OpenProjectCommand = new RelayCommand(OpenProject); @@ -1473,7 +1473,7 @@ namespace Tango.MachineStudio.Technician.ViewModels { if (item is MotorGroupItem) { - (item as MotorGroupItem).TechMotors = ObservablesEntitiesAdapter.Instance.HardwareMotorTypes.Where(x => (item as MotorGroupItem).ItemsGuids.Contains(x.Guid)).ToObservableCollection(); + (item as MotorGroupItem).TechMotors = ObservablesStaticCollections.Instance.HardwareMotorTypes.Where(x => (item as MotorGroupItem).ItemsGuids.Contains(x.Guid)).ToObservableCollection(); } AddTechItem(item); @@ -1666,83 +1666,93 @@ namespace Tango.MachineStudio.Technician.ViewModels { if (MachineOperator != null) { - var hw = ApplicationManager.ConnectedMachine.Machine.Configuration.HardwareVersion.Clone(); - - foreach (var motorConfig in hw.HardwareMotors) + using (_notification.PushTaskItem("Uploading hardware configuration...")) { - var itemConfig = MotorItem.MotorConfigurations.SingleOrDefault(x => x.HardwareMotorType.Code == motorConfig.HardwareMotorType.Code); - - if (itemConfig != null) + try { - itemConfig.MapPrimitivesTo(motorConfig); - } - } + HardwareVersion hw = null; + Configuration config = null; - foreach (var pidConfig in hw.HardwarePidControls) - { - var itemConfig = PidItem.PidConfigurations.SingleOrDefault(x => x.HardwarePidControlType.Code == pidConfig.HardwarePidControlType.Code); + await Task.Factory.StartNew(() => + { + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + config = db.GetConfiguration(x => x.Guid == ApplicationManager.ConnectedMachine.Machine.ConfigurationGuid).Clone(); + hw = db.GetHardwareVersionByMachine(ApplicationManager.ConnectedMachine.Machine.Guid).Clone(); + } + }); - if (itemConfig != null) - { - itemConfig.MapPrimitivesTo(pidConfig); - } - } + foreach (var motorConfig in hw.HardwareMotors) + { + var itemConfig = MotorItem.MotorConfigurations.SingleOrDefault(x => x.HardwareMotorType.Code == motorConfig.HardwareMotorType.Code); - foreach (var winderConfig in hw.HardwareWinders) - { - var itemConfig = WinderItem.WinderConfigurations.SingleOrDefault(x => x.HardwareWinderType.Code == winderConfig.HardwareWinderType.Code); + if (itemConfig != null) + { + itemConfig.MapPrimitivesTo(motorConfig); + } + } - if (itemConfig != null) - { - itemConfig.MapPrimitivesTo(winderConfig); - } - } + foreach (var pidConfig in hw.HardwarePidControls) + { + var itemConfig = PidItem.PidConfigurations.SingleOrDefault(x => x.HardwarePidControlType.Code == pidConfig.HardwarePidControlType.Code); - foreach (var dancerConfig in hw.HardwareDancers) - { - var itemConfig = DancerItem.DancerConfigurations.SingleOrDefault(x => x.HardwareDancerType.Code == dancerConfig.HardwareDancerType.Code); + if (itemConfig != null) + { + itemConfig.MapPrimitivesTo(pidConfig); + } + } - if (itemConfig != null) - { - itemConfig.MapPrimitivesTo(dancerConfig); - } - } + foreach (var winderConfig in hw.HardwareWinders) + { + var itemConfig = WinderItem.WinderConfigurations.SingleOrDefault(x => x.HardwareWinderType.Code == winderConfig.HardwareWinderType.Code); - foreach (var speedSensorConfig in hw.HardwareSpeedSensors) - { - var itemConfig = SpeedSensorItem.SpeedSensorConfigurations.SingleOrDefault(x => x.HardwareSpeedSensorType.Code == speedSensorConfig.HardwareSpeedSensorType.Code); + if (itemConfig != null) + { + itemConfig.MapPrimitivesTo(winderConfig); + } + } - if (itemConfig != null) - { - itemConfig.MapPrimitivesTo(speedSensorConfig); - } - } + foreach (var dancerConfig in hw.HardwareDancers) + { + var itemConfig = DancerItem.DancerConfigurations.SingleOrDefault(x => x.HardwareDancerType.Code == dancerConfig.HardwareDancerType.Code); - foreach (var blowerConfig in hw.HardwareBlowers) - { - var itemConfig = BlowerItem.BlowerConfigurations.SingleOrDefault(x => x.HardwareBlowerType.Code == blowerConfig.HardwareBlowerType.Code); + if (itemConfig != null) + { + itemConfig.MapPrimitivesTo(dancerConfig); + } + } - if (itemConfig != null) - { - itemConfig.MapPrimitivesTo(blowerConfig); - } - } + foreach (var speedSensorConfig in hw.HardwareSpeedSensors) + { + var itemConfig = SpeedSensorItem.SpeedSensorConfigurations.SingleOrDefault(x => x.HardwareSpeedSensorType.Code == speedSensorConfig.HardwareSpeedSensorType.Code); - foreach (var breakSensorConfig in hw.HardwareBreakSensors) - { - var itemConfig = BreakSensorItem.BreakSensorConfigurations.SingleOrDefault(x => x.HardwareBreakSensorType.Code == breakSensorConfig.HardwareBreakSensorType.Code); + if (itemConfig != null) + { + itemConfig.MapPrimitivesTo(speedSensorConfig); + } + } - if (itemConfig != null) - { - itemConfig.MapPrimitivesTo(breakSensorConfig); - } - } + foreach (var blowerConfig in hw.HardwareBlowers) + { + var itemConfig = BlowerItem.BlowerConfigurations.SingleOrDefault(x => x.HardwareBlowerType.Code == blowerConfig.HardwareBlowerType.Code); - using (_notification.PushTaskItem("Uploading hardware configuration...")) - { - try - { - await MachineOperator.UploadHardwareConfiguration(hw, ApplicationManager.ConnectedMachine.Machine.Configuration); + if (itemConfig != null) + { + itemConfig.MapPrimitivesTo(blowerConfig); + } + } + + foreach (var breakSensorConfig in hw.HardwareBreakSensors) + { + var itemConfig = BreakSensorItem.BreakSensorConfigurations.SingleOrDefault(x => x.HardwareBreakSensorType.Code == breakSensorConfig.HardwareBreakSensorType.Code); + + if (itemConfig != null) + { + itemConfig.MapPrimitivesTo(breakSensorConfig); + } + } + + await MachineOperator.UploadHardwareConfiguration(hw, config); } catch (Exception ex) { @@ -1753,11 +1763,18 @@ namespace Tango.MachineStudio.Technician.ViewModels } } - private void ResetHardwareConfiguration(bool showMessage = true) + private async void ResetHardwareConfiguration(bool showMessage = true) { if (MachineOperator != null) { - var hw = ApplicationManager.ConnectedMachine.Machine.Configuration.HardwareVersion; + ObservablesContext db = ObservablesContext.CreateDefault(); + + HardwareVersion hw = null; + + await Task.Factory.StartNew(() => + { + hw = db.GetHardwareVersionByMachine(ApplicationManager.ConnectedMachine.Machine.Guid); + }); foreach (var motorConfig in hw.HardwareMotors) { -- cgit v1.3.1 From 2c8da378c82e5181f0566a564de529ab7ef96f4f Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 23 Aug 2018 09:45:01 +0300 Subject: Improvements to machine studio view models and navigation system. Improvements to tech board selection and edit modes handling. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 15400960 -> 15400960 bytes .../ViewModels/MainViewVM.cs | 4 +- .../ViewModels/MainViewVM.cs | 45 +-- .../Navigation/DeveloperNavigationManager.cs | 2 +- .../ViewModels/MainViewVM.cs | 8 +- .../Views/MainView.xaml | 2 +- .../ViewModels/MainViewVM.cs | 4 +- .../ViewModels/MainViewVM.cs | 13 +- .../ViewModels/MainViewVM.cs | 7 +- .../Editors/BlowerElementEditor.xaml | 19 +- .../Editors/BreakSensorElementEditor.xaml | 19 +- .../Editors/ControllerElementEditor.xaml | 19 +- .../Editors/DancerElementEditor.xaml | 19 +- .../Editors/DigitalInElementEditor.xaml | 19 +- .../Editors/DigitalOutElementEditor.xaml | 19 +- .../Editors/DispenserElementEditor.xaml | 19 +- .../Editors/JobRunnerElementEditor.xaml | 19 +- .../Editors/MeterElementEditor.xaml | 19 +- .../Editors/MonitorElementEditor.xaml | 19 +- .../Editors/MotorElementEditor.xaml | 19 +- .../Editors/MotorGroupElementEditor.xaml | 19 +- .../Editors/MultiGraphElementEditor.xaml | 17 +- .../Editors/PidElementEditor.xaml | 19 +- .../Editors/ProcessParametersElementEditor.xaml | 19 +- .../Editors/SingleGraphElementEditor.xaml | 17 +- .../Editors/SpeedSensorElementEditor.xaml | 19 +- .../Editors/ThreadMotionElementEditor.xaml | 19 +- .../Editors/WinderElementEditor.xaml | 19 +- .../ViewModels/MachineTechViewVM.cs | 7 +- .../Views/MachineTechView.xaml.cs | 2 +- .../ViewModels/MainViewVM.cs | 3 +- .../Tango.MachineStudio.Common/IStudioViewModel.cs | 19 +- .../Navigation/INavigationBlocker.cs | 28 ++ .../Navigation/INavigationManager.cs | 98 +++++- .../Navigation/INavigationObjectReceiver.cs | 21 ++ .../Navigation/INavigationResultProvider.cs | 28 ++ .../StudioApplication/IStudioApplicationManager.cs | 7 - .../Tango.MachineStudio.Common/StudioViewModel.cs | 180 ++-------- .../Tango.MachineStudio.Common.csproj | 10 +- .../Threading/IDispatcherProvider.cs | 26 ++ .../Tango.MachineStudio.UI/MainWindow.xaml | 2 +- .../Navigation/DefaultNavigationManager.cs | 369 ++++++++++++++++++++- .../DefaultStudioApplicationManager.cs | 25 -- .../Tango.MachineStudio.UI.csproj | 1 + .../Threading/DefaultDispatcherProvider.cs | 46 +++ .../Tango.MachineStudio.UI/ViewModelLocator.cs | 6 + .../ViewModels/LoadingViewVM.cs | 7 +- .../ViewModels/MainViewVM.cs | 20 +- .../Tango.MachineStudio.UI/Views/MainView.xaml | 2 +- .../Tango.MachineStudio.UI/Views/MainView.xaml.cs | 8 +- .../PPC/Tango.PPC.UI/Tango.PPC.UI.csproj | 4 +- .../Threading/DefaultDispatcherProvider.cs | 46 +++ .../Threading/DefaultDispetcherProvider.cs | 46 --- .../PPC/Tango.PPC.UI/ViewModelLocator.cs | 2 +- .../Tango.Editors/ElementsEditor.xaml.cs | 2 +- 56 files changed, 1089 insertions(+), 368 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationBlocker.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationObjectReceiver.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationResultProvider.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Threading/IDispatcherProvider.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Threading/DefaultDispatcherProvider.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispatcherProvider.cs delete mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispetcherProvider.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index bc799ae05..90fced504 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 01ebc50c0..f93b47d89 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs index 5c513af9e..f0b33ed06 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs @@ -25,7 +25,7 @@ using Tango.SharedUI.Controls; namespace Tango.MachineStudio.ColorLab.ViewModels { - public class MainViewVM : StudioViewModel + public class MainViewVM : StudioViewModel { private ObservablesContext _dbContext; private INotificationProvider _notification; @@ -278,8 +278,6 @@ namespace Tango.MachineStudio.ColorLab.ViewModels public override void OnApplicationReady() { - base.OnApplicationReady(); - Task.Factory.StartNew(() => { _dbContext = ObservablesContext.CreateDefault(); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/MainViewVM.cs index 2f3419d67..9503e4c38 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/MainViewVM.cs @@ -15,7 +15,7 @@ using Tango.SharedUI; namespace Tango.MachineStudio.DB.ViewModels { - public class MainViewVM : StudioViewModel + public class MainViewVM : StudioViewModel { private bool _isLoading; public bool IsLoading @@ -53,29 +53,34 @@ namespace Tango.MachineStudio.DB.ViewModels NotLoaded = false; } - public override void OnModuleRequest(params object[] args) + public override void OnApplicationReady() { - if (args != null && args.Length > 0 && args[0] is IObservableEntity) - { - var arg = args[0]; + + } - String vmName = arg.GetType().Name + "sViewVM"; + //public override void OnModuleRequest(params object[] args) + //{ + // if (args != null && args.Length > 0 && args[0] is IObservableEntity) + // { + // var arg = args[0]; - Type vmType = Assembly.GetAssembly(typeof(MainViewVM)).GetTypes().SingleOrDefault(x => x.Name == vmName); + // String vmName = arg.GetType().Name + "sViewVM"; - if (vmType == null) - { - vmName = arg.GetType().BaseType.Name + "sViewVM"; - vmType = Assembly.GetAssembly(typeof(MainViewVM)).GetTypes().SingleOrDefault(x => x.Name == vmName); - } + // Type vmType = Assembly.GetAssembly(typeof(MainViewVM)).GetTypes().SingleOrDefault(x => x.Name == vmName); - if (vmType != null) - { - var vm = TangoIOC.Default.GetInstance(vmType); - vmType.GetProperty("SelectedEntity").SetValue(vm, arg); - vmType.GetMethod("OnEdit", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(vm, new object[] { }); - } - } - } + // if (vmType == null) + // { + // vmName = arg.GetType().BaseType.Name + "sViewVM"; + // vmType = Assembly.GetAssembly(typeof(MainViewVM)).GetTypes().SingleOrDefault(x => x.Name == vmName); + // } + + // if (vmType != null) + // { + // var vm = TangoIOC.Default.GetInstance(vmType); + // vmType.GetProperty("SelectedEntity").SetValue(vm, arg); + // vmType.GetMethod("OnEdit", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(vm, new object[] { }); + // } + // } + //} } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Navigation/DeveloperNavigationManager.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Navigation/DeveloperNavigationManager.cs index ff8b0320d..b1039c2c5 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Navigation/DeveloperNavigationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Navigation/DeveloperNavigationManager.cs @@ -16,7 +16,7 @@ namespace Tango.MachineStudio.Developer.Navigation public void NavigateTo(DeveloperNavigationView view) { LogManager.Log(String.Format("Navigating to view {0}...", view.ToString())); - MainView.Instance.TransitionControl.NavigateTo(view.ToString()); + MainView.Instance.NavigationControl.NavigateTo(view.ToString()); } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index 9eaa56870..6178ae30a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -52,7 +52,7 @@ namespace Tango.MachineStudio.Developer.ViewModels /// /// [TangoCreateWhenRegistered] - public class MainViewVM : StudioViewModel + public class MainViewVM : StudioViewModel { private static object _syncLock = new object(); private const string EMB_FORMATS_EXPORT = "Baby Lock (PES)|*.pes|Tajima (DST)|*.dst|EXP|*.exp|PCS|*.pcs|HUS|*.hus|KSM|*.ksm"; @@ -699,7 +699,7 @@ namespace Tango.MachineStudio.Developer.ViewModels PushProcessParametersCommand = new RelayCommand(PushProcessParameters, () => SelectedRML != null && CanWork && SelectedRML.ProcessParametersTablesGroups.Count > 0 && SelectedProcessParametersTable != null && MachineOperator != null); ImportEmbroideryFileCommand = new RelayCommand(ImportEmbroideryFile, () => SelectedMachine != null && CanWork); DisplayJobEmbroideryFileCommand = new RelayCommand(DisplayJobEmbroideryFile, () => CanWork); - ReloadMachinesCommand = new RelayCommand(() => LoadMachine(), () => CanWork); + ReloadMachinesCommand = new RelayCommand(() => LoadMachine(), () => CanWork && SelectedMachine != null); ApplicationManager.ConnectedMachineChanged += ApplicationManager_ConnectedMachineChanged; @@ -725,8 +725,6 @@ namespace Tango.MachineStudio.Developer.ViewModels public override void OnApplicationReady() { - base.OnApplicationReady(); - _settings = SettingsManager.Default.GetOrCreate(); SelectedJobs = new ObservableCollection(); @@ -1348,7 +1346,6 @@ namespace Tango.MachineStudio.Developer.ViewModels private void EditRML() { LogManager.Log(String.Format("Requesting DB module for RML {0} editing...", SelectedRML.Name)); - ApplicationManager.RequestModule("Data Base", SelectedRML); } /// @@ -1713,7 +1710,6 @@ namespace Tango.MachineStudio.Developer.ViewModels private void EditMachine() { LogManager.Log(String.Format("Requesting machine designer module for machine {0} editing...", SelectedMachine.SerialNumber)); - ApplicationManager.RequestModule("Machine Designer", SelectedMachine); } #endregion diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml index a7348d869..68cd65ad4 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml @@ -575,7 +575,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs index 9197ad989..8dcd92691 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs @@ -15,7 +15,7 @@ using Tango.MachineStudio.Common; namespace Tango.MachineStudio.HardwareDesigner.ViewModels { - public class MainViewVM : StudioViewModel + public class MainViewVM : StudioViewModel { private INotificationProvider _notification; private bool _isNew; @@ -81,8 +81,6 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels public override void OnApplicationReady() { - base.OnApplicationReady(); - Task.Factory.StartNew(() => { RefreshVersions(); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs index d2838b758..bac916771 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs @@ -21,7 +21,7 @@ using System.Data.Entity; namespace Tango.MachineStudio.MachineDesigner.ViewModels { - public class MainViewVM : StudioViewModel + public class MainViewVM : StudioViewModel { private INotificationProvider _notification; private ObservablesContext _db; @@ -206,8 +206,6 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels public async override void OnApplicationReady() { - base.OnApplicationReady(); - await InitCollections(); } @@ -760,14 +758,5 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels } #endregion - - #region IStudioModuleVM - - public override void OnModuleRequest(params object[] args) - { - //SelectedMachine = Adapter.Machines.SingleOrDefault(x => x.Guid == (args[0] as Machine).Guid); - } - - #endregion } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Stubs/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Stubs/ViewModels/MainViewVM.cs index fb05a0b94..ca598881a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Stubs/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Stubs/ViewModels/MainViewVM.cs @@ -27,7 +27,7 @@ namespace Tango.MachineStudio.Stubs.ViewModels /// Represents the script execution module main view model. /// /// - public class MainViewVM : StudioViewModel + public class MainViewVM : StudioViewModel { private INotificationProvider _notification; @@ -75,6 +75,11 @@ namespace Tango.MachineStudio.Stubs.ViewModels StubsViewVM.SaveSettings(); } + public override void OnApplicationReady() + { + + } + #endregion } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/BlowerElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/BlowerElementEditor.xaml index 675571657..e06d1f559 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/BlowerElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/BlowerElementEditor.xaml @@ -27,7 +27,7 @@ - + @@ -38,7 +38,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/BreakSensorElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/BreakSensorElementEditor.xaml index 18c992193..78834aca7 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/BreakSensorElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/BreakSensorElementEditor.xaml @@ -27,7 +27,7 @@ - + @@ -38,7 +38,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ControllerElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ControllerElementEditor.xaml index 346c0067b..de604625d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ControllerElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ControllerElementEditor.xaml @@ -28,7 +28,7 @@ - + @@ -99,7 +99,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DancerElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DancerElementEditor.xaml index 3c6ee7d49..2960a8807 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DancerElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DancerElementEditor.xaml @@ -27,7 +27,7 @@ - + @@ -38,7 +38,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DigitalInElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DigitalInElementEditor.xaml index 8c72798d5..5c1cfc3ad 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DigitalInElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DigitalInElementEditor.xaml @@ -27,7 +27,7 @@ - + @@ -51,7 +51,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DigitalOutElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DigitalOutElementEditor.xaml index 5fd92c336..862fa0597 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DigitalOutElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DigitalOutElementEditor.xaml @@ -28,7 +28,7 @@ - + @@ -62,7 +62,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DispenserElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DispenserElementEditor.xaml index 0a088df69..1fa1c6c48 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DispenserElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DispenserElementEditor.xaml @@ -45,7 +45,7 @@ - + @@ -254,7 +254,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/JobRunnerElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/JobRunnerElementEditor.xaml index c481f1e1b..76a6a16a7 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/JobRunnerElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/JobRunnerElementEditor.xaml @@ -42,7 +42,7 @@ - + @@ -239,7 +239,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MeterElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MeterElementEditor.xaml index 98ace7816..2631f3a06 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MeterElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MeterElementEditor.xaml @@ -28,7 +28,7 @@ - + @@ -47,7 +47,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MonitorElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MonitorElementEditor.xaml index 8f66adeeb..a39fa975c 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MonitorElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MonitorElementEditor.xaml @@ -27,7 +27,7 @@ - + @@ -55,7 +55,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorElementEditor.xaml index 48186fd56..80bfe8f96 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorElementEditor.xaml @@ -47,7 +47,7 @@ - + @@ -243,7 +243,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml index 64ed5bb43..3adee13d6 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml @@ -47,7 +47,7 @@ - + @@ -229,7 +229,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MultiGraphElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MultiGraphElementEditor.xaml index 9bc22d0f6..dcba1e77b 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MultiGraphElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MultiGraphElementEditor.xaml @@ -43,7 +43,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/PidElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/PidElementEditor.xaml index 6d4f49ace..197640b14 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/PidElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/PidElementEditor.xaml @@ -27,7 +27,7 @@ - + @@ -38,7 +38,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ProcessParametersElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ProcessParametersElementEditor.xaml index 716ac0a2d..f057521e0 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ProcessParametersElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ProcessParametersElementEditor.xaml @@ -31,7 +31,7 @@ - + @@ -73,7 +73,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/SingleGraphElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/SingleGraphElementEditor.xaml index 16f94b251..a9eb9e9f4 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/SingleGraphElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/SingleGraphElementEditor.xaml @@ -43,7 +43,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/SpeedSensorElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/SpeedSensorElementEditor.xaml index b9dce9112..8696a3c53 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/SpeedSensorElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/SpeedSensorElementEditor.xaml @@ -27,7 +27,7 @@ - + @@ -38,7 +38,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ThreadMotionElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ThreadMotionElementEditor.xaml index 3bac433ad..6e2315dc8 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ThreadMotionElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ThreadMotionElementEditor.xaml @@ -47,7 +47,7 @@ - + @@ -158,7 +158,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/WinderElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/WinderElementEditor.xaml index f81597574..2b6ee303d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/WinderElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/WinderElementEditor.xaml @@ -27,7 +27,7 @@ - + @@ -38,7 +38,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs index 8b331b5f5..f96960883 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs @@ -41,7 +41,7 @@ namespace Tango.MachineStudio.Technician.ViewModels /// /// /// - public class MachineTechViewVM : StudioViewModel + public class MachineTechViewVM : StudioViewModel { private List _diagnoticsMonitorsDataProperties; private IDiagnosticsFrameProvider _diagnosticsFrameProvider; @@ -1572,6 +1572,11 @@ namespace Tango.MachineStudio.Technician.ViewModels }); } + public override void OnApplicationReady() + { + + } + #endregion #region Hardware Configuration diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml.cs index b60f4d725..977974f8a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml.cs @@ -59,7 +59,7 @@ namespace Tango.MachineStudio.Technician.Views private void OnActionModeClicked(object sender, MouseButtonEventArgs e) { - editor.DeselectElements(); + //editor.DeselectElements(); } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs index 56888e631..a5ef4f095 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs @@ -17,7 +17,7 @@ using System.Data.Entity; namespace Tango.MachineStudio.UsersAndRoles.ViewModels { - public class MainViewVM : StudioViewModel + public class MainViewVM : StudioViewModel { private ObservablesContext _organizationsContext; private ObservablesContext _manageContext; @@ -146,7 +146,6 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels public override void OnApplicationReady() { - base.OnApplicationReady(); LoadOrganizations(); } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/IStudioViewModel.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/IStudioViewModel.cs index 76cc0433c..be0906fc4 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/IStudioViewModel.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/IStudioViewModel.cs @@ -3,24 +3,15 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using static Tango.SharedUI.Controls.NavigationControl; namespace Tango.MachineStudio.Common { /// /// Represents a Machine Studio view model. /// - public interface IStudioViewModel + public interface IStudioViewModel : INavigationViewModel { - /// - /// Called when the user has navigated in to the module. - /// - void OnNavigatedTo(); - - /// - /// Called when the user has navigated out of the module. - /// - void OnNavigatedFrom(); - /// /// Called when application is shutting down. /// @@ -33,12 +24,6 @@ namespace Tango.MachineStudio.Common /// Task OnShutdownRequest(); - /// - /// Called when another module has wants to navigate to this module with some arguments. - /// - /// The arguments. - void OnModuleRequest(params object[] args); - /// /// Called when the application has been started /// diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationBlocker.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationBlocker.cs new file mode 100644 index 000000000..abd6db172 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationBlocker.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Common.Navigation +{ + /// + /// Represents an object which can abort the navigation from it. + /// + public interface INavigationBlocker + { + /// + /// Called before the navigation system navigates from this object. + /// Return false to abort the navigation. + /// + /// + Task OnNavigateOutRequest(); + + /// + /// Called before the navigation system navigates back from this object. + /// Return false to abort the navigation. + /// + /// + Task OnNavigateBackRequest(); + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationManager.cs index 4d1cbea8c..e20940c8d 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core.Commands; namespace Tango.MachineStudio.Common.Navigation { @@ -12,9 +13,102 @@ namespace Tango.MachineStudio.Common.Navigation public interface INavigationManager { /// - /// Navigates to the specified view. + /// Gets the current module. + /// + IStudioModule CurrentModule { get; } + + /// + /// Gets the current view model. + /// + StudioViewModel CurrentVM { get; } + + /// + /// Gets a value indicating whether the navigation system is able to navigate to the previous view. + /// + bool CanNavigateBack { get; } + + /// + /// Navigates to the previous view if is true. + /// + Task NavigateBack(); + + /// + /// Navigates to the previous view.. + /// + RelayCommand NavigateBackCommand { get; } + + /// + /// Navigates to the specified full path in command parameter. + /// + RelayCommand NavigateToCommand { get; } + + /// + /// Navigates to the specified PPC view. /// /// The view. - void NavigateTo(NavigationView view); + Task NavigateTo(NavigationView view, bool pushToHistory = true); + + /// + /// Navigates to the specified PPC view with the specified receive object. + /// + /// The view. + Task NavigateWithObject(NavigationView view, TPass obj, bool pushToHistory = true); + + /// + /// Navigates to the specified module. + /// + /// + Task NavigateTo(bool pushToHistory = true) where T : IStudioModule; + + /// + /// Navigates to the specified module using the view path (e.g MainView.JobsView). + /// + /// + /// The view path. + Task NavigateTo(String viewPath, bool pushToHistory = true) where T : IStudioModule; + + /// + /// Navigates to the specified module using the view path (e.g MainView,JobsView). + /// This method makes it easy to do stuff like NavigateTo(nameof(MainView),nameof(JobsView)); + /// + /// + /// The view path. + Task NavigateTo(bool pushToHistory = true, params String[] viewPath) where T : IStudioModule; + + /// + /// Navigates to the specified module and view by full path (e.g Jobs.JobsView). + /// + /// The full path. + Task NavigateTo(String fullPath, bool pushToHistory = true); + + /// + /// Navigates to the specified module and view with the specified object and expecting a return parameter. + /// The view must be of type INavigationResultProvider. + /// + /// The full path. + Task NavigateForResult(TPass obj, bool pushToHistory = true) + where TModule : IStudioModule; + + /// + /// Navigates to the specified module and view with the specified object. + /// + /// The type of the module. + /// The type of the view. + /// The type of the pass. + /// The object. + /// if set to true [push to history]. + /// + Task NavigateWithObject(TPass obj, bool pushToHistory = true) + where TModule : IStudioModule; + + /// + /// Clears the navigation back history. + /// + void ClearHistory(); + + /// + /// Clears the navigation back history except the specified view type. + /// + void ClearHistoryExcept(); } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationObjectReceiver.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationObjectReceiver.cs new file mode 100644 index 000000000..5072881d2 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationObjectReceiver.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Common.Navigation +{ + /// + /// Represents an object which supports receiving an object as part of the navigation to it. + /// + /// + public interface INavigationObjectReceiver + { + /// + /// Called when navigation system is going to navigate to this instance with the specified object. + /// + /// The object. + void OnNavigatedToWithObject(T obj); + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationResultProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationResultProvider.cs new file mode 100644 index 000000000..dee037432 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationResultProvider.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Common.Navigation +{ + /// + /// Represents a object which provides a result the navigation system navigates away from it. + /// + /// The type of the result. + /// The type of the pass. + public interface INavigationResultProvider + { + /// + /// Called when the navigation system requests a result when it is navigating away from this instance. + /// + /// + TResult GetNavigationResult(); + + /// + /// Called when navigation system is going to navigate to this instance with the specified object. + /// + /// The object. + void OnNavigationObjectReceived(TPass obj); + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs index 441a4ca93..96de3eea0 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs @@ -44,13 +44,6 @@ namespace Tango.MachineStudio.Common.StudioApplication /// bool IsMachineConnectedViaTCP { get; } - /// - /// Loads the specified module if permitted. - /// - /// Name of the module. - /// The arguments. - void RequestModule(String moduleName, params object[] args); - /// /// Gets the machine studio application version. /// diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioViewModel.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioViewModel.cs index 08ddbc073..63ff2119a 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioViewModel.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioViewModel.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core.DI; using Tango.SharedUI; namespace Tango.MachineStudio.Common @@ -10,128 +11,42 @@ namespace Tango.MachineStudio.Common /// /// Represents a Machine Studio view model /// - /// The type of the module. /// /// - public abstract class StudioViewModelInternal : ViewModel, IStudioViewModel + public abstract class StudioViewModel : ViewModel, IStudioViewModel { - public bool IsVisible { get; private set; } - - /// - /// Gets or sets a value indicating whether this view model studio module is currently loaded. - /// - public bool IsModuleLoaded { get; private set; } - - /// - /// Initializes a new instance of the class. - /// - public StudioViewModelInternal() : base() - { - - } - - /// - /// Called when another module has wants to navigate to this module with some arguments. - /// - /// The arguments. - public virtual void OnModuleRequest(params object[] args) - { - - } - + private bool _isVisible; /// - /// Called when the user has navigated out of the module. + /// Gets or sets a value indicating whether this view model view's is visible. /// - public virtual void OnNavigatedFrom() + public bool IsVisible { - IsVisible = false; - IsModuleLoaded = false; + get { return _isVisible; } + set { _isVisible = value; RaisePropertyChangedAuto(); } } /// - /// Called when the user has navigated in to the module. - /// - public virtual void OnNavigatedTo() - { - IsVisible = true; - IsModuleLoaded = true; - } - - /// - /// Called before the application is shutting down. - /// Return false to cancel the shutdown in case an important process is in progress. - /// - /// - public virtual Task OnShutdownRequest() - { - return Task.FromResult(true); - } - - /// - /// Called when application is shutting down. - /// - public virtual void OnShuttingDown() - { - - } - - /// - /// Called when the application has been started - /// - public virtual void OnApplicationStarted() - { - - } - - /// - /// Called when the application is ready and all modules are loaded. - /// - public virtual void OnApplicationReady() - { - - } - } - - /// - /// Represents a Machine Studio view model - /// - /// The type of the module. - /// - /// - public abstract class StudioViewModel : ViewModel, IStudioViewModel where Module : IStudioModule - { - public bool IsVisible { get; private set; } - - /// - /// Gets or sets a value indicating whether this view model studio module is currently loaded. - /// - public bool IsModuleLoaded { get; private set; } - - /// - /// Called when another module has wants to navigate to this module with some arguments. + /// Initializes a new instance of the class. /// - /// The arguments. - public virtual void OnModuleRequest(params object[] args) + public StudioViewModel() : base() { } /// - /// Called when the user has navigated out of the module. + /// Called when the user has navigated out of this view model. /// public virtual void OnNavigatedFrom() { IsVisible = false; - IsModuleLoaded = false; } /// - /// Called when the user has navigated in to the module. + /// Called when the user has navigated in to this view model. /// public virtual void OnNavigatedTo() { IsVisible = true; - IsModuleLoaded = true; } /// @@ -163,79 +78,38 @@ namespace Tango.MachineStudio.Common /// /// Called when the application is ready and all modules are loaded. /// - public virtual void OnApplicationReady() - { - - } + public abstract void OnApplicationReady(); } /// - /// Represents a Machine Studio view model. + /// Represents a Machine Studio view model with a support for a view contract. /// - /// The type of the module. - /// + /// /// - /// - public abstract class StudioViewModel : ViewModel, IStudioViewModel where Module : IStudioModule where T : IView + public abstract class StudioViewModel : StudioViewModel where TView : IView { /// - /// Called when the application has been started - /// - public virtual void OnApplicationStarted() - { - - } - - /// - /// Called when the application is ready and all modules are loaded. - /// - public virtual void OnApplicationReady() - { - - } - - /// - /// Called when another module has wants to navigate to this module with some arguments. + /// Gets the view model's view. /// - /// The arguments. - public virtual void OnModuleRequest(params object[] args) - { - - } + public TView View { get; private set; } /// - /// Called when the user has navigated out of the module. + /// Initializes a new instance of the class. /// - public virtual void OnNavigatedFrom() + public StudioViewModel() : base() { - + TangoIOC.Default.GetInstanceWhenAvailable((view) => + { + View = view; + OnViewAttached(view); + }); } /// - /// Called when the user has navigated in to the module. + /// Called when the view has been attached /// - public virtual void OnNavigatedTo() - { - - } - - /// - /// Called before the application is shutting down. - /// Return false to cancel the shutdown in case an important process is in progress. - /// - /// - public virtual Task OnShutdownRequest() - { - return Task.FromResult(true); - } - - /// - /// Called when application is shutting down. - /// - public virtual void OnShuttingDown() - { - - } + /// The view. + protected abstract void OnViewAttached(TView view); } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj index 8b251074d..09678b515 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj @@ -106,6 +106,9 @@ + + + @@ -115,6 +118,7 @@ + @@ -292,13 +296,11 @@ True - - - + - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Threading/IDispatcherProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Threading/IDispatcherProvider.cs new file mode 100644 index 000000000..1c960ed3a --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Threading/IDispatcherProvider.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Common.Threading +{ + /// + /// Represents a mechanism for invoking actions on the main application thread. + /// + public interface IDispatcherProvider + { + /// + /// Invokes the specified action asynchronously. + /// + /// The action. + void Invoke(Action action); + + /// + /// Invokes the specified action synchronously. + /// + /// The action. + void InvokeSync(Action action); + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/MainWindow.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/MainWindow.xaml index b8a6cd1c0..44b2ed401 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/MainWindow.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/MainWindow.xaml @@ -17,7 +17,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Navigation/DefaultNavigationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Navigation/DefaultNavigationManager.cs index 092b958cc..899ba846e 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Navigation/DefaultNavigationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Navigation/DefaultNavigationManager.cs @@ -3,8 +3,13 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core; +using Tango.Core.Commands; using Tango.MachineStudio.Common; +using Tango.MachineStudio.Common.Modules; using Tango.MachineStudio.Common.Navigation; +using Tango.MachineStudio.Common.Threading; +using Tango.SharedUI.Controls; namespace Tango.MachineStudio.UI.Navigation { @@ -12,18 +17,372 @@ namespace Tango.MachineStudio.UI.Navigation /// Represents the Machine Studio default Navigation Manager. /// /// - public class DefaultNavigationManager : INavigationManager + public class DefaultNavigationManager : ExtendedObject, INavigationManager { + private event Action NavigationCycleCompleted; + + private IDispatcherProvider _dispatcherProvider; + private IStudioModuleLoader _moduleLoader; + private Object _currentVM; + private String _lastFullPath; + private bool _preventHistory; + private bool _navigating_back; + + private Stack _navigationHistory; + + /// + /// Gets the current view model. + /// + public StudioViewModel CurrentVM + { + get { return _currentVM as StudioViewModel; } + } + + private IStudioModule _currentModule; + /// + /// Gets or sets the current module. + /// + public IStudioModule CurrentModule + { + get { return _currentModule; } + private set { _currentModule = value; RaisePropertyChangedAuto(); } + } + + /// + /// Navigates to the previous view. + /// + public RelayCommand NavigateBackCommand { get; private set; } + + /// + /// Navigates to the specified full path in command parameter. + /// + public RelayCommand NavigateToCommand { get; private set; } + + /// + /// Initializes a new instance of the class. + /// + /// The module loader. + public DefaultNavigationManager(IStudioModuleLoader moduleLoader, IDispatcherProvider dispatcherProvider) + { + _navigationHistory = new Stack(); + _moduleLoader = moduleLoader; + + NavigateToCommand = new RelayCommand(async (x) => await NavigateTo(x)); + NavigateBackCommand = new RelayCommand(async () => await NavigateBack()); + + _dispatcherProvider = dispatcherProvider; + } + /// - /// Navigates to the specified view. + /// Navigates to the specified PPC view. /// /// The view. - public void NavigateTo(NavigationView view) + public Task NavigateTo(NavigationView view, bool pushToHistory = true) { - MainWindow.Instance.Dispatcher.Invoke(() => + LogManager.Log($"Navigating to: {view.ToString()}..."); + + _dispatcherProvider.Invoke(() => { - MainWindow.Instance.TransitionControl.NavigateTo(view.ToString()); + MainWindow.Instance.NavigationControl.NavigateTo(view.ToString()); }); + + return Task.FromResult(true); + } + + /// + /// Navigates to the specified PPC view with the specified receive object. + /// + /// The view. + /// + /// + /// + public Task NavigateWithObject(NavigationView view, TPass obj, bool pushToHistory = true) + { + LogManager.Log($"Navigating to: {view.ToString()}, with object {typeof(TPass).Name}..."); + MainWindow.Instance.NavigationControl.NavigateTo(view.ToString()); + INavigationObjectReceiver receiver = MainWindow.Instance.NavigationControl.Elements.FirstOrDefault(x => (x.GetType().Name == view.ToString() || NavigationControl.GetNavigationName(x) == view.ToString()) && x.DataContext is INavigationObjectReceiver).DataContext as INavigationObjectReceiver; + + if (receiver != null) + { + receiver.OnNavigatedToWithObject(obj); + } + + return Task.FromResult(true); + } + + /// + /// Navigates to the specified module. + /// + /// + public Task NavigateTo(bool pushToHistory = true) where T : IStudioModule + { + return NavigateTo(typeof(T)); + } + + /// + /// Navigates to the specified module using the view path (e.g MainView.JobsView). + /// + /// + /// The view path. + public Task NavigateTo(string viewPath, bool pushToHistory = true) where T : IStudioModule + { + return NavigateTo(pushToHistory, viewPath.Split('.')); + } + + /// + /// Navigates to the specified module using the view path (e.g MainView,JobsView). + /// This method makes it easy to do stuff like NavigateTo(nameof(MainView),nameof(JobsView)); + /// + /// + /// The view path. + public Task NavigateTo(bool pushToHistory = true, params String[] viewPath) where T : IStudioModule + { + return NavigateTo(typeof(T), pushToHistory, viewPath); + } + + /// + /// Navigates to the specified module and view by full path (e.g Jobs.JobsView). + /// + /// The full path. + public async Task NavigateTo(String fullPath, bool pushToHistory = true) + { + String[] path = fullPath.Split('.'); + var module = _moduleLoader.UserModules.SingleOrDefault(x => x.GetType().Name == path[0] || x.Name == path[0]); + + if (path.Length == 1 && path[0] == CurrentModule.Name) return true; + + LogManager.Log($"Navigating to: {fullPath}..."); + + var fromVM = _currentVM; + + if (_currentVM != null && _currentVM is INavigationBlocker) + { + if (_navigating_back) + { + if (!await (_currentVM as INavigationBlocker).OnNavigateBackRequest()) + { + return false; + } + } + else + { + if (!await (_currentVM as INavigationBlocker).OnNavigateOutRequest()) + { + return false; + } + } + } + + if (pushToHistory && _lastFullPath != null && !_preventHistory) + { + _navigationHistory.Push(_lastFullPath); + RaisePropertyChanged(nameof(CanNavigateBack)); + } + + _lastFullPath = fullPath; + + MainWindow.Instance.NavigationControl.NavigateTo(NavigationView.MainView.ToString()); + var navigationControl = MachineStudio.UI.Views.MainView.Instance.NavigationControl; + CurrentModule = module; + var moduleView = navigationControl.NavigateTo(module.Name); + + _currentVM = moduleView.DataContext; + + if (path.Length > 1) + { + var moduleNavigation = moduleView.FindChildOffline(); + + moduleNavigation.RegisterForLoadedOrNow(async (x, e) => + { + foreach (var view in path.Skip(1)) + { + await Task.Delay(100); + var v = moduleNavigation.NavigateTo(view); + + if (v != null) + { + _currentVM = v.DataContext; + + if (view != path.Last()) + { + moduleNavigation = v.FindChildOffline(); + } + } + else + { + throw LogManager.Log(new ArgumentNullException("Could not navigate to " + fullPath)); + } + } + + NavigationCycleCompleted?.Invoke(fromVM, _currentVM); + }); + } + + return true; + } + + /// + /// Navigates for result. + /// + /// The type of the module. + /// The type of the view. + /// The type of the result. + /// The type of the object. + /// The object. + /// if set to true [push to history]. + /// + public Task NavigateForResult(TObject obj, bool pushToHistory = true) + where TModule : IStudioModule + { + TaskCompletionSource source = new TaskCompletionSource(); + + var fromVM = _currentVM; + Object toVM = null; + + + Action handler = null; + + handler = (from, to) => + { + if (toVM == null) + { + toVM = to; + if (toVM is INavigationResultProvider) + { + (toVM as INavigationResultProvider).OnNavigationObjectReceived(obj); + } + } + else + { + if (to == fromVM && from == toVM) + { + if (from is INavigationResultProvider) + { + source.SetResult((from as INavigationResultProvider).GetNavigationResult()); + } + } + + NavigationCycleCompleted -= handler; + } + }; + + NavigationCycleCompleted += handler; + + NavigateTo(typeof(TView).Name, pushToHistory); + + return source.Task; + } + + /// + /// Navigates to the specified module and view with the specified object. + /// + /// The type of the module. + /// The type of the view. + /// The type of the pass. + /// The object. + /// if set to true [push to history]. + /// + public Task NavigateWithObject(TPass obj, bool pushToHistory = true) where TModule : IStudioModule + { + TaskCompletionSource source = new TaskCompletionSource(); + + Action handler = null; + + handler = (from, to) => + { + if (to is INavigationObjectReceiver) + { + (to as INavigationObjectReceiver).OnNavigatedToWithObject(obj); + } + + NavigationCycleCompleted -= handler; + }; + + NavigationCycleCompleted += handler; + + NavigateTo(typeof(TView).Name, pushToHistory); + + return source.Task; + } + + private Task NavigateTo(Type moduleType, bool pushToHistory = true, params String[] viewPath) + { + if (viewPath != null && viewPath.Length > 0) + { + return NavigateTo(moduleType.Name + "." + String.Join(".", viewPath), pushToHistory); + } + else + { + return NavigateTo(moduleType.Name, pushToHistory); + } + } + + /// + /// Gets a value indicating whether the navigation system is able to navigate to the previous view. + /// + public bool CanNavigateBack + { + get { return _navigationHistory.Count > 0; } + } + + /// + /// Navigates to the previous view if is true. + /// + public async Task NavigateBack() + { + LogManager.Log("Navigating back..."); + + _navigating_back = true; + + String first = _navigationHistory.Pop(); + _preventHistory = true; + + + if (await NavigateTo(first)) + { + RaisePropertyChanged(nameof(CanNavigateBack)); + _preventHistory = false; + _navigating_back = false; + return true; + } + else + { + _navigationHistory.Push(first); + _preventHistory = false; + _navigating_back = false; + RaisePropertyChanged(nameof(CanNavigateBack)); + return false; + } + } + + /// + /// Clears the navigation back history. + /// + public void ClearHistory() + { + LogManager.Log("Navigation history cleared."); + _navigationHistory.Clear(); + RaisePropertyChanged(nameof(CanNavigateBack)); + } + + /// + /// Clears the navigation back history except the specified view type. + /// + /// + public void ClearHistoryExcept() + { + LogManager.Log($"Navigation history cleared except for {typeof(T).Name}."); + + var history_list = _navigationHistory.ToList(); + history_list = history_list.Where(x => x.Contains(typeof(T).Name)).Distinct().ToList(); + _navigationHistory.Clear(); + + foreach (var item in history_list) + { + _navigationHistory.Push(item); + } + + RaisePropertyChanged(nameof(CanNavigateBack)); } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs index b8e6e1670..7c7e18276 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs @@ -225,31 +225,6 @@ namespace Tango.MachineStudio.UI.StudioApplication } } - /// - /// Loads the specified module if permitted. - /// - /// Name of the module. - /// The arguments. - public void RequestModule(string moduleName, params object[] args) - { - IStudioModule module = _moduleLoader.UserModules.SingleOrDefault(x => x.Name == moduleName); - - if (module != null) - { - TangoIOC.Default.GetInstance().StartModule(module); - - //Notify request listeners. - foreach (var vm in TangoIOC.Default.GetAllInstancesByBase()) - { - vm.OnModuleRequest(module, args); - } - } - else - { - throw new InvalidOperationException("The module was not found or you do not have sufficient privileges."); - } - } - /// /// Notify the application manager about an external opened window. /// When application exists. All registered windows will be closed. diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj index 4ded3b300..1bbabb0af 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj @@ -168,6 +168,7 @@ + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Threading/DefaultDispatcherProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Threading/DefaultDispatcherProvider.cs new file mode 100644 index 000000000..611dca6b9 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Threading/DefaultDispatcherProvider.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Threading; +using Tango.MachineStudio.Common.Threading; + +namespace Tango.MachineStudio.UI.Threading +{ + /// + /// Represents the default PPC which will invoke action on the current application dispatcher. + /// + /// + public class DefaultDispatcherProvider : IDispatcherProvider + { + private Dispatcher _dispatcher; + + /// + /// Initializes a new instance of the class. + /// + /// The dispatcher. + public DefaultDispatcherProvider(Dispatcher dispatcher) + { + _dispatcher = dispatcher; + } + + /// + /// Invokes the specified action asynchronously. + /// + /// The action. + public void Invoke(Action action) + { + _dispatcher.BeginInvoke(action); + } + + /// + /// Invokes the specified action synchronously. + /// + /// The action. + public void InvokeSync(Action action) + { + _dispatcher.Invoke(action); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs index 2c816eb6c..10aa86ad1 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs @@ -1,4 +1,5 @@ using System; +using System.Windows; using Tango.Core.DI; using Tango.Integration.ExternalBridge; using Tango.Logging; @@ -11,6 +12,7 @@ using Tango.MachineStudio.Common.Navigation; using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.Common.Speech; using Tango.MachineStudio.Common.StudioApplication; +using Tango.MachineStudio.Common.Threading; using Tango.MachineStudio.Common.Video; using Tango.MachineStudio.UI.Authentication; using Tango.MachineStudio.UI.Console; @@ -21,6 +23,7 @@ using Tango.MachineStudio.UI.Notifications; using Tango.MachineStudio.UI.StudioApplication; using Tango.MachineStudio.UI.SupervisingController; using Tango.MachineStudio.UI.TFS; +using Tango.MachineStudio.UI.Threading; using Tango.MachineStudio.UI.ViewModels; using Tango.MachineStudio.UI.Views; using Tango.Settings; @@ -64,7 +67,10 @@ namespace Tango.MachineStudio.UI TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); + TangoIOC.Default.Unregister(); + + TangoIOC.Default.Register(new DefaultDispatcherProvider(Application.Current.Dispatcher)); TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs index eacc8a4cb..215f7afb5 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs @@ -28,7 +28,7 @@ namespace Tango.MachineStudio.UI.ViewModels /// Represents the Machine Studio loading view, view model. /// /// - public class LoadingViewVM : StudioViewModelInternal + public class LoadingViewVM : StudioViewModel { private INotificationProvider _notificationProvider; private TeamFoundationServiceExtendedClient _tfs; @@ -172,5 +172,10 @@ namespace Tango.MachineStudio.UI.ViewModels } }); } + + public override void OnApplicationReady() + { + + } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index 23dd4ecd7..36ce62897 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -629,20 +629,19 @@ namespace Tango.MachineStudio.UI.ViewModels { LogManager.Log(String.Format("Starting module '{0}'...", module.Name)); - if (!(MainView.Self as MainView).TransitionControl.Elements.ToList().Exists(x => x.GetType() == module.MainViewType)) + if (!(MainView.Self as MainView).NavigationControl.Elements.ToList().Exists(x => x.GetType() == module.MainViewType)) { LogManager.Log("Module was not initialized. Initializing..."); FrameworkElement view = Activator.CreateInstance(module.MainViewType) as FrameworkElement; NavigationControl.SetNavigationName(view, module.Name); - (MainView.Self as MainView).TransitionControl.Elements.Add(view); + (MainView.Self as MainView).NavigationControl.Elements.Add(view); } } foreach (var m in StudioModuleLoader.AllModules.Where(x => x != module && !x.InNewWindow)) { m.IsLoaded = false; - TangoIOC.Default.GetModuleViewModels(m).ToList().ForEach(x => x.OnNavigatedFrom()); } if (module != null) @@ -652,15 +651,13 @@ namespace Tango.MachineStudio.UI.ViewModels IsModuleLoaded = true; LogManager.Log(String.Format("Navigating to module '{0}'...", module.Name)); - (MainView.Self as MainView).TransitionControl.NavigateTo(module.Name); - - TangoIOC.Default.GetModuleViewModels(module).ToList().ForEach(x => x.OnNavigatedTo()); + (MainView.Self as MainView).NavigationControl.NavigateTo(module.Name); } else { IsModuleLoaded = false; LogManager.Log(String.Format("Navigating to Home...")); - (MainView.Self as MainView).TransitionControl.NavigateTo("Home"); + (MainView.Self as MainView).NavigationControl.NavigateTo("Home"); } } @@ -680,16 +677,16 @@ namespace Tango.MachineStudio.UI.ViewModels LogManager.Log(String.Format("Starting module '{0}' in new window...", module.Name)); - if (!(MainView.Self as MainView).TransitionControl.Elements.ToList().Exists(x => x.GetType() == module.MainViewType)) + if (!(MainView.Self as MainView).NavigationControl.Elements.ToList().Exists(x => x.GetType() == module.MainViewType)) { LogManager.Log("Module was not initialized. Initializing..."); FrameworkElement v = Activator.CreateInstance(module.MainViewType) as FrameworkElement; NavigationControl.SetNavigationName(v, module.Name); - (MainView.Self as MainView).TransitionControl.Elements.Add(v); + (MainView.Self as MainView).NavigationControl.Elements.Add(v); } LogManager.Log("Detaching module view..."); - var view = (MainView.Self as MainView).TransitionControl.GetAndDetach(module.Name); + var view = (MainView.Self as MainView).NavigationControl.GetAndDetach(module.Name); ModuleWindowVM vm = new ModuleWindowVM(module); ModuleWindow window = new ModuleWindow(this, vm, view); @@ -700,7 +697,6 @@ namespace Tango.MachineStudio.UI.ViewModels window.grid.Children.Remove(view); module.InNewWindow = false; - TangoIOC.Default.GetModuleViewModels(module).ToList().ForEach(v => v.OnNavigatedFrom()); }; window.Owner = MainWindow.Instance; @@ -708,8 +704,6 @@ namespace Tango.MachineStudio.UI.ViewModels LogManager.Log("Opening new window..."); window.Show(); - TangoIOC.Default.GetModuleViewModels(module).ToList().ForEach(x => x.OnNavigatedTo()); - (_applicationManager as DefaultStudioApplicationManager).RegisterOpenedWindow(window); } catch (Exception ex) diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml index bb5c6458b..9a494f862 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml @@ -397,7 +397,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml.cs index 7ed119abd..ca8d7066c 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml.cs @@ -38,10 +38,14 @@ namespace Tango.MachineStudio.UI.Views { private DefaultStudioModuleLoader _loader; + public static MainView Instance { get; set; } + public MainView() : base() { InitializeComponent(); + Instance = this; + _loader = TangoIOC.Default.GetInstance() as DefaultStudioModuleLoader; _loader.ModulesLoaded += Loader_ModulesLoaded; } @@ -69,11 +73,11 @@ namespace Tango.MachineStudio.UI.Views ThreadsHelper.InvokeUI(() => { - if (!TransitionControl.Elements.ToList().Exists(x => x.GetType() == module.MainViewType)) + if (!NavigationControl.Elements.ToList().Exists(x => x.GetType() == module.MainViewType)) { FrameworkElement view = Activator.CreateInstance(module.MainViewType) as FrameworkElement; NavigationControl.SetNavigationName(view, module.Name); - TransitionControl.Elements.Add(view); + NavigationControl.Elements.Add(view); } _loader.UserModules.Add(module); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj index fdaf37c09..2b2752a24 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj @@ -126,7 +126,7 @@ - + @@ -421,7 +421,7 @@ copy /Y "$(SolutionDir)Referenced Assemblies\vcruntime140d.dll" "$(TargetDir)" - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispatcherProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispatcherProvider.cs new file mode 100644 index 000000000..940c13052 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispatcherProvider.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Threading; +using Tango.PPC.Common.Threading; + +namespace Tango.PPC.UI.Threading +{ + /// + /// Represents the default PPC which will invoke action on the current application dispatcher. + /// + /// + public class DefaultDispatcherProvider : IDispatcherProvider + { + private Dispatcher _dispatcher; + + /// + /// Initializes a new instance of the class. + /// + /// The dispatcher. + public DefaultDispatcherProvider(Dispatcher dispatcher) + { + _dispatcher = dispatcher; + } + + /// + /// Invokes the specified action asynchronously. + /// + /// The action. + public void Invoke(Action action) + { + _dispatcher.BeginInvoke(action); + } + + /// + /// Invokes the specified action synchronously. + /// + /// The action. + public void InvokeSync(Action action) + { + _dispatcher.Invoke(action); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispetcherProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispetcherProvider.cs deleted file mode 100644 index 0051ca329..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispetcherProvider.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Threading; -using Tango.PPC.Common.Threading; - -namespace Tango.PPC.UI.Threading -{ - /// - /// Represents the default PPC which will invoke action on the current application dispatcher. - /// - /// - public class DefaultDispetcherProvider : IDispatcherProvider - { - private Dispatcher _dispatcher; - - /// - /// Initializes a new instance of the class. - /// - /// The dispatcher. - public DefaultDispetcherProvider(Dispatcher dispatcher) - { - _dispatcher = dispatcher; - } - - /// - /// Invokes the specified action asynchronously. - /// - /// The action. - public void Invoke(Action action) - { - _dispatcher.BeginInvoke(action); - } - - /// - /// Invokes the specified action synchronously. - /// - /// The action. - public void InvokeSync(Action action) - { - _dispatcher.Invoke(action); - } - } -} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs index 5c416a289..bec1d2b48 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs @@ -58,7 +58,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); - TangoIOC.Default.Register(new DefaultDispetcherProvider(Application.Current.Dispatcher)); + TangoIOC.Default.Register(new DefaultDispatcherProvider(Application.Current.Dispatcher)); TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); diff --git a/Software/Visual_Studio/Tango.Editors/ElementsEditor.xaml.cs b/Software/Visual_Studio/Tango.Editors/ElementsEditor.xaml.cs index 4d2eabbb8..e32ae6dd3 100644 --- a/Software/Visual_Studio/Tango.Editors/ElementsEditor.xaml.cs +++ b/Software/Visual_Studio/Tango.Editors/ElementsEditor.xaml.cs @@ -723,7 +723,7 @@ namespace Tango.Editors /// The instance containing the event data. private void Element_PreviewMouseDown(object sender, MouseButtonEventArgs e) { - if (e.ChangedButton == MouseButton.Left && !Keyboard.IsKeyDown(Key.LeftShift) && IsEditable) + if (e.ChangedButton == MouseButton.Left && !Keyboard.IsKeyDown(Key.LeftShift)) { SelectedElement = sender as IElementEditor; } -- cgit v1.3.1 From a8718859eea4329ec9ecd3f7155e0001aa610c3d Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 23 Aug 2018 11:07:15 +0300 Subject: Added ObservablesContextAdapter and it's interactions. --- .../ViewModels/MainViewVM.cs | 10 +- .../ViewModels/MainViewVM.cs | 4 +- .../ViewModels/MainViewVM.cs | 6 +- .../TechItems/ProcessParametersItem.cs | 2 +- .../ViewModels/MachineTechViewVM.cs | 7 +- .../ViewModels/MainViewVM.cs | 4 +- .../ViewModels/MainViewVM.cs | 4 +- .../Tango.BL/ObservablesContextAdapter.cs | 188 +++++++++++++++++++++ .../Tango.BL/ObservablesContextExtension.cs | 97 +---------- .../Tango.BL/ObservablesStaticCollections.cs | 4 +- Software/Visual_Studio/Tango.BL/Tango.BL.csproj | 3 +- 11 files changed, 217 insertions(+), 112 deletions(-) create mode 100644 Software/Visual_Studio/Tango.BL/ObservablesContextAdapter.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs index f0b33ed06..1811ea7c7 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs @@ -443,7 +443,7 @@ namespace Tango.MachineStudio.ColorLab.ViewModels { IsFree = false; - _dbContext.GetConfiguration(x => x.Guid == SelectedMachine.ConfigurationGuid); + _dbContext.Adapter.GetConfiguration(x => x.Guid == SelectedMachine.ConfigurationGuid); LiquidVolumes = SelectedMachine.Configuration.NoneEmptyIdsPacks.OrderBy(x => x.PackIndex).Select(x => new LiquidVolumeVM() { @@ -558,10 +558,10 @@ namespace Tango.MachineStudio.ColorLab.ViewModels { using (_notification.PushTaskItem("Loading RML data...")) { - _dbContext.GetConfiguration(x => x.Guid == SelectedMachine.ConfigurationGuid); - _dbContext.GetRmlCCTs(SelectedRML.Guid); - _dbContext.GetRmlCATs(SelectedRML.Guid, SelectedMachine.Guid); - _dbContext.GetRmlLiquidTypes(SelectedRML.Guid); + _dbContext.Adapter.GetConfiguration(x => x.Guid == SelectedMachine.ConfigurationGuid); + _dbContext.Adapter.GetRmlCCTs(SelectedRML.Guid); + _dbContext.Adapter.GetRmlCATs(SelectedRML.Guid, SelectedMachine.Guid); + _dbContext.Adapter.GetRmlLiquidTypes(SelectedRML.Guid); LiquidTypesRmls = SelectedMachine.Configuration.NoneEmptyIdsPacks.OrderBy(x => x.PackIndex).Select(x => x.LiquidType).SelectMany(x => x.LiquidTypesRmls).Where(x => x.Rml.Guid == SelectedRML.Guid).ToList(); //RmlProcessParametersTableGroup = SelectedRML.ProcessParametersTablesGroups.ToList().SingleOrDefault(x => x.Active); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs index 8dcd92691..54b954745 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs @@ -70,7 +70,7 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels CurrentVersion = new HardwareVersion(); SaveCommand = new RelayCommand(Save, () => SelectedVersion != null && IsFree); - NewCommand = new RelayCommand(New,() => IsFree); + NewCommand = new RelayCommand(New, () => IsFree); DeleteCommand = new RelayCommand(Delete, () => !_isNew && SelectedVersion != null && IsFree); CurrentVersion = new HardwareVersion(); @@ -133,7 +133,7 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels _db = ObservablesContext.CreateDefault(); _db.Configuration.LazyLoadingEnabled = false; - CurrentVersion = _db.GetHardwareVersion(x => x.Guid == selectedVersion.Guid); + CurrentVersion = _db.Adapter.GetHardwareVersion(x => x.Guid == selectedVersion.Guid); InvokeUINow(() => diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs index bac916771..183cdb247 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs @@ -271,7 +271,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { InitCollections().Wait(); Machine = _db.Machines.Where(x => x.Guid == SelectedMachine.Guid).Include(x => x.Organization).SingleOrDefault(x => x.Guid == SelectedMachine.Guid); - Configuration = _db.GetConfiguration(x => x.Guid == Machine.ConfigurationGuid); + Configuration = _db.Adapter.GetConfiguration(x => x.Guid == Machine.ConfigurationGuid); SetHistory(); @@ -300,7 +300,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { CanWork = false; - SelectedHistoryConfiguration = _db.GetConfiguration(x => x.Guid == SelectedHistoryConfiguration.Guid); + SelectedHistoryConfiguration = _db.Adapter.GetConfiguration(x => x.Guid == SelectedHistoryConfiguration.Guid); Configuration = SelectedHistoryConfiguration; Machine.Configuration = Configuration; @@ -688,7 +688,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels await Task.Factory.StartNew(() => { var version = _db.MachineVersions.Where(x => x.Guid == Machine.MachineVersion.Guid).Include(x => x.DefaultConfiguration).FirstOrDefault(); - var version_config = _db.GetConfiguration(x => x.Guid == version.DefaultConfiguration.Guid); + var version_config = _db.Adapter.GetConfiguration(x => x.Guid == version.DefaultConfiguration.Guid); Configuration = version_config.Clone(); Machine.Configuration = Configuration; }); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ProcessParametersItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ProcessParametersItem.cs index 1bedcb1ca..4aedf8bc7 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ProcessParametersItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ProcessParametersItem.cs @@ -106,7 +106,7 @@ namespace Tango.MachineStudio.Technician.TechItems { using (ObservablesContext db = ObservablesContext.CreateDefault()) { - var group = db.GetActiveProcessParametersTablesGroup(SelectedResetRML.Guid); + var group = db.Adapter.GetRmlActiveProcessParametersTablesGroup(SelectedResetRML.Guid); if (group != null) { diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs index f96960883..55235b3c2 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs @@ -1682,8 +1682,8 @@ namespace Tango.MachineStudio.Technician.ViewModels { using (ObservablesContext db = ObservablesContext.CreateDefault()) { - config = db.GetConfiguration(x => x.Guid == ApplicationManager.ConnectedMachine.Machine.ConfigurationGuid).Clone(); - hw = db.GetHardwareVersionByMachine(ApplicationManager.ConnectedMachine.Machine.Guid).Clone(); + config = db.Adapter.GetConfiguration(x => x.Guid == ApplicationManager.ConnectedMachine.Machine.ConfigurationGuid).Clone(); + hw = db.Adapter.GetHardwareVersionByMachine(ApplicationManager.ConnectedMachine.Machine.Guid).Clone(); } }); @@ -1773,12 +1773,13 @@ namespace Tango.MachineStudio.Technician.ViewModels if (MachineOperator != null) { ObservablesContext db = ObservablesContext.CreateDefault(); + ObservablesContextAdapter adapter = new ObservablesContextAdapter(db); HardwareVersion hw = null; await Task.Factory.StartNew(() => { - hw = db.GetHardwareVersionByMachine(ApplicationManager.ConnectedMachine.Machine.Guid); + hw = adapter.GetHardwareVersionByMachine(ApplicationManager.ConnectedMachine.Machine.Guid); }); foreach (var motorConfig in hw.HardwareMotors) diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs index a5ef4f095..0def388d3 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs @@ -202,7 +202,7 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels _userContext.Configuration.LazyLoadingEnabled = false; Roles = _userContext.Roles.ToObservableCollection(); - ManagedUser = _userContext.GetUser(SelectedUser.Guid); + ManagedUser = _userContext.Adapter.GetUser(SelectedUser.Guid); ManagedUserRoles = ManagedUser.Roles.ToObservableCollection(); }); @@ -258,7 +258,7 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels _manageContext = ObservablesContext.CreateDefault(); _manageContext.Configuration.LazyLoadingEnabled = false; - ManagedOrganization = _manageContext.GetOrganizationAndUsers(SelectedOrganization.Guid); + ManagedOrganization = _manageContext.Adapter.GetOrganizationAndUsers(SelectedOrganization.Guid); }); _navigation.NavigateTo(UsersAndRolesNavigationView.OrganizationManagementView); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index 36ce62897..f164d7f14 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -550,8 +550,8 @@ namespace Tango.MachineStudio.UI.ViewModels { using (ObservablesContext db = ObservablesContext.CreateDefault()) { - var config = db.GetConfiguration(s => s.Guid == ApplicationManager.ConnectedMachine.Machine.ConfigurationGuid); - var hw = db.GetHardwareVersionByMachine(ApplicationManager.ConnectedMachine.Machine.Guid); + var config = db.Adapter.GetConfiguration(s => s.Guid == ApplicationManager.ConnectedMachine.Machine.ConfigurationGuid); + var hw = db.Adapter.GetHardwareVersionByMachine(ApplicationManager.ConnectedMachine.Machine.Guid); await ApplicationManager.ConnectedMachine.UploadHardwareConfiguration(hw, config); } diff --git a/Software/Visual_Studio/Tango.BL/ObservablesContextAdapter.cs b/Software/Visual_Studio/Tango.BL/ObservablesContextAdapter.cs new file mode 100644 index 000000000..805afaf67 --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/ObservablesContextAdapter.cs @@ -0,0 +1,188 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using System.Data.Entity; +using System.Collections.ObjectModel; + +namespace Tango.BL +{ + /// + /// Represents an adapter for retrieving aggregated entities. + /// + public class ObservablesContextAdapter : IDisposable + { + private ObservablesContext _db; + /// + /// Gets the underlying . + /// + public ObservablesContext Context + { + get { return _db; } + } + + /// + /// Initializes a new instance of the class. + /// + /// The context. + public ObservablesContextAdapter(ObservablesContext context) + { + _db = context; + } + + /// + /// Creates the a new instance of wrapping a default . + /// + /// + public static ObservablesContextAdapter CreateDefault() + { + var context = ObservablesContext.CreateDefault(); + return new ObservablesContextAdapter(context); + } + + /// + /// Loads the configuration with it's Ids packs. + /// + /// The condition. + /// + public Configuration GetConfiguration(Expression> condition) + { + var config = _db.Configurations.SingleOrDefault(condition); + + config.IdsPacks = _db.IdsPacks.Where(x => x.ConfigurationGuid == config.Guid) + .Include(x => x.LiquidType) + .Include(x => x.DispenserType) + .Include(x => x.CartridgeType) + .Include(x => x.DispenserType) + .Include(x => x.IdsPackFormula).OrderBy(x => x.PackIndex).ToObservableCollection(); + + return config; + } + + /// + /// Gets the hardware version by the specified condition. + /// + /// The condition. + /// + public HardwareVersion GetHardwareVersion(Expression> condition) + { + HardwareVersion version = _db.HardwareVersions.SingleOrDefault(condition); + + version.HardwareBlowers = _db.HardwareBlowers.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareBlowerType).ToList().OrderBy(x => x.HardwareBlowerType.Code).ToObservableCollection(); + version.HardwareBreakSensors = _db.HardwareBreakSensors.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareBreakSensorType).ToList().OrderBy(x => x.HardwareBreakSensorType.Code).ToObservableCollection(); + version.HardwareDancers = _db.HardwareDancers.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareDancerType).ToList().OrderBy(x => x.HardwareDancerType.Code).ToObservableCollection(); + version.HardwareMotors = _db.HardwareMotors.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareMotorType).ToList().OrderBy(x => x.HardwareMotorType.Code).ToObservableCollection(); + version.HardwarePidControls = _db.HardwarePidControls.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwarePidControlType).ToList().OrderBy(x => x.HardwarePidControlType.Code).ToObservableCollection(); + version.HardwareSpeedSensors = _db.HardwareSpeedSensors.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareSpeedSensorType).ToList().OrderBy(x => x.HardwareSpeedSensorType.Code).ToObservableCollection(); + version.HardwareWinders = _db.HardwareWinders.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareWinderType).ToList().OrderBy(x => x.HardwareWinderType.Code).ToObservableCollection(); + + return version; + } + + /// + /// Gets the hardware version by machine. + /// + /// The machine unique identifier. + /// + public HardwareVersion GetHardwareVersionByMachine(String machineGuid) + { + var machine = _db.Machines.Where(x => x.Guid == machineGuid).Include(x => x.Configuration).FirstOrDefault(); + return GetHardwareVersion(x => x.Guid == machine.Configuration.HardwareVersionGuid); + } + + /// + /// Gets the active process parameters tables group. + /// + /// The RML unique identifier. + /// + public ProcessParametersTablesGroup GetRmlActiveProcessParametersTablesGroup(String rmlGuid) + { + return _db.ProcessParametersTablesGroups.Where(x => x.RmlGuid == rmlGuid && x.Active).Include(x => x.ProcessParametersTables).FirstOrDefault(); + } + + /// + /// Gets the RML CCTS. + /// + /// The RML unique identifier. + /// + public ObservableCollection GetRmlCCTs(String rmlGuid) + { + return _db.Ccts.Where(x => x.RmlGuid == rmlGuid).ToObservableCollection(); + } + + /// + /// Gets the RML CATS. + /// + /// The RML unique identifier. + /// The machine unique identifier. + /// + public ObservableCollection GetRmlCATs(String rmlGuid, String machineGuid) + { + return _db.Cats.Where(x => x.MachineGuid == machineGuid && x.RmlGuid == rmlGuid).ToObservableCollection(); + } + + /// + /// Gets the RML liquid types factors. + /// + /// The RML unique identifier. + /// + public ObservableCollection GetRmlLiquidTypes(String rmlGuid) + { + return _db.LiquidTypesRmls.Where(x => x.RmlGuid == rmlGuid).ToObservableCollection(); + } + + /// + /// Gets the organization with all it's users addresses and contacts. + /// + /// The organization unique identifier. + /// + public Organization GetOrganizationAndUsers(String organizationGuid) + { + var org = _db.Organizations.SingleOrDefault(x => x.Guid == organizationGuid); + + org.Address = _db.Addresses.SingleOrDefault(x => x.Guid == org.AddressGuid); + org.Contact = _db.Contacts.SingleOrDefault(x => x.Guid == org.ContactGuid); + + _db.Roles.Load(); + _db.Permissions.Load(); + _db.RolesPermissions.Load(); + + + org.Users = _db.Users.Where(x => x.OrganizationGuid == organizationGuid) + .Include(x => x.Address) + .Include(x => x.Contact) + .Include(x => x.UsersRoles).ToObservableCollection(); + + return org; + } + + /// + /// Gets the user with it's address and contact. + /// + /// The user unique identifier. + /// + public User GetUser(String userGuid) + { + _db.Roles.Load(); + _db.Permissions.Load(); + _db.RolesPermissions.Load(); + + return _db.Users.Where(x => x.Guid == userGuid) + .Include(x => x.Address) + .Include(x => x.Contact) + .Include(x => x.UsersRoles) + .FirstOrDefault(); + } + + /// + /// Disposes the underlying . + /// + public void Dispose() + { + _db.Dispose(); + } + } +} diff --git a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs index d265fbe01..49c80695f 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs @@ -19,6 +19,7 @@ namespace Tango.BL public partial class ObservablesContext { private List _pending_notifications = new List(); + private ObservablesContextAdapter _adapter; public ObservablesContext() { @@ -33,6 +34,7 @@ namespace Tango.BL public ObservablesContext(DataSource dataSource) : base(dataSource.ToConnection(), true) { Database.SetInitializer(null); + _adapter = new ObservablesContextAdapter(this); } /// @@ -161,101 +163,12 @@ namespace Tango.BL return base.ShouldValidateEntity(entityEntry); } - #region Public Methods - /// - /// Loads the configuration with it's Ids packs. + /// Gets an instance of which wraps this instance. /// - /// The condition. - /// - public Configuration GetConfiguration(Expression> condition) - { - var config = Configurations.SingleOrDefault(condition); - - config.IdsPacks = IdsPacks.Where(x => x.ConfigurationGuid == config.Guid) - .Include(x => x.LiquidType) - .Include(x => x.DispenserType) - .Include(x => x.CartridgeType) - .Include(x => x.DispenserType) - .Include(x => x.IdsPackFormula).OrderBy(x => x.PackIndex).ToObservableCollection(); - - return config; - } - - public HardwareVersion GetHardwareVersion(Expression> condition) + public ObservablesContextAdapter Adapter { - HardwareVersion version = HardwareVersions.SingleOrDefault(condition); - - version.HardwareBlowers = HardwareBlowers.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareBlowerType).ToList().OrderBy(x => x.HardwareBlowerType.Code).ToObservableCollection(); - version.HardwareBreakSensors = HardwareBreakSensors.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareBreakSensorType).ToList().OrderBy(x => x.HardwareBreakSensorType.Code).ToObservableCollection(); - version.HardwareDancers = HardwareDancers.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareDancerType).ToList().OrderBy(x => x.HardwareDancerType.Code).ToObservableCollection(); - version.HardwareMotors = HardwareMotors.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareMotorType).ToList().OrderBy(x => x.HardwareMotorType.Code).ToObservableCollection(); - version.HardwarePidControls = HardwarePidControls.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwarePidControlType).ToList().OrderBy(x => x.HardwarePidControlType.Code).ToObservableCollection(); - version.HardwareSpeedSensors = HardwareSpeedSensors.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareSpeedSensorType).ToList().OrderBy(x => x.HardwareSpeedSensorType.Code).ToObservableCollection(); - version.HardwareWinders = HardwareWinders.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareWinderType).ToList().OrderBy(x => x.HardwareWinderType.Code).ToObservableCollection(); - - return version; + get { return _adapter; } } - - public HardwareVersion GetHardwareVersionByMachine(String machineGuid) - { - var machine = Machines.Where(x => x.Guid == machineGuid).Include(x => x.Configuration).FirstOrDefault(); - return GetHardwareVersion(x => x.Guid == machine.Configuration.HardwareVersionGuid); - } - - public ProcessParametersTablesGroup GetActiveProcessParametersTablesGroup(String rmlGuid) - { - return ProcessParametersTablesGroups.Where(x => x.RmlGuid == rmlGuid && x.Active).Include(x => x.ProcessParametersTables).FirstOrDefault(); - } - - public ObservableCollection GetRmlCCTs(String rmlGuid) - { - return Ccts.Where(x => x.RmlGuid == rmlGuid).ToObservableCollection(); - } - - public ObservableCollection GetRmlCATs(String rmlGuid, String machineGuid) - { - return Cats.Where(x => x.MachineGuid == machineGuid && x.RmlGuid == rmlGuid).ToObservableCollection(); - } - - public ObservableCollection GetRmlLiquidTypes(String rmlGuid) - { - return LiquidTypesRmls.Where(x => x.RmlGuid == rmlGuid).ToObservableCollection(); - } - - public Organization GetOrganizationAndUsers(String organizationGuid) - { - var org = Organizations.SingleOrDefault(x => x.Guid == organizationGuid); - - org.Address = Addresses.SingleOrDefault(x => x.Guid == org.AddressGuid); - org.Contact = Contacts.SingleOrDefault(x => x.Guid == org.ContactGuid); - - Roles.Load(); - Permissions.Load(); - RolesPermissions.Load(); - - - org.Users = Users.Where(x => x.OrganizationGuid == organizationGuid) - .Include(x => x.Address) - .Include(x => x.Contact) - .Include(x => x.UsersRoles).ToObservableCollection(); - - return org; - } - - public User GetUser(String userGuid) - { - Roles.Load(); - Permissions.Load(); - RolesPermissions.Load(); - - return Users.Where(x => x.Guid == userGuid) - .Include(x => x.Address) - .Include(x => x.Contact) - .Include(x => x.UsersRoles) - .FirstOrDefault(); - } - - #endregion } } diff --git a/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs b/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs index 1356206ea..db5faef4b 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs @@ -103,7 +103,9 @@ namespace Tango.BL foreach (var machine in Machines) { - db.GetConfiguration(x => x.Guid == machine.ConfigurationGuid); + ObservablesContextAdapter adapter = new ObservablesContextAdapter(db); + + adapter.GetConfiguration(x => x.Guid == machine.ConfigurationGuid); } }); diff --git a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj index eb6cd7b6c..bfc1a033a 100644 --- a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj +++ b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj @@ -240,6 +240,7 @@ + @@ -322,7 +323,7 @@ - + \ No newline at end of file -- cgit v1.3.1