From 4e81425d99f39b8edc10660d72566c6c1408810d Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Thu, 23 Aug 2018 14:52:22 +0300 Subject: changes on other computers --- .../Properties/AssemblyInfo.cs | 2 +- .../Tango.MachineStudio.ColorLab.csproj | 2 +- .../ViewModels/MainViewVM.cs | 131 +++- .../Views/MainView.xaml | 6 +- .../Properties/AssemblyInfo.cs | 2 +- .../Tango.MachineStudio.DB.csproj | 2 +- .../ViewModels/MainViewVM.cs | 77 ++- .../Tango.MachineStudio.DB/Views/MainDBView.xaml | 14 + .../Properties/AssemblyInfo.cs | 2 +- .../Tango.MachineStudio.DataCapture.csproj | 11 +- .../Tango.MachineStudio.DataCapture/app.config | 14 + .../packages.config | 1 + .../Navigation/DeveloperNavigationManager.cs | 2 +- .../Properties/AssemblyInfo.cs | 2 +- .../Tango.MachineStudio.Developer.csproj | 14 +- .../ViewModelLocator.cs | 2 +- .../ViewModels/MainViewVM.cs | 474 ++++++++----- .../Views/JobView.xaml | 6 +- .../Views/JobView.xaml.cs | 2 +- .../Views/MachineJobSelectionView.xaml | 271 ++++---- .../Views/MainView.xaml | 2 +- .../Tango.MachineStudio.Developer/app.config | 4 + .../Properties/AssemblyInfo.cs | 2 +- .../Tango.MachineStudio.HardwareDesigner.csproj | 2 +- .../ViewModels/MainViewVM.cs | 761 +++++++-------------- .../Views/MainView.xaml | 78 +-- .../Modules/Tango.MachineStudio.Logging/App.config | 4 + .../Properties/AssemblyInfo.cs | 2 +- .../Tango.MachineStudio.Logging.csproj | 2 +- .../ViewModels/EventsViewVM.cs | 74 +- .../AutoComplete/MachineVersionsProvider.cs | 2 +- .../Properties/AssemblyInfo.cs | 2 +- .../Tango.MachineStudio.MachineDesigner.csproj | 16 +- .../ViewModels/MachineVersionDialogVM.cs | 4 +- .../ViewModels/MainViewVM.cs | 268 +++++--- .../Views/MachineView.xaml | 1 - .../Views/MainView.xaml | 9 +- .../Tango.MachineStudio.MachineDesigner/app.config | 14 + .../packages.config | 1 + .../Properties/AssemblyInfo.cs | 2 +- .../Tango.MachineStudio.Stubs.csproj | 11 +- .../ViewModels/MainViewVM.cs | 7 +- .../Modules/Tango.MachineStudio.Stubs/app.config | 10 + .../Tango.MachineStudio.Stubs/packages.config | 1 + .../Tango.MachineStudio.Synchronization.csproj | 2 +- .../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 | 22 +- .../Editors/JobRunnerElementEditor.xaml | 19 +- .../Editors/MeterElementEditor.xaml | 19 +- .../Editors/MonitorElementEditor.xaml | 19 +- .../Editors/MotorElementEditor.xaml | 21 +- .../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 +- .../Properties/AssemblyInfo.cs | 2 +- .../PropertiesTemplates/JobRunnerTemplate.xaml | 4 +- .../ProcessParametersTemplate.xaml | 2 +- .../Tango.MachineStudio.Technician.csproj | 11 +- .../TechItems/BlowerItem.cs | 3 +- .../TechItems/BreakSensorItem.cs | 3 +- .../TechItems/DancerItem.cs | 2 +- .../TechItems/DispenserItem.cs | 2 +- .../TechItems/JobRunnerItem.cs | 1 + .../TechItems/MotorGroupItem.cs | 2 +- .../TechItems/MotorItem.cs | 2 +- .../TechItems/PidItem.cs | 2 +- .../TechItems/ProcessParametersItem.cs | 18 +- .../TechItems/SpeedSensorItem.cs | 2 +- .../TechItems/TechItem.cs | 4 +- .../TechItems/WinderItem.cs | 2 +- .../ViewModels/MachineTechViewVM.cs | 159 +++-- .../Views/MachineTechView.xaml.cs | 2 +- .../Tango.MachineStudio.Technician/app.config | 10 + .../Tango.MachineStudio.Technician/packages.config | 1 + .../Properties/AssemblyInfo.cs | 2 +- .../Tango.MachineStudio.UsersAndRoles.csproj | 2 +- .../ViewModels/MainViewVM.cs | 52 +- .../AutoComplete/MachinesProvider.cs | 2 +- .../Controls/LoadingPanel.cs | 37 + .../EventLogging/DefaultEventLogger.cs | 1 - .../Tango.MachineStudio.Common/IStudioViewModel.cs | 22 +- .../Modules/IStudioModuleLoader.cs | 5 + .../Navigation/INavigationBlocker.cs | 28 + .../Navigation/INavigationManager.cs | 98 ++- .../Navigation/INavigationObjectReceiver.cs | 21 + .../Navigation/INavigationResultProvider.cs | 28 + .../Properties/AssemblyInfo.cs | 2 +- .../Resources/MaterialDesign.xaml | 1 + .../StudioApplication/IStudioApplicationManager.cs | 12 +- .../Tango.MachineStudio.Common/StudioViewModel.cs | 175 +---- .../Tango.MachineStudio.Common.csproj | 15 +- .../Tango.MachineStudio.Common/Themes/Generic.xaml | 31 + .../Threading/IDispatcherProvider.cs | 26 + .../Tango.MachineStudio.Common/app.config | 4 + .../Tango.MachineStudio.Publisher/App.config | 8 + .../Tango.MachineStudio.Publisher.csproj | 2 +- .../Tango.MachineStudio.UI/App.config | 12 +- .../Tango.MachineStudio.UI/App.xaml.cs | 15 +- .../DefaultAuthenticationProvider.cs | 43 +- .../Tango.MachineStudio.UI/MainWindow.xaml | 2 +- .../Modules/DefaultStudioModuleLoader.cs | 25 +- .../Navigation/DefaultNavigationManager.cs | 369 +++++++++- .../Properties/AssemblyInfo.cs | 2 +- .../DefaultStudioApplicationManager.cs | 47 +- .../Tango.MachineStudio.UI.csproj | 9 +- .../Threading/DefaultDispatcherProvider.cs | 46 ++ .../Tango.MachineStudio.UI/ViewModelLocator.cs | 6 + .../ViewModels/LoadingViewVM.cs | 9 +- .../ViewModels/LoginViewVM.cs | 41 +- .../ViewModels/MachineSerialViewVM.cs | 2 +- .../ViewModels/MainViewVM.cs | 30 +- .../ViewModels/UpdateViewVM.cs | 3 + .../Tango.MachineStudio.UI/Views/LoginView.xaml | 43 +- .../Tango.MachineStudio.UI/Views/MainView.xaml | 3 +- .../Tango.MachineStudio.UI/Views/MainView.xaml.cs | 14 +- .../Tango.MachineStudio.UpdateService.csproj | 2 +- .../Tango.MachineStudio.UpdateService/Web.config | 9 +- .../Tango.MachineStudio.Updater/MainWindow.xaml.cs | 16 +- .../Tango.MachineStudio.Updater.csproj | 2 +- 129 files changed, 2683 insertions(+), 1555 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/LoadingPanel.cs 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/Themes/Generic.xaml 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 (limited to 'Software/Visual_Studio/MachineStudio') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Properties/AssemblyInfo.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Properties/AssemblyInfo.cs index bda64c925..7af9df838 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Properties/AssemblyInfo.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Properties/AssemblyInfo.cs @@ -5,7 +5,7 @@ using System.Runtime.InteropServices; using System.Windows; [assembly: AssemblyTitle("Tango - Machine Studio Color Lab Module")] -[assembly: AssemblyVersion("2.0.8.1633")] +[assembly: AssemblyVersion("2.0.9.1119")] [assembly: ComVisible(false)] diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj index a0d471522..7e8a9e126 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj @@ -8,7 +8,7 @@ library Tango.MachineStudio.ColorLab Tango.MachineStudio.ColorLab - v4.6 + v4.7.2 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 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 5b317e6d2..02f496b1f 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; @@ -239,34 +239,57 @@ namespace Tango.MachineStudio.ColorLab.ViewModels #endregion + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The notification. public MainViewVM(INotificationProvider notification) : base() { _notification = notification; - _dbContext = ObservablesContext.CreateDefault(); - CCT = new Cct(); SourceColor = new RgbVM(); SourceColor.ColorChanged += SourceColor_ColorChanged; - Machines = _dbContext.Machines.ToObservableCollection(); - ColorSpaces = _dbContext.ColorSpaces.ToObservableCollection(); - Rmls = _dbContext.Rmls.ToObservableCollection(); - ImportForwardDataCommand = new RelayCommand(ImportForwardData, () => SelectedRML != null); - ImportInverseDataCommand = new RelayCommand(ImportInverseData, () => SelectedRML != null); + ImportForwardDataCommand = new RelayCommand(ImportForwardData, () => SelectedRML != null && IsFree); + ImportInverseDataCommand = new RelayCommand(ImportInverseData, () => SelectedRML != null && IsFree); - ExportForwardDataCommand = new RelayCommand(ExportForwardData, () => SelectedRML != null && CCT != null && CCT.ForwardFileName != null); - ExportInverseDataCommand = new RelayCommand(ExportInverseData, () => SelectedRML != null && CCT != null && CCT.InverseFileName != null); + ExportForwardDataCommand = new RelayCommand(ExportForwardData, () => SelectedRML != null && CCT != null && CCT.ForwardFileName != null && IsFree); + ExportInverseDataCommand = new RelayCommand(ExportInverseData, () => SelectedRML != null && CCT != null && CCT.InverseFileName != null && IsFree); - SaveCommand = new RelayCommand(Save, () => SelectedRML != null); + SaveCommand = new RelayCommand(Save, () => SelectedRML != null && IsFree); } + #endregion + + #region Event Handlers + private void SourceColor_ColorChanged(object sender, Color e) { GetHiveSuggestions(); } + #endregion + + #region Application Ready + + public override void OnApplicationReady() + { + Task.Factory.StartNew(() => + { + _dbContext = ObservablesContext.CreateDefault(); + + Machines = _dbContext.Machines.ToObservableCollection(); + ColorSpaces = _dbContext.ColorSpaces.ToObservableCollection(); + Rmls = _dbContext.Rmls.ToObservableCollection(); + }); + } + + #endregion + #region ColorLab private void GetHiveSuggestions() @@ -417,6 +440,10 @@ namespace Tango.MachineStudio.ColorLab.ViewModels { if (SelectedMachine != null) { + IsFree = false; + + _dbContext.Adapter.GetConfiguration(x => x.Guid == SelectedMachine.ConfigurationGuid); + LiquidVolumes = SelectedMachine.Configuration.NoneEmptyIdsPacks.OrderBy(x => x.PackIndex).Select(x => new LiquidVolumeVM() { Color = x.LiquidType.Color, @@ -424,12 +451,17 @@ namespace Tango.MachineStudio.ColorLab.ViewModels IdsPack = x, }).ToObservableCollection(); + + LiquidVolumes.EnableCrossThreadOperations(); + LiquidVolumes.ToList().ForEach(x => x.VolumeChanged += (s, e) => OnLiquidVolumeChanged()); InvalidateLiquidFactorsCalibrationData(); SelectedMachine.Modified -= SelectedMachine_Modified; SelectedMachine.Modified += SelectedMachine_Modified; + + IsFree = true; } } @@ -515,42 +547,61 @@ namespace Tango.MachineStudio.ColorLab.ViewModels #region RML - private void InvalidateLiquidFactorsCalibrationData() + private async void InvalidateLiquidFactorsCalibrationData() { if (SelectedRML != null && SelectedMachine != null) { - 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); + IsFree = false; - LiquidsCalibrationData = new ObservableCollection(); - - foreach (var idsPack in SelectedMachine.Configuration.NoneEmptyIdsPacks.OrderBy(x => x.PackIndex)) + await Task.Factory.StartNew(() => { - CalibrationDataVM vm = new CalibrationDataVM(); - vm.Name = idsPack.LiquidType.Name; - vm.Color = idsPack.LiquidType.Color; - vm.IdsPack = idsPack; + using (_notification.PushTaskItem("Loading RML data...")) + { + _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); - var cat = idsPack.LiquidType.Cats.FirstOrDefault(x => x.Machine == SelectedMachine && x.Rml == SelectedRML); + 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); - if (cat != null) - { - var calData = cat.GetCalibrationData(); - vm.CalibrationPoints = calData.CalibrationPoints.Select(x => new CalibrationDataPointVM(x.X, x.Y)).ToObservableCollection(); - } + LiquidsCalibrationData = new ObservableCollection(); + LiquidsCalibrationData.EnableCrossThreadOperations(); - LiquidsCalibrationData.Add(vm); - } + foreach (var idsPack in SelectedMachine.Configuration.NoneEmptyIdsPacks.OrderBy(x => x.PackIndex)) + { + CalibrationDataVM vm = new CalibrationDataVM(); + vm.Name = idsPack.LiquidType.Name; + vm.Color = idsPack.LiquidType.Color; + vm.IdsPack = idsPack; + + var cat = idsPack.LiquidType.Cats.FirstOrDefault(x => x.Machine == SelectedMachine && x.Rml == SelectedRML); + + if (cat != null) + { + var calData = cat.GetCalibrationData(); + vm.CalibrationPoints = calData.CalibrationPoints.Select(x => new CalibrationDataPointVM(x.X, x.Y)).ToObservableCollection(); + } + + InvokeUINow(() => + { + LiquidsCalibrationData.Add(vm); + }); + } - _isNewCCT = false; - CCT = SelectedRML.Ccts.FirstOrDefault(); + _isNewCCT = false; + CCT = SelectedRML.Ccts.FirstOrDefault(); - if (CCT == null) - { - CCT = new Cct(); - CCT.Rml = SelectedRML; - _isNewCCT = true; - } + if (CCT == null) + { + CCT = new Cct(); + CCT.Rml = SelectedRML; + _isNewCCT = true; + } + } + }); + + IsFree = true; } } @@ -564,6 +615,8 @@ namespace Tango.MachineStudio.ColorLab.ViewModels { try { + IsFree = false; + if (_isNewCCT) { _dbContext.Ccts.Add(CCT); @@ -601,6 +654,10 @@ namespace Tango.MachineStudio.ColorLab.ViewModels { _notification.ShowError(LogManager.Log(ex, "An error occurred while trying to save to data base.").Message + Environment.NewLine + ex.Message); } + finally + { + IsFree = true; + } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml index d8ef015be..78eaf04e8 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml @@ -35,7 +35,7 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Properties/AssemblyInfo.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Properties/AssemblyInfo.cs index 51246a5d1..24afc84e3 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Properties/AssemblyInfo.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Properties/AssemblyInfo.cs @@ -5,7 +5,7 @@ using System.Runtime.InteropServices; using System.Windows; [assembly: AssemblyTitle("Tango - Machine Studio Data Capturing Module")] -[assembly: AssemblyVersion("2.0.8.1633")] +[assembly: AssemblyVersion("2.0.9.1119")] [assembly: ComVisible(false)] diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Tango.MachineStudio.DataCapture.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Tango.MachineStudio.DataCapture.csproj index a8cd6b1cd..15df43f6e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Tango.MachineStudio.DataCapture.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Tango.MachineStudio.DataCapture.csproj @@ -8,7 +8,7 @@ library Tango.MachineStudio.DataCapture Tango.MachineStudio.DataCapture - v4.6 + v4.7.2 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 @@ -31,6 +31,12 @@ 4 + + ..\..\..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.dll + + + ..\..\..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.SqlServer.dll + ..\..\..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll @@ -44,6 +50,7 @@ ..\..\..\packages\MaterialDesignThemes.2.3.1.953\lib\net45\MaterialDesignThemes.Wpf.dll + @@ -188,7 +195,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/app.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/app.config index 5d794b958..0e58ccf54 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/app.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/app.config @@ -1,5 +1,9 @@  + + +
+ @@ -46,6 +50,16 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/packages.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/packages.config index 73dae1a0c..d1cf6cd7a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/packages.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/packages.config @@ -1,6 +1,7 @@  + 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/Properties/AssemblyInfo.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Properties/AssemblyInfo.cs index 66e36649b..333ca0b2e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Properties/AssemblyInfo.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Properties/AssemblyInfo.cs @@ -5,7 +5,7 @@ using System.Runtime.InteropServices; using System.Windows; [assembly: AssemblyTitle("Tango - Machine Studio Developer Module")] -[assembly: AssemblyVersion("2.0.15.1633")] +[assembly: AssemblyVersion("2.0.16.1119")] [assembly: ComVisible(false)] diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj index bd7484de8..cc9831ad9 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj @@ -8,7 +8,7 @@ library Tango.MachineStudio.Developer Tango.MachineStudio.Developer - v4.6 + v4.7.2 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 @@ -196,6 +196,10 @@ {b9ae25d6-be35-492f-9079-21a7f3e6f7cc} RealTimeGraphEx + + {BB2ABB74-BA58-4812-83AA-EC8171F42DF4} + Tango.AutoComplete + {f441feee-322a-4943-b566-110e12fd3b72} Tango.BL @@ -264,10 +268,6 @@ {fc337a7f-1214-41d8-9992-78092a3b961e} Tango.MachineStudio.DataCapture - - {94f7acf8-55e1-4a02-b9bc-a818413fdbbf} - Tango.MachineStudio.DB - {1674f726-0e66-414f-b9fd-c6f20d7f07c7} Tango.MachineStudio.Logging @@ -276,10 +276,6 @@ {d0ce8122-077d-42a2-9490-028ae4769b52} Tango.MachineStudio.MachineDesigner - - {5d39c1e1-3ecd-4634-bd1b-2bcf71c54a15} - Tango.MachineStudio.Technician - diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModelLocator.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModelLocator.cs index ebf2f2446..5f82984a4 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModelLocator.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModelLocator.cs @@ -16,8 +16,8 @@ namespace Tango.MachineStudio.Developer /// static ViewModelLocator() { - TangoIOC.Default.Register(); TangoIOC.Default.Register(); + TangoIOC.Default.Register(); } public static MainViewVM MainViewVM 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 dace2ceac..60c2e65f9 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 @@ -41,6 +41,9 @@ using Tango.MachineStudio.Common; using Tango.BL.ColorConversion; using Tango.MachineStudio.Logging.ViewModels; using Tango.MachineStudio.Logging.Views; +using Tango.AutoComplete.Editors; +using System.Data.Entity; +using System.Runtime.ExceptionServices; namespace Tango.MachineStudio.Developer.ViewModels { @@ -48,7 +51,8 @@ namespace Tango.MachineStudio.Developer.ViewModels /// Represents the developer module main view, view model. /// /// - public class MainViewVM : StudioViewModel + [TangoCreateWhenRegistered] + 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"; @@ -71,6 +75,7 @@ namespace Tango.MachineStudio.Developer.ViewModels private bool _hiveOpened; private bool _color_changed_from_hive; private bool _dialog_shown; + private bool _disable_gamut_check; #region Properties @@ -104,16 +109,6 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _runningJobStatus = value; RaisePropertyChangedAuto(); } } - private ObservableCollection _machines; - /// - /// Gets or sets the machines. - /// - public ObservableCollection Machines - { - get { return _machines; } - set { _machines = value; RaisePropertyChangedAuto(); } - } - private ObservableCollection _colorSpaces; /// /// Gets or sets the color spaces. @@ -173,19 +168,32 @@ namespace Tango.MachineStudio.Developer.ViewModels get { return _selectedMachine; } set { - _selectedMachine = value; - OnSelectedMachineChanged(); - RaisePropertyChangedAuto(); - InvalidateRelayCommands(); - - if (_selectedMachine != null) + if (value != null && _selectedMachine != value) { - _selectedMachine.Modified -= SelectedMachine_Modified; - _selectedMachine.Modified += SelectedMachine_Modified; + _selectedMachine = value; + OnSelectedMachineChanged(); + RaisePropertyChangedAuto(); + InvalidateRelayCommands(); + + if (_selectedMachine != null) + { + _selectedMachine.Modified -= SelectedMachine_Modified; + _selectedMachine.Modified += SelectedMachine_Modified; + } } } } + private bool _canWork; + /// + /// Gets or sets a value indicating whether this instance is loading machine. + /// + public bool CanWork + { + get { return _canWork; } + set { _canWork = value; RaisePropertyChangedAuto(); } + } + private List _liquidTypesRmls; /// /// Gets or sets the liquid types RMLS. @@ -248,7 +256,6 @@ namespace Tango.MachineStudio.Developer.ViewModels { _activeJob = value; RaisePropertyChangedAuto(); - OnActiveJobChanged(); } } @@ -322,7 +329,7 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _selectedRML = value; - InvalidateLiquidFactorsAndProcessTables(); + OnSelectedRMLChanged(); RaisePropertyChangedAuto(); InvalidateRelayCommands(); } @@ -504,6 +511,11 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _selectedJobEvent = value; RaisePropertyChangedAuto(); OnSelectedJobEventChanged(); } } + /// + /// Gets or sets the machines providers. + /// + public ISuggestionProvider MachinesProvider { get; set; } + #endregion #region Commands @@ -643,28 +655,7 @@ namespace Tango.MachineStudio.Developer.ViewModels /// The notification provider. public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IDiagnosticsFrameProvider diagnosticsFrameProvider, IVideoCaptureProvider videoCaptureProvider, DeveloperNavigationManager navigation, IAuthenticationProvider authentication, IEventLogger eventLogger, ISpeechProvider speech) { - _settings = SettingsManager.Default.GetOrCreate(); - - SelectedJobs = new ObservableCollection(); - - JobEvents = new ObservableCollection(); - - LogManager.Log("Initializing machine Db context..."); - _machineDbContext = ObservablesContext.CreateDefault(); - - Machines = _machineDbContext.Machines.ToObservableCollection(); - - if (_settings.LastSelectedMachineGuid != null) - { - LogManager.Log("Setting last selected machine from settings..."); - SelectedMachine = _machineDbContext.Machines.SingleOrDefault(x => x.Guid == _settings.LastSelectedMachineGuid); - } - - if (_settings.LastSelectedJobGuid != null && SelectedMachine != null) - { - LogManager.Log("Setting last selected job from settings..."); - SelectedMachineJob = SelectedMachine.Jobs.SingleOrDefault(x => x.Guid == _settings.LastSelectedJobGuid); - } + CanWork = true; _authentication = authentication; @@ -684,36 +675,76 @@ namespace Tango.MachineStudio.Developer.ViewModels }); //Initialize Commands... - EditMachineCommand = new RelayCommand(EditMachine, () => SelectedMachine != null); - EditRMLCommand = new RelayCommand(EditRML, () => SelectedRML != null); + EditMachineCommand = new RelayCommand(EditMachine, () => SelectedMachine != null && CanWork); + EditRMLCommand = new RelayCommand(EditRML, () => SelectedRML != null && CanWork); ToggleSideBarCommand = new RelayCommand(() => IsSideBarOpened = !IsSideBarOpened); - SaveLiquidFactorsCommand = new RelayCommand(SaveLiquidFactors, () => SelectedRML != null); - AddSegmentCommand = new RelayCommand(AddSegment, () => ActiveJob != null); - RemoveSegmentCommand = new RelayCommand(RemoveSelectedSegments, () => SelectedSegment != null); - AddJobCommand = new RelayCommand(AddJob, () => SelectedMachine != null); - RemoveJobCommand = new RelayCommand(RemoveSelectedJobs, () => SelectedMachineJob != null); - AddBrushStopCommand = new RelayCommand(AddBrushStop, () => SelectedSegment != null); - RemoveBrushStopCommand = new RelayCommand(RemoveSelectedBrushStops, () => SelectedBrushStop != null); - SaveJobCommand = new RelayCommand(SaveActiveJob, () => SelectedMachine != null); - DiscardJobCommand = new RelayCommand(BackToJobs, () => SelectedMachine != null); - StartJobCommand = new RelayCommand(StartJob, () => ActiveJob != null && !IsJobRunning && MachineOperator != null && !MachineOperator.MachineEventsStateProvider.Events.ToList().Exists(x => x.ActionTypes.Contains(BL.Enumerations.ActionTypes.PreventJobExecution))); + SaveLiquidFactorsCommand = new RelayCommand(SaveLiquidFactors, () => SelectedRML != null && CanWork); + AddSegmentCommand = new RelayCommand(AddSegment, () => ActiveJob != null && CanWork); + RemoveSegmentCommand = new RelayCommand(RemoveSelectedSegments, () => SelectedSegment != null && CanWork); + AddJobCommand = new RelayCommand(AddJob, () => SelectedMachine != null && CanWork); + RemoveJobCommand = new RelayCommand(RemoveSelectedJobs, () => SelectedMachineJob != null && CanWork); + AddBrushStopCommand = new RelayCommand(AddBrushStop, () => SelectedSegment != null && CanWork); + RemoveBrushStopCommand = new RelayCommand(RemoveSelectedBrushStops, () => SelectedBrushStop != null && CanWork); + SaveJobCommand = new RelayCommand(SaveActiveJob, () => SelectedMachine != null && CanWork); + DiscardJobCommand = new RelayCommand(BackToJobs, () => SelectedMachine != null && CanWork); + StartJobCommand = new RelayCommand(StartJob, () => ActiveJob != null && CanWork && !IsJobRunning && MachineOperator != null && !MachineOperator.MachineEventsStateProvider.Events.ToList().Exists(x => x.ActionTypes.Contains(BL.Enumerations.ActionTypes.PreventJobExecution))); StartJobAndRecordCommand = new RelayCommand(StartJobAndRecord, () => _dataCaptureVM != null && !_dataCaptureVM.Recorder.IsRecording && !_dataCaptureVM.Player.IsPlaying && ActiveJob != null && !IsJobRunning && MachineOperator != null && !MachineOperator.MachineEventsStateProvider.Events.ToList().Exists(x => x.ActionTypes.Contains(BL.Enumerations.ActionTypes.PreventJobExecution))); - StopJobCommand = new RelayCommand(StopJob, () => IsJobRunning); + StopJobCommand = new RelayCommand(StopJob, () => IsJobRunning && CanWork); CloseJobCompletionStatusCommand = new RelayCommand(CloseJobCompletionStatusBar); - LoadJobCommand = new RelayCommand(LoadSelectedJob, () => SelectedMachineJob != null); - DuplicateJobCommand = new RelayCommand(DuplicateSelectedJobs, () => SelectedMachineJob != null); - DuplicateSegmentCommand = new RelayCommand(DuplicateSelectedSegments, () => SelectedSegment != null); - DuplicateBrushStopCommand = new RelayCommand(DuplicateSelectedBrushStops, () => SelectedBrushStop != null); - SaveProcessParametersCommand = new RelayCommand(SaveProcessParameters, () => SelectedRML != null && SelectedRML.ProcessParametersTablesGroups.Count > 0); - PushProcessParametersCommand = new RelayCommand(PushProcessParameters, () => SelectedRML != null && SelectedRML.ProcessParametersTablesGroups.Count > 0 && SelectedProcessParametersTable != null && MachineOperator != null); - ImportEmbroideryFileCommand = new RelayCommand(ImportEmbroideryFile, () => SelectedMachine != null); - DisplayJobEmbroideryFileCommand = new RelayCommand(DisplayJobEmbroideryFile); - ReloadMachinesCommand = new RelayCommand(ReloadMachine); + LoadJobCommand = new RelayCommand(LoadSelectedJob, () => SelectedMachineJob != null && CanWork); + DuplicateJobCommand = new RelayCommand(DuplicateSelectedJobs, () => SelectedMachineJob != null && CanWork); + DuplicateSegmentCommand = new RelayCommand(DuplicateSelectedSegments, () => SelectedSegment != null && CanWork); + DuplicateBrushStopCommand = new RelayCommand(DuplicateSelectedBrushStops, () => SelectedBrushStop != null && CanWork); + SaveProcessParametersCommand = new RelayCommand(SaveProcessParameters, () => SelectedRML != null && CanWork && SelectedRML.ProcessParametersTablesGroups.Count > 0); + 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 && SelectedMachine != null); ApplicationManager.ConnectedMachineChanged += ApplicationManager_ConnectedMachineChanged; _eventLogger.NewLog += _eventLogger_NewLog; + + MachinesProvider = new SuggestionProvider((filter) => + { + try + { + return _machineDbContext.Machines.Where(x => x.SerialNumber.StartsWith(filter)).ToList(); + } + catch + { + return null; + } + }); + } + + #endregion + + #region Application Ready + + public override void OnApplicationReady() + { + _settings = SettingsManager.Default.GetOrCreate(); + + SelectedJobs = new ObservableCollection(); + JobEvents = new ObservableCollection(); + + LogManager.Log("Initializing machine Db context..."); + _machineDbContext = ObservablesContext.CreateDefault(); + + if (_settings.LastSelectedMachineGuid != null) + { + LogManager.Log("Setting last selected machine from settings..."); + SelectedMachine = _machineDbContext.Machines.SingleOrDefault(x => x.Guid == _settings.LastSelectedMachineGuid); + } + + if (_settings.LastSelectedJobGuid != null && SelectedMachine != null) + { + LogManager.Log("Setting last selected job from settings..."); + SelectedMachineJob = SelectedMachine.Jobs.SingleOrDefault(x => x.Guid == _settings.LastSelectedJobGuid); + } + _colorConversionThread = new Thread(ColorConversionThreadMethod); _colorConversionThread.IsBackground = true; _colorConversionThread.Start(); @@ -723,37 +754,42 @@ namespace Tango.MachineStudio.Developer.ViewModels #region Color Conversion + [HandleProcessCorruptedStateExceptions] private void ColorConversionThreadMethod() { while (true) { - if (IsVisible && ActiveJob != null && ActiveJob.Segments != null) + if (!_disable_gamut_check && IsVisible && ActiveJob != null && ActiveJob.Segments != null) { - var stops = ActiveJob.Segments.SelectMany(x => x.BrushStops).ToList(); - - foreach (var stop in stops) + try { - if (stop.ColorSpace.Code == BL.Enumerations.ColorSpaces.Volume.ToInt32() && !stop.IsLiquidVolumesOutOfRange) + var stops = ActiveJob.Segments.SelectMany(x => x.BrushStops).ToList(); + + foreach (var stop in stops) { - try + if (stop.ColorSpace.Code == BL.Enumerations.ColorSpaces.Volume.ToInt32() && !stop.IsLiquidVolumesOutOfRange) { - var output = TangoColorConverter.GetSuggestions(stop); - - stop.Red = output.SingleCoordinates.Red; - stop.Green = output.SingleCoordinates.Green; - stop.Blue = output.SingleCoordinates.Blue; + try + { + var output = TangoColorConverter.GetSuggestions(stop); + + stop.Red = output.SingleCoordinates.Red; + stop.Green = output.SingleCoordinates.Green; + stop.Blue = output.SingleCoordinates.Blue; + } + catch { } } - catch { } - } - else if (stop.ColorSpace.Code == BL.Enumerations.ColorSpaces.RGB.ToInt32() && !stop.Corrected) - { - try + else if (stop.ColorSpace.Code == BL.Enumerations.ColorSpaces.RGB.ToInt32() && !stop.Corrected) { - stop.IsOutOfGamut = TangoColorConverter.IsOutOfGamut(stop); + try + { + stop.IsOutOfGamut = TangoColorConverter.IsOutOfGamut(stop); + } + catch { } } - catch { } } } + catch { } } Thread.Sleep(500); @@ -950,9 +986,12 @@ namespace Tango.MachineStudio.Developer.ViewModels if (RmlProcessParametersTableGroup != null && RmlProcessParametersTableGroup.ProcessParametersTables.Count > 0) { LogManager.Log("Process parameters group changed..."); - SelectedProcessParametersTable = RmlProcessParametersTableGroup.ProcessParametersTables.OrderBy(x => x.TableIndex).FirstOrDefault(); - UpdateEstimatedDuration(); + InvokeUI(() => + { + SelectedProcessParametersTable = RmlProcessParametersTableGroup.ProcessParametersTables.OrderBy(x => x.TableIndex).FirstOrDefault(); + UpdateEstimatedDuration(); + }); } } @@ -992,9 +1031,7 @@ namespace Tango.MachineStudio.Developer.ViewModels if (SelectedMachine != null) { LogManager.Log(String.Format("Machine {0} changed.", SelectedMachine.SerialNumber)); - ReloadMachine(); - JobsCollectionView = CollectionViewSource.GetDefaultView(SelectedMachine.Jobs); - JobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); + LoadMachine(); } } @@ -1018,19 +1055,6 @@ namespace Tango.MachineStudio.Developer.ViewModels }; } - /// - /// Called when the active job has changed. - /// - protected virtual void OnActiveJobChanged() - { - if (ActiveJob != null) - { - LogManager.Log(String.Format("Active job {0} changed.", ActiveJob.Name)); - SegmentsCollectionView = CollectionViewSource.GetDefaultView(ActiveJob.Segments); - SegmentsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Segment.SegmentIndex), ListSortDirection.Ascending)); - } - } - #endregion #region Drag & Drop @@ -1297,12 +1321,21 @@ namespace Tango.MachineStudio.Developer.ViewModels { if (SelectedRML != null) { + CanWork = false; + using (_notification.PushTaskItem("Saving Liquid Factors...")) { LogManager.Log(String.Format("Saving liquid factors for RML {0}...", SelectedRML.Name)); await SelectedRML.SaveAsync(_activeJobDbContext); - InvalidateLiquidFactorsAndProcessTables(); + LiquidTypesRmls = ActiveJob.Machine.Configuration.NoneEmptyIdsPacks.Where(x => !x.IsEmpty).OrderBy(x => x.PackIndex).Select(x => x.LiquidType).SelectMany(x => x.LiquidTypesRmls).Where(x => x.Rml.Guid == SelectedRML.Guid).ToList(); + + if (SelectedSegment != null) + { + SetSegmentBrushStopsLiquidVolumes(SelectedSegment); + } } + + CanWork = true; } } @@ -1312,7 +1345,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); } /// @@ -1323,7 +1355,10 @@ namespace Tango.MachineStudio.Developer.ViewModels if (SelectedRML != null && SelectedMachine != null) { LogManager.Log("Invalidating liquid factors, process parameters and process group history..."); - LiquidTypesRmls = SelectedMachine.Configuration.NoneEmptyIdsPacks.Where(x => !x.IsEmpty).OrderBy(x => x.PackIndex).Select(x => x.LiquidType).SelectMany(x => x.LiquidTypesRmls).Where(x => x.Rml.Guid == SelectedRML.Guid).ToList(); + LiquidTypesRmls = ActiveJob.Machine.Configuration.NoneEmptyIdsPacks.Where(x => !x.IsEmpty).OrderBy(x => x.PackIndex).Select(x => x.LiquidType).SelectMany(x => x.LiquidTypesRmls).Where(x => x.Rml.Guid == SelectedRML.Guid).ToList(); + + _activeJobDbContext.ProcessParametersTablesGroups.Where(x => x.RmlGuid == SelectedRML.Guid).Include(x => x.ProcessParametersTables).ToList(); + RmlProcessParametersTableGroup = SelectedRML.ProcessParametersTablesGroups.ToList().SingleOrDefault(x => x.Active); var selectedHistory = RmlProcessParametersTableGroup; @@ -1334,11 +1369,26 @@ namespace Tango.MachineStudio.Developer.ViewModels RmlProcessParametersTableGroup.ProcessParametersTables = RmlProcessParametersTableGroup.ProcessParametersTables.OrderBy(x => x.TableIndex).ToObservableCollection(); } - GroupsHistory = SelectedRML.ProcessParametersTablesGroups.OrderByDescending(x => x.SaveDate).OrderBy(x => !x.Active).ToObservableCollection(); + GroupsHistory = SelectedRML.ProcessParametersTablesGroups.OrderByDescending(x => x.SaveDate).OrderBy(x => !x.Active).ToObservableCollection(); _selectedGroupHistory = selectedHistory; - RaisePropertyChangedAuto(nameof(SelectedGroupHistory)); + InvokeUI(() => + { + RaisePropertyChanged(nameof(SelectedGroupHistory)); + RaisePropertyChanged(nameof(RmlProcessParametersTableGroup)); + }); + } + } + + private async void OnSelectedRMLChanged() + { + using (_notification.PushTaskItem("Loading RML...")) + { + await Task.Factory.StartNew(() => + { + InvalidateLiquidFactorsAndProcessTables(); + }); } } @@ -1375,6 +1425,8 @@ namespace Tango.MachineStudio.Developer.ViewModels if (response == null) return; + CanWork = false; + using (_notification.PushTaskItem("Saving Parameters Group...")) { LogManager.Log(String.Format("Saving process parameters group under the name {0}...", response)); @@ -1408,6 +1460,8 @@ namespace Tango.MachineStudio.Developer.ViewModels InvalidateLiquidFactorsAndProcessTables(); } + + CanWork = true; } #endregion @@ -1417,84 +1471,138 @@ namespace Tango.MachineStudio.Developer.ViewModels /// /// Loads the selected job. /// - private void LoadSelectedJob() + private async void LoadSelectedJob() { if (SelectedMachineJob != null) { + CanWork = false; + using (_notification.PushTaskItem("Loading job details...")) { - LogManager.Log(String.Format("Loading job {0}...", SelectedMachineJob.Name)); - SelectedSegments = new ObservableCollection(); - SelectedBrushStops = new ObservableCollection(); - SelectedRML = null; - SelectedSegment = null; - SelectedGroupHistory = null; - SelectedBrushStop = null; - SelectedProcessParametersTable = null; - RmlProcessParametersTableGroup = null; + await Task.Factory.StartNew(() => + { + _disable_gamut_check = true; + LogManager.Log(String.Format("Loading job {0}...", SelectedMachineJob.Name)); + SelectedSegments = new ObservableCollection(); + SelectedBrushStops = new ObservableCollection(); + SelectedRML = null; + SelectedSegment = null; + SelectedGroupHistory = null; + SelectedBrushStop = null; + SelectedProcessParametersTable = null; + RmlProcessParametersTableGroup = null; - _blockInvalidateCommands = false; + _blockInvalidateCommands = false; - LogManager.Log("Creating active job DB context..."); - _activeJobDbContext = ObservablesContext.CreateDefault(); - _activeJobDbContext.Configuration.LazyLoadingEnabled = true; + LogManager.Log("Creating active job DB context..."); + _activeJobDbContext = ObservablesContext.CreateDefault(); - LogManager.Log("Initializing available color spaces, RMLs & Winding methods..."); - var processParamsGroups = _activeJobDbContext.ProcessParametersTablesGroups.ToList(); - var processParams = _activeJobDbContext.ProcessParametersTables.ToList(); - ColorSpaces = _activeJobDbContext.ColorSpaces.ToObservableCollection(); - Rmls = _activeJobDbContext.Rmls.ToObservableCollection(); - WindingMethods = _activeJobDbContext.WindingMethods.ToObservableCollection(); - SpoolTypes = _activeJobDbContext.SpoolTypes.ToObservableCollection(); + LogManager.Log("Initializing available color spaces, RMLs & Winding methods..."); + //var processParamsGroups = _activeJobDbContext.ProcessParametersTablesGroups.ToList(); + //var processParams = _activeJobDbContext.ProcessParametersTables.ToList(); - LogManager.Log("Setting active job..."); - _activeJob = _activeJobDbContext.Jobs.SingleOrDefault(x => x.Guid == SelectedMachineJob.Guid); + ColorSpaces = _activeJobDbContext.ColorSpaces.ToObservableCollection(); + Rmls = _activeJobDbContext.Rmls.ToObservableCollection(); + WindingMethods = _activeJobDbContext.WindingMethods.ToObservableCollection(); + SpoolTypes = _activeJobDbContext.SpoolTypes.ToObservableCollection(); - _selectedRML = ActiveJob.Rml; + LogManager.Log("Setting active job..."); + ActiveJob = _activeJobDbContext.Jobs.Include(x => x.Rml).Include(x => x.Segments).Include(x => x.Segments.Select(y => y.BrushStops)).SingleOrDefault(x => x.Guid == SelectedMachineJob.Guid); - LogManager.Log("Setting selected segment..."); - _selectedSegment = ActiveJob.Segments.FirstOrDefault(); + _activeJobDbContext.Ccts.Where(x => x.RmlGuid == ActiveJob.RmlGuid).ToList(); + _activeJobDbContext.Cats.Where(x => x.RmlGuid == ActiveJob.RmlGuid).ToList(); + _activeJobDbContext.Machines.SingleOrDefault(x => x.Guid == ActiveJob.MachineGuid); + _activeJobDbContext.Configurations.SingleOrDefault(x => x.Guid == ActiveJob.Machine.ConfigurationGuid); - ActiveJob.LengthChanged -= ActiveJob_LengthChanged; - ActiveJob.LengthChanged += ActiveJob_LengthChanged; + _activeJobDbContext.LiquidTypesRmls.ToList(); - ActiveJob = _activeJob; + _activeJobDbContext.IdsPackFormulas.ToList(); + _activeJobDbContext.LiquidTypes.ToList(); + _activeJobDbContext.MidTankTypes.ToList(); + _activeJobDbContext.DispenserTypes.ToList(); - SelectedRML = _selectedRML; - SelectedSegment = _selectedSegment; + _activeJobDbContext.IdsPacks.Where(x => x.ConfigurationGuid == ActiveJob.Machine.ConfigurationGuid).ToList(); - UpdateEstimatedDuration(); - _blockInvalidateCommands = false; - InvalidateRelayCommands(); + + LogManager.Log("Setting selected segment..."); + _selectedSegment = ActiveJob.Segments.FirstOrDefault(); + + ActiveJob.LengthChanged -= ActiveJob_LengthChanged; + ActiveJob.LengthChanged += ActiveJob_LengthChanged; + + _selectedRML = ActiveJob.Rml; + InvalidateLiquidFactorsAndProcessTables(); + RaisePropertyChanged(nameof(SelectedRML)); + + UpdateEstimatedDuration(); + + _blockInvalidateCommands = false; + InvalidateRelayCommands(); + + _disable_gamut_check = false; + }); + + SegmentsCollectionView = CollectionViewSource.GetDefaultView(ActiveJob.Segments); + SegmentsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Segment.SegmentIndex), ListSortDirection.Ascending)); + + SelectedSegment = _selectedSegment; UIHelper.DoEvents(); _navigation.NavigateTo(DeveloperNavigationView.JobView); - } + + CanWork = true; } } /// /// Saves the active job. /// - private void SaveActiveJob() + private async void SaveActiveJob() { if (ActiveJob != null) { + CanWork = false; + using (_notification.PushTaskItem("Saving job details...")) { - LogManager.Log(String.Format("Saving the active job {0}...", ActiveJob.Name)); - ActiveJob.LastUpdated = DateTime.UtcNow; - ActiveJob.Rml = SelectedRML; - ActiveJob.EstimatedDurationMili = (int)EstimatedDuration.TotalMilliseconds; - - _activeJobDbContext.SaveChanges(); - ReloadMachine(); - SelectedMachineJob = SelectedMachine.Jobs.SingleOrDefault(x => x.Guid == ActiveJob.Guid); + await Task.Factory.StartNew(() => + { + LogManager.Log(String.Format("Saving the active job {0}...", ActiveJob.Name)); + ActiveJob.LastUpdated = DateTime.UtcNow; + ActiveJob.Rml = SelectedRML; + ActiveJob.EstimatedDurationMili = (int)EstimatedDuration.TotalMilliseconds; + _activeJobDbContext.SaveChanges(); + + _machineDbContext.Entry(SelectedMachineJob).Reload(); + + + _machineDbContext.Entry(SelectedMachineJob).Collection(x => x.Segments).Load(); + + foreach (var segment in SelectedMachineJob.Segments.ToList()) + { + _machineDbContext.Entry(segment).Collection(x => x.BrushStops).Load(); + + foreach (var brushStop in segment.BrushStops.ToList()) + { + _machineDbContext.Entry(brushStop).Reload(); + } + + _machineDbContext.Entry(segment).Reload(); + } + + InvokeUI(() => + { + SelectedMachineJob.Segments = SelectedMachineJob.Segments; + }); + + }); } + + CanWork = true; } } @@ -1527,19 +1635,51 @@ namespace Tango.MachineStudio.Developer.ViewModels #region Private Methods - private void ReloadMachine() + private async void LoadMachine() { - LogManager.Log("Reloading selected machine..."); - _machineDbContext.Dispose(); - _machineDbContext = ObservablesContext.CreateDefault(); - _machineDbContext.Configuration.LazyLoadingEnabled = true; - String machineGuid = _selectedMachine.Guid; - Machines = _machineDbContext.Machines.ToObservableCollection(); - _selectedMachine = Machines.SingleOrDefault(x => x.Guid == machineGuid); - RaisePropertyChanged(nameof(SelectedMachine)); + try + { + LogManager.Log("Loading selected machine..."); + + CanWork = false; + + using (_notification.PushTaskItem("Loading selected machine...")) + { + await _machineDbContext.Jobs.Where(x => x.MachineGuid == SelectedMachine.Guid).Include(x => x.User).Include(x => x.User.Contact).LoadAsync(); + await _machineDbContext.Configurations.SingleOrDefaultAsync(x => x.Guid == SelectedMachine.ConfigurationGuid); + + await _machineDbContext.ColorSpaces.LoadAsync(); + + SelectedMachine.Configuration.IdsPacks.EnableCrossThreadOperations(); + + await _machineDbContext.IdsPacks.OrderBy(x => x.PackIndex).Where(x => x.ConfigurationGuid == SelectedMachine.ConfigurationGuid). + Include(x => x.CartridgeType). + Include(x => x.DispenserType). + Include(x => x.LiquidType). + Include(x => x.IdsPackFormula). + Include(x => x.MidTankType).LoadAsync(); + + RaisePropertyChanged(nameof(SelectedMachine)); + + JobsCollectionView = CollectionViewSource.GetDefaultView(SelectedMachine.Jobs); + JobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); + } + + CanWork = true; - JobsCollectionView = CollectionViewSource.GetDefaultView(SelectedMachine.Jobs); - JobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); + foreach (var job in SelectedMachine.Jobs.OrderByDescending(x => x.LastUpdated)) + { + if (!CanWork) break; + job.Segments.EnableCrossThreadOperations(); + await _machineDbContext.Segments.Where(x => x.JobGuid == job.Guid).Include(x => x.BrushStops).OrderBy(x => x.SegmentIndex).LoadAsync(); + } + } + catch (Exception ex) + { + LogManager.Log(ex); + _notification.ShowError("An error occurred while trying to load the selected machine."); + CanWork = true; + } } private void UpdateEstimatedDuration() @@ -1557,7 +1697,7 @@ namespace Tango.MachineStudio.Developer.ViewModels LogManager.Log("Setting segment brush stops liquid volumes..."); foreach (var stop in segment.BrushStops) { - stop.SetLiquidVolumes(SelectedMachine.Configuration, SelectedRML, SelectedProcessParametersTable); + stop.SetLiquidVolumes(ActiveJob.Machine.Configuration, SelectedRML, SelectedProcessParametersTable); } } } @@ -1568,7 +1708,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 @@ -1713,14 +1852,15 @@ namespace Tango.MachineStudio.Developer.ViewModels newJob.Rml = _machineDbContext.Rmls.FirstOrDefault(); newJob.WindingMethod = _machineDbContext.WindingMethods.FirstOrDefault(); newJob.SpoolType = _machineDbContext.SpoolTypes.FirstOrDefault(); + newJob.ColorSpace = _machineDbContext.ColorSpaces.FirstOrDefault(); newJob.Machine = SelectedMachine; SelectedMachine.Jobs.Add(newJob); + newJob.AddSolidSegment(); LogManager.Log("Saving selected machine to database..."); await SelectedMachine.SaveAsync(_machineDbContext); SelectedMachineJob = newJob; LoadSelectedJob(); - AddSegment(); } } } @@ -1769,7 +1909,7 @@ namespace Tango.MachineStudio.Developer.ViewModels stop.OffsetPercent = 100; stop.Segment = SelectedSegment; - stop.ColorSpace = _activeJobDbContext.ColorSpaces.FirstOrDefault(); + stop.ColorSpace = ColorSpaces.FirstOrDefault(); stop.Color = Colors.Black; stop.SetLiquidVolumes(SelectedMachine.Configuration, SelectedRML, SelectedProcessParametersTable); SelectedSegment.BrushStops.Add(stop); @@ -1821,6 +1961,8 @@ namespace Tango.MachineStudio.Developer.ViewModels { using (_notification.PushTaskItem("Cloning selected jobs...")) { + CanWork = false; + LogManager.LogFormat("Duplicating {0} jobs...", SelectedJobs.Count); int index = SelectedMachine.Jobs.Max(x => x.JobIndex); @@ -1834,6 +1976,8 @@ namespace Tango.MachineStudio.Developer.ViewModels LogManager.Log("Saving selected machine to database..."); await SelectedMachine.SaveAsync(_machineDbContext); + + CanWork = true; } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml index 1b96b27ce..016718075 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml @@ -11,11 +11,9 @@ xmlns:hive="clr-namespace:Tango.Hive;assembly=Tango.Hive" xmlns:automation="clr-namespace:Tango.MachineStudio.Common.Automation;assembly=Tango.MachineStudio.Common" xmlns:sys="clr-namespace:System;assembly=mscorlib" - xmlns:techViews="clr-namespace:Tango.MachineStudio.Technician.Views;assembly=Tango.MachineStudio.Technician" xmlns:colorPicker="clr-namespace:Tango;assembly=Tango.ColorPicker" xmlns:dispensing="clr-namespace:Tango.BL.Dispensing;assembly=Tango.BL" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" - xmlns:db="clr-namespace:Tango.MachineStudio.DB.Views.DBViews;assembly=Tango.MachineStudio.DB" xmlns:commonControls="clr-namespace:Tango.MachineStudio.Common.Controls;assembly=Tango.MachineStudio.Common" xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:designer="clr-namespace:Tango.MachineStudio.MachineDesigner.Views;assembly=Tango.MachineStudio.MachineDesigner" @@ -1495,9 +1493,9 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs index bb17a502d..2942d36af 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs @@ -64,7 +64,7 @@ namespace Tango.MachineStudio.Developer.Views if (_vm != null && _vm.ActiveJob != null) { List segments = new List(); - foreach (var s in _vm.ActiveJob.Segments) + foreach (var s in _vm.ActiveJob.Segments.OrderBy(x => x.SegmentIndex)) { segments.Add(s); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MachineJobSelectionView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MachineJobSelectionView.xaml index c151b62bc..279a9daf3 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MachineJobSelectionView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MachineJobSelectionView.xaml @@ -6,6 +6,7 @@ xmlns:global="clr-namespace:Tango.MachineStudio.Developer" xmlns:designer="clr-namespace:Tango.MachineStudio.MachineDesigner.Views;assembly=Tango.MachineStudio.MachineDesigner" xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls" + xmlns:autoComplete="clr-namespace:Tango.AutoComplete.Editors;assembly=Tango.AutoComplete" xmlns:automation="clr-namespace:Tango.MachineStudio.Common.Automation;assembly=Tango.MachineStudio.Common" xmlns:localConverters="clr-namespace:Tango.MachineStudio.Developer.Converters" xmlns:vm="clr-namespace:Tango.MachineStudio.Developer.ViewModels" @@ -13,6 +14,7 @@ xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" xmlns:observables="clr-namespace:Tango.BL.Entities;assembly=Tango.BL" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:commonControls="clr-namespace:Tango.MachineStudio.Common.Controls;assembly=Tango.MachineStudio.Common" xmlns:local="clr-namespace:Tango.MachineStudio.Developer.Views" mc:Ignorable="d" x:Name="control" d:DesignHeight="1080" d:DesignWidth="1920" Background="Transparent" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> @@ -23,6 +25,7 @@ + @@ -36,20 +39,20 @@ TARGET MACHINE - + - - + + - - + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj index 8490800ad..e187db982 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj @@ -8,7 +8,7 @@ library Tango.MachineStudio.Technician Tango.MachineStudio.Technician - v4.6 + v4.7.2 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 @@ -31,6 +31,12 @@ 4 + + ..\..\..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.dll + + + ..\..\..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.SqlServer.dll + ..\..\..\packages\FontAwesome.WPF.4.7.0.9\lib\net40\FontAwesome.WPF.dll @@ -47,6 +53,7 @@ ..\..\..\packages\MaterialDesignThemes.2.3.1.953\lib\net45\MaterialDesignThemes.Wpf.dll + ..\..\..\packages\System.Reactive.Core.3.1.1\lib\net46\System.Reactive.Core.dll @@ -612,7 +619,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/BlowerItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/BlowerItem.cs index 59a96f107..6b532204e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/BlowerItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/BlowerItem.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Media; using System.Xml.Serialization; +using Tango.BL; using Tango.BL.Entities; using Tango.SharedUI.Helpers; @@ -31,7 +32,7 @@ namespace Tango.MachineStudio.Technician.TechItems { BlowerConfigurations = new List(); - foreach (var BlowerType in BL.ObservablesEntitiesAdapter.Instance.HardwareBlowerTypes) + foreach (var BlowerType in ObservablesStaticCollections.Instance.HardwareBlowerTypes) { BlowerConfigurations.Add(new HardwareBlower() { HardwareBlowerType = BlowerType }); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/BreakSensorItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/BreakSensorItem.cs index cf1ed682e..4a0d1c9c9 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/BreakSensorItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/BreakSensorItem.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Media; using System.Xml.Serialization; +using Tango.BL; using Tango.BL.Entities; using Tango.SharedUI.Helpers; @@ -31,7 +32,7 @@ namespace Tango.MachineStudio.Technician.TechItems { BreakSensorConfigurations = new List(); - foreach (var BreakSensorType in BL.ObservablesEntitiesAdapter.Instance.HardwareBreakSensorTypes) + foreach (var BreakSensorType in ObservablesStaticCollections.Instance.HardwareBreakSensorTypes) { BreakSensorConfigurations.Add(new HardwareBreakSensor() { HardwareBreakSensorType = BreakSensorType }); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/DancerItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/DancerItem.cs index e5651acce..1115c6dbf 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/DancerItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/DancerItem.cs @@ -33,7 +33,7 @@ namespace Tango.MachineStudio.Technician.TechItems { DancerConfigurations = new List(); - foreach (var winderType in BL.ObservablesEntitiesAdapter.Instance.HardwareDancerTypes) + foreach (var winderType in BL.ObservablesStaticCollections.Instance.HardwareDancerTypes) { DancerConfigurations.Add(new HardwareDancer() { HardwareDancerType = winderType }); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/DispenserItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/DispenserItem.cs index f058036d0..7945c5b73 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/DispenserItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/DispenserItem.cs @@ -37,7 +37,7 @@ namespace Tango.MachineStudio.Technician.TechItems { DispenserTypes = new List(); - foreach (var techDispenser in BL.ObservablesEntitiesAdapter.Instance.TechDispensers) + foreach (var techDispenser in BL.ObservablesStaticCollections.Instance.TechDispensers) { DispenserTypes.Add(new DispenserType() { Code = int.Parse(techDispenser.Name.Replace("Dispenser", "")) - 1 }); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/JobRunnerItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/JobRunnerItem.cs index 8d102d6c0..3443c008e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/JobRunnerItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/JobRunnerItem.cs @@ -160,6 +160,7 @@ namespace Tango.MachineStudio.Technician.TechItems { Job.Machine = Machine; Job.Rml = Rml; + BrushStop.SetLiquidVolumes(Machine.Configuration, Rml, ProcessParameters); } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MotorGroupItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MotorGroupItem.cs index 5cdb8017e..a5288e6bc 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MotorGroupItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MotorGroupItem.cs @@ -59,7 +59,7 @@ namespace Tango.MachineStudio.Technician.TechItems { if (TechMotors != null) { - SelectedMotors = new SelectedObjectCollection(ObservablesEntitiesAdapter.Instance.HardwareMotorTypes.ToObservableCollection(), TechMotors); + SelectedMotors = new SelectedObjectCollection(ObservablesStaticCollections.Instance.HardwareMotorTypes.ToObservableCollection(), TechMotors); } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MotorItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MotorItem.cs index 779919039..c097a0b7b 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MotorItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MotorItem.cs @@ -38,7 +38,7 @@ namespace Tango.MachineStudio.Technician.TechItems { MotorConfigurations = new List(); - foreach (var motorType in BL.ObservablesEntitiesAdapter.Instance.HardwareMotorTypes) + foreach (var motorType in BL.ObservablesStaticCollections.Instance.HardwareMotorTypes) { MotorConfigurations.Add(new HardwareMotor() { HardwareMotorType = motorType }); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/PidItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/PidItem.cs index a56c3b0c1..70ecc1a70 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/PidItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/PidItem.cs @@ -33,7 +33,7 @@ namespace Tango.MachineStudio.Technician.TechItems { PidConfigurations = new List(); - foreach (var pidType in BL.ObservablesEntitiesAdapter.Instance.HardwarePidControlTypes) + foreach (var pidType in BL.ObservablesStaticCollections.Instance.HardwarePidControlTypes) { PidConfigurations.Add(new HardwarePidControl() { HardwarePidControlType = pidType }); } 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 79aea7a0c..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 @@ -6,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Media; using System.Xml.Serialization; +using Tango.BL; using Tango.BL.Entities; using Tango.Core.Commands; using Tango.SharedUI.Helpers; @@ -93,7 +94,9 @@ namespace Tango.MachineStudio.Technician.TechItems if (_counter > 1) { + String name = ProcessParameters.Name; ProcessParametersTables.Add(ProcessParameters); + ProcessParameters.Name = name; } } @@ -101,15 +104,18 @@ namespace Tango.MachineStudio.Technician.TechItems { if (SelectedResetRML != null) { - var group = SelectedResetRML.ProcessParametersTablesGroups.FirstOrDefault(x => x.Active); - - if (group != null) + using (ObservablesContext db = ObservablesContext.CreateDefault()) { - var table = group.ProcessParametersTables.OrderBy(x => x.TableIndex).FirstOrDefault(); + var group = db.Adapter.GetRmlActiveProcessParametersTablesGroup(SelectedResetRML.Guid); - if (table != null) + if (group != null) { - ProcessParameters = table.Clone(); + var table = group.ProcessParametersTables.OrderBy(x => x.TableIndex).FirstOrDefault(); + + if (table != null) + { + table.MapPrimitivesTo(ProcessParameters); + } } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/SpeedSensorItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/SpeedSensorItem.cs index a067ec95f..e43a518c1 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/SpeedSensorItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/SpeedSensorItem.cs @@ -33,7 +33,7 @@ namespace Tango.MachineStudio.Technician.TechItems { SpeedSensorConfigurations = new List(); - foreach (var SpeedSensorType in BL.ObservablesEntitiesAdapter.Instance.HardwareSpeedSensorTypes) + foreach (var SpeedSensorType in BL.ObservablesStaticCollections.Instance.HardwareSpeedSensorTypes) { SpeedSensorConfigurations.Add(new HardwareSpeedSensor() { HardwareSpeedSensorType = SpeedSensorType }); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/TechItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/TechItem.cs index 11188c69d..b6ebf2857 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/TechItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/TechItem.cs @@ -47,7 +47,7 @@ namespace Tango.MachineStudio.Technician.TechItems { ID = Guid.NewGuid().ToString(); Name = "Untitled"; - Adapter = ObservablesEntitiesAdapter.Instance; + Adapter = ObservablesStaticCollections.Instance; _color = Colors.DodgerBlue; } @@ -77,7 +77,7 @@ namespace Tango.MachineStudio.Technician.TechItems /// Gets or sets the db adapter. /// [XmlIgnore] - public ObservablesEntitiesAdapter Adapter { get; set; } + public ObservablesStaticCollections Adapter { get; set; } private String _id; /// diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/WinderItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/WinderItem.cs index 425baf471..2df2d7ad7 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/WinderItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/WinderItem.cs @@ -33,7 +33,7 @@ namespace Tango.MachineStudio.Technician.TechItems { WinderConfigurations = new List(); - foreach (var winderType in BL.ObservablesEntitiesAdapter.Instance.HardwareWinderTypes) + foreach (var winderType in BL.ObservablesStaticCollections.Instance.HardwareWinderTypes) { WinderConfigurations.Add(new HardwareWinder() { HardwareWinderType = winderType }); } 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..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 @@ -41,7 +41,7 @@ namespace Tango.MachineStudio.Technician.ViewModels /// /// /// - public class MachineTechViewVM : StudioViewModel + public class MachineTechViewVM : StudioViewModel { private List _diagnoticsMonitorsDataProperties; private IDiagnosticsFrameProvider _diagnosticsFrameProvider; @@ -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); @@ -1572,6 +1572,11 @@ namespace Tango.MachineStudio.Technician.ViewModels }); } + public override void OnApplicationReady() + { + + } + #endregion #region Hardware Configuration @@ -1666,83 +1671,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.Adapter.GetConfiguration(x => x.Guid == ApplicationManager.ConnectedMachine.Machine.ConfigurationGuid).Clone(); + hw = db.Adapter.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 +1768,19 @@ 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(); + ObservablesContextAdapter adapter = new ObservablesContextAdapter(db); + + HardwareVersion hw = null; + + await Task.Factory.StartNew(() => + { + hw = adapter.GetHardwareVersionByMachine(ApplicationManager.ConnectedMachine.Machine.Guid); + }); foreach (var motorConfig in hw.HardwareMotors) { 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.Technician/app.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/app.config index 5d794b958..77b7003e2 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/app.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/app.config @@ -1,5 +1,9 @@  + + +
+ @@ -48,4 +52,10 @@ + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/packages.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/packages.config index 49b90c865..ea48e62ff 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/packages.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/packages.config @@ -1,6 +1,7 @@  + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Properties/AssemblyInfo.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Properties/AssemblyInfo.cs index 45b3ef1ce..995336499 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Properties/AssemblyInfo.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Properties/AssemblyInfo.cs @@ -5,7 +5,7 @@ using System.Runtime.InteropServices; using System.Windows; [assembly: AssemblyTitle("Tango - Machine Studio Users & Roles Module")] -[assembly: AssemblyVersion("2.0.7.1633")] +[assembly: AssemblyVersion("2.0.8.1119")] [assembly: ComVisible(false)] diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Tango.MachineStudio.UsersAndRoles.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Tango.MachineStudio.UsersAndRoles.csproj index 48fe2b34c..539f10574 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Tango.MachineStudio.UsersAndRoles.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Tango.MachineStudio.UsersAndRoles.csproj @@ -8,7 +8,7 @@ library Tango.MachineStudio.UsersAndRoles Tango.MachineStudio.UsersAndRoles - v4.6 + v4.7.2 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 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 7d82cbbbc..db312b78f 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 @@ -8,14 +8,16 @@ using System.Threading.Tasks; using Tango.BL; using Tango.BL.Entities; using Tango.Core.Commands; +using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.UsersAndRoles.Navigation; using Tango.MachineStudio.UsersAndRoles.Providers; using Tango.SharedUI; +using System.Data.Entity; namespace Tango.MachineStudio.UsersAndRoles.ViewModels { - public class MainViewVM : ViewModel + public class MainViewVM : StudioViewModel { private ObservablesContext _organizationsContext; private ObservablesContext _manageContext; @@ -129,8 +131,6 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels _navigation = navigation; _notification = notification; - LoadOrganizations(); - ManageOrganizationCommand = new RelayCommand(LoadSelectedOrganization, () => SelectedOrganization != null); BackToOrganizationsCommand = new RelayCommand(BackToOrganizations); ManageUserCommand = new RelayCommand(LoadSelectedUser, () => SelectedUser != null); @@ -144,6 +144,11 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels RemoveUserCommand = new RelayCommand(RemoveSelectedUser, () => SelectedUser != null); } + public override void OnApplicationReady() + { + LoadOrganizations(); + } + private async void AddOrganization() { String name = _notification.ShowTextInput("Enter organization name", "Name"); @@ -187,19 +192,20 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels } } - private void LoadSelectedUser() + private async void LoadSelectedUser() { using (_notification.PushTaskItem("Loading user details...")) { - Task.Factory.StartNew(() => + await Task.Factory.StartNew(() => { _userContext = ObservablesContext.CreateDefault(); + Roles = _userContext.Roles.ToObservableCollection(); - ManagedUser = _userContext.Users.SingleOrDefault(x => x.Guid == SelectedUser.Guid); + ManagedUser = _userContext.Adapter.GetUser(SelectedUser.Guid); ManagedUserRoles = ManagedUser.Roles.ToObservableCollection(); - - InvokeUI(() => _navigation.NavigateTo(UsersAndRolesNavigationView.UserManagementView)); }); + + _navigation.NavigateTo(UsersAndRolesNavigationView.UserManagementView); } } @@ -242,31 +248,35 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels } } - private void LoadSelectedOrganization() + private async void LoadSelectedOrganization() { using (_notification.PushTaskItem("Loading organization...")) { - Task.Factory.StartNew(() => + await Task.Factory.StartNew(() => { _manageContext = ObservablesContext.CreateDefault(); - ManagedOrganization = _manageContext.Organizations.SingleOrDefault(x => x.Guid == SelectedOrganization.Guid); - InvokeUI(() => _navigation.NavigateTo(UsersAndRolesNavigationView.OrganizationManagementView)); + ManagedOrganization = _manageContext.Adapter.GetOrganizationAndUsers(SelectedOrganization.Guid); }); + + _navigation.NavigateTo(UsersAndRolesNavigationView.OrganizationManagementView); } } private void LoadOrganizations() { - _organizationsContext = ObservablesContext.CreateDefault(); - _organizationsContext.Configuration.LazyLoadingEnabled = false; - - _organizationsContext.Users.ToList(); - _organizationsContext.Contacts.ToList(); - _organizationsContext.Addresses.ToList(); - _organizationsContext.Machines.ToList(); - - Organizations = _organizationsContext.Organizations.ToObservableCollection(); + Task.Factory.StartNew(() => + { + _organizationsContext = ObservablesContext.CreateDefault(); + + Organizations = _organizationsContext.Organizations + .Include(x => x.Machines) + .Include(x => x.Users) + .Include(x => x.Users.Select(y => y.Contact)) + .Include(x => x.Users.Select(y => y.Address)) + .Include(x => x.Address) + .ToObservableCollection(); + }); } public void OnDropRole(Role role) diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/AutoComplete/MachinesProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/AutoComplete/MachinesProvider.cs index e486ec79a..ec23fefee 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/AutoComplete/MachinesProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/AutoComplete/MachinesProvider.cs @@ -23,7 +23,7 @@ namespace Tango.MachineStudio.Common.AutoComplete /// public IEnumerable GetSuggestions(string filter) { - return ObservablesEntitiesAdapter.Instance.Machines.Where(x => x.SerialNumber.StartsWith(filter, StringComparison.CurrentCultureIgnoreCase) || x.Name.ToLower().Contains(filter.ToLower())).ToList(); + return ObservablesStaticCollections.Instance.Machines.Where(x => x.SerialNumber.StartsWith(filter, StringComparison.CurrentCultureIgnoreCase) || x.Name.ToLower().Contains(filter.ToLower())).ToList(); } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/LoadingPanel.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/LoadingPanel.cs new file mode 100644 index 000000000..665d6995b --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/LoadingPanel.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.MachineStudio.Common.Controls +{ + public class LoadingPanel : ContentControl + { + + + public bool IsLoading + { + get { return (bool)GetValue(IsLoadingProperty); } + set { SetValue(IsLoadingProperty, value); } + } + public static readonly DependencyProperty IsLoadingProperty = + DependencyProperty.Register("IsLoading", typeof(bool), typeof(LoadingPanel), new PropertyMetadata(false)); + + + + static LoadingPanel() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(LoadingPanel), new FrameworkPropertyMetadata(typeof(LoadingPanel))); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs index c5b9c63cb..cb4611cad 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs @@ -81,7 +81,6 @@ namespace Tango.MachineStudio.Common.EventLogging try { _db = ObservablesContext.CreateDefault(); - _db.Configuration.LazyLoadingEnabled = false; _db.ActionTypes.ToList(); _db.EventTypesActions.ToList(); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/IStudioViewModel.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/IStudioViewModel.cs index 4203a1e8b..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. /// @@ -34,14 +25,13 @@ namespace Tango.MachineStudio.Common Task OnShutdownRequest(); /// - /// Called when another module has wants to navigate to this module with some arguments. + /// Called when the application has been started /// - /// The arguments. - void OnModuleRequest(params object[] args); + void OnApplicationStarted(); /// - /// Called when the application has been started + /// Called when the application is ready and all modules are loaded. /// - void OnApplicationStarted(); + void OnApplicationReady(); } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Modules/IStudioModuleLoader.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Modules/IStudioModuleLoader.cs index 1fd72c53a..990300143 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Modules/IStudioModuleLoader.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Modules/IStudioModuleLoader.cs @@ -12,6 +12,11 @@ namespace Tango.MachineStudio.Common.Modules ///
public interface IStudioModuleLoader { + /// + /// Occurs when all modules are initialized. + /// + event EventHandler ModulesLoaded; + /// /// Gets all loaded modules. /// 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/Properties/AssemblyInfo.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Properties/AssemblyInfo.cs index 4b671e2e1..ccb580abf 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Properties/AssemblyInfo.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Properties/AssemblyInfo.cs @@ -5,7 +5,7 @@ using System.Runtime.InteropServices; using System.Windows; [assembly: AssemblyTitle("Tango - Machine Studio Common Components")] -[assembly: AssemblyVersion("2.0.24.1647")] +[assembly: AssemblyVersion("2.0.25.1119")] [assembly: ComVisible(false)] [assembly:ThemeInfo( diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml index 07818269b..6fcf6dd72 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml @@ -3,6 +3,7 @@ xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters;assembly=MaterialDesignThemes.Wpf" xmlns:editors="clr-namespace:Tango.AutoComplete.Editors;assembly=Tango.AutoComplete" xmlns:dragAndDrop="clr-namespace:Tango.DragAndDrop;assembly=Tango.DragAndDrop" + xmlns:sharedConverters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" xmlns:mahApps="http://metro.mahapps.com/winfx/xaml/controls" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:local="clr-namespace:Tango.MachineStudio.Common.Resources"> 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 07f02df3a..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. /// @@ -77,5 +70,10 @@ namespace Tango.MachineStudio.Common.StudioApplication ///
/// The window. void RegisterOpenedWindow(Window window); + + /// + /// Raises the application ready event. + /// + void NotifyApplicationReady(); } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioViewModel.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioViewModel.cs index 96715dc20..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,51 +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; } - + private bool _isVisible; /// - /// Initializes a new instance of the class. + /// Gets or sets a value indicating whether this view model view's is visible. /// - public StudioViewModelInternal() : base() + public bool IsVisible { - + get { return _isVisible; } + set { _isVisible = value; RaisePropertyChangedAuto(); } } /// - /// 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; } /// @@ -82,153 +74,42 @@ namespace Tango.MachineStudio.Common { } - } - - /// - /// 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; } - - /// - /// Initializes a new instance of the class. - /// - public StudioViewModel() : base() - { - - } - - /// - /// Called when another module has wants to navigate to this module with some arguments. - /// - /// The arguments. - public virtual void OnModuleRequest(params object[] args) - { - - } /// - /// Called when the user has navigated out of the module. - /// - public virtual void OnNavigatedFrom() - { - IsVisible = false; - IsModuleLoaded = false; - } - - /// - /// 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. + /// Called when the application is ready and all modules are loaded. /// - public virtual void OnShuttingDown() - { - - } - - /// - /// Called when the application has been started - /// - public virtual void OnApplicationStarted() - { - - } + 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 { /// - /// Initializes a new instance of the class. + /// Gets the view model's view. /// - /// The view. - public StudioViewModel(T view) : base(view) - { - - } - - /// - /// Called when the application has been started - /// - public virtual void OnApplicationStarted() - { - - } + public TView View { 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) - { - - } - - /// - /// Called when the user has navigated out of the module. - /// - public virtual void OnNavigatedFrom() - { - - } - - /// - /// Called when the user has navigated in to the module. - /// - 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() + public StudioViewModel() : base() { - return Task.FromResult(true); + TangoIOC.Default.GetInstanceWhenAvailable((view) => + { + View = view; + OnViewAttached(view); + }); } /// - /// Called when application is shutting down. + /// Called when the view has been attached /// - 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 6d6803076..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 @@ -8,7 +8,7 @@ library Tango.MachineStudio.Common Tango.MachineStudio.Common - v4.6 + v4.7.2 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 @@ -85,6 +85,7 @@ HiveComboControl.xaml + RealTimeGraphMultiControl.xaml @@ -105,6 +106,9 @@ + + + @@ -114,6 +118,7 @@ + @@ -163,6 +168,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + @@ -287,9 +296,7 @@ True - - - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Themes/Generic.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Themes/Generic.xaml new file mode 100644 index 000000000..9cc398753 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Themes/Generic.xaml @@ -0,0 +1,31 @@ + + + + + + + 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.Common/app.config b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/app.config index 77b7003e2..0e58ccf54 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/app.config +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/app.config @@ -50,6 +50,10 @@ + + + + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher/App.config b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher/App.config index 209c9be3f..156c5f7e1 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher/App.config +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher/App.config @@ -49,6 +49,14 @@ + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher/Tango.MachineStudio.Publisher.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher/Tango.MachineStudio.Publisher.csproj index e86b3ddf0..f9f337b70 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher/Tango.MachineStudio.Publisher.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher/Tango.MachineStudio.Publisher.csproj @@ -8,7 +8,7 @@ WinExe Tango.MachineStudio.Publisher Tango.MachineStudio.Publisher - v4.6 + v4.7.2 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.config b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.config index 004400788..4147a78ec 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.config +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.config @@ -39,7 +39,7 @@ - + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs index ed2cbdbd7..4e1c36593 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs @@ -37,9 +37,20 @@ namespace Tango.MachineStudio.UI { #if DEBUG - CoreSettings.DefaultDataBaseSource = "localhost\\SQLEXPRESS"; + CoreSettings.DefaultDataSource = new DataSource() + { + Address = "localhost\\SQLEXPRESS", + Catalog = "Tango", + IntegratedSecurity = true, + }; #else - CoreSettings.DefaultDataBaseSource = "twine01\\SQLTWINE"; + + CoreSettings.DefaultDataSource = new DataSource() + { + Address = "twine01\\SQLTWINE", + Catalog = "Tango", + IntegratedSecurity = true, + }; #endif diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs index 4e5425138..c16f76449 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs @@ -9,6 +9,7 @@ using Tango.BL.Entities; using Tango.MachineStudio.Common.Authentication; using Tango.BL; using Tango.BL.Enumerations; +using System.Data.Entity; namespace Tango.MachineStudio.UI.Authentication { @@ -48,32 +49,38 @@ namespace Tango.MachineStudio.UI.Authentication /// Login failed for user " + email public User Login(string email, string password) { - String hash = User.GetPasswordHash(password); + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { - User user = ObservablesEntitiesAdapter.Instance.Users.SingleOrDefault(x => x.Email.ToLower() == email.ToLower() && x.Password == hash); + String hash = User.GetPasswordHash(password); - if (user == null) - { - throw new AuthenticationException("Invalid credentials for " + email); - } + db.Roles.Load(); + db.Permissions.Load(); + db.RolesPermissions.Load(); - if (!user.HasPermission(Permissions.RunMachineStudio)) - { - throw new AuthenticationException("It seems like you do not have sufficient privileges to run Machine Studio. Please contact your administrator."); - } + User user = db.Users + .Include(x => x.UsersRoles) + .Include(x => x.Organization).SingleOrDefault(x => x.Email.ToLower() == email.ToLower() && x.Password == hash); - if (user != null) - { - using (ObservablesContext db = ObservablesContext.CreateDefault()) + if (user == null) + { + throw new AuthenticationException("Invalid credentials for " + email); + } + + if (!user.HasPermission(Permissions.RunMachineStudio)) { - var u = db.Users.Single(x => x.Guid == user.Guid); - u.LastLogin = DateTime.UtcNow; + throw new AuthenticationException("It seems like you do not have sufficient privileges to run Machine Studio. Please contact your administrator."); + } + + if (user != null) + { + user.LastLogin = DateTime.UtcNow; db.SaveChanges(); } - } - CurrentUser = user; - return user; + CurrentUser = user; + return user; + } } /// 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/Modules/DefaultStudioModuleLoader.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs index 26a789d0f..13c3d6779 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs @@ -12,9 +12,6 @@ using Tango.Logging; using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.Authentication; using Tango.MachineStudio.Common.Modules; -using Tango.MachineStudio.DB; -using Tango.MachineStudio.MachineDesigner; -using Tango.MachineStudio.Stubs; namespace Tango.MachineStudio.UI.Modules { @@ -27,7 +24,6 @@ namespace Tango.MachineStudio.UI.Modules { private IAuthenticationProvider _authenticationProvider; private bool _loaded; - public event EventHandler ModulesLoaded; /// /// Initializes a new instance of the class. @@ -78,15 +74,15 @@ namespace Tango.MachineStudio.UI.Modules { if (!_loaded) { - //Preloaded + ////Preloaded - LogManager.Log(String.Format("Loading module '{0}'...", nameof(StubsModule))); - AllModules.Add(new StubsModule()); - LogManager.Log(String.Format("Loading module '{0}'...", nameof(DBModule))); - AllModules.Add(new DBModule()); - LogManager.Log(String.Format("Loading module '{0}'...", nameof(MachineDesignerModule))); - AllModules.Add(new MachineDesignerModule()); - //Preloaded + //LogManager.Log(String.Format("Loading module '{0}'...", nameof(StubsModule))); + //AllModules.Add(new StubsModule()); + //LogManager.Log(String.Format("Loading module '{0}'...", nameof(DBModule))); + //AllModules.Add(new DBModule()); + //LogManager.Log(String.Format("Loading module '{0}'...", nameof(MachineDesignerModule))); + //AllModules.Add(new MachineDesignerModule()); + ////Preloaded AllModules.Clear(); string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); @@ -146,5 +142,10 @@ namespace Tango.MachineStudio.UI.Modules { return UserModules.OfType().FirstOrDefault(); } + + /// + /// Occurs when all modules are initialized. + /// + public event EventHandler ModulesLoaded; } } 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/Properties/AssemblyInfo.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Properties/AssemblyInfo.cs index 822e551c1..3e03d33f8 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Properties/AssemblyInfo.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Properties/AssemblyInfo.cs @@ -4,5 +4,5 @@ using System.Runtime.InteropServices; [assembly: System.Windows.ThemeInfo(System.Windows.ResourceDictionaryLocation.None, System.Windows.ResourceDictionaryLocation.SourceAssembly)] [assembly: AssemblyTitle("Tango - Machine Studio")] -[assembly: AssemblyVersion("2.8.22.18226")] +[assembly: AssemblyVersion("3.0.25.18235")] [assembly: ComVisible(false)] \ No newline at end of file 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 ee9337eb3..7c7e18276 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs @@ -43,21 +43,10 @@ namespace Tango.MachineStudio.UI.StudioApplication _navigationManager = navigationManager; _openedWindows = new List(); - Task.Factory.StartNew(() => + Application.Current.MainWindow.ContentRendered += (_, __) => { - while (MainWindow.Instance == null) - { - Thread.Sleep(100); - } - - InvokeUI(() => - { - MainWindow.Instance.ContentRendered += (_, __) => - { - TangoIOC.Default.GetAllInstancesByBase().ToList().ForEach(x => x.OnApplicationStarted()); - }; - }); - }); + TangoIOC.Default.GetAllInstancesByBase().ToList().ForEach(x => x.OnApplicationStarted()); + }; } /// @@ -236,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. @@ -305,5 +269,10 @@ namespace Tango.MachineStudio.UI.StudioApplication return EmbeddedResourceHelper.GetEmbeddedResourceText("Tango.MachineStudio.UI.ChangeLog.txt"); } } + + public void NotifyApplicationReady() + { + TangoIOC.Default.GetAllInstancesByBase().ToList().ForEach(x => x.OnApplicationReady()); + } } } 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 724f83680..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 @@ -8,7 +8,7 @@ WinExe Tango.MachineStudio.UI Tango.MachineStudio.UI - v4.6 + v4.7.2 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 @@ -168,6 +168,7 @@ + @@ -432,10 +433,6 @@ {22c2aa72-9493-4d0d-b421-8ef9789fb192} Tango.MachineStudio.Stubs - - {12d0c43c-391f-4c74-92ab-82e9a9beeb9b} - Tango.MachineStudio.Synchronization - {5d39c1e1-3ecd-4634-bd1b-2bcf71c54a15} Tango.MachineStudio.Technician @@ -577,7 +574,7 @@ copy /Y "$(SolutionDir)Referenced Assemblies\vcruntime140d.dll" "$(TargetDir)" - + \ No newline at end of file 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 a468dc2e7..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; @@ -141,7 +141,7 @@ namespace Tango.MachineStudio.UI.ViewModels Status = "Loading, please wait..."; - ObservablesEntitiesAdapter.Instance.Initialize(); + ObservablesStaticCollections.Instance.Initialize(); _eventLogger.Log(EventTypes.ApplicationStarted, "Application Started!"); @@ -172,5 +172,10 @@ namespace Tango.MachineStudio.UI.ViewModels } }); } + + public override void OnApplicationReady() + { + + } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs index f2a4f1143..a37879a5e 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs @@ -51,6 +51,15 @@ namespace Tango.MachineStudio.UI.ViewModels set { _password = value; RaisePropertyChangedAuto(); } } + private bool _isLogging; + /// + /// Gets or sets a value indicating whether this instance is logging. + /// + public bool IsLogging + { + get { return _isLogging; } + set { _isLogging = value; RaisePropertyChangedAuto(); } + } private bool _rememberMe; /// @@ -81,7 +90,7 @@ namespace Tango.MachineStudio.UI.ViewModels _navigationManager = navigationManager; _authenticationProvider = authenticationProvider; _eventLogger = eventLogger; - LoginCommand = new RelayCommand(Login); + LoginCommand = new RelayCommand(Login,() => !IsLogging); cryptographer = new Rfc2898Cryptographer(); Email = _settings.LastLoginEmail; @@ -100,26 +109,38 @@ namespace Tango.MachineStudio.UI.ViewModels /// /// Logins the requested user. /// - private void Login() + private async void Login() { if (Validate()) { try { - _authenticationProvider.Login(Email, Password); - _navigationManager.NavigateTo(NavigationView.MainView); - _settings.LastLoginEmail = Email; - _settings.RememberMe = RememberMe; + IsLogging = true; + InvalidateRelayCommands(); - _settings.LastLoginPassword = RememberMe ? cryptographer.Encrypt(Password) : null; - _settings.Save(); + await Task.Factory.StartNew(() => + { + _authenticationProvider.Login(Email, Password); + _navigationManager.NavigateTo(NavigationView.MainView); + _settings.LastLoginEmail = Email; + _settings.RememberMe = RememberMe; - _eventLogger.Log("User logged in"); + _settings.LastLoginPassword = RememberMe ? cryptographer.Encrypt(Password) : null; + _settings.Save(); + + _eventLogger.Log("User logged in"); + }); } - catch + catch (Exception) { + _notificationProvider.ShowError("Invalid credentials. Please try again."); } + finally + { + IsLogging = false; + InvalidateRelayCommands(); + } } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineSerialViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineSerialViewVM.cs index 44cfc6788..db32fe623 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineSerialViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineSerialViewVM.cs @@ -29,7 +29,7 @@ namespace Tango.MachineStudio.UI.ViewModels var settings = SettingsManager.Default.GetOrCreate(); - SelectedMachine = ObservablesEntitiesAdapter.Instance.Machines.SingleOrDefault(x => x.SerialNumber == settings.LastVirtualMachineSerialNumber); + SelectedMachine = ObservablesStaticCollections.Instance.Machines.SingleOrDefault(x => x.SerialNumber == settings.LastVirtualMachineSerialNumber); } } } 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 f8320e1f2..f164d7f14 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Media; +using Tango.BL; using Tango.BL.Entities; using Tango.Core.Commands; using Tango.Core.DI; @@ -547,8 +548,13 @@ namespace Tango.MachineStudio.UI.ViewModels { try { - var configuration = ApplicationManager.ConnectedMachine.Machine.Configuration; - await ApplicationManager.ConnectedMachine.UploadHardwareConfiguration(configuration.HardwareVersion, configuration); + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + 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); + } NotificationProvider.ShowInfo("Hardware configuration uploaded successfully."); } catch (Exception ex) @@ -623,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) @@ -646,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"); } } @@ -674,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); @@ -694,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; @@ -702,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/ViewModels/UpdateViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs index f2550c598..6dbc99591 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs @@ -294,6 +294,9 @@ namespace Tango.MachineStudio.UI.ViewModels } } + //Copy new updater utility to app path. + File.Copy(Path.Combine(_newPackageTempFolder, "Tango.MachineStudio.Updater.exe"), Path.Combine(_appPath, "Tango.MachineStudio.Updater.exe"), true); + TangoIOC.Default.GetInstance().DisableCheckForUpdates = true; Status = UpdateStatus.UpdateCompleted; } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoginView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoginView.xaml index 08e1006c1..68334ad24 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoginView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/LoginView.xaml @@ -5,7 +5,9 @@ xmlns:rules="clr-namespace:Tango.MachineStudio.Common.ValidationRules;assembly=Tango.MachineStudio.Common" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls" xmlns:automation="clr-namespace:Tango.MachineStudio.Common.Automation;assembly=Tango.MachineStudio.Common" + xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" xmlns:helpers="clr-namespace:Tango.SharedUI.Helpers;assembly=Tango.SharedUI" xmlns:local="clr-namespace:Tango.MachineStudio.UI.Views" mc:Ignorable="d" @@ -13,6 +15,8 @@ + + @@ -24,21 +28,30 @@ Machine Studio - - Login to your account - - - - - - - - - - Remember me - - + + + + + Login to your account + + + + + + + + + + Remember me + + + + + Logging you in... + + + 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 7044ad32e..9a494f862 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml @@ -12,7 +12,6 @@ xmlns:entities="clr-namespace:Tango.BL.Entities;assembly=Tango.BL" xmlns:enumerations="clr-namespace:Tango.BL.Enumerations;assembly=Tango.BL" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" - xmlns:db="clr-namespace:Tango.MachineStudio.DB.Views;assembly=Tango.MachineStudio.DB" xmlns:local="clr-namespace:Tango.MachineStudio.UI.Views" xmlns:commonConverters="clr-namespace:Tango.MachineStudio.Common.Converters;assembly=Tango.MachineStudio.Common" mc:Ignorable="d" @@ -398,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 1e894f3f2..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 @@ -27,6 +27,7 @@ using Tango.SharedUI.Helpers; using Tango.Logging; using static Tango.SharedUI.Controls.NavigationControl; using Tango.Core.DI; +using Tango.MachineStudio.Common.StudioApplication; namespace Tango.MachineStudio.UI.Views { @@ -37,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; } @@ -68,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); @@ -84,6 +89,11 @@ namespace Tango.MachineStudio.UI.Views } item.Pop(); + + ThreadsHelper.InvokeUI(() => + { + TangoIOC.Default.GetInstance().NotifyApplicationReady(); + }); }); } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UpdateService/Tango.MachineStudio.UpdateService.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UpdateService/Tango.MachineStudio.UpdateService.csproj index 8e9d60541..b2200895c 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UpdateService/Tango.MachineStudio.UpdateService.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UpdateService/Tango.MachineStudio.UpdateService.csproj @@ -12,7 +12,7 @@ Properties Tango.MachineStudio.UpdateService Tango.MachineStudio.UpdateService - v4.6 + v4.7.2 True true true diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UpdateService/Web.config b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UpdateService/Web.config index 6fd5e637f..32a2460df 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UpdateService/Web.config +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UpdateService/Web.config @@ -1,4 +1,4 @@ - + @@ -27,8 +27,7 @@ - + @@ -106,6 +105,10 @@ + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/MainWindow.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/MainWindow.xaml.cs index a0c6928d2..4e6a8ad63 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/MainWindow.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/MainWindow.xaml.cs @@ -47,6 +47,7 @@ namespace Tango.MachineStudio.Updater private void Update() { EnsureMachineStudioIsDown(); + RemoveOldDLLFiles(); ReplaceFiles(); StartMachineStudio(); Environment.Exit(0); @@ -65,6 +66,18 @@ namespace Tango.MachineStudio.Updater p.Start(); } + private void RemoveOldDLLFiles() + { + foreach (string dll in Directory.GetFiles(_appPath, "*.dll")) + { + try + { + File.Delete(dll); + } + catch { } + } + } + private void ReplaceFiles() { int maxProgress = Directory.GetFiles(_sourceFolder, "*.*", SearchOption.AllDirectories).Length; @@ -133,9 +146,6 @@ namespace Tango.MachineStudio.Updater } while (appProcess != null); } - /// - /// Forces UI rendering. - /// private void DoEvents() { Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { })); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Tango.MachineStudio.Updater.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Tango.MachineStudio.Updater.csproj index db6fcb52f..241085122 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Tango.MachineStudio.Updater.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Tango.MachineStudio.Updater.csproj @@ -8,7 +8,7 @@ WinExe Tango.MachineStudio.Updater Tango.MachineStudio.Updater - v4.6 + v4.7.2 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 -- cgit v1.3.1