diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2018-12-30 01:27:53 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2018-12-30 01:27:53 +0200 |
| commit | cc3480d4aac4175b1072060dd2d6d398d3451ae8 (patch) | |
| tree | 0c416705eca9d499a3118d83d84b5143f3cee262 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs | |
| parent | 7b69f9a96ab82e3a6e2345092600edf5854f5f4f (diff) | |
| download | Tango-cc3480d4aac4175b1072060dd2d6d398d3451ae8.tar.gz Tango-cc3480d4aac4175b1072060dd2d6d398d3451ae8.zip | |
Working on dispenserssssssss
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs | 769 |
1 files changed, 317 insertions, 452 deletions
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 5a5df0d0f..e2924a185 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 @@ -18,45 +18,38 @@ using Tango.MachineStudio.Common; using Tango.BL; using Tango.AutoComplete.Editors; using System.Data.Entity; +using Tango.BL.Builders; +using Tango.MachineStudio.MachineDesigner.Contracts; namespace Tango.MachineStudio.MachineDesigner.ViewModels { - public class MainViewVM : StudioViewModel + public class MainViewVM : StudioViewModel<IMainView> { private INotificationProvider _notification; - private ObservablesContext _db; - private Configuration _original_configuration; + private ObservablesContext _dbContext; + private ObservablesContext _machineContext; + private ObservablesContext _configContext; #region Properties - private ObservablesStaticCollections _adapter; + private ObservableCollection<Machine> _machines; /// <summary> - /// Gets or sets the db static adapter. + /// Gets or sets the machines. /// </summary> - public ObservablesStaticCollections Adapter + public ObservableCollection<Machine> Machines { - get { return _adapter; } - set { _adapter = value; RaisePropertyChangedAuto(); } + get { return _machines; } + set { _machines = value; RaisePropertyChangedAuto(); } } - private bool _canWork; + private ObservableCollection<Dispenser> _dispensers; /// <summary> - /// Gets or sets a value indicating whether this instance can work. + /// Gets or sets the dispensers. /// </summary> - public bool CanWork + public ObservableCollection<Dispenser> Dispensers { - get { return _canWork; } - set { _canWork = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } - } - - private Machine _machine; - /// <summary> - /// Gets or sets the current editable machine. - /// </summary> - public Machine Machine - { - get { return _machine; } - set { _machine = value; RaisePropertyChangedAuto(); } + get { return _dispensers; } + set { _dispensers = value; RaisePropertyChangedAuto(); } } private Machine _selectedMachine; @@ -70,11 +63,24 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { if (_selectedMachine != value) { - _selectedMachine = value; RaisePropertyChangedAuto(); OnSelectedMachineChanged(); + _selectedMachine = value; + RaisePropertyChangedAuto(); + InvalidateRelayCommands(); } } } + private Machine _activeMachine; + /// <summary> + /// Gets or sets the active machine. + /// </summary> + public Machine ActiveMachine + { + get { return _activeMachine; } + set { _activeMachine = value; RaisePropertyChangedAuto(); } + } + + private Configuration _configuration; /// <summary> /// Gets or sets the editable machine configuration. @@ -95,29 +101,19 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels set { _selectedIds = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } } - private ObservableCollection<Configuration> _history; + private String _dispensersFilter; /// <summary> - /// Gets or sets the machine configuration history. + /// Gets or sets the dispensers filter. /// </summary> - public ObservableCollection<Configuration> History + public String DispensersFilter { - get { return _history; } - set { _history = value; RaisePropertyChangedAuto(); } - } - - private Configuration _selectedHistoryConfiguration; - /// <summary> - /// Gets or sets the machine selected configuration from history. - /// </summary> - public Configuration SelectedHistoryConfiguration - { - get { return _selectedHistoryConfiguration; } - set { _selectedHistoryConfiguration = value; RaisePropertyChangedAuto(); OnHistoryConfigurationSelected(); } + get { return _dispensersFilter; } + set { _dispensersFilter = value; RaisePropertyChangedAuto(); OnDispensersFilterChanged(); } } private String _filter; /// <summary> - /// Gets or sets the configuration components filter. + /// Gets or sets the machines filter. /// </summary> public String Filter { @@ -125,11 +121,6 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels set { _filter = value; RaisePropertyChangedAuto(); OnFilterChanged(); } } - /// <summary> - /// Gets or sets the machines provider. - /// </summary> - public ISuggestionProvider MachinesProvider { get; set; } - #endregion #region Commands @@ -150,19 +141,19 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels public RelayCommand RemoveIdsCommand { get; set; } /// <summary> - /// Gets or sets the set version configuration command. + /// Gets or sets the remove machine command. /// </summary> - public RelayCommand SetVersionConfigurationCommand { get; set; } + public RelayCommand RemoveMachineCommand { get; set; } /// <summary> - /// Gets or sets the set as default command. + /// Gets or sets the add machine command. /// </summary> - public RelayCommand SetAsDefaultCommand { get; set; } + public RelayCommand AddMachineCommand { get; set; } /// <summary> - /// Gets or sets the reset command. + /// Gets or sets the edit machine command. /// </summary> - public RelayCommand ResetCommand { get; set; } + public RelayCommand EditMachineCommand { get; set; } #endregion @@ -178,195 +169,95 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// </summary> public MainViewVM(INotificationProvider notification) { - CanWork = true; - + _dbContext = ObservablesContext.CreateDefault(); _notification = notification; - Configuration = new Configuration(); - Configuration.Name = "Untitled"; - Machine = new Machine(); - Machine.Configuration = Configuration; - - 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); + //SaveCommand = new RelayCommand(Save); + AddIdsCommand = new RelayCommand(AddIds, (x) => Configuration != null && Configuration.IdsPacks.Count < 8); + RemoveIdsCommand = new RelayCommand(RemoveIds, (x) => SelectedIds != null); + EditMachineCommand = new RelayCommand(EditSelectedMachine, () => SelectedMachine != null); + } - MachinesProvider = new SuggestionProvider((filter) => + private async void EditSelectedMachine() + { + using (_notification.PushTaskItem("Loading machine details...")) { - try - { - return _db.Machines.Where(x => x.SerialNumber.StartsWith(filter)).ToList(); - } - catch + IsFree = false; + + if (_machineContext != null) { - return new List<Machine>(); + _machineContext.Dispose(); } - }); + + _machineContext = ObservablesContext.CreateDefault(); + ActiveMachine = (await new MachineBuilder(_machineContext).Set(SelectedMachine).WithOrganization().WithConfiguration().BuildAsync()); + View.NavigateTo(MachineDesignerNavigationView.MachineDetailsView); + + IsFree = true; + } } #endregion #region Application Ready - public async override void OnApplicationReady() + public override void OnApplicationReady() { - await InitCollections(); + } #endregion - private Task InitCollections() - { - return Task.Factory.StartNew(() => - { - CanWork = false; + //private Task InitCollections() + //{ + // return Task.Factory.StartNew(() => + // { + // CanWork = false; - _db = ObservablesContext.CreateDefault(); + // _dbContext = ObservablesContext.CreateDefault(); - 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 = new ObservablesStaticCollections(); + // Adapter.ApplicationDisplayPanelVersions = _dbContext.ApplicationDisplayPanelVersions.ToObservableCollection(); + // Adapter.ApplicationFirmwareVersions = _dbContext.ApplicationFirmwareVersions.ToObservableCollection(); + // Adapter.ApplicationOsVersions = _dbContext.ApplicationOsVersions.ToObservableCollection(); + // Adapter.EmbeddedFirmwareVersions = _dbContext.EmbeddedFirmwareVersions.ToObservableCollection(); + // Adapter.DispenserTypes = _dbContext.DispenserTypes.ToObservableCollection(); + // Adapter.LiquidTypes = _dbContext.LiquidTypes.ToObservableCollection(); + // Adapter.MidTankTypes = _dbContext.MidTankTypes.ToObservableCollection(); + // Adapter.CartridgeTypes = _dbContext.CartridgeTypes.ToObservableCollection(); + // Adapter.IdsPackFormulas = _dbContext.IdsPackFormulas.ToObservableCollection(); + // Adapter.HardwareVersions = _dbContext.HardwareVersions.ToObservableCollection(); + // Adapter.MachineVersions = _dbContext.MachineVersions.ToObservableCollection(); + // Adapter.Organizations = _dbContext.Organizations.ToObservableCollection(); - Adapter.InitCollectionSources(); + // Adapter.InitCollectionSources(); - CanWork = true; - }); - } + // CanWork = true; + // }); + //} private void Reset() { - using (_notification.PushTaskItem("Resetting designer...")) - { - SelectedMachine = null; - Machine = new Machine(); - Configuration = new Configuration(); - History = new ObservableCollection<Configuration>(); - SelectedHistoryConfiguration = null; - Filter = String.Empty; - InitCollections(); - } + //using (_notification.PushTaskItem("Resetting designer...")) + //{ + // SelectedMachine = null; + // Machine = new Machine(); + // Configuration = new Configuration(); + // InitCollections(); + //} } - #region Virtual Methods - - /// <summary> - /// Called when the selected machine has changed. - /// </summary> - protected virtual void OnSelectedMachineChanged() + private async void OnDispensersFilterChanged() { - if (SelectedMachine != null) + if (!String.IsNullOrWhiteSpace(DispensersFilter)) { - 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.Adapter.GetConfiguration(x => x.Guid == Machine.ConfigurationGuid); - - SetHistory(); - - _original_configuration = Configuration.Clone(); - }); - } - - CanWork = true; - } - else - { - History = new ObservableCollection<Configuration>(); - } - } - - /// <summary> - /// Called when the history configuration has been selected - /// </summary> - protected virtual void OnHistoryConfigurationSelected() - { - if (SelectedHistoryConfiguration != null && CanWork) - { - using (_notification.PushTaskItem("Loading Configuration...")) - { - Task.Factory.StartNew(() => - { - CanWork = false; - - SelectedHistoryConfiguration = _db.Adapter.GetConfiguration(x => x.Guid == SelectedHistoryConfiguration.Guid); - Configuration = SelectedHistoryConfiguration; - Machine.Configuration = Configuration; - - CanWork = true; - }); - } - } - } - - /// <summary> - /// Called when the filter has changed - /// </summary> - protected virtual void OnFilterChanged() - { - List<ICollectionView> collections = new List<ICollectionView>(); - collections.Add(Adapter.ApplicationFirmwareVersionsViewSource); - collections.Add(Adapter.ApplicationDisplayPanelVersionsViewSource); - collections.Add(Adapter.ApplicationOsVersionsViewSource); - collections.Add(Adapter.EmbeddedFirmwareVersionsViewSource); - collections.Add(Adapter.DispenserTypesViewSource); - collections.Add(Adapter.CartridgeTypesViewSource); - collections.Add(Adapter.LiquidTypesViewSource); - collections.Add(Adapter.MidTankTypesViewSource); - collections.Add(Adapter.HardwareVersionsViewSource); - - foreach (var collection in collections) - { - collection.Filter = (x) => - { - foreach (var prop in x.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(y => y.PropertyType == typeof(String))) - { - String value = prop.GetValue(x).ToStringSafe(); - - if (value != null && Filter != null) - { - if (value.ToLower().Contains(Filter.ToLower())) - { - return true; - } - } - } - - return false; - }; + IsFree = false; + Dispensers = (await _configContext.Dispensers.Where(x => x.SerialNumber.ToLower().StartsWith(DispensersFilter.ToLower())).ToListAsync()).ToObservableCollection(); + IsFree = true; } } - #endregion - - #region Public Methods - - /// <summary> - /// Sets the selected machine without any further processing. - /// </summary> - /// <param name="machine">The machine.</param> - public void SetSelectedMachine(Machine machine) - { - _machine = machine; - RaisePropertyChanged(nameof(Machine)); - } + #region Virtual Methods #endregion @@ -433,25 +324,25 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels } /// <summary> - /// Drops the type of the cartridge. + /// Drops the dispenser. /// </summary> - /// <param name="cartridgeType">Type of the cartridge.</param> + /// <param name="dispenser">The dispenser.</param> /// <param name="idsPack">The ids pack.</param> - public void DropCartridgeType(CartridgeType cartridgeType, IdsPack idsPack) + public void DropDispenser(Dispenser dispenser, IdsPack idsPack) { - idsPack.CartridgeType = cartridgeType; - idsPack.CartridgeTypeGuid = cartridgeType.Guid; + idsPack.Dispenser = dispenser; + idsPack.DispenserGuid = dispenser.Guid; } /// <summary> - /// Drops the dispenser. + /// Drops the type of the cartridge. /// </summary> - /// <param name="dispenserType">The dispenser.</param> + /// <param name="cartridgeType">Type of the cartridge.</param> /// <param name="idsPack">The ids pack.</param> - public void DropDispenserType(DispenserType dispenserType, IdsPack idsPack) + public void DropCartridgeType(CartridgeType cartridgeType, IdsPack idsPack) { - idsPack.DispenserType = dispenserType; - idsPack.DispenserTypeGuid = dispenserType.Guid; + idsPack.CartridgeType = cartridgeType; + idsPack.CartridgeTypeGuid = cartridgeType.Guid; } /// <summary> @@ -497,7 +388,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// </summary> private void RemoveIds() { - _db.IdsPacks.Remove(SelectedIds); + _dbContext.IdsPacks.Remove(SelectedIds); SelectedIds = null; } @@ -506,277 +397,251 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// </summary> private void AddIds() { - _db.IdsPacks.Add(new IdsPack() { Configuration = Configuration }); + _dbContext.IdsPacks.Add(new IdsPack() { Configuration = Configuration }); InvalidateRelayCommands(); } - /// <summary> - /// Saves the current machine configuration. - /// </summary> - private async void Save() - { - foreach (var ids in Configuration.IdsPacks) - { - ids.PackIndex = Configuration.IdsPacks.IndexOf(ids); - ids.Configuration = Configuration; - ids.ConfigurationGuid = Configuration.Guid; - } + ///// <summary> + ///// Saves the current machine configuration. + ///// </summary> + //private async void Save() + //{ + // foreach (var ids in Configuration.IdsPacks) + // { + // ids.PackIndex = Configuration.IdsPacks.IndexOf(ids); + // ids.Configuration = Configuration; + // ids.ConfigurationGuid = Configuration.Guid; + // } - //Validate + // //Validate - List<String> errors = new List<string>(); + // List<String> errors = new List<string>(); - if (Machine.MachineVersion == null) - { - errors.Add("Machine version is required."); - } + // if (Machine.MachineVersion == null) + // { + // errors.Add("Machine version is required."); + // } - if (Machine.Name.IsNullOrWhiteSpace()) - { - errors.Add("Machine name is required."); - } + // if (Machine.Name.IsNullOrWhiteSpace()) + // { + // errors.Add("Machine name is required."); + // } - if (Machine.Organization == null) - { - errors.Add("Machine organization is required."); - } + // if (Machine.Organization == null) + // { + // errors.Add("Machine organization is required."); + // } - if (Machine.SerialNumber.IsNullOrWhiteSpace()) - { - errors.Add("Machine serial number is required."); - } + // if (Machine.SerialNumber.IsNullOrWhiteSpace()) + // { + // errors.Add("Machine serial number is required."); + // } - if (Configuration.Name.IsNullOrWhiteSpace()) - { - errors.Add("Configuration name is required."); - } + // if (Configuration.Name.IsNullOrWhiteSpace()) + // { + // errors.Add("Configuration name is required."); + // } - if (Configuration.ApplicationDisplayPanelVersion == null) - { - errors.Add("Touch Panel is required."); - } + // if (Configuration.ApplicationDisplayPanelVersion == null) + // { + // errors.Add("Touch Panel is required."); + // } - if (Configuration.ApplicationFirmwareVersion == null) - { - errors.Add("Application firmware is required."); - } + // if (Configuration.ApplicationFirmwareVersion == null) + // { + // errors.Add("Application firmware is required."); + // } - if (Configuration.ApplicationOsVersion == null) - { - errors.Add("Application operation system is required."); - } + // if (Configuration.ApplicationOsVersion == null) + // { + // errors.Add("Application operation system is required."); + // } - if (Configuration.EmbeddedFirmwareVersion == null) - { - errors.Add("Embedded firmware is required."); - } + // if (Configuration.EmbeddedFirmwareVersion == null) + // { + // errors.Add("Embedded firmware is required."); + // } - if (Configuration.HardwareVersion == null) - { - errors.Add("Hardware version is required."); - } + // if (Configuration.HardwareVersion == null) + // { + // errors.Add("Hardware version is required."); + // } - foreach (var pack in Configuration.IdsPacks) - { - if (pack.LiquidType != null || pack.CartridgeType != null || pack.DispenserType != null || pack.IdsPackFormula != null || pack.MidTankType != null) - { - if (pack.Name.IsNullOrWhiteSpace()) - { - errors.Add(String.Format("Name is required on IDS pack number '{0}'.", Configuration.IdsPacks.IndexOf(pack) + 1)); - continue; - } - if (pack.CartridgeType == null) - { - errors.Add(String.Format("Cartridge type is required on IDS pack '{0}'.", pack.Name)); - } - if (pack.DispenserType == null) - { - errors.Add(String.Format("Dispenser type is required on IDS pack '{0}'.", pack.Name)); - } - if (pack.LiquidType == null) - { - errors.Add(String.Format("Liquid type is required on IDS pack '{0}'.", pack.Name)); - } - if (pack.MidTankType == null) - { - errors.Add(String.Format("Mid Tank type is required on IDS pack '{0}'.", pack.Name)); - } - if (pack.IdsPackFormula == null) - { - errors.Add(String.Format("Formula type is required on IDS pack '{0}'.", pack.Name)); - } + // foreach (var pack in Configuration.IdsPacks) + // { + // if (pack.LiquidType != null || pack.CartridgeType != null || pack.Dispenser != null || pack.IdsPackFormula != null || pack.MidTankType != null) + // { + // if (pack.CartridgeType == null) + // { + // errors.Add(String.Format("Cartridge type is required on IDS pack '{0}'.", pack.PackIndex)); + // } + // if (pack.Dispenser == null) + // { + // errors.Add(String.Format("Dispenser is required on IDS pack '{0}'.", pack.PackIndex)); + // } + // if (pack.LiquidType == null) + // { + // errors.Add(String.Format("Liquid type is required on IDS pack '{0}'.", pack.PackIndex)); + // } + // if (pack.MidTankType == null) + // { + // errors.Add(String.Format("Mid Tank type is required on IDS pack '{0}'.", pack.PackIndex)); + // } + // if (pack.IdsPackFormula == null) + // { + // errors.Add(String.Format("Formula type is required on IDS pack '{0}'.", pack.PackIndex)); + // } - pack.IsEmpty = false; - } - else - { - pack.IsEmpty = true; - pack.Name = String.Empty; - } - } + // pack.IsEmpty = false; + // } + // else + // { + // pack.IsEmpty = true; + // } + // } - if (errors.Count > 0) - { - String errorsString = "Please fix the following validation errors before trying to save." + Environment.NewLine + Environment.NewLine; - errorsString += String.Join(Environment.NewLine, errors); - _notification.ShowError(errorsString); - return; - } + // if (errors.Count > 0) + // { + // String errorsString = "Please fix the following validation errors before trying to save." + Environment.NewLine + Environment.NewLine; + // errorsString += String.Join(Environment.NewLine, errors); + // _notification.ShowError(errorsString); + // return; + // } - //Validate + // //Validate - try - { - CanWork = false; + // try + // { + // CanWork = false; - using (_notification.PushTaskItem("Saving Machine Configuration...")) - { - 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 - { - Machine.Configuration = Configuration; - Configuration.CreationDate = DateTime.UtcNow; - Machine.ProductionDate = DateTime.UtcNow; + // using (_notification.PushTaskItem("Saving Machine Configuration...")) + // { + // if (!_dbContext.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 + // { + // Machine.Configuration = Configuration; + // Configuration.CreationDate = DateTime.UtcNow; + // Machine.ProductionDate = DateTime.UtcNow; - _db.Machines.Add(Machine); - _db.MachinesConfigurations.Add(new MachinesConfiguration() - { - Configuration = Configuration, - Machine = Machine, - }); - } - } - else - { - bool add_history = History.Count == 0 || _original_configuration.Name != Configuration.Name; + // _dbContext.Machines.Add(Machine); + // } + // } - if (add_history) - { - _db.Configurations.Add(_original_configuration); + // await _dbContext.SaveChangesAsync(); + // OnSelectedMachineChanged(); - _db.MachinesConfigurations.Add(new MachinesConfiguration() - { - Configuration = _original_configuration, - Machine = Machine - }); - } - } + // } + // } + // catch (Exception ex) + // { + // _notification.ShowError("An error occurred while trying to save the configuration" + Environment.NewLine + ex.Message); + // } + // finally + // { + // CanWork = true; + // InvalidateRelayCommands(); + // } + //} - await _db.SaveChangesAsync(); - OnSelectedMachineChanged(); + ///// <summary> + ///// Sets the current configuration to the selected machine version default configuration. + ///// </summary> + //private async void SetVersionConfiguration() + //{ + // if (Machine.MachineVersion != null) + // { + // using (_notification.PushTaskItem("Applying default configuration...")) + // { + // CanWork = false; - } - } - catch (Exception ex) - { - _notification.ShowError("An error occurred while trying to save the configuration" + Environment.NewLine + ex.Message); - } - finally - { - CanWork = true; - InvalidateRelayCommands(); - } - } + // await Task.Factory.StartNew(() => + // { + // var version = _dbContext.MachineVersions.Where(x => x.Guid == Machine.MachineVersion.Guid).Include(x => x.DefaultConfiguration).FirstOrDefault(); + // var version_config = _dbContext.Adapter.GetConfiguration(x => x.Guid == version.DefaultConfiguration.Guid); + // Configuration = version_config.Clone(); + // Machine.Configuration = Configuration; + // }); - /// <summary> - /// Sets the specified machine history. - /// </summary> - /// <param name="machine">The machine.</param> - private void SetHistory() - { - History = _db.MachinesConfigurations.Where(x => x.MachineGuid == Machine.Guid).Select(x => x.Configuration).ToObservableCollection(); - //History.Insert(0, Machine.Configuration); - } + // CanWork = true; + // } + // } + // else + // { + // _notification.ShowError("No machine version selected."); + // } + //} - /// <summary> - /// Sets the current configuration to the selected machine version default configuration. - /// </summary> - private async void SetVersionConfiguration() - { - if (Machine.MachineVersion != null) - { - using (_notification.PushTaskItem("Applying default configuration...")) - { - CanWork = false; + ///// <summary> + ///// Sets the current configuration as a default machine version configuration. + ///// </summary> + //private void SetAsDefaultConfiguration() + //{ + // _notification.ShowModalDialog<MachineVersionDialogVM>(async (vm) => + // { + // 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.Adapter.GetConfiguration(x => x.Guid == version.DefaultConfiguration.Guid); - Configuration = version_config.Clone(); - Machine.Configuration = Configuration; - }); + // try + // { + // using (_notification.PushTaskItem("Saving Default Configuration...")) + // { + // if (vm.SelectedVersion != null) + // { + // var version = _dbContext.MachineVersions.Where(x => x.Guid == vm.SelectedVersion.Guid).Include(x => x.DefaultConfiguration).SingleOrDefault(x => x.Guid == vm.SelectedVersion.Guid); - CanWork = true; - } - } - else - { - _notification.ShowError("No machine version selected."); - } - } + // _dbContext.Configurations.Remove(version.DefaultConfiguration); - /// <summary> - /// Sets the current configuration as a default machine version configuration. - /// </summary> - private void SetAsDefaultConfiguration() - { - _notification.ShowModalDialog<MachineVersionDialogVM>(async (vm) => - { - CanWork = false; + // var cloned = Configuration.Clone(); + // _dbContext.Configurations.Add(cloned); + // version.DefaultConfiguration = cloned; - try - { - using (_notification.PushTaskItem("Saving Default Configuration...")) - { - if (vm.SelectedVersion != null) - { - var version = _db.MachineVersions.Where(x => x.Guid == vm.SelectedVersion.Guid).Include(x => x.DefaultConfiguration).SingleOrDefault(x => x.Guid == vm.SelectedVersion.Guid); + // await _dbContext.SaveChangesAsync(); + // } + // else + // { + // MachineVersion newVersion = new MachineVersion(); + // newVersion.Version = vm.Version; + // newVersion.Name = vm.VersionName; - _db.Configurations.Remove(version.DefaultConfiguration); + // var cloned = Configuration.Clone(); - var cloned = Configuration.Clone(); - _db.Configurations.Add(cloned); - version.DefaultConfiguration = cloned; + // _dbContext.Configurations.Add(cloned); + // newVersion.DefaultConfiguration = cloned; + // _dbContext.MachineVersions.Add(newVersion); + // await _dbContext.SaveChangesAsync(); + // } + // } + // } + // catch (Exception ex) + // { + // _notification.ShowError(ex.Message); + // } + // finally + // { + // CanWork = true; + // } - await _db.SaveChangesAsync(); - } - else - { - MachineVersion newVersion = new MachineVersion(); - newVersion.Version = vm.Version; - newVersion.Name = vm.VersionName; + // }, () => + // { - var cloned = Configuration.Clone(); + // }); + //} - _db.Configurations.Add(cloned); - newVersion.DefaultConfiguration = cloned; - _db.MachineVersions.Add(newVersion); - await _db.SaveChangesAsync(); - } - } - } - catch (Exception ex) - { - _notification.ShowError(ex.Message); - } - finally - { - CanWork = true; - } + #endregion - }, () => + private async void OnFilterChanged() + { + if (!String.IsNullOrWhiteSpace(Filter)) { - - }); + IsFree = false; + Machines = (await _dbContext.Machines.Where(x => x.SerialNumber.StartsWith(Filter)).ToListAsync()).ToObservableCollection(); + IsFree = true; + } } - - #endregion } } |
