From f0588aa546e9497b0f6def56e8b3b1756d30fbfb Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 21 Aug 2018 15:49:10 +0300 Subject: Machine designer working good ! --- .../ViewModels/MachineVersionDialogVM.cs | 4 +- .../ViewModels/MainViewVM.cs | 272 +++++++++++++++------ 2 files changed, 204 insertions(+), 72 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineVersionDialogVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineVersionDialogVM.cs index 40358344d..b332ebc6b 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineVersionDialogVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineVersionDialogVM.cs @@ -14,7 +14,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { public class MachineVersionDialogVM : DialogViewVM { - public ObservablesEntitiesAdapter Adapter { get; set; } + public ObservablesStaticCollections Adapter { get; set; } public double Version { get; set; } @@ -46,7 +46,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels public MachineVersionDialogVM() { - Adapter = ObservablesEntitiesAdapter.Instance; + Adapter = ObservablesStaticCollections.Instance; AcceptCommand = new RelayCommand(() => { Accept(); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs index 1f410d49c..a819a4d1a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs @@ -16,27 +16,39 @@ using SimpleValidator.Extensions; using Tango.MachineStudio.Common.StudioApplication; using Tango.MachineStudio.Common; using Tango.BL; +using Tango.AutoComplete.Editors; +using System.Data.Entity; namespace Tango.MachineStudio.MachineDesigner.ViewModels { public class MainViewVM : StudioViewModel { - private bool _isSaving; private INotificationProvider _notification; - + private ObservablesContext _db; + private Configuration _original_configuration; #region Properties - private ObservablesEntitiesAdapter _adapter; + private ObservablesStaticCollections _adapter; /// - /// Gets or sets the db adapter. + /// Gets or sets the db static adapter. /// - public ObservablesEntitiesAdapter Adapter + public ObservablesStaticCollections Adapter { get { return _adapter; } set { _adapter = value; RaisePropertyChangedAuto(); } } + private bool _canWork; + /// + /// Gets or sets a value indicating whether this instance can work. + /// + public bool CanWork + { + get { return _canWork; } + set { _canWork = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + private Machine _machine; /// /// Gets or sets the current editable machine. @@ -54,7 +66,13 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels public Machine SelectedMachine { get { return _selectedMachine; } - set { _selectedMachine = value; RaisePropertyChangedAuto(); OnSelectedMachineChanged(); } + set + { + if (_selectedMachine != value) + { + _selectedMachine = value; RaisePropertyChangedAuto(); OnSelectedMachineChanged(); + } + } } private Configuration _configuration; @@ -107,6 +125,16 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels set { _filter = value; RaisePropertyChangedAuto(); OnFilterChanged(); } } + /// + /// Gets or sets the machines provider. + /// + public ISuggestionProvider MachinesProvider { get; set; } + + /// + /// Gets or sets the versions provider. + /// + public ISuggestionProvider VersionsProvider { get; set; } + #endregion #region Commands @@ -136,6 +164,11 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// public RelayCommand SetAsDefaultCommand { get; set; } + /// + /// Gets or sets the reset command. + /// + public RelayCommand ResetCommand { get; set; } + #endregion #region Constructors @@ -150,23 +183,89 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// public MainViewVM(INotificationProvider notification) { + CanWork = true; + _notification = notification; - Adapter = ObservablesEntitiesAdapter.Instance; Configuration = new Configuration(); Configuration.Name = "Untitled"; Machine = new Machine(); Machine.Configuration = Configuration; - SaveCommand = new RelayCommand(Save, (x) => !_isSaving); - AddIdsCommand = new RelayCommand(AddIds, (x) => !_isSaving && Configuration.IdsPacks.Count < 8); - RemoveIdsCommand = new RelayCommand(RemoveIds, (x) => !_isSaving && SelectedIds != null); - SetVersionConfigurationCommand = new RelayCommand(SetVersionConfiguration, (x) => !_isSaving); - SetAsDefaultCommand = new RelayCommand(SetAsDefaultConfiguration, (x) => !_isSaving); + SaveCommand = new RelayCommand(Save, (x) => CanWork); + AddIdsCommand = new RelayCommand(AddIds, (x) => CanWork && Configuration.IdsPacks.Count < 8); + RemoveIdsCommand = new RelayCommand(RemoveIds, (x) => CanWork && SelectedIds != null); + SetVersionConfigurationCommand = new RelayCommand(SetVersionConfiguration, (x) => CanWork); + SetAsDefaultCommand = new RelayCommand(SetAsDefaultConfiguration, (x) => CanWork); + ResetCommand = new RelayCommand(Reset, () => CanWork); + + MachinesProvider = new SuggestionProvider((filter) => + { + return _db.Machines.Where(x => x.SerialNumber.StartsWith(filter)).ToList(); + }); + + VersionsProvider = new SuggestionProvider((filter) => + { + return _db.MachineVersions.Where(x => x.Version.ToString().StartsWith(filter) || x.Name.StartsWith(filter)).ToList(); + }); + } + + #endregion + + #region Application Ready + + public async override void OnApplicationReady() + { + base.OnApplicationReady(); + + await InitCollections(); } #endregion + private Task InitCollections() + { + return Task.Factory.StartNew(() => + { + CanWork = false; + + _db = ObservablesContext.CreateDefault(); + _db.Configuration.LazyLoadingEnabled = false; + + Adapter = new ObservablesStaticCollections(); + Adapter.ApplicationDisplayPanelVersions = _db.ApplicationDisplayPanelVersions.ToObservableCollection(); + Adapter.ApplicationFirmwareVersions = _db.ApplicationFirmwareVersions.ToObservableCollection(); + Adapter.ApplicationOsVersions = _db.ApplicationOsVersions.ToObservableCollection(); + Adapter.EmbeddedFirmwareVersions = _db.EmbeddedFirmwareVersions.ToObservableCollection(); + Adapter.DispenserTypes = _db.DispenserTypes.ToObservableCollection(); + Adapter.LiquidTypes = _db.LiquidTypes.ToObservableCollection(); + Adapter.MidTankTypes = _db.MidTankTypes.ToObservableCollection(); + Adapter.CartridgeTypes = _db.CartridgeTypes.ToObservableCollection(); + Adapter.IdsPackFormulas = _db.IdsPackFormulas.ToObservableCollection(); + Adapter.HardwareVersions = _db.HardwareVersions.ToObservableCollection(); + Adapter.MachineVersions = _db.MachineVersions.ToObservableCollection(); + Adapter.Organizations = _db.Organizations.ToObservableCollection(); + + Adapter.InitCollectionSources(); + + CanWork = true; + }); + } + + private void Reset() + { + using (_notification.PushTaskItem("Resetting designer...")) + { + SelectedMachine = null; + Machine = new Machine(); + Configuration = new Configuration(); + History = new ObservableCollection(); + SelectedHistoryConfiguration = null; + Filter = String.Empty; + InitCollections(); + } + } + #region Virtual Methods /// @@ -176,9 +275,23 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { if (SelectedMachine != null) { - Machine = SelectedMachine.Clone(); - Configuration = Machine.Configuration.Clone(); - History = SelectedMachine.MachinesConfigurations.Select(x => x.Configuration).ToObservableCollection(); + CanWork = false; + + using (_notification.PushTaskItem("Loading machine configuration...")) + { + Task.Factory.StartNew(() => + { + InitCollections().Wait(); + Machine = _db.Machines.Where(x => x.Guid == SelectedMachine.Guid).Include(x => x.Organization).SingleOrDefault(x => x.Guid == SelectedMachine.Guid); + Configuration = _db.LoadConfiguration(x => x.Guid == Machine.ConfigurationGuid); + + SetHistory(); + + _original_configuration = Configuration.Clone(); + }); + } + + CanWork = true; } else { @@ -191,9 +304,21 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// protected virtual void OnHistoryConfigurationSelected() { - if (SelectedHistoryConfiguration != null) + if (SelectedHistoryConfiguration != null && CanWork) { - Configuration = SelectedHistoryConfiguration.Clone(); + using (_notification.PushTaskItem("Loading Configuration...")) + { + Task.Factory.StartNew(() => + { + CanWork = false; + + SelectedHistoryConfiguration = _db.LoadConfiguration(x => x.Guid == SelectedHistoryConfiguration.Guid); + Configuration = SelectedHistoryConfiguration; + Machine.Configuration = Configuration; + + CanWork = true; + }); + } } } @@ -202,8 +327,6 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// protected virtual void OnFilterChanged() { - - List collections = new List(); collections.Add(Adapter.ApplicationFirmwareVersionsViewSource); collections.Add(Adapter.ApplicationDisplayPanelVersionsViewSource); @@ -223,7 +346,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { String value = prop.GetValue(x).ToStringSafe(); - if (value != null) + if (value != null && Filter != null) { if (value.ToLower().Contains(Filter.ToLower())) { @@ -366,7 +489,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// private void RemoveIds() { - Configuration.IdsPacks.Remove(SelectedIds); + _db.IdsPacks.Remove(SelectedIds); SelectedIds = null; } @@ -375,7 +498,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// private void AddIds() { - Configuration.IdsPacks.Add(new IdsPack() { Configuration = Configuration }); + _db.IdsPacks.Add(new IdsPack() { Configuration = Configuration }); InvalidateRelayCommands(); } @@ -494,17 +617,17 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels //Validate - _isSaving = true; - InvalidateRelayCommands(); - try { + CanWork = false; + using (_notification.PushTaskItem("Saving Machine Configuration...")) { - if (!Adapter.Machines.ToList().Exists(x => x.SerialNumber.ToLower() == Machine.SerialNumber.ToLower())) + if (!_db.Machines.Any(x => x.SerialNumber.ToLower() == Machine.SerialNumber.ToLower())) { if (!_notification.ShowQuestion("The specified machine serial number does not exist. Do you wish to create a new machine?")) { + CanWork = true; return; } else @@ -512,53 +635,34 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels Machine.Configuration = Configuration; Configuration.CreationDate = DateTime.UtcNow; Machine.ProductionDate = DateTime.UtcNow; - Machine.MachinesConfigurations.Add(new MachinesConfiguration() + + _db.Machines.Add(Machine); + _db.MachinesConfigurations.Add(new MachinesConfiguration() { Configuration = Configuration, Machine = Machine, }); - await Machine.SaveAsync(Adapter.Context); - - Machine = Adapter.Machines.SingleOrDefault(x => x.Guid == Machine.Guid); - Configuration = Machine.Configuration.Clone(); } } else { - var machine = Adapter.Machines.Single(x => x.SerialNumber.ToLower() == Machine.SerialNumber.ToLower()); - - //Set 'Real machine' parameters... - - bool add_history = History.Count == 0 || History.First().Name != Configuration.Name; - - machine.Name = Machine.Name; - machine.SerialNumber = Machine.SerialNumber; - machine.Organization = Machine.Organization; - + bool add_history = History.Count == 0 || _original_configuration.Name != Configuration.Name; if (add_history) { - machine.MachinesConfigurations.Add(new MachinesConfiguration() + _db.Configurations.Add(_original_configuration); + + _db.MachinesConfigurations.Add(new MachinesConfiguration() { - Configuration = Configuration, - Machine = machine + Configuration = _original_configuration, + Machine = Machine }); } - else - { - machine.Configuration.DefferedDelete(Adapter.Context); - } - - machine.Configuration = Configuration; - - await machine.SaveAsync(Adapter.Context); - - Machine = Adapter.Machines.SingleOrDefault(x => x.Guid == machine.Guid); - Configuration = Machine.Configuration.Clone(); } - SetHistory(Machine); - Machine = Machine.Clone(); + await _db.SaveChangesAsync(); + OnSelectedMachineChanged(); + } } catch (Exception ex) @@ -567,7 +671,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels } finally { - _isSaving = false; + CanWork = true; InvalidateRelayCommands(); } } @@ -576,20 +680,33 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// Sets the specified machine history. /// /// The machine. - private void SetHistory(Machine machine) + private void SetHistory() { - History = machine.MachinesConfigurations.Select(x => x.Configuration).ToObservableCollection(); - History.Insert(0, machine.Configuration); + History = _db.MachinesConfigurations.Where(x => x.MachineGuid == Machine.Guid).Select(x => x.Configuration).ToObservableCollection(); + //History.Insert(0, Machine.Configuration); } /// /// Sets the current configuration to the selected machine version default configuration. /// - private void SetVersionConfiguration() + private async void SetVersionConfiguration() { if (Machine.MachineVersion != null) { - Configuration = Machine.MachineVersion.DefaultConfiguration.Clone(); + using (_notification.PushTaskItem("Applying default configuration...")) + { + CanWork = false; + + await Task.Factory.StartNew(() => + { + var version = _db.MachineVersions.Where(x => x.Guid == Machine.MachineVersion.Guid).Include(x => x.DefaultConfiguration).FirstOrDefault(); + var version_config = _db.LoadConfiguration(x => x.Guid == version.DefaultConfiguration.Guid); + Configuration = version_config.Clone(); + Machine.Configuration = Configuration; + }); + + CanWork = true; + } } else { @@ -604,15 +721,23 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { _notification.ShowModalDialog(async (vm) => { + CanWork = false; + try { using (_notification.PushTaskItem("Saving Default Configuration...")) { if (vm.SelectedVersion != null) { - vm.SelectedVersion.DefaultConfiguration = Configuration.Clone(); - vm.SelectedVersion.DefaultConfigurationGuid = vm.SelectedVersion.DefaultConfiguration.Guid; - await vm.SelectedVersion.SaveAsync(Adapter.Context); + var version = _db.MachineVersions.Where(x => x.Guid == vm.SelectedVersion.Guid).Include(x => x.DefaultConfiguration).SingleOrDefault(x => x.Guid == vm.SelectedVersion.Guid); + + _db.Configurations.Remove(version.DefaultConfiguration); + + var cloned = Configuration.Clone(); + _db.Configurations.Add(cloned); + version.DefaultConfiguration = cloned; + + await _db.SaveChangesAsync(); } else { @@ -620,9 +745,12 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels newVersion.Version = vm.Version; newVersion.Name = vm.VersionName; - newVersion.DefaultConfiguration = Configuration.Clone(); - newVersion.DefaultConfigurationGuid = newVersion.DefaultConfiguration.Guid; - await newVersion.SaveAsync(Adapter.Context); + var cloned = Configuration.Clone(); + + _db.Configurations.Add(cloned); + newVersion.DefaultConfiguration = cloned; + _db.MachineVersions.Add(newVersion); + await _db.SaveChangesAsync(); } } } @@ -630,6 +758,10 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { _notification.ShowError(ex.Message); } + finally + { + CanWork = true; + } }, () => { @@ -643,7 +775,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels public override void OnModuleRequest(params object[] args) { - SelectedMachine = Adapter.Machines.SingleOrDefault(x => x.Guid == (args[0] as Machine).Guid); + //SelectedMachine = Adapter.Machines.SingleOrDefault(x => x.Guid == (args[0] as Machine).Guid); } #endregion -- cgit v1.3.1 From 24149160c17fabe143f143de2796f9485d64410b Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 21 Aug 2018 18:39:38 +0300 Subject: Tech Board Module seems to be working good !! --- .../AutoComplete/MachineVersionsProvider.cs | 2 +- .../AutoComplete/MachinesProvider.cs | 29 ---- .../Tango.MachineStudio.MachineDesigner.csproj | 1 - .../ViewModels/MainViewVM.cs | 16 +-- .../Views/MachineView.xaml | 1 - .../PropertiesTemplates/JobRunnerTemplate.xaml | 4 +- .../ProcessParametersTemplate.xaml | 2 +- .../Tango.MachineStudio.Technician.csproj | 9 +- .../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 | 151 ++++++++++++--------- .../Tango.MachineStudio.Technician/app.config | 10 ++ .../Tango.MachineStudio.Technician/packages.config | 1 + .../Tango.MachineStudio.UI.csproj | 10 +- .../ViewModels/MainViewVM.cs | 10 +- .../Tango.BL/ObservablesContextExtension.cs | 41 +++++- .../Tango.BL/ObservablesStaticCollections.cs | 86 +++++++----- 27 files changed, 248 insertions(+), 168 deletions(-) delete mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/AutoComplete/MachinesProvider.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/AutoComplete/MachineVersionsProvider.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/AutoComplete/MachineVersionsProvider.cs index 18cfca79d..75b4718cd 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/AutoComplete/MachineVersionsProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/AutoComplete/MachineVersionsProvider.cs @@ -21,7 +21,7 @@ namespace Tango.MachineStudio.MachineDesigner.AutoComplete public IEnumerable GetSuggestions(string filter) { Text = filter; - return ObservablesEntitiesAdapter.Instance.MachineVersions.Where(x => x.Version.ToString().StartsWith(filter, StringComparison.CurrentCultureIgnoreCase) || x.Name.StartsWith(filter, StringComparison.CurrentCultureIgnoreCase)).ToList(); + return ObservablesStaticCollections.Instance.MachineVersions.Where(x => x.Version.ToString().StartsWith(filter, StringComparison.CurrentCultureIgnoreCase) || x.Name.StartsWith(filter, StringComparison.CurrentCultureIgnoreCase)).ToList(); } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/AutoComplete/MachinesProvider.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/AutoComplete/MachinesProvider.cs deleted file mode 100644 index 01b74e8a6..000000000 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/AutoComplete/MachinesProvider.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.AutoComplete.Editors; -using Tango.BL; -using Tango.BL.Entities; - -namespace Tango.MachineStudio.MachineDesigner.AutoComplete -{ - /// - /// Represents an auto-complete Machines provider. - /// - /// - public class MachinesProvider : ISuggestionProvider - { - /// - /// Gets the suggestions. - /// - /// The filter. - /// - public IEnumerable GetSuggestions(string filter) - { - return ObservablesEntitiesAdapter.Instance.Machines.Where(x => x.SerialNumber.StartsWith(filter, StringComparison.CurrentCultureIgnoreCase)).ToList(); - } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Tango.MachineStudio.MachineDesigner.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Tango.MachineStudio.MachineDesigner.csproj index 78f52b3fd..a578d0e54 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Tango.MachineStudio.MachineDesigner.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Tango.MachineStudio.MachineDesigner.csproj @@ -75,7 +75,6 @@ GlobalVersionInfo.cs - diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs index a819a4d1a..d2838b758 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs @@ -130,11 +130,6 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// public ISuggestionProvider MachinesProvider { get; set; } - /// - /// Gets or sets the versions provider. - /// - public ISuggestionProvider VersionsProvider { get; set; } - #endregion #region Commands @@ -203,11 +198,6 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { return _db.Machines.Where(x => x.SerialNumber.StartsWith(filter)).ToList(); }); - - VersionsProvider = new SuggestionProvider((filter) => - { - return _db.MachineVersions.Where(x => x.Version.ToString().StartsWith(filter) || x.Name.StartsWith(filter)).ToList(); - }); } #endregion @@ -283,7 +273,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { InitCollections().Wait(); Machine = _db.Machines.Where(x => x.Guid == SelectedMachine.Guid).Include(x => x.Organization).SingleOrDefault(x => x.Guid == SelectedMachine.Guid); - Configuration = _db.LoadConfiguration(x => x.Guid == Machine.ConfigurationGuid); + Configuration = _db.GetConfiguration(x => x.Guid == Machine.ConfigurationGuid); SetHistory(); @@ -312,7 +302,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { CanWork = false; - SelectedHistoryConfiguration = _db.LoadConfiguration(x => x.Guid == SelectedHistoryConfiguration.Guid); + SelectedHistoryConfiguration = _db.GetConfiguration(x => x.Guid == SelectedHistoryConfiguration.Guid); Configuration = SelectedHistoryConfiguration; Machine.Configuration = Configuration; @@ -700,7 +690,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels await Task.Factory.StartNew(() => { var version = _db.MachineVersions.Where(x => x.Guid == Machine.MachineVersion.Guid).Include(x => x.DefaultConfiguration).FirstOrDefault(); - var version_config = _db.LoadConfiguration(x => x.Guid == version.DefaultConfiguration.Guid); + var version_config = _db.GetConfiguration(x => x.Guid == version.DefaultConfiguration.Guid); Configuration = version_config.Clone(); Machine.Configuration = Configuration; }); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineView.xaml index 4d75651f7..e2dd7c5a9 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineView.xaml @@ -17,7 +17,6 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/BreakSensorElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/BreakSensorElementEditor.xaml index 18c992193..78834aca7 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/BreakSensorElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/BreakSensorElementEditor.xaml @@ -27,7 +27,7 @@ - + @@ -38,7 +38,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ControllerElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ControllerElementEditor.xaml index 346c0067b..de604625d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ControllerElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ControllerElementEditor.xaml @@ -28,7 +28,7 @@ - + @@ -99,7 +99,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DancerElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DancerElementEditor.xaml index 3c6ee7d49..2960a8807 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DancerElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DancerElementEditor.xaml @@ -27,7 +27,7 @@ - + @@ -38,7 +38,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DigitalInElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DigitalInElementEditor.xaml index 8c72798d5..5c1cfc3ad 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DigitalInElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DigitalInElementEditor.xaml @@ -27,7 +27,7 @@ - + @@ -51,7 +51,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DigitalOutElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DigitalOutElementEditor.xaml index 5fd92c336..862fa0597 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DigitalOutElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DigitalOutElementEditor.xaml @@ -28,7 +28,7 @@ - + @@ -62,7 +62,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DispenserElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DispenserElementEditor.xaml index 0a088df69..1fa1c6c48 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DispenserElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DispenserElementEditor.xaml @@ -45,7 +45,7 @@ - + @@ -254,7 +254,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/JobRunnerElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/JobRunnerElementEditor.xaml index c481f1e1b..76a6a16a7 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/JobRunnerElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/JobRunnerElementEditor.xaml @@ -42,7 +42,7 @@ - + @@ -239,7 +239,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MeterElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MeterElementEditor.xaml index 98ace7816..2631f3a06 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MeterElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MeterElementEditor.xaml @@ -28,7 +28,7 @@ - + @@ -47,7 +47,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MonitorElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MonitorElementEditor.xaml index 8f66adeeb..a39fa975c 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MonitorElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MonitorElementEditor.xaml @@ -27,7 +27,7 @@ - + @@ -55,7 +55,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorElementEditor.xaml index 48186fd56..80bfe8f96 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorElementEditor.xaml @@ -47,7 +47,7 @@ - + @@ -243,7 +243,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml index 64ed5bb43..3adee13d6 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml @@ -47,7 +47,7 @@ - + @@ -229,7 +229,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MultiGraphElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MultiGraphElementEditor.xaml index 9bc22d0f6..dcba1e77b 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MultiGraphElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MultiGraphElementEditor.xaml @@ -43,7 +43,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/PidElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/PidElementEditor.xaml index 6d4f49ace..197640b14 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/PidElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/PidElementEditor.xaml @@ -27,7 +27,7 @@ - + @@ -38,7 +38,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ProcessParametersElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ProcessParametersElementEditor.xaml index 716ac0a2d..f057521e0 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ProcessParametersElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ProcessParametersElementEditor.xaml @@ -31,7 +31,7 @@ - + @@ -73,7 +73,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/SingleGraphElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/SingleGraphElementEditor.xaml index 16f94b251..a9eb9e9f4 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/SingleGraphElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/SingleGraphElementEditor.xaml @@ -43,7 +43,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/SpeedSensorElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/SpeedSensorElementEditor.xaml index b9dce9112..8696a3c53 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/SpeedSensorElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/SpeedSensorElementEditor.xaml @@ -27,7 +27,7 @@ - + @@ -38,7 +38,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ThreadMotionElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ThreadMotionElementEditor.xaml index 3bac433ad..6e2315dc8 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ThreadMotionElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ThreadMotionElementEditor.xaml @@ -47,7 +47,7 @@ - + @@ -158,7 +158,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/WinderElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/WinderElementEditor.xaml index f81597574..2b6ee303d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/WinderElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/WinderElementEditor.xaml @@ -27,7 +27,7 @@ - + @@ -38,7 +38,22 @@ - + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs index 8b331b5f5..f96960883 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs @@ -41,7 +41,7 @@ namespace Tango.MachineStudio.Technician.ViewModels /// /// /// - public class MachineTechViewVM : StudioViewModel + public class MachineTechViewVM : StudioViewModel { private List _diagnoticsMonitorsDataProperties; private IDiagnosticsFrameProvider _diagnosticsFrameProvider; @@ -1572,6 +1572,11 @@ namespace Tango.MachineStudio.Technician.ViewModels }); } + public override void OnApplicationReady() + { + + } + #endregion #region Hardware Configuration diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml.cs index b60f4d725..977974f8a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml.cs @@ -59,7 +59,7 @@ namespace Tango.MachineStudio.Technician.Views private void OnActionModeClicked(object sender, MouseButtonEventArgs e) { - editor.DeselectElements(); + //editor.DeselectElements(); } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs index 56888e631..a5ef4f095 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs @@ -17,7 +17,7 @@ using System.Data.Entity; namespace Tango.MachineStudio.UsersAndRoles.ViewModels { - public class MainViewVM : StudioViewModel + public class MainViewVM : StudioViewModel { private ObservablesContext _organizationsContext; private ObservablesContext _manageContext; @@ -146,7 +146,6 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels public override void OnApplicationReady() { - base.OnApplicationReady(); LoadOrganizations(); } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/IStudioViewModel.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/IStudioViewModel.cs index 76cc0433c..be0906fc4 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/IStudioViewModel.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/IStudioViewModel.cs @@ -3,24 +3,15 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using static Tango.SharedUI.Controls.NavigationControl; namespace Tango.MachineStudio.Common { /// /// Represents a Machine Studio view model. /// - public interface IStudioViewModel + public interface IStudioViewModel : INavigationViewModel { - /// - /// Called when the user has navigated in to the module. - /// - void OnNavigatedTo(); - - /// - /// Called when the user has navigated out of the module. - /// - void OnNavigatedFrom(); - /// /// Called when application is shutting down. /// @@ -33,12 +24,6 @@ namespace Tango.MachineStudio.Common /// Task OnShutdownRequest(); - /// - /// Called when another module has wants to navigate to this module with some arguments. - /// - /// The arguments. - void OnModuleRequest(params object[] args); - /// /// Called when the application has been started /// diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationBlocker.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationBlocker.cs new file mode 100644 index 000000000..abd6db172 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationBlocker.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Common.Navigation +{ + /// + /// Represents an object which can abort the navigation from it. + /// + public interface INavigationBlocker + { + /// + /// Called before the navigation system navigates from this object. + /// Return false to abort the navigation. + /// + /// + Task OnNavigateOutRequest(); + + /// + /// Called before the navigation system navigates back from this object. + /// Return false to abort the navigation. + /// + /// + Task OnNavigateBackRequest(); + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationManager.cs index 4d1cbea8c..e20940c8d 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core.Commands; namespace Tango.MachineStudio.Common.Navigation { @@ -12,9 +13,102 @@ namespace Tango.MachineStudio.Common.Navigation public interface INavigationManager { /// - /// Navigates to the specified view. + /// Gets the current module. + /// + IStudioModule CurrentModule { get; } + + /// + /// Gets the current view model. + /// + StudioViewModel CurrentVM { get; } + + /// + /// Gets a value indicating whether the navigation system is able to navigate to the previous view. + /// + bool CanNavigateBack { get; } + + /// + /// Navigates to the previous view if is true. + /// + Task NavigateBack(); + + /// + /// Navigates to the previous view.. + /// + RelayCommand NavigateBackCommand { get; } + + /// + /// Navigates to the specified full path in command parameter. + /// + RelayCommand NavigateToCommand { get; } + + /// + /// Navigates to the specified PPC view. /// /// The view. - void NavigateTo(NavigationView view); + Task NavigateTo(NavigationView view, bool pushToHistory = true); + + /// + /// Navigates to the specified PPC view with the specified receive object. + /// + /// The view. + Task NavigateWithObject(NavigationView view, TPass obj, bool pushToHistory = true); + + /// + /// Navigates to the specified module. + /// + /// + Task NavigateTo(bool pushToHistory = true) where T : IStudioModule; + + /// + /// Navigates to the specified module using the view path (e.g MainView.JobsView). + /// + /// + /// The view path. + Task NavigateTo(String viewPath, bool pushToHistory = true) where T : IStudioModule; + + /// + /// Navigates to the specified module using the view path (e.g MainView,JobsView). + /// This method makes it easy to do stuff like NavigateTo(nameof(MainView),nameof(JobsView)); + /// + /// + /// The view path. + Task NavigateTo(bool pushToHistory = true, params String[] viewPath) where T : IStudioModule; + + /// + /// Navigates to the specified module and view by full path (e.g Jobs.JobsView). + /// + /// The full path. + Task NavigateTo(String fullPath, bool pushToHistory = true); + + /// + /// Navigates to the specified module and view with the specified object and expecting a return parameter. + /// The view must be of type INavigationResultProvider. + /// + /// The full path. + Task NavigateForResult(TPass obj, bool pushToHistory = true) + where TModule : IStudioModule; + + /// + /// Navigates to the specified module and view with the specified object. + /// + /// The type of the module. + /// The type of the view. + /// The type of the pass. + /// The object. + /// if set to true [push to history]. + /// + Task NavigateWithObject(TPass obj, bool pushToHistory = true) + where TModule : IStudioModule; + + /// + /// Clears the navigation back history. + /// + void ClearHistory(); + + /// + /// Clears the navigation back history except the specified view type. + /// + void ClearHistoryExcept(); } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationObjectReceiver.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationObjectReceiver.cs new file mode 100644 index 000000000..5072881d2 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationObjectReceiver.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Common.Navigation +{ + /// + /// Represents an object which supports receiving an object as part of the navigation to it. + /// + /// + public interface INavigationObjectReceiver + { + /// + /// Called when navigation system is going to navigate to this instance with the specified object. + /// + /// The object. + void OnNavigatedToWithObject(T obj); + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationResultProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationResultProvider.cs new file mode 100644 index 000000000..dee037432 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationResultProvider.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Common.Navigation +{ + /// + /// Represents a object which provides a result the navigation system navigates away from it. + /// + /// The type of the result. + /// The type of the pass. + public interface INavigationResultProvider + { + /// + /// Called when the navigation system requests a result when it is navigating away from this instance. + /// + /// + TResult GetNavigationResult(); + + /// + /// Called when navigation system is going to navigate to this instance with the specified object. + /// + /// The object. + void OnNavigationObjectReceived(TPass obj); + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs index 441a4ca93..96de3eea0 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs @@ -44,13 +44,6 @@ namespace Tango.MachineStudio.Common.StudioApplication /// bool IsMachineConnectedViaTCP { get; } - /// - /// Loads the specified module if permitted. - /// - /// Name of the module. - /// The arguments. - void RequestModule(String moduleName, params object[] args); - /// /// Gets the machine studio application version. /// diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioViewModel.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioViewModel.cs index 08ddbc073..63ff2119a 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioViewModel.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioViewModel.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core.DI; using Tango.SharedUI; namespace Tango.MachineStudio.Common @@ -10,128 +11,42 @@ namespace Tango.MachineStudio.Common /// /// Represents a Machine Studio view model /// - /// The type of the module. /// /// - public abstract class StudioViewModelInternal : ViewModel, IStudioViewModel + public abstract class StudioViewModel : ViewModel, IStudioViewModel { - public bool IsVisible { get; private set; } - - /// - /// Gets or sets a value indicating whether this view model studio module is currently loaded. - /// - public bool IsModuleLoaded { get; private set; } - - /// - /// Initializes a new instance of the class. - /// - public StudioViewModelInternal() : base() - { - - } - - /// - /// Called when another module has wants to navigate to this module with some arguments. - /// - /// The arguments. - public virtual void OnModuleRequest(params object[] args) - { - - } - + private bool _isVisible; /// - /// Called when the user has navigated out of the module. + /// Gets or sets a value indicating whether this view model view's is visible. /// - public virtual void OnNavigatedFrom() + public bool IsVisible { - IsVisible = false; - IsModuleLoaded = false; + get { return _isVisible; } + set { _isVisible = value; RaisePropertyChangedAuto(); } } /// - /// Called when the user has navigated in to the module. - /// - public virtual void OnNavigatedTo() - { - IsVisible = true; - IsModuleLoaded = true; - } - - /// - /// Called before the application is shutting down. - /// Return false to cancel the shutdown in case an important process is in progress. - /// - /// - public virtual Task OnShutdownRequest() - { - return Task.FromResult(true); - } - - /// - /// Called when application is shutting down. - /// - public virtual void OnShuttingDown() - { - - } - - /// - /// Called when the application has been started - /// - public virtual void OnApplicationStarted() - { - - } - - /// - /// Called when the application is ready and all modules are loaded. - /// - public virtual void OnApplicationReady() - { - - } - } - - /// - /// Represents a Machine Studio view model - /// - /// The type of the module. - /// - /// - public abstract class StudioViewModel : ViewModel, IStudioViewModel where Module : IStudioModule - { - public bool IsVisible { get; private set; } - - /// - /// Gets or sets a value indicating whether this view model studio module is currently loaded. - /// - public bool IsModuleLoaded { get; private set; } - - /// - /// Called when another module has wants to navigate to this module with some arguments. + /// Initializes a new instance of the class. /// - /// The arguments. - public virtual void OnModuleRequest(params object[] args) + public StudioViewModel() : base() { } /// - /// Called when the user has navigated out of the module. + /// Called when the user has navigated out of this view model. /// public virtual void OnNavigatedFrom() { IsVisible = false; - IsModuleLoaded = false; } /// - /// Called when the user has navigated in to the module. + /// Called when the user has navigated in to this view model. /// public virtual void OnNavigatedTo() { IsVisible = true; - IsModuleLoaded = true; } /// @@ -163,79 +78,38 @@ namespace Tango.MachineStudio.Common /// /// Called when the application is ready and all modules are loaded. /// - public virtual void OnApplicationReady() - { - - } + public abstract void OnApplicationReady(); } /// - /// Represents a Machine Studio view model. + /// Represents a Machine Studio view model with a support for a view contract. /// - /// The type of the module. - /// + /// /// - /// - public abstract class StudioViewModel : ViewModel, IStudioViewModel where Module : IStudioModule where T : IView + public abstract class StudioViewModel : StudioViewModel where TView : IView { /// - /// Called when the application has been started - /// - public virtual void OnApplicationStarted() - { - - } - - /// - /// Called when the application is ready and all modules are loaded. - /// - public virtual void OnApplicationReady() - { - - } - - /// - /// Called when another module has wants to navigate to this module with some arguments. + /// Gets the view model's view. /// - /// The arguments. - public virtual void OnModuleRequest(params object[] args) - { - - } + public TView View { get; private set; } /// - /// Called when the user has navigated out of the module. + /// Initializes a new instance of the class. /// - public virtual void OnNavigatedFrom() + public StudioViewModel() : base() { - + TangoIOC.Default.GetInstanceWhenAvailable((view) => + { + View = view; + OnViewAttached(view); + }); } /// - /// Called when the user has navigated in to the module. + /// Called when the view has been attached /// - public virtual void OnNavigatedTo() - { - - } - - /// - /// Called before the application is shutting down. - /// Return false to cancel the shutdown in case an important process is in progress. - /// - /// - public virtual Task OnShutdownRequest() - { - return Task.FromResult(true); - } - - /// - /// Called when application is shutting down. - /// - public virtual void OnShuttingDown() - { - - } + /// The view. + protected abstract void OnViewAttached(TView view); } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj index 8b251074d..09678b515 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj @@ -106,6 +106,9 @@ + + + @@ -115,6 +118,7 @@ + @@ -292,13 +296,11 @@ True - - - + - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Threading/IDispatcherProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Threading/IDispatcherProvider.cs new file mode 100644 index 000000000..1c960ed3a --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Threading/IDispatcherProvider.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Common.Threading +{ + /// + /// Represents a mechanism for invoking actions on the main application thread. + /// + public interface IDispatcherProvider + { + /// + /// Invokes the specified action asynchronously. + /// + /// The action. + void Invoke(Action action); + + /// + /// Invokes the specified action synchronously. + /// + /// The action. + void InvokeSync(Action action); + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/MainWindow.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/MainWindow.xaml index b8a6cd1c0..44b2ed401 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/MainWindow.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/MainWindow.xaml @@ -17,7 +17,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Navigation/DefaultNavigationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Navigation/DefaultNavigationManager.cs index 092b958cc..899ba846e 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Navigation/DefaultNavigationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Navigation/DefaultNavigationManager.cs @@ -3,8 +3,13 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core; +using Tango.Core.Commands; using Tango.MachineStudio.Common; +using Tango.MachineStudio.Common.Modules; using Tango.MachineStudio.Common.Navigation; +using Tango.MachineStudio.Common.Threading; +using Tango.SharedUI.Controls; namespace Tango.MachineStudio.UI.Navigation { @@ -12,18 +17,372 @@ namespace Tango.MachineStudio.UI.Navigation /// Represents the Machine Studio default Navigation Manager. /// /// - public class DefaultNavigationManager : INavigationManager + public class DefaultNavigationManager : ExtendedObject, INavigationManager { + private event Action NavigationCycleCompleted; + + private IDispatcherProvider _dispatcherProvider; + private IStudioModuleLoader _moduleLoader; + private Object _currentVM; + private String _lastFullPath; + private bool _preventHistory; + private bool _navigating_back; + + private Stack _navigationHistory; + + /// + /// Gets the current view model. + /// + public StudioViewModel CurrentVM + { + get { return _currentVM as StudioViewModel; } + } + + private IStudioModule _currentModule; + /// + /// Gets or sets the current module. + /// + public IStudioModule CurrentModule + { + get { return _currentModule; } + private set { _currentModule = value; RaisePropertyChangedAuto(); } + } + + /// + /// Navigates to the previous view. + /// + public RelayCommand NavigateBackCommand { get; private set; } + + /// + /// Navigates to the specified full path in command parameter. + /// + public RelayCommand NavigateToCommand { get; private set; } + + /// + /// Initializes a new instance of the class. + /// + /// The module loader. + public DefaultNavigationManager(IStudioModuleLoader moduleLoader, IDispatcherProvider dispatcherProvider) + { + _navigationHistory = new Stack(); + _moduleLoader = moduleLoader; + + NavigateToCommand = new RelayCommand(async (x) => await NavigateTo(x)); + NavigateBackCommand = new RelayCommand(async () => await NavigateBack()); + + _dispatcherProvider = dispatcherProvider; + } + /// - /// Navigates to the specified view. + /// Navigates to the specified PPC view. /// /// The view. - public void NavigateTo(NavigationView view) + public Task NavigateTo(NavigationView view, bool pushToHistory = true) { - MainWindow.Instance.Dispatcher.Invoke(() => + LogManager.Log($"Navigating to: {view.ToString()}..."); + + _dispatcherProvider.Invoke(() => { - MainWindow.Instance.TransitionControl.NavigateTo(view.ToString()); + MainWindow.Instance.NavigationControl.NavigateTo(view.ToString()); }); + + return Task.FromResult(true); + } + + /// + /// Navigates to the specified PPC view with the specified receive object. + /// + /// The view. + /// + /// + /// + public Task NavigateWithObject(NavigationView view, TPass obj, bool pushToHistory = true) + { + LogManager.Log($"Navigating to: {view.ToString()}, with object {typeof(TPass).Name}..."); + MainWindow.Instance.NavigationControl.NavigateTo(view.ToString()); + INavigationObjectReceiver receiver = MainWindow.Instance.NavigationControl.Elements.FirstOrDefault(x => (x.GetType().Name == view.ToString() || NavigationControl.GetNavigationName(x) == view.ToString()) && x.DataContext is INavigationObjectReceiver).DataContext as INavigationObjectReceiver; + + if (receiver != null) + { + receiver.OnNavigatedToWithObject(obj); + } + + return Task.FromResult(true); + } + + /// + /// Navigates to the specified module. + /// + /// + public Task NavigateTo(bool pushToHistory = true) where T : IStudioModule + { + return NavigateTo(typeof(T)); + } + + /// + /// Navigates to the specified module using the view path (e.g MainView.JobsView). + /// + /// + /// The view path. + public Task NavigateTo(string viewPath, bool pushToHistory = true) where T : IStudioModule + { + return NavigateTo(pushToHistory, viewPath.Split('.')); + } + + /// + /// Navigates to the specified module using the view path (e.g MainView,JobsView). + /// This method makes it easy to do stuff like NavigateTo(nameof(MainView),nameof(JobsView)); + /// + /// + /// The view path. + public Task NavigateTo(bool pushToHistory = true, params String[] viewPath) where T : IStudioModule + { + return NavigateTo(typeof(T), pushToHistory, viewPath); + } + + /// + /// Navigates to the specified module and view by full path (e.g Jobs.JobsView). + /// + /// The full path. + public async Task NavigateTo(String fullPath, bool pushToHistory = true) + { + String[] path = fullPath.Split('.'); + var module = _moduleLoader.UserModules.SingleOrDefault(x => x.GetType().Name == path[0] || x.Name == path[0]); + + if (path.Length == 1 && path[0] == CurrentModule.Name) return true; + + LogManager.Log($"Navigating to: {fullPath}..."); + + var fromVM = _currentVM; + + if (_currentVM != null && _currentVM is INavigationBlocker) + { + if (_navigating_back) + { + if (!await (_currentVM as INavigationBlocker).OnNavigateBackRequest()) + { + return false; + } + } + else + { + if (!await (_currentVM as INavigationBlocker).OnNavigateOutRequest()) + { + return false; + } + } + } + + if (pushToHistory && _lastFullPath != null && !_preventHistory) + { + _navigationHistory.Push(_lastFullPath); + RaisePropertyChanged(nameof(CanNavigateBack)); + } + + _lastFullPath = fullPath; + + MainWindow.Instance.NavigationControl.NavigateTo(NavigationView.MainView.ToString()); + var navigationControl = MachineStudio.UI.Views.MainView.Instance.NavigationControl; + CurrentModule = module; + var moduleView = navigationControl.NavigateTo(module.Name); + + _currentVM = moduleView.DataContext; + + if (path.Length > 1) + { + var moduleNavigation = moduleView.FindChildOffline(); + + moduleNavigation.RegisterForLoadedOrNow(async (x, e) => + { + foreach (var view in path.Skip(1)) + { + await Task.Delay(100); + var v = moduleNavigation.NavigateTo(view); + + if (v != null) + { + _currentVM = v.DataContext; + + if (view != path.Last()) + { + moduleNavigation = v.FindChildOffline(); + } + } + else + { + throw LogManager.Log(new ArgumentNullException("Could not navigate to " + fullPath)); + } + } + + NavigationCycleCompleted?.Invoke(fromVM, _currentVM); + }); + } + + return true; + } + + /// + /// Navigates for result. + /// + /// The type of the module. + /// The type of the view. + /// The type of the result. + /// The type of the object. + /// The object. + /// if set to true [push to history]. + /// + public Task NavigateForResult(TObject obj, bool pushToHistory = true) + where TModule : IStudioModule + { + TaskCompletionSource source = new TaskCompletionSource(); + + var fromVM = _currentVM; + Object toVM = null; + + + Action handler = null; + + handler = (from, to) => + { + if (toVM == null) + { + toVM = to; + if (toVM is INavigationResultProvider) + { + (toVM as INavigationResultProvider).OnNavigationObjectReceived(obj); + } + } + else + { + if (to == fromVM && from == toVM) + { + if (from is INavigationResultProvider) + { + source.SetResult((from as INavigationResultProvider).GetNavigationResult()); + } + } + + NavigationCycleCompleted -= handler; + } + }; + + NavigationCycleCompleted += handler; + + NavigateTo(typeof(TView).Name, pushToHistory); + + return source.Task; + } + + /// + /// Navigates to the specified module and view with the specified object. + /// + /// The type of the module. + /// The type of the view. + /// The type of the pass. + /// The object. + /// if set to true [push to history]. + /// + public Task NavigateWithObject(TPass obj, bool pushToHistory = true) where TModule : IStudioModule + { + TaskCompletionSource source = new TaskCompletionSource(); + + Action handler = null; + + handler = (from, to) => + { + if (to is INavigationObjectReceiver) + { + (to as INavigationObjectReceiver).OnNavigatedToWithObject(obj); + } + + NavigationCycleCompleted -= handler; + }; + + NavigationCycleCompleted += handler; + + NavigateTo(typeof(TView).Name, pushToHistory); + + return source.Task; + } + + private Task NavigateTo(Type moduleType, bool pushToHistory = true, params String[] viewPath) + { + if (viewPath != null && viewPath.Length > 0) + { + return NavigateTo(moduleType.Name + "." + String.Join(".", viewPath), pushToHistory); + } + else + { + return NavigateTo(moduleType.Name, pushToHistory); + } + } + + /// + /// Gets a value indicating whether the navigation system is able to navigate to the previous view. + /// + public bool CanNavigateBack + { + get { return _navigationHistory.Count > 0; } + } + + /// + /// Navigates to the previous view if is true. + /// + public async Task NavigateBack() + { + LogManager.Log("Navigating back..."); + + _navigating_back = true; + + String first = _navigationHistory.Pop(); + _preventHistory = true; + + + if (await NavigateTo(first)) + { + RaisePropertyChanged(nameof(CanNavigateBack)); + _preventHistory = false; + _navigating_back = false; + return true; + } + else + { + _navigationHistory.Push(first); + _preventHistory = false; + _navigating_back = false; + RaisePropertyChanged(nameof(CanNavigateBack)); + return false; + } + } + + /// + /// Clears the navigation back history. + /// + public void ClearHistory() + { + LogManager.Log("Navigation history cleared."); + _navigationHistory.Clear(); + RaisePropertyChanged(nameof(CanNavigateBack)); + } + + /// + /// Clears the navigation back history except the specified view type. + /// + /// + public void ClearHistoryExcept() + { + LogManager.Log($"Navigation history cleared except for {typeof(T).Name}."); + + var history_list = _navigationHistory.ToList(); + history_list = history_list.Where(x => x.Contains(typeof(T).Name)).Distinct().ToList(); + _navigationHistory.Clear(); + + foreach (var item in history_list) + { + _navigationHistory.Push(item); + } + + RaisePropertyChanged(nameof(CanNavigateBack)); } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs index b8e6e1670..7c7e18276 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs @@ -225,31 +225,6 @@ namespace Tango.MachineStudio.UI.StudioApplication } } - /// - /// Loads the specified module if permitted. - /// - /// Name of the module. - /// The arguments. - public void RequestModule(string moduleName, params object[] args) - { - IStudioModule module = _moduleLoader.UserModules.SingleOrDefault(x => x.Name == moduleName); - - if (module != null) - { - TangoIOC.Default.GetInstance().StartModule(module); - - //Notify request listeners. - foreach (var vm in TangoIOC.Default.GetAllInstancesByBase()) - { - vm.OnModuleRequest(module, args); - } - } - else - { - throw new InvalidOperationException("The module was not found or you do not have sufficient privileges."); - } - } - /// /// Notify the application manager about an external opened window. /// When application exists. All registered windows will be closed. diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj index 4ded3b300..1bbabb0af 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj @@ -168,6 +168,7 @@ + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Threading/DefaultDispatcherProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Threading/DefaultDispatcherProvider.cs new file mode 100644 index 000000000..611dca6b9 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Threading/DefaultDispatcherProvider.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Threading; +using Tango.MachineStudio.Common.Threading; + +namespace Tango.MachineStudio.UI.Threading +{ + /// + /// Represents the default PPC which will invoke action on the current application dispatcher. + /// + /// + public class DefaultDispatcherProvider : IDispatcherProvider + { + private Dispatcher _dispatcher; + + /// + /// Initializes a new instance of the class. + /// + /// The dispatcher. + public DefaultDispatcherProvider(Dispatcher dispatcher) + { + _dispatcher = dispatcher; + } + + /// + /// Invokes the specified action asynchronously. + /// + /// The action. + public void Invoke(Action action) + { + _dispatcher.BeginInvoke(action); + } + + /// + /// Invokes the specified action synchronously. + /// + /// The action. + public void InvokeSync(Action action) + { + _dispatcher.Invoke(action); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs index 2c816eb6c..10aa86ad1 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs @@ -1,4 +1,5 @@ using System; +using System.Windows; using Tango.Core.DI; using Tango.Integration.ExternalBridge; using Tango.Logging; @@ -11,6 +12,7 @@ using Tango.MachineStudio.Common.Navigation; using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.Common.Speech; using Tango.MachineStudio.Common.StudioApplication; +using Tango.MachineStudio.Common.Threading; using Tango.MachineStudio.Common.Video; using Tango.MachineStudio.UI.Authentication; using Tango.MachineStudio.UI.Console; @@ -21,6 +23,7 @@ using Tango.MachineStudio.UI.Notifications; using Tango.MachineStudio.UI.StudioApplication; using Tango.MachineStudio.UI.SupervisingController; using Tango.MachineStudio.UI.TFS; +using Tango.MachineStudio.UI.Threading; using Tango.MachineStudio.UI.ViewModels; using Tango.MachineStudio.UI.Views; using Tango.Settings; @@ -64,7 +67,10 @@ namespace Tango.MachineStudio.UI TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); + TangoIOC.Default.Unregister(); + + TangoIOC.Default.Register(new DefaultDispatcherProvider(Application.Current.Dispatcher)); TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs index eacc8a4cb..215f7afb5 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs @@ -28,7 +28,7 @@ namespace Tango.MachineStudio.UI.ViewModels /// Represents the Machine Studio loading view, view model. /// /// - public class LoadingViewVM : StudioViewModelInternal + public class LoadingViewVM : StudioViewModel { private INotificationProvider _notificationProvider; private TeamFoundationServiceExtendedClient _tfs; @@ -172,5 +172,10 @@ namespace Tango.MachineStudio.UI.ViewModels } }); } + + public override void OnApplicationReady() + { + + } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index 23dd4ecd7..36ce62897 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -629,20 +629,19 @@ namespace Tango.MachineStudio.UI.ViewModels { LogManager.Log(String.Format("Starting module '{0}'...", module.Name)); - if (!(MainView.Self as MainView).TransitionControl.Elements.ToList().Exists(x => x.GetType() == module.MainViewType)) + if (!(MainView.Self as MainView).NavigationControl.Elements.ToList().Exists(x => x.GetType() == module.MainViewType)) { LogManager.Log("Module was not initialized. Initializing..."); FrameworkElement view = Activator.CreateInstance(module.MainViewType) as FrameworkElement; NavigationControl.SetNavigationName(view, module.Name); - (MainView.Self as MainView).TransitionControl.Elements.Add(view); + (MainView.Self as MainView).NavigationControl.Elements.Add(view); } } foreach (var m in StudioModuleLoader.AllModules.Where(x => x != module && !x.InNewWindow)) { m.IsLoaded = false; - TangoIOC.Default.GetModuleViewModels(m).ToList().ForEach(x => x.OnNavigatedFrom()); } if (module != null) @@ -652,15 +651,13 @@ namespace Tango.MachineStudio.UI.ViewModels IsModuleLoaded = true; LogManager.Log(String.Format("Navigating to module '{0}'...", module.Name)); - (MainView.Self as MainView).TransitionControl.NavigateTo(module.Name); - - TangoIOC.Default.GetModuleViewModels(module).ToList().ForEach(x => x.OnNavigatedTo()); + (MainView.Self as MainView).NavigationControl.NavigateTo(module.Name); } else { IsModuleLoaded = false; LogManager.Log(String.Format("Navigating to Home...")); - (MainView.Self as MainView).TransitionControl.NavigateTo("Home"); + (MainView.Self as MainView).NavigationControl.NavigateTo("Home"); } } @@ -680,16 +677,16 @@ namespace Tango.MachineStudio.UI.ViewModels LogManager.Log(String.Format("Starting module '{0}' in new window...", module.Name)); - if (!(MainView.Self as MainView).TransitionControl.Elements.ToList().Exists(x => x.GetType() == module.MainViewType)) + if (!(MainView.Self as MainView).NavigationControl.Elements.ToList().Exists(x => x.GetType() == module.MainViewType)) { LogManager.Log("Module was not initialized. Initializing..."); FrameworkElement v = Activator.CreateInstance(module.MainViewType) as FrameworkElement; NavigationControl.SetNavigationName(v, module.Name); - (MainView.Self as MainView).TransitionControl.Elements.Add(v); + (MainView.Self as MainView).NavigationControl.Elements.Add(v); } LogManager.Log("Detaching module view..."); - var view = (MainView.Self as MainView).TransitionControl.GetAndDetach(module.Name); + var view = (MainView.Self as MainView).NavigationControl.GetAndDetach(module.Name); ModuleWindowVM vm = new ModuleWindowVM(module); ModuleWindow window = new ModuleWindow(this, vm, view); @@ -700,7 +697,6 @@ namespace Tango.MachineStudio.UI.ViewModels window.grid.Children.Remove(view); module.InNewWindow = false; - TangoIOC.Default.GetModuleViewModels(module).ToList().ForEach(v => v.OnNavigatedFrom()); }; window.Owner = MainWindow.Instance; @@ -708,8 +704,6 @@ namespace Tango.MachineStudio.UI.ViewModels LogManager.Log("Opening new window..."); window.Show(); - TangoIOC.Default.GetModuleViewModels(module).ToList().ForEach(x => x.OnNavigatedTo()); - (_applicationManager as DefaultStudioApplicationManager).RegisterOpenedWindow(window); } catch (Exception ex) diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml index bb5c6458b..9a494f862 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml @@ -397,7 +397,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml.cs index 7ed119abd..ca8d7066c 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml.cs @@ -38,10 +38,14 @@ namespace Tango.MachineStudio.UI.Views { private DefaultStudioModuleLoader _loader; + public static MainView Instance { get; set; } + public MainView() : base() { InitializeComponent(); + Instance = this; + _loader = TangoIOC.Default.GetInstance() as DefaultStudioModuleLoader; _loader.ModulesLoaded += Loader_ModulesLoaded; } @@ -69,11 +73,11 @@ namespace Tango.MachineStudio.UI.Views ThreadsHelper.InvokeUI(() => { - if (!TransitionControl.Elements.ToList().Exists(x => x.GetType() == module.MainViewType)) + if (!NavigationControl.Elements.ToList().Exists(x => x.GetType() == module.MainViewType)) { FrameworkElement view = Activator.CreateInstance(module.MainViewType) as FrameworkElement; NavigationControl.SetNavigationName(view, module.Name); - TransitionControl.Elements.Add(view); + NavigationControl.Elements.Add(view); } _loader.UserModules.Add(module); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj index fdaf37c09..2b2752a24 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj @@ -126,7 +126,7 @@ - + @@ -421,7 +421,7 @@ copy /Y "$(SolutionDir)Referenced Assemblies\vcruntime140d.dll" "$(TargetDir)" - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispatcherProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispatcherProvider.cs new file mode 100644 index 000000000..940c13052 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispatcherProvider.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Threading; +using Tango.PPC.Common.Threading; + +namespace Tango.PPC.UI.Threading +{ + /// + /// Represents the default PPC which will invoke action on the current application dispatcher. + /// + /// + public class DefaultDispatcherProvider : IDispatcherProvider + { + private Dispatcher _dispatcher; + + /// + /// Initializes a new instance of the class. + /// + /// The dispatcher. + public DefaultDispatcherProvider(Dispatcher dispatcher) + { + _dispatcher = dispatcher; + } + + /// + /// Invokes the specified action asynchronously. + /// + /// The action. + public void Invoke(Action action) + { + _dispatcher.BeginInvoke(action); + } + + /// + /// Invokes the specified action synchronously. + /// + /// The action. + public void InvokeSync(Action action) + { + _dispatcher.Invoke(action); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispetcherProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispetcherProvider.cs deleted file mode 100644 index 0051ca329..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispetcherProvider.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Threading; -using Tango.PPC.Common.Threading; - -namespace Tango.PPC.UI.Threading -{ - /// - /// Represents the default PPC which will invoke action on the current application dispatcher. - /// - /// - public class DefaultDispetcherProvider : IDispatcherProvider - { - private Dispatcher _dispatcher; - - /// - /// Initializes a new instance of the class. - /// - /// The dispatcher. - public DefaultDispetcherProvider(Dispatcher dispatcher) - { - _dispatcher = dispatcher; - } - - /// - /// Invokes the specified action asynchronously. - /// - /// The action. - public void Invoke(Action action) - { - _dispatcher.BeginInvoke(action); - } - - /// - /// Invokes the specified action synchronously. - /// - /// The action. - public void InvokeSync(Action action) - { - _dispatcher.Invoke(action); - } - } -} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs index 5c416a289..bec1d2b48 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs @@ -58,7 +58,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); - TangoIOC.Default.Register(new DefaultDispetcherProvider(Application.Current.Dispatcher)); + TangoIOC.Default.Register(new DefaultDispatcherProvider(Application.Current.Dispatcher)); TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); diff --git a/Software/Visual_Studio/Tango.Editors/ElementsEditor.xaml.cs b/Software/Visual_Studio/Tango.Editors/ElementsEditor.xaml.cs index 4d2eabbb8..e32ae6dd3 100644 --- a/Software/Visual_Studio/Tango.Editors/ElementsEditor.xaml.cs +++ b/Software/Visual_Studio/Tango.Editors/ElementsEditor.xaml.cs @@ -723,7 +723,7 @@ namespace Tango.Editors /// The instance containing the event data. private void Element_PreviewMouseDown(object sender, MouseButtonEventArgs e) { - if (e.ChangedButton == MouseButton.Left && !Keyboard.IsKeyDown(Key.LeftShift) && IsEditable) + if (e.ChangedButton == MouseButton.Left && !Keyboard.IsKeyDown(Key.LeftShift)) { SelectedElement = sender as IElementEditor; } -- cgit v1.3.1 From a8718859eea4329ec9ecd3f7155e0001aa610c3d Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 23 Aug 2018 11:07:15 +0300 Subject: Added ObservablesContextAdapter and it's interactions. --- .../ViewModels/MainViewVM.cs | 10 +- .../ViewModels/MainViewVM.cs | 4 +- .../ViewModels/MainViewVM.cs | 6 +- .../TechItems/ProcessParametersItem.cs | 2 +- .../ViewModels/MachineTechViewVM.cs | 7 +- .../ViewModels/MainViewVM.cs | 4 +- .../ViewModels/MainViewVM.cs | 4 +- .../Tango.BL/ObservablesContextAdapter.cs | 188 +++++++++++++++++++++ .../Tango.BL/ObservablesContextExtension.cs | 97 +---------- .../Tango.BL/ObservablesStaticCollections.cs | 4 +- Software/Visual_Studio/Tango.BL/Tango.BL.csproj | 3 +- 11 files changed, 217 insertions(+), 112 deletions(-) create mode 100644 Software/Visual_Studio/Tango.BL/ObservablesContextAdapter.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs index f0b33ed06..1811ea7c7 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs @@ -443,7 +443,7 @@ namespace Tango.MachineStudio.ColorLab.ViewModels { IsFree = false; - _dbContext.GetConfiguration(x => x.Guid == SelectedMachine.ConfigurationGuid); + _dbContext.Adapter.GetConfiguration(x => x.Guid == SelectedMachine.ConfigurationGuid); LiquidVolumes = SelectedMachine.Configuration.NoneEmptyIdsPacks.OrderBy(x => x.PackIndex).Select(x => new LiquidVolumeVM() { @@ -558,10 +558,10 @@ namespace Tango.MachineStudio.ColorLab.ViewModels { using (_notification.PushTaskItem("Loading RML data...")) { - _dbContext.GetConfiguration(x => x.Guid == SelectedMachine.ConfigurationGuid); - _dbContext.GetRmlCCTs(SelectedRML.Guid); - _dbContext.GetRmlCATs(SelectedRML.Guid, SelectedMachine.Guid); - _dbContext.GetRmlLiquidTypes(SelectedRML.Guid); + _dbContext.Adapter.GetConfiguration(x => x.Guid == SelectedMachine.ConfigurationGuid); + _dbContext.Adapter.GetRmlCCTs(SelectedRML.Guid); + _dbContext.Adapter.GetRmlCATs(SelectedRML.Guid, SelectedMachine.Guid); + _dbContext.Adapter.GetRmlLiquidTypes(SelectedRML.Guid); LiquidTypesRmls = SelectedMachine.Configuration.NoneEmptyIdsPacks.OrderBy(x => x.PackIndex).Select(x => x.LiquidType).SelectMany(x => x.LiquidTypesRmls).Where(x => x.Rml.Guid == SelectedRML.Guid).ToList(); //RmlProcessParametersTableGroup = SelectedRML.ProcessParametersTablesGroups.ToList().SingleOrDefault(x => x.Active); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs index 8dcd92691..54b954745 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs @@ -70,7 +70,7 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels CurrentVersion = new HardwareVersion(); SaveCommand = new RelayCommand(Save, () => SelectedVersion != null && IsFree); - NewCommand = new RelayCommand(New,() => IsFree); + NewCommand = new RelayCommand(New, () => IsFree); DeleteCommand = new RelayCommand(Delete, () => !_isNew && SelectedVersion != null && IsFree); CurrentVersion = new HardwareVersion(); @@ -133,7 +133,7 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels _db = ObservablesContext.CreateDefault(); _db.Configuration.LazyLoadingEnabled = false; - CurrentVersion = _db.GetHardwareVersion(x => x.Guid == selectedVersion.Guid); + CurrentVersion = _db.Adapter.GetHardwareVersion(x => x.Guid == selectedVersion.Guid); InvokeUINow(() => diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs index bac916771..183cdb247 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs @@ -271,7 +271,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { InitCollections().Wait(); Machine = _db.Machines.Where(x => x.Guid == SelectedMachine.Guid).Include(x => x.Organization).SingleOrDefault(x => x.Guid == SelectedMachine.Guid); - Configuration = _db.GetConfiguration(x => x.Guid == Machine.ConfigurationGuid); + Configuration = _db.Adapter.GetConfiguration(x => x.Guid == Machine.ConfigurationGuid); SetHistory(); @@ -300,7 +300,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { CanWork = false; - SelectedHistoryConfiguration = _db.GetConfiguration(x => x.Guid == SelectedHistoryConfiguration.Guid); + SelectedHistoryConfiguration = _db.Adapter.GetConfiguration(x => x.Guid == SelectedHistoryConfiguration.Guid); Configuration = SelectedHistoryConfiguration; Machine.Configuration = Configuration; @@ -688,7 +688,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels await Task.Factory.StartNew(() => { var version = _db.MachineVersions.Where(x => x.Guid == Machine.MachineVersion.Guid).Include(x => x.DefaultConfiguration).FirstOrDefault(); - var version_config = _db.GetConfiguration(x => x.Guid == version.DefaultConfiguration.Guid); + var version_config = _db.Adapter.GetConfiguration(x => x.Guid == version.DefaultConfiguration.Guid); Configuration = version_config.Clone(); Machine.Configuration = Configuration; }); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ProcessParametersItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ProcessParametersItem.cs index 1bedcb1ca..4aedf8bc7 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ProcessParametersItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ProcessParametersItem.cs @@ -106,7 +106,7 @@ namespace Tango.MachineStudio.Technician.TechItems { using (ObservablesContext db = ObservablesContext.CreateDefault()) { - var group = db.GetActiveProcessParametersTablesGroup(SelectedResetRML.Guid); + var group = db.Adapter.GetRmlActiveProcessParametersTablesGroup(SelectedResetRML.Guid); if (group != null) { diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs index f96960883..55235b3c2 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs @@ -1682,8 +1682,8 @@ namespace Tango.MachineStudio.Technician.ViewModels { using (ObservablesContext db = ObservablesContext.CreateDefault()) { - config = db.GetConfiguration(x => x.Guid == ApplicationManager.ConnectedMachine.Machine.ConfigurationGuid).Clone(); - hw = db.GetHardwareVersionByMachine(ApplicationManager.ConnectedMachine.Machine.Guid).Clone(); + config = db.Adapter.GetConfiguration(x => x.Guid == ApplicationManager.ConnectedMachine.Machine.ConfigurationGuid).Clone(); + hw = db.Adapter.GetHardwareVersionByMachine(ApplicationManager.ConnectedMachine.Machine.Guid).Clone(); } }); @@ -1773,12 +1773,13 @@ namespace Tango.MachineStudio.Technician.ViewModels if (MachineOperator != null) { ObservablesContext db = ObservablesContext.CreateDefault(); + ObservablesContextAdapter adapter = new ObservablesContextAdapter(db); HardwareVersion hw = null; await Task.Factory.StartNew(() => { - hw = db.GetHardwareVersionByMachine(ApplicationManager.ConnectedMachine.Machine.Guid); + hw = adapter.GetHardwareVersionByMachine(ApplicationManager.ConnectedMachine.Machine.Guid); }); foreach (var motorConfig in hw.HardwareMotors) diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs index a5ef4f095..0def388d3 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs @@ -202,7 +202,7 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels _userContext.Configuration.LazyLoadingEnabled = false; Roles = _userContext.Roles.ToObservableCollection(); - ManagedUser = _userContext.GetUser(SelectedUser.Guid); + ManagedUser = _userContext.Adapter.GetUser(SelectedUser.Guid); ManagedUserRoles = ManagedUser.Roles.ToObservableCollection(); }); @@ -258,7 +258,7 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels _manageContext = ObservablesContext.CreateDefault(); _manageContext.Configuration.LazyLoadingEnabled = false; - ManagedOrganization = _manageContext.GetOrganizationAndUsers(SelectedOrganization.Guid); + ManagedOrganization = _manageContext.Adapter.GetOrganizationAndUsers(SelectedOrganization.Guid); }); _navigation.NavigateTo(UsersAndRolesNavigationView.OrganizationManagementView); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index 36ce62897..f164d7f14 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -550,8 +550,8 @@ namespace Tango.MachineStudio.UI.ViewModels { using (ObservablesContext db = ObservablesContext.CreateDefault()) { - var config = db.GetConfiguration(s => s.Guid == ApplicationManager.ConnectedMachine.Machine.ConfigurationGuid); - var hw = db.GetHardwareVersionByMachine(ApplicationManager.ConnectedMachine.Machine.Guid); + var config = db.Adapter.GetConfiguration(s => s.Guid == ApplicationManager.ConnectedMachine.Machine.ConfigurationGuid); + var hw = db.Adapter.GetHardwareVersionByMachine(ApplicationManager.ConnectedMachine.Machine.Guid); await ApplicationManager.ConnectedMachine.UploadHardwareConfiguration(hw, config); } diff --git a/Software/Visual_Studio/Tango.BL/ObservablesContextAdapter.cs b/Software/Visual_Studio/Tango.BL/ObservablesContextAdapter.cs new file mode 100644 index 000000000..805afaf67 --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/ObservablesContextAdapter.cs @@ -0,0 +1,188 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using System.Data.Entity; +using System.Collections.ObjectModel; + +namespace Tango.BL +{ + /// + /// Represents an adapter for retrieving aggregated entities. + /// + public class ObservablesContextAdapter : IDisposable + { + private ObservablesContext _db; + /// + /// Gets the underlying . + /// + public ObservablesContext Context + { + get { return _db; } + } + + /// + /// Initializes a new instance of the class. + /// + /// The context. + public ObservablesContextAdapter(ObservablesContext context) + { + _db = context; + } + + /// + /// Creates the a new instance of wrapping a default . + /// + /// + public static ObservablesContextAdapter CreateDefault() + { + var context = ObservablesContext.CreateDefault(); + return new ObservablesContextAdapter(context); + } + + /// + /// Loads the configuration with it's Ids packs. + /// + /// The condition. + /// + public Configuration GetConfiguration(Expression> condition) + { + var config = _db.Configurations.SingleOrDefault(condition); + + config.IdsPacks = _db.IdsPacks.Where(x => x.ConfigurationGuid == config.Guid) + .Include(x => x.LiquidType) + .Include(x => x.DispenserType) + .Include(x => x.CartridgeType) + .Include(x => x.DispenserType) + .Include(x => x.IdsPackFormula).OrderBy(x => x.PackIndex).ToObservableCollection(); + + return config; + } + + /// + /// Gets the hardware version by the specified condition. + /// + /// The condition. + /// + public HardwareVersion GetHardwareVersion(Expression> condition) + { + HardwareVersion version = _db.HardwareVersions.SingleOrDefault(condition); + + version.HardwareBlowers = _db.HardwareBlowers.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareBlowerType).ToList().OrderBy(x => x.HardwareBlowerType.Code).ToObservableCollection(); + version.HardwareBreakSensors = _db.HardwareBreakSensors.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareBreakSensorType).ToList().OrderBy(x => x.HardwareBreakSensorType.Code).ToObservableCollection(); + version.HardwareDancers = _db.HardwareDancers.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareDancerType).ToList().OrderBy(x => x.HardwareDancerType.Code).ToObservableCollection(); + version.HardwareMotors = _db.HardwareMotors.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareMotorType).ToList().OrderBy(x => x.HardwareMotorType.Code).ToObservableCollection(); + version.HardwarePidControls = _db.HardwarePidControls.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwarePidControlType).ToList().OrderBy(x => x.HardwarePidControlType.Code).ToObservableCollection(); + version.HardwareSpeedSensors = _db.HardwareSpeedSensors.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareSpeedSensorType).ToList().OrderBy(x => x.HardwareSpeedSensorType.Code).ToObservableCollection(); + version.HardwareWinders = _db.HardwareWinders.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareWinderType).ToList().OrderBy(x => x.HardwareWinderType.Code).ToObservableCollection(); + + return version; + } + + /// + /// Gets the hardware version by machine. + /// + /// The machine unique identifier. + /// + public HardwareVersion GetHardwareVersionByMachine(String machineGuid) + { + var machine = _db.Machines.Where(x => x.Guid == machineGuid).Include(x => x.Configuration).FirstOrDefault(); + return GetHardwareVersion(x => x.Guid == machine.Configuration.HardwareVersionGuid); + } + + /// + /// Gets the active process parameters tables group. + /// + /// The RML unique identifier. + /// + public ProcessParametersTablesGroup GetRmlActiveProcessParametersTablesGroup(String rmlGuid) + { + return _db.ProcessParametersTablesGroups.Where(x => x.RmlGuid == rmlGuid && x.Active).Include(x => x.ProcessParametersTables).FirstOrDefault(); + } + + /// + /// Gets the RML CCTS. + /// + /// The RML unique identifier. + /// + public ObservableCollection GetRmlCCTs(String rmlGuid) + { + return _db.Ccts.Where(x => x.RmlGuid == rmlGuid).ToObservableCollection(); + } + + /// + /// Gets the RML CATS. + /// + /// The RML unique identifier. + /// The machine unique identifier. + /// + public ObservableCollection GetRmlCATs(String rmlGuid, String machineGuid) + { + return _db.Cats.Where(x => x.MachineGuid == machineGuid && x.RmlGuid == rmlGuid).ToObservableCollection(); + } + + /// + /// Gets the RML liquid types factors. + /// + /// The RML unique identifier. + /// + public ObservableCollection GetRmlLiquidTypes(String rmlGuid) + { + return _db.LiquidTypesRmls.Where(x => x.RmlGuid == rmlGuid).ToObservableCollection(); + } + + /// + /// Gets the organization with all it's users addresses and contacts. + /// + /// The organization unique identifier. + /// + public Organization GetOrganizationAndUsers(String organizationGuid) + { + var org = _db.Organizations.SingleOrDefault(x => x.Guid == organizationGuid); + + org.Address = _db.Addresses.SingleOrDefault(x => x.Guid == org.AddressGuid); + org.Contact = _db.Contacts.SingleOrDefault(x => x.Guid == org.ContactGuid); + + _db.Roles.Load(); + _db.Permissions.Load(); + _db.RolesPermissions.Load(); + + + org.Users = _db.Users.Where(x => x.OrganizationGuid == organizationGuid) + .Include(x => x.Address) + .Include(x => x.Contact) + .Include(x => x.UsersRoles).ToObservableCollection(); + + return org; + } + + /// + /// Gets the user with it's address and contact. + /// + /// The user unique identifier. + /// + public User GetUser(String userGuid) + { + _db.Roles.Load(); + _db.Permissions.Load(); + _db.RolesPermissions.Load(); + + return _db.Users.Where(x => x.Guid == userGuid) + .Include(x => x.Address) + .Include(x => x.Contact) + .Include(x => x.UsersRoles) + .FirstOrDefault(); + } + + /// + /// Disposes the underlying . + /// + public void Dispose() + { + _db.Dispose(); + } + } +} diff --git a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs index d265fbe01..49c80695f 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs @@ -19,6 +19,7 @@ namespace Tango.BL public partial class ObservablesContext { private List _pending_notifications = new List(); + private ObservablesContextAdapter _adapter; public ObservablesContext() { @@ -33,6 +34,7 @@ namespace Tango.BL public ObservablesContext(DataSource dataSource) : base(dataSource.ToConnection(), true) { Database.SetInitializer(null); + _adapter = new ObservablesContextAdapter(this); } /// @@ -161,101 +163,12 @@ namespace Tango.BL return base.ShouldValidateEntity(entityEntry); } - #region Public Methods - /// - /// Loads the configuration with it's Ids packs. + /// Gets an instance of which wraps this instance. /// - /// The condition. - /// - public Configuration GetConfiguration(Expression> condition) - { - var config = Configurations.SingleOrDefault(condition); - - config.IdsPacks = IdsPacks.Where(x => x.ConfigurationGuid == config.Guid) - .Include(x => x.LiquidType) - .Include(x => x.DispenserType) - .Include(x => x.CartridgeType) - .Include(x => x.DispenserType) - .Include(x => x.IdsPackFormula).OrderBy(x => x.PackIndex).ToObservableCollection(); - - return config; - } - - public HardwareVersion GetHardwareVersion(Expression> condition) + public ObservablesContextAdapter Adapter { - HardwareVersion version = HardwareVersions.SingleOrDefault(condition); - - version.HardwareBlowers = HardwareBlowers.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareBlowerType).ToList().OrderBy(x => x.HardwareBlowerType.Code).ToObservableCollection(); - version.HardwareBreakSensors = HardwareBreakSensors.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareBreakSensorType).ToList().OrderBy(x => x.HardwareBreakSensorType.Code).ToObservableCollection(); - version.HardwareDancers = HardwareDancers.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareDancerType).ToList().OrderBy(x => x.HardwareDancerType.Code).ToObservableCollection(); - version.HardwareMotors = HardwareMotors.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareMotorType).ToList().OrderBy(x => x.HardwareMotorType.Code).ToObservableCollection(); - version.HardwarePidControls = HardwarePidControls.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwarePidControlType).ToList().OrderBy(x => x.HardwarePidControlType.Code).ToObservableCollection(); - version.HardwareSpeedSensors = HardwareSpeedSensors.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareSpeedSensorType).ToList().OrderBy(x => x.HardwareSpeedSensorType.Code).ToObservableCollection(); - version.HardwareWinders = HardwareWinders.Where(x => x.HardwareVersionGuid == version.Guid).Include(x => x.HardwareWinderType).ToList().OrderBy(x => x.HardwareWinderType.Code).ToObservableCollection(); - - return version; + get { return _adapter; } } - - public HardwareVersion GetHardwareVersionByMachine(String machineGuid) - { - var machine = Machines.Where(x => x.Guid == machineGuid).Include(x => x.Configuration).FirstOrDefault(); - return GetHardwareVersion(x => x.Guid == machine.Configuration.HardwareVersionGuid); - } - - public ProcessParametersTablesGroup GetActiveProcessParametersTablesGroup(String rmlGuid) - { - return ProcessParametersTablesGroups.Where(x => x.RmlGuid == rmlGuid && x.Active).Include(x => x.ProcessParametersTables).FirstOrDefault(); - } - - public ObservableCollection GetRmlCCTs(String rmlGuid) - { - return Ccts.Where(x => x.RmlGuid == rmlGuid).ToObservableCollection(); - } - - public ObservableCollection GetRmlCATs(String rmlGuid, String machineGuid) - { - return Cats.Where(x => x.MachineGuid == machineGuid && x.RmlGuid == rmlGuid).ToObservableCollection(); - } - - public ObservableCollection GetRmlLiquidTypes(String rmlGuid) - { - return LiquidTypesRmls.Where(x => x.RmlGuid == rmlGuid).ToObservableCollection(); - } - - public Organization GetOrganizationAndUsers(String organizationGuid) - { - var org = Organizations.SingleOrDefault(x => x.Guid == organizationGuid); - - org.Address = Addresses.SingleOrDefault(x => x.Guid == org.AddressGuid); - org.Contact = Contacts.SingleOrDefault(x => x.Guid == org.ContactGuid); - - Roles.Load(); - Permissions.Load(); - RolesPermissions.Load(); - - - org.Users = Users.Where(x => x.OrganizationGuid == organizationGuid) - .Include(x => x.Address) - .Include(x => x.Contact) - .Include(x => x.UsersRoles).ToObservableCollection(); - - return org; - } - - public User GetUser(String userGuid) - { - Roles.Load(); - Permissions.Load(); - RolesPermissions.Load(); - - return Users.Where(x => x.Guid == userGuid) - .Include(x => x.Address) - .Include(x => x.Contact) - .Include(x => x.UsersRoles) - .FirstOrDefault(); - } - - #endregion } } diff --git a/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs b/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs index 1356206ea..db5faef4b 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs @@ -103,7 +103,9 @@ namespace Tango.BL foreach (var machine in Machines) { - db.GetConfiguration(x => x.Guid == machine.ConfigurationGuid); + ObservablesContextAdapter adapter = new ObservablesContextAdapter(db); + + adapter.GetConfiguration(x => x.Guid == machine.ConfigurationGuid); } }); diff --git a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj index eb6cd7b6c..bfc1a033a 100644 --- a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj +++ b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj @@ -240,6 +240,7 @@ + @@ -322,7 +323,7 @@ - + \ No newline at end of file -- cgit v1.3.1 From ea97f593f82a1176125901c257c8e81c45c23b67 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 23 Aug 2018 11:17:23 +0300 Subject: ObservablesContext is now LazyLoading = 'false' by default. --- .../ViewModels/MainViewVM.cs | 1 - .../ViewModels/MainViewVM.cs | 2 -- .../ViewModels/MainViewVM.cs | 3 --- .../ViewModels/EventsViewVM.cs | 1 - .../ViewModels/MainViewVM.cs | 1 - .../ViewModels/MainViewVM.cs | 3 --- .../EventLogging/DefaultEventLogger.cs | 1 - .../Authentication/DefaultAuthenticationProvider.cs | 1 - .../EventLogging/DefaultEventLogger.cs | 1 - Software/Visual_Studio/Tango.BL/ObservableEntity.cs | 21 ++++++++++++++++++++- .../Tango.BL/ObservablesContextExtension.cs | 1 + .../Tango.BL/ObservablesEntitiesAdapter.cs | 1 + .../Tango.BL/ObservablesStaticCollections.cs | 2 -- 13 files changed, 22 insertions(+), 17 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels') 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 1811ea7c7..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 @@ -281,7 +281,6 @@ namespace Tango.MachineStudio.ColorLab.ViewModels Task.Factory.StartNew(() => { _dbContext = ObservablesContext.CreateDefault(); - _dbContext.Configuration.LazyLoadingEnabled = false; Machines = _dbContext.Machines.ToObservableCollection(); ColorSpaces = _dbContext.ColorSpaces.ToObservableCollection(); 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 6178ae30a..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 @@ -732,7 +732,6 @@ namespace Tango.MachineStudio.Developer.ViewModels LogManager.Log("Initializing machine Db context..."); _machineDbContext = ObservablesContext.CreateDefault(); - _machineDbContext.Configuration.LazyLoadingEnabled = false; if (_settings.LastSelectedMachineGuid != null) { @@ -1498,7 +1497,6 @@ namespace Tango.MachineStudio.Developer.ViewModels LogManager.Log("Creating active job DB context..."); _activeJobDbContext = ObservablesContext.CreateDefault(); - _activeJobDbContext.Configuration.LazyLoadingEnabled = false; LogManager.Log("Initializing available color spaces, RMLs & Winding methods..."); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs index 54b954745..6ba28cb72 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs @@ -102,7 +102,6 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels if (_db != null) _db.Dispose(); _db = ObservablesContext.CreateDefault(); - _db.Configuration.LazyLoadingEnabled = false; CurrentVersion.HardwareMotors = _db.HardwareMotorTypes.ToList().Select(x => new HardwareMotor() { HardwareMotorType = x }).ToObservableCollection(); CurrentVersion.HardwareDancers = _db.HardwareDancerTypes.ToList().Select(x => new HardwareDancer() { HardwareDancerType = x }).ToObservableCollection(); @@ -117,7 +116,6 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels { using (var db = ObservablesContext.CreateDefault()) { - db.Configuration.LazyLoadingEnabled = false; _hardwareVersions = db.HardwareVersions.ToObservableCollection(); InvokeUI(() => { @@ -131,7 +129,6 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels if (_db != null) _db.Dispose(); _db = ObservablesContext.CreateDefault(); - _db.Configuration.LazyLoadingEnabled = false; CurrentVersion = _db.Adapter.GetHardwareVersion(x => x.Guid == selectedVersion.Guid); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs index 20eba4b8e..68094d91f 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs @@ -138,7 +138,6 @@ namespace Tango.MachineStudio.Logging.ViewModels await Task.Factory.StartNew(() => { _db = ObservablesContext.CreateDefault(); - _db.Configuration.LazyLoadingEnabled = false; _db.EventTypes.Load(); _db.EventTypesCategories.Load(); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs index 183cdb247..de9a8de4a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs @@ -218,7 +218,6 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels CanWork = false; _db = ObservablesContext.CreateDefault(); - _db.Configuration.LazyLoadingEnabled = false; Adapter = new ObservablesStaticCollections(); Adapter.ApplicationDisplayPanelVersions = _db.ApplicationDisplayPanelVersions.ToObservableCollection(); 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 0def388d3..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 @@ -199,7 +199,6 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels await Task.Factory.StartNew(() => { _userContext = ObservablesContext.CreateDefault(); - _userContext.Configuration.LazyLoadingEnabled = false; Roles = _userContext.Roles.ToObservableCollection(); ManagedUser = _userContext.Adapter.GetUser(SelectedUser.Guid); @@ -256,7 +255,6 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels await Task.Factory.StartNew(() => { _manageContext = ObservablesContext.CreateDefault(); - _manageContext.Configuration.LazyLoadingEnabled = false; ManagedOrganization = _manageContext.Adapter.GetOrganizationAndUsers(SelectedOrganization.Guid); }); @@ -270,7 +268,6 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels Task.Factory.StartNew(() => { _organizationsContext = ObservablesContext.CreateDefault(); - _organizationsContext.Configuration.LazyLoadingEnabled = false; Organizations = _organizationsContext.Organizations .Include(x => x.Machines) 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.UI/Authentication/DefaultAuthenticationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs index de84e43e8..c16f76449 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs @@ -51,7 +51,6 @@ namespace Tango.MachineStudio.UI.Authentication { using (ObservablesContext db = ObservablesContext.CreateDefault()) { - db.Configuration.LazyLoadingEnabled = false; String hash = User.GetPasswordHash(password); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/EventLogging/DefaultEventLogger.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/EventLogging/DefaultEventLogger.cs index d981723be..adf99e3a3 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/EventLogging/DefaultEventLogger.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/EventLogging/DefaultEventLogger.cs @@ -80,7 +80,6 @@ namespace Tango.PPC.Common.EventLogging try { _db = ObservablesContext.CreateDefault(); - _db.Configuration.LazyLoadingEnabled = false; _db.ActionTypes.ToList(); _db.EventTypesActions.ToList(); diff --git a/Software/Visual_Studio/Tango.BL/ObservableEntity.cs b/Software/Visual_Studio/Tango.BL/ObservableEntity.cs index d6cdcfb16..1b69a8bdb 100644 --- a/Software/Visual_Studio/Tango.BL/ObservableEntity.cs +++ b/Software/Visual_Studio/Tango.BL/ObservableEntity.cs @@ -157,7 +157,26 @@ namespace Tango.BL /// public virtual void Save(ObservablesContext context) { - context.SaveChanges(); + if (context == ObservablesEntitiesAdapter.Instance.Context) + { + var tableName = this.GetType().GetCustomAttribute().Name; + + String propName = tableName.FromDalNameToTitleCase(); + + DbSet set = ObservablesEntitiesAdapter.Instance.Context.GetType().GetProperty(propName, BindingFlags.Instance | BindingFlags.Public).GetValue(context) as DbSet; + ObservableCollection obs = ObservablesEntitiesAdapter.Instance.GetType().GetProperty(propName, BindingFlags.Instance | BindingFlags.Public).GetValue(ObservablesEntitiesAdapter.Instance) as ObservableCollection; + + if (!obs.Contains(this as T)) + { + set.Add(this as T); + } + + ObservablesEntitiesAdapter.Instance.SaveChanges(); + } + else + { + context.SaveChanges(); + } } /// diff --git a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs index 49c80695f..f387bd1e1 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs @@ -34,6 +34,7 @@ namespace Tango.BL public ObservablesContext(DataSource dataSource) : base(dataSource.ToConnection(), true) { Database.SetInitializer(null); + Configuration.LazyLoadingEnabled = false; _adapter = new ObservablesContextAdapter(this); } diff --git a/Software/Visual_Studio/Tango.BL/ObservablesEntitiesAdapter.cs b/Software/Visual_Studio/Tango.BL/ObservablesEntitiesAdapter.cs index fdc359da0..4fdaf9071 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesEntitiesAdapter.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesEntitiesAdapter.cs @@ -69,6 +69,7 @@ namespace Tango.BL private ObservablesEntitiesAdapter() { Context = ObservablesContext.CreateDefault(); + Context.Configuration.LazyLoadingEnabled = true; } /// diff --git a/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs b/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs index db5faef4b..4820c784b 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs @@ -42,8 +42,6 @@ namespace Tango.BL { db = ObservablesContext.CreateDefault(); - db.Configuration.LazyLoadingEnabled = false; - WindingMethods = db.WindingMethods.ToObservableCollection(); ColorSpaces = db.ColorSpaces.ToObservableCollection(); SpoolTypes = db.SpoolTypes.ToObservableCollection(); -- cgit v1.3.1