From bfcc978160dfdc00256cbbe11551cd32be459dda Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Tue, 4 May 2021 05:54:03 +0300 Subject: Machine Manager Module !! --- .../Images/module.png | Bin 0 -> 189560 bytes .../MachineManagerModule.cs | 62 ++++ .../Models/MachineModel.cs | 68 +++++ .../Properties/AssemblyInfo.cs | 19 ++ .../Properties/Resources.Designer.cs | 71 +++++ .../Properties/Resources.resx | 117 ++++++++ .../Properties/Settings.Designer.cs | 30 ++ .../Properties/Settings.settings | 7 + .../Tango.MachineStudio.MachineManager.csproj | 164 +++++++++++ .../ViewModelLocator.cs | 29 ++ .../ViewModels/MainViewVM.cs | 313 +++++++++++++++++++++ .../Views/MainView.xaml | 109 +++++++ .../Views/MainView.xaml.cs | 28 ++ .../Tango.MachineStudio.MachineManager/app.config | 85 ++++++ .../packages.config | 12 + 15 files changed, 1114 insertions(+) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Images/module.png create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/MachineManagerModule.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Models/MachineModel.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Properties/AssemblyInfo.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Properties/Resources.Designer.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Properties/Resources.resx create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Properties/Settings.Designer.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Properties/Settings.settings create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Tango.MachineStudio.MachineManager.csproj create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/ViewModelLocator.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/ViewModels/MainViewVM.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Views/MainView.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Views/MainView.xaml.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/app.config create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/packages.config (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Images/module.png b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Images/module.png new file mode 100644 index 000000000..1fb079543 Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Images/module.png differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/MachineManagerModule.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/MachineManagerModule.cs new file mode 100644 index 000000000..a55e332cf --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/MachineManagerModule.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; +using Tango.BL.Enumerations; +using Tango.MachineStudio.Common; +using Tango.MachineStudio.MachineManager.Views; +using Tango.SharedUI.Helpers; + +namespace Tango.MachineStudio.MachineManager +{ + [StudioModule(3)] + public class MachineManagerModule : StudioModuleBase + { + public override string Name + { + get + { + return "Machine Manager"; + } + } + + public override string Description + { + get + { + return "Apply machine configuration to a set of machine on the current environment."; + } + } + + public override BitmapSource Image + { + get + { + return ResourceHelper.GetImageFromResources("Images/module.png"); + } + } + + public override Type MainViewType + { + get + { + return typeof(MainView); + } + } + + public override Permissions Permission + { + get + { + return Permissions.RunMachineStudio; + } + } + + public override void Dispose() + { + + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Models/MachineModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Models/MachineModel.cs new file mode 100644 index 000000000..3923ae981 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Models/MachineModel.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; + +namespace Tango.MachineStudio.MachineManager.Models +{ + public class MachineModel : ExtendedObject + { + public String Guid { get; set; } + + private bool _isSelected; + + public bool IsSelected + { + get { return _isSelected; } + set { _isSelected = value; RaisePropertyChangedAuto(); } + } + + public String SerialNumber { get; set; } + + public String Name { get; set; } + + public String OrganizationName { get; set; } + + public String Site { get; set; } + + public String ConfigurationGuid { get; set; } + + public String HardwareVersionGuid { get; set; } + + private String _hardwareVersionName; + public String HardwareVersionName + { + get { return _hardwareVersionName; } + set { _hardwareVersionName = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(HardwareVersion)); } + } + + private double _hardwareVersionVersion; + public double HardwareVersionVersion + { + get { return _hardwareVersionVersion; } + set { _hardwareVersionVersion = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(HardwareVersion)); } + } + + public String HardwareVersion + { + get { return HardwareVersionName + " " + HardwareVersionVersion; } + } + + private bool _enableSoftwareUpdate; + public bool EnableSoftwareUpdate + { + get { return _enableSoftwareUpdate; } + set { _enableSoftwareUpdate = value; RaisePropertyChangedAuto(); } + } + + private bool _enableFirmwareUpgrade; + public bool EnableFirmwareUpgrade + { + get { return _enableFirmwareUpgrade; } + set { _enableFirmwareUpgrade = value; RaisePropertyChangedAuto(); } + } + + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Properties/AssemblyInfo.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..b7417c065 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Properties/AssemblyInfo.cs @@ -0,0 +1,19 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +[assembly: AssemblyTitle("Tango - Machine Studio Machine Manager Module")] +[assembly: AssemblyVersion("1.0.0.1737")] + +[assembly: ComVisible(false)] + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Properties/Resources.Designer.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Properties/Resources.Designer.cs new file mode 100644 index 000000000..75d5fee21 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Tango.MachineStudio.MachineManager.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Tango.MachineStudio.MachineManager.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Properties/Resources.resx b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Properties/Settings.Designer.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Properties/Settings.Designer.cs new file mode 100644 index 000000000..d14fa98d1 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Tango.MachineStudio.MachineManager.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Properties/Settings.settings b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Properties/Settings.settings new file mode 100644 index 000000000..033d7a5e9 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Tango.MachineStudio.MachineManager.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Tango.MachineStudio.MachineManager.csproj new file mode 100644 index 000000000..aa1d8d37f --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Tango.MachineStudio.MachineManager.csproj @@ -0,0 +1,164 @@ + + + + + Debug + AnyCPU + {6C784296-CCF9-469C-A7C1-4C13305E1203} + library + Tango.MachineStudio.MachineManager + Tango.MachineStudio.MachineManager + v4.6.1 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + + + true + full + false + ..\..\..\Build\Machine Studio\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\Build\Machine Studio\Release\ + TRACE + prompt + 4 + + + + ..\..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll + + + ..\..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll + + + ..\..\..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll + + + ..\..\..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll + + + ..\..\..\packages\MaterialDesignColors.1.1.2\lib\net45\MaterialDesignColors.dll + + + ..\..\..\packages\MaterialDesignThemes.2.3.1.953\lib\net45\MaterialDesignThemes.Wpf.dll + + + ..\..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + + + + + + ..\..\..\packages\MahApps.Metro.1.5.0\lib\net45\System.Windows.Interactivity.dll + + + + + + + + + 4.0 + + + + + + ..\..\..\packages\Z.EntityFramework.Extensions.5.1.6\lib\net45\Z.EntityFramework.Extensions.dll + + + ..\..\..\packages\Z.EntityFramework.Plus.EF6.5.1.6\lib\net45\Z.EntityFramework.Plus.EF6.dll + + + ..\..\..\packages\Z.Expressions.Eval.4.0.27\lib\net45\Z.Expressions.Eval.dll + + + + + GlobalVersionInfo.cs + + + + + + MainView.xaml + + + + Designer + MSBuild:Compile + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + {f441feee-322a-4943-b566-110e12fd3b72} + Tango.BL + + + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} + Tango.Core + + + {4206ac58-3b57-4699-8835-90bf6db01a61} + Tango.Integration + + + {bc932dbd-7cdb-488c-99e4-f02cf441f55e} + Tango.Logging + + + {d8f1ad85-526a-4f50-b6dc-d437af63d8d8} + Tango.Settings + + + {8491D07B-C1F6-4B62-A412-41B9FD2D6538} + Tango.SharedUI + + + {74e700b0-1156-4126-be40-ee450d3c3026} + Tango.Transport + + + {cb0b0aa2-bb24-4bca-a720-45e397684e12} + Tango.MachineStudio.Common + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/ViewModelLocator.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/ViewModelLocator.cs new file mode 100644 index 000000000..94c06daaa --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/ViewModelLocator.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.DI; +using Tango.MachineStudio.MachineManager.ViewModels; + +namespace Tango.MachineStudio.MachineManager +{ + public static class ViewModelLocator + { + /// + /// Initializes a new instance of the ViewModelLocator class. + /// + static ViewModelLocator() + { + TangoIOC.Default.Register(); + } + + public static MainViewVM MainViewVM + { + get + { + return TangoIOC.Default.GetInstance(); + } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/ViewModels/MainViewVM.cs new file mode 100644 index 000000000..b97f5e1d9 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/ViewModels/MainViewVM.cs @@ -0,0 +1,313 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Data.Entity; +using Tango.BL; +using Tango.MachineStudio.Common; +using Tango.MachineStudio.MachineManager.Models; +using Tango.BL.Entities; +using Tango.Core.Commands; +using Tango.MachineStudio.Common.Notifications; +using Z.EntityFramework.Plus; + +namespace Tango.MachineStudio.MachineManager.ViewModels +{ + public class MainViewVM : StudioViewModel + { + private INotificationProvider _notification; + private bool _preventChange; + + private List _machines; + public List Machines + { + get { return _machines; } + set { _machines = value; RaisePropertyChangedAuto(); } + } + + private String _filter; + public String Filter + { + get { return _filter; } + set + { + if (_filter != value) + { + _filter = value; + OnFilterChanged(); + } + } + } + + private List _hardwareVersions; + public List HardwareVersions + { + get { return _hardwareVersions; } + set { _hardwareVersions = value; RaisePropertyChangedAuto(); } + } + + private HardwareVersion _selectedHardwareVersion; + public HardwareVersion SelectedHardwareVersion + { + get { return _selectedHardwareVersion; } + set { _selectedHardwareVersion = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + + private bool? _enableSoftwareUpdate; + public bool? EnableSoftwareUpdate + { + get { return _enableSoftwareUpdate; } + set { _enableSoftwareUpdate = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + + private bool? _enableFirmwareUpgrade; + public bool? EnableFirmwareUpgrade + { + get { return _enableFirmwareUpgrade; } + set { _enableFirmwareUpgrade = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + + private bool? _selectAll; + public bool? SelectAll + { + get { return _selectAll; } + set { _selectAll = value; RaisePropertyChangedAuto(); OnSelectAllChanged(); InvalidateRelayCommands(); } + } + + public RelayCommand ApplyCommand { get; set; } + + public MainViewVM(INotificationProvider notificationProvider) + { + Machines = new List(); + _notification = notificationProvider; + ApplyCommand = new RelayCommand(Apply, CanApply); + } + + public override void OnApplicationReady() + { + + } + + private async void OnFilterChanged() + { + await LoadMachines(); + } + + private void OnSelectAllChanged() + { + if (Machines != null && SelectAll != null) + { + _preventChange = true; + Machines.ForEach(x => x.IsSelected = SelectAll.Value); + _preventChange = false; + } + } + + private async Task LoadMachines() + { + SelectAll = null; + + foreach (var machine in Machines.ToList()) + { + machine.PropertyChanged -= Machine_PropertyChanged; + } + + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + var sites = await db.Sites.ToListAsync(); + + var machines = await db.Machines + .Include(x => x.Organization.Name) + .Include(x => x.Configuration.HardwareVersion.Name) + .Include(x => x.Configuration.HardwareVersion.Version) + .Include(x => x.Configuration.HardwareVersion.Guid) + .Select(x => new + { + x.Guid, + x.SerialNumber, + x.Name, + x.SuspendVersionUpdate, + x.SetupFirmware, + x.SetupFpga, + x.ConfigurationGuid, + HardwareVersionGuid = x.Configuration.HardwareVersion.Guid, + HardwareVersionName = x.Configuration.HardwareVersion.Name, + HardwareVersionVersion = x.Configuration.HardwareVersion.Version, + OrganizationName = x.Organization.Name, + x.SiteGuid + }).ToListAsync(); + + var models = new List(); + + foreach (var machine in machines) + { + MachineModel model = new MachineModel(); + model.Guid = machine.Guid; + model.SerialNumber = machine.SerialNumber; + model.Name = machine.Name; + model.EnableFirmwareUpgrade = machine.SetupFirmware; + model.EnableSoftwareUpdate = !machine.SuspendVersionUpdate; + model.ConfigurationGuid = machine.ConfigurationGuid; + model.HardwareVersionGuid = machine.HardwareVersionGuid; + model.HardwareVersionName = machine.HardwareVersionName; + model.HardwareVersionVersion = machine.HardwareVersionVersion; + model.OrganizationName = machine.OrganizationName; + model.Site = sites.FirstOrDefault(x => x.Guid == machine.SiteGuid)?.Name; + + models.Add(model); + } + + if (Filter.IsNotNullOrEmpty()) + { + var filter = Filter.ToLower(); + + models = models.Where(x => + x.SerialNumber.ToLower().StartsWith(filter) || + x.Name.ToLower().StartsWith(filter) || + x.OrganizationName.ToLower().StartsWith(filter) || + x.Site.ToStringOrEmpty().ToLower().StartsWith(filter) + ).ToList(); + } + + HardwareVersions = (await db.HardwareVersions.ToListAsync()).OrderByDescending(x => x.Version).ToList(); + + SelectedHardwareVersion = null; + EnableSoftwareUpdate = null; + EnableFirmwareUpgrade = null; + + Machines = models; + + foreach (var machine in Machines.ToList()) + { + machine.PropertyChanged += Machine_PropertyChanged; + } + } + } + + private void Machine_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + { + if (_preventChange) return; + + if (e.PropertyName == nameof(MachineModel.IsSelected)) + { + if (Machines.TrueForAll(x => x.IsSelected)) + { + _selectAll = true; + } + else if (Machines.TrueForAll(x => !x.IsSelected)) + { + _selectAll = false; + } + else + { + _selectAll = null; + } + + RaisePropertyChanged(nameof(SelectAll)); + + var selectedMachines = Machines.Where(x => x.IsSelected).ToList(); + + if (selectedMachines.Count > 0) + { + if (selectedMachines.TrueForAll(x => x.EnableSoftwareUpdate)) + { + EnableSoftwareUpdate = true; + } + else if (selectedMachines.TrueForAll(x => !x.EnableSoftwareUpdate)) + { + EnableSoftwareUpdate = false; + } + else + { + EnableSoftwareUpdate = null; + } + + if (selectedMachines.TrueForAll(x => x.EnableFirmwareUpgrade)) + { + EnableFirmwareUpgrade = true; + } + else if (selectedMachines.TrueForAll(x => !x.EnableFirmwareUpgrade)) + { + EnableFirmwareUpgrade = false; + } + else + { + EnableFirmwareUpgrade = null; + } + + if (selectedMachines.TrueForAll(x => x.HardwareVersionGuid == selectedMachines.First().HardwareVersionGuid)) + { + SelectedHardwareVersion = HardwareVersions.FirstOrDefault(x => x.Guid == selectedMachines.First().HardwareVersionGuid); + } + else + { + SelectedHardwareVersion = null; + } + } + + InvalidateRelayCommands(); + } + } + + private bool CanApply() + { + var selectedMachines = Machines.Where(x => x.IsSelected).ToList(); + + if (selectedMachines.Count == 0) return false; + if (EnableSoftwareUpdate != null && selectedMachines.Any(x => x.EnableSoftwareUpdate != EnableSoftwareUpdate)) return true; + if (EnableFirmwareUpgrade != null && selectedMachines.Any(x => x.EnableFirmwareUpgrade != EnableFirmwareUpgrade)) return true; + if (SelectedHardwareVersion != null && selectedMachines.Any(x => x.HardwareVersionGuid != SelectedHardwareVersion.Guid)) return true; + + return false; + } + + private async void Apply() + { + if (Machines == null || Machines.Count(x => x.IsSelected) == 0) + { + _notification.ShowInfo("No machines selected"); + return; + } + + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + var machines = Machines.Where(x => x.IsSelected).ToList(); + + var guids = machines.Select(x => x.Guid).ToArray(); + + if (EnableSoftwareUpdate != null) + { + await db.Machines.Where(x => guids.Contains(x.Guid)).UpdateAsync(x => + new Machine() + { + SuspendVersionUpdate = !EnableSoftwareUpdate.Value + }); + } + + if (EnableFirmwareUpgrade != null) + { + await db.Machines.Where(x => guids.Contains(x.Guid)).UpdateAsync(x => + new Machine() + { + SetupFirmware = EnableFirmwareUpgrade.Value, + SetupFpga = EnableFirmwareUpgrade.Value, + }); + } + + if (SelectedHardwareVersion != null) + { + guids = machines.Select(x => x.ConfigurationGuid).ToArray(); + + await db.Configurations.Where(x => guids.Contains(x.Guid)).UpdateAsync(x => + new Configuration() + { + HardwareVersionGuid = SelectedHardwareVersion.Guid + }); + } + } + + await LoadMachines(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Views/MainView.xaml new file mode 100644 index 000000000..3af1ba9dd --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Views/MainView.xaml @@ -0,0 +1,109 @@ + + + + + + + Machine Manager + + + + + + + + + + + + + + + + + Hardware Version + + + Enable Software Update + Enable Firmware Update + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Views/MainView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Views/MainView.xaml.cs new file mode 100644 index 000000000..1a97209b5 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/Views/MainView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.MachineStudio.MachineManager.Views +{ + /// + /// Interaction logic for MainView.xaml + /// + public partial class MainView : UserControl + { + public MainView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/app.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/app.config new file mode 100644 index 000000000..7b82e5f7c --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/app.config @@ -0,0 +1,85 @@ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/packages.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/packages.config new file mode 100644 index 000000000..c0448e250 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineManager/packages.config @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file -- cgit v1.3.1