From 024eb7867d2b400212ce4ce0e4845d99bf532568 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Wed, 4 Nov 2020 13:01:49 +0200 Subject: First steps on FSE configuration module. --- .../ViewModels/MainViewVM.cs | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MainViewVM.cs (limited to 'Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MainViewVM.cs') diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MainViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MainViewVM.cs new file mode 100644 index 000000000..efb2fc3cc --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MainViewVM.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.FSE.Common; +using Tango.FSE.Common.Navigation; +using Tango.FSE.MachineConfiguration.Navigation; +using Tango.SharedUI.Helpers; + +namespace Tango.FSE.MachineConfiguration.ViewModels +{ + [ModularNavigationContainer] + public class MainViewVM : ConfigurationViewModel + { + public override void OnApplicationStarted() + { + InvokeUI(() => + { + NavigationManager.MenuItems.Add(new NavigationMenuItem(() => + { + NavigationManager.NavigateTo(); + }) + { + Name = "Configuration", + Index = 8, + Description = "Access to the organization machines configuration and settings", + Image = ResourceHelper.GetImageFromResources("Images/configuration.png"), + }); + }); + } + + public async override Task OnApplicationLogout() + { + while (ModularNavigationManager.CurrentView != ConfigurationView.SelectionView) + { + if (!await ModularNavigationManager.NavigateBack()) + { + return false; + } + } + + return await base.OnApplicationLogout(); + } + + public async override Task OnNavigateBackRequest() + { + if (ModularNavigationManager.CurrentView == ConfigurationView.SelectionView) + { + return await base.OnNavigateBackRequest(); + } + else + { + await ModularNavigationManager.NavigateBack(); + return false; + } + } + } +} -- cgit v1.3.1 From d6db3244c15e3937d339064da0a5c7186f32daa1 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Mon, 9 Nov 2020 07:00:47 +0200 Subject: Working on machine configuration. --- .../Messages/EditingCompositionLoadedMessage.cs | 16 ++ .../Messages/MachineLoadedMessage.cs | 14 -- .../Tango.FSE.MachineConfiguration.csproj | 2 +- .../ViewModels/ConfigurationViewVM.cs | 85 ++++++-- .../ViewModels/MachineViewVM.cs | 19 +- .../ViewModels/MainViewVM.cs | 2 +- .../ViewModels/SelectionViewVM.cs | 19 +- .../Views/ConfigurationView.xaml | 234 ++++++++++++++------- .../Views/MachineView.xaml | 4 +- .../FSE/Tango.FSE.BL/FSEServicesContainer.cs | 6 + .../Services/MachineConfigurationService.cs | 88 ++++++++ .../FSE/Tango.FSE.BL/Tango.FSE.BL.csproj | 1 + .../Connection/IMachineProvider.cs | 2 +- .../FSE/Tango.FSE.Common/Controls/MachineView.xaml | 12 +- .../FSE/Tango.FSE.Common/Resources/Styles.xaml | 197 +++++++++++++++-- .../Connection/DefaultMachineProvider.cs | 1 + .../DefaultFileAssociationProvider.cs | 5 + .../Tango.BL/Entities/HardwareVersion.cs | 11 + 18 files changed, 578 insertions(+), 140 deletions(-) create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Messages/EditingCompositionLoadedMessage.cs delete mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Messages/MachineLoadedMessage.cs create mode 100644 Software/Visual_Studio/FSE/Tango.FSE.BL/Services/MachineConfigurationService.cs (limited to 'Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MainViewVM.cs') diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Messages/EditingCompositionLoadedMessage.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Messages/EditingCompositionLoadedMessage.cs new file mode 100644 index 000000000..b858c34e0 --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Messages/EditingCompositionLoadedMessage.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using Tango.FSE.BL.Services; +using static Tango.FSE.BL.Services.MachineConfigurationService; + +namespace Tango.FSE.MachineConfiguration.Messages +{ + public class EditingCompositionLoadedMessage + { + public MachineEditingComposition EditingComposition { get; set; } + } +} diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Messages/MachineLoadedMessage.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Messages/MachineLoadedMessage.cs deleted file mode 100644 index 4a703b2a9..000000000 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Messages/MachineLoadedMessage.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.BL.Entities; - -namespace Tango.FSE.MachineConfiguration.Messages -{ - public class MachineLoadedMessage - { - public Machine Machine { get; set; } - } -} diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Tango.FSE.MachineConfiguration.csproj b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Tango.FSE.MachineConfiguration.csproj index e7adc1d3f..c5aa8c4bf 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Tango.FSE.MachineConfiguration.csproj +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Tango.FSE.MachineConfiguration.csproj @@ -79,7 +79,7 @@ - + diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/ConfigurationViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/ConfigurationViewVM.cs index 1540a4e67..63e3f22d9 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/ConfigurationViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/ConfigurationViewVM.cs @@ -4,41 +4,96 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.BL.Entities; +using Tango.Core.Commands; +using Tango.Core.DI; using Tango.FSE.Common; using Tango.FSE.Common.AutoComplete; +using Tango.FSE.Common.SQL; using Tango.FSE.MachineConfiguration.Messages; +using static Tango.FSE.BL.Services.MachineConfigurationService; namespace Tango.FSE.MachineConfiguration.ViewModels { public class ConfigurationViewVM : FSEViewModel { - private Machine _machine; - public Machine Machine + [TangoInject] + private IRemoteSqlProvider RemoteSqlProvider { get; set; } + + private MachineEditingComposition _editingComposition; + public MachineEditingComposition EditingComposition { - get { return _machine; } - set { _machine = value; RaisePropertyChangedAuto(); } + get { return _editingComposition; } + set { _editingComposition = value; RaisePropertyChangedAuto(); } } - private List _organizations; - public List Organizations + public RelayCommand SaveCommand { get; set; } + public RelayCommand ResetCountersCommand { get; set; } + public RelayCommand ResetDeviceRegistrationCommand { get; set; } + + + public ConfigurationViewVM() { - get { return _organizations; } - set { _organizations = value; RaisePropertyChangedAuto(); } + RegisterForMessage(OnEditingCompositionLoaded); + SaveCommand = new RelayCommand(SaveConfiguration); + ResetCountersCommand = new RelayCommand(ResetCounters); + ResetDeviceRegistrationCommand = new RelayCommand(ResetDeviceRegistration); } - public ConfigurationViewVM() + private void OnEditingCompositionLoaded(EditingCompositionLoadedMessage msg) { - RegisterForMessage(HandleMachineLoadedMessage); + using (NotificationProvider.PushTaskItem("Loading machine configuration...")) + { + EditingComposition = msg.EditingComposition; + } } - private async void HandleMachineLoadedMessage(MachineLoadedMessage msg) + private async void SaveConfiguration() { - using (NotificationProvider.PushTaskItem("Loading configuration options...")) + using (NotificationProvider.PushTaskItem("Saving machine configuration...")) { - Machine = msg.Machine; - Organizations = await Services.OrganizationsService.GetCurrentUserOrganizations(); - Machine.Organization = Organizations.SingleOrDefault(x => x.Guid == Machine.OrganizationGuid); + EditingComposition = await Services.MachineConfigurationService.SaveMachineEditingComposition(EditingComposition); + await NotificationProvider.ShowSuccess("Machine configuration saved successfully."); } } + + private async void ResetCounters() + { + if (!MachineProvider.IsPPCAvailable) + { + await NotificationProvider.ShowError("Resetting the machine counters requires an active connection to this machine."); + return; + } + + if (!await NotificationProvider.ShowWarningQuestion("Resetting the machine counters will delete the entire job runs history. Are you sure?", "RESET COUNTERS", "CANCEL")) return; + + using (var task = NotificationProvider.PushTaskItem("Resetting machine counters...")) + { + task.UpdateProgress("Resetting local machine counters..."); + + var result = await RemoteSqlProvider.ExecuteSqlCommandAsync(new RemoteSqlCommand() + { + Mode = RemoteSqlCommandMode.Local, + Timeout = 30, + SQL = "DELETE FROM JOB_RUNS" + }); + + int localJobRuns = result.LocalAffectedRecords; + + task.UpdateProgress("Resetting global machine counters..."); + + int remoteJobRuns = await Services.MachineConfigurationService.ResetCounters(EditingComposition.Machine.Guid); + + await NotificationProvider.ShowSuccess("Machine counters deleted successfully."); + } + } + + private async void ResetDeviceRegistration() + { + if (!await NotificationProvider.ShowWarningQuestion("Resetting the machine's device registration will allow other panel PCs to perform a machine setup for this machine. Are you sure?", "RESET", "CANCEL")) return; + + EditingComposition.Machine.IsDeviceRegistered = false; + EditingComposition.Machine.DeviceId = null; + EditingComposition.Machine.DeviceName = null; + } } } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MachineViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MachineViewVM.cs index cbd6c1cf1..24a0cbc42 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MachineViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MachineViewVM.cs @@ -7,6 +7,7 @@ using Tango.BL.Entities; using Tango.FSE.Common; using Tango.FSE.Common.Navigation; using Tango.FSE.MachineConfiguration.Messages; +using static Tango.FSE.BL.Services.MachineConfigurationService; using static Tango.FSE.MachineConfiguration.ViewModels.MachineViewVM; namespace Tango.FSE.MachineConfiguration.ViewModels @@ -15,7 +16,7 @@ namespace Tango.FSE.MachineConfiguration.ViewModels { public class NavigationObject { - public String MachineSerialNumber { get; set; } + public String MachineGuid { get; set; } } public enum NavigationView @@ -35,25 +36,25 @@ namespace Tango.FSE.MachineConfiguration.ViewModels } } - private Machine _machine; - public Machine Machine + private MachineEditingComposition _editingComposition; + public MachineEditingComposition EditingComposition { - get { return _machine; } - set { _machine = value; RaisePropertyChangedAuto(); } + get { return _editingComposition; } + set { _editingComposition = value; RaisePropertyChangedAuto(); } } public void OnNavigatedToWithObject(NavigationObject obj) { SelectedView = NavigationView.ConfigurationView; - LoadMachine(obj.MachineSerialNumber); + LoadMachine(obj.MachineGuid); } - private async void LoadMachine(String serialNumber) + private async void LoadMachine(String machineGuid) { using (NotificationProvider.PushTaskItem("Loading machine configuration...")) { - Machine = await Services.MachinesService.GetMachineFull(serialNumber); - RaiseMessage(new MachineLoadedMessage() { Machine = Machine }); + EditingComposition = await Services.MachineConfigurationService.GetMachineEditingComposition(machineGuid); + RaiseMessage(new EditingCompositionLoadedMessage() { EditingComposition = EditingComposition }); } } } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MainViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MainViewVM.cs index efb2fc3cc..5b8ca21ac 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MainViewVM.cs @@ -14,7 +14,7 @@ namespace Tango.FSE.MachineConfiguration.ViewModels [ModularNavigationContainer] public class MainViewVM : ConfigurationViewModel { - public override void OnApplicationStarted() + public override void OnApplicationReady() { InvokeUI(() => { diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/SelectionViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/SelectionViewVM.cs index c62ade6fb..b65ad7102 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/SelectionViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/SelectionViewVM.cs @@ -39,9 +39,26 @@ namespace Tango.FSE.MachineConfiguration.ViewModels ModularNavigationManager.NavigateTo(ConfigurationView.MachineView, new MachineViewVM.NavigationObject() { - MachineSerialNumber = SelectedMachine.SerialNumber + MachineGuid = SelectedMachine.Guid }); } + + public override void OnNavigatedTo() + { + base.OnNavigatedTo(); + + if (SelectedMachine == null && MachineProvider.Machine != null) + { + SelectedMachine = MachineProvider.Machine; + } + } + + public override Task OnApplicationLogout() + { + ModularNavigationManager.NavigateTo(ConfigurationView.SelectionView); + SelectedMachine = null; + return base.OnApplicationLogout(); + } } } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/ConfigurationView.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/ConfigurationView.xaml index 8d8aa7b0e..9c8b2d878 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/ConfigurationView.xaml +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/ConfigurationView.xaml @@ -5,111 +5,191 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Tango.FSE.MachineConfiguration.Views" xmlns:global="clr-namespace:Tango.FSE.MachineConfiguration" + xmlns:material="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:vm="clr-namespace:Tango.FSE.MachineConfiguration.ViewModels" + xmlns:enumerations="clr-namespace:Tango.BL.Enumerations;assembly=Tango.BL" xmlns:commonControls="clr-namespace:Tango.FSE.Common.Controls;assembly=Tango.FSE.Common" xmlns:resolution="clr-namespace:Tango.FSE.Common.Resolution;assembly=Tango.FSE.Common" xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:autoComplete="clr-namespace:Tango.AutoComplete.Editors;assembly=Tango.AutoComplete" mc:Ignorable="d" - d:DesignHeight="1080" d:DesignWidth="1920" d:DataContext="{d:DesignInstance Type=vm:ConfigurationViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.ConfigurationViewVM}" d:DesignStyle="{StaticResource FSE_User_Control_Designer}"> - + d:DesignHeight="2000" d:DesignWidth="1920" d:DataContext="{d:DesignInstance Type=vm:ConfigurationViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.ConfigurationViewVM}" d:DesignStyle="{StaticResource FSE_User_Control_Designer}"> - - + - - - - - Activate Windows License - + - - License Key - - + + + + + - - - Setup Team Viewer - + - - - Activate Disk Protection - + - - - Use Firmware Emulator (Demo Machine) - - - Device Registration + + + + + Activate Windows License + + + + License Key + + + + + + Setup Team Viewer + + + + + Activate Disk Protection + + + + + Use Firmware Emulator (Demo Machine) + + + + - - + Device Registration - + + + + Registered: - - + + - + Device ID: - - + + - + Device Name: - - - + + + - - - - - - - - - - - Perform Firmware Upgrade - + + + - - - Force Version Update - + - - - Suspend Version Update - - - + - - + Machine Counters - - Serial Number - - + + + + + Total Dye Time: + + - - Name - + + Total Dye Meters: + + + + + + + + + + + + + + Perform Firmware Upgrade + + + + + Force Version Update + - - Organization - + + + Suspend Version Update + - - - + + + + + + + Serial Number + + + + + Name + + + + + Organization + + + + + Site + + + + + + + + + Head Type + + + + + Hardware Version + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/MachineView.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/MachineView.xaml index ba9418d5d..9f81f82e4 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/MachineView.xaml +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/MachineView.xaml @@ -29,8 +29,8 @@ - - + + diff --git a/Software/Visual_Studio/FSE/Tango.FSE.BL/FSEServicesContainer.cs b/Software/Visual_Studio/FSE/Tango.FSE.BL/FSEServicesContainer.cs index e5487bc1e..14b74fd9c 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.BL/FSEServicesContainer.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.BL/FSEServicesContainer.cs @@ -62,6 +62,11 @@ namespace Tango.FSE.BL /// public OrganizationsService OrganizationsService { get; set; } + /// + /// Gets or sets the machine configuration service. + /// + public MachineConfigurationService MachineConfigurationService { get; set; } + /// /// Initializes a new instance of the class. /// @@ -78,6 +83,7 @@ namespace Tango.FSE.BL PublishedProcedureProjectsService = new PublishedProcedureProjectsService(); MachineEventsService = new MachineEventsService(); OrganizationsService = new OrganizationsService(); + MachineConfigurationService = new MachineConfigurationService(); } } } diff --git a/Software/Visual_Studio/FSE/Tango.FSE.BL/Services/MachineConfigurationService.cs b/Software/Visual_Studio/FSE/Tango.FSE.BL/Services/MachineConfigurationService.cs new file mode 100644 index 000000000..e6798e197 --- /dev/null +++ b/Software/Visual_Studio/FSE/Tango.FSE.BL/Services/MachineConfigurationService.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL; +using Tango.BL.Entities; +using System.Data.Entity; +using Tango.BL.Builders; + +namespace Tango.FSE.BL.Services +{ + public class MachineConfigurationService : FSEServiceBase + { + public class MachineEditingComposition : IDisposable + { + public Machine Machine { get; set; } + public List Organizations { get; set; } + public List HardwareVersions { get; set; } + public String TotalDyeTime { get; set; } + public String TotalDyeMeters { get; set; } + internal ObservablesContext Context { get; set; } + + public MachineEditingComposition() + { + Organizations = new List(); + HardwareVersions = new List(); + } + + public void Dispose() + { + Context?.Dispose(); + Context = null; + } + } + + public Task GetMachineEditingComposition(String machineGuid) + { + return Task.Factory.StartNew(() => + { + ObservablesContext db = ObservablesContext.CreateDefault(); + + MachineEditingComposition composition = new MachineEditingComposition(); + + //Organizations + bool allowAll = CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.FSE_ManageAllOrganizationsUsersAndRoles); + composition.Organizations = db.Organizations.Where(x => allowAll || x.Guid == CurrentUser.OrganizationGuid).Include(x => x.Sites).ToList(); + + //Machine + composition.Machine = new MachineBuilder(db).Set(machineGuid).WithConfiguration().Build(); + + //Hardware Versions + composition.HardwareVersions = db.HardwareVersions.OrderByDescending(x => x.Version).ToList(); + + //Counters + var jobRuns = db.JobRuns.Where(x => x.MachineGuid == machineGuid).Select(x => new { x.StartDate, x.EndDate, x.EndPosition }).ToList(); + composition.TotalDyeTime = TimeSpan.FromHours(jobRuns.Select(x => x.EndDate - x.StartDate).Sum(x => x.TotalHours)).ToStringUnlimitedHours(); + int meters = (int)jobRuns.Select(x => x.EndPosition).Sum(); + composition.TotalDyeMeters = $"{meters.ToString("N0")} meters"; + + composition.Context = db; + + return composition; + }); + } + + public Task SaveMachineEditingComposition(MachineEditingComposition composition) + { + return Task.Factory.StartNew(() => + { + composition.Context.SaveChanges(); + composition.Context.Dispose(); + return GetMachineEditingComposition(composition.Machine.Guid).Result; + }); + } + + public Task ResetCounters(String machineGuid) + { + return Task.Factory.StartNew(() => + { + using (ObservablesContext db = new ObservablesContext()) + { + return db.JobRuns.Where(x => x.MachineGuid == machineGuid).DeleteFromQuery(); + } + }); + } + } +} diff --git a/Software/Visual_Studio/FSE/Tango.FSE.BL/Tango.FSE.BL.csproj b/Software/Visual_Studio/FSE/Tango.FSE.BL/Tango.FSE.BL.csproj index 39257df86..fba87644b 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.BL/Tango.FSE.BL.csproj +++ b/Software/Visual_Studio/FSE/Tango.FSE.BL/Tango.FSE.BL.csproj @@ -119,6 +119,7 @@ + diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Connection/IMachineProvider.cs b/Software/Visual_Studio/FSE/Tango.FSE.Common/Connection/IMachineProvider.cs index 9a98477b8..8c4512c41 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/Connection/IMachineProvider.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Connection/IMachineProvider.cs @@ -41,7 +41,7 @@ namespace Tango.FSE.Common.Connection MachineConnectionTypes ConnectionType { get; } /// - /// Gets a value indicating whether the equals or . + /// Gets a value indicating whether the machine is connected and the equals or . /// bool IsPPCAvailable { get; } diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Controls/MachineView.xaml b/Software/Visual_Studio/FSE/Tango.FSE.Common/Controls/MachineView.xaml index c37613e3e..8d375cc6d 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/Controls/MachineView.xaml +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Controls/MachineView.xaml @@ -47,11 +47,11 @@ - Hardware + 1 @@ -217,17 +217,17 @@ - Mid Tanks + - Cartridges + diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Resources/Styles.xaml b/Software/Visual_Studio/FSE/Tango.FSE.Common/Resources/Styles.xaml index 8d5e5ae0d..2b7ea3640 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/Resources/Styles.xaml +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Resources/Styles.xaml @@ -9,6 +9,8 @@ xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:local="clr-namespace:Tango.FSE.Common.Resources"> + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/Connection/DefaultMachineProvider.cs b/Software/Visual_Studio/FSE/Tango.FSE.UI/Connection/DefaultMachineProvider.cs index 94b035ab5..aad63fdf9 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/Connection/DefaultMachineProvider.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/Connection/DefaultMachineProvider.cs @@ -342,6 +342,7 @@ namespace Tango.FSE.UI.Connection { IsConnected = false; IsBusy = false; + Machine = null; OnMachineDisconnected(MachineOperator, null); } } diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/FileAssociation/DefaultFileAssociationProvider.cs b/Software/Visual_Studio/FSE/Tango.FSE.UI/FileAssociation/DefaultFileAssociationProvider.cs index 0d582cb11..89364cbbd 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/FileAssociation/DefaultFileAssociationProvider.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/FileAssociation/DefaultFileAssociationProvider.cs @@ -19,6 +19,7 @@ namespace Tango.FSE.UI.FileAssociation { private Dictionary> _handlers; private IpcServer _ipcServer; + private bool _initialized; public const string FILE_ASSOCIATION_PREFIX = "-file"; public const int FILE_ASSOCIATION_ARGS_COUNT = 3; @@ -44,6 +45,10 @@ namespace Tango.FSE.UI.FileAssociation public async void OnApplicationReady(IFSEApplicationManager applicationManager) { + if (!_initialized) return; + + _initialized = true; + try { LogManager.Log("Starting file association IPC service..."); diff --git a/Software/Visual_Studio/Tango.BL/Entities/HardwareVersion.cs b/Software/Visual_Studio/Tango.BL/Entities/HardwareVersion.cs index 590fe9e13..bc65c33ce 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/HardwareVersion.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/HardwareVersion.cs @@ -109,5 +109,16 @@ namespace Tango.BL.Entities { } + + /// + /// Returns a that represents this instance. + /// + /// + /// A that represents this instance. + /// + public override string ToString() + { + return FullName; + } } } -- cgit v1.3.1 From 4613356b6a9898f7c61f3f17cf82e933b8077cee Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sat, 14 Nov 2020 00:39:20 +0200 Subject: Implemented all roles and permissions for configuration module. --- Software/DB/TCC/TCC.mdf | Bin 8388608 -> 8388608 bytes Software/DB/TCC/TCC_log.ldf | Bin 8388608 -> 8388608 bytes Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 22675456 -> 22675456 bytes .../ViewModels/ConfigurationViewVM.cs | 13 +++++ .../ViewModels/DataStoreViewVM.cs | 46 +++++++++++++++- .../ViewModels/MachineViewVM.cs | 13 +++++ .../ViewModels/MainViewVM.cs | 23 ++++---- .../Views/ConfigurationView.xaml | 9 ++-- .../ViewModels/UserDetailsViewVM.cs | 7 +-- .../Tango.BL/Enumerations/Permissions.cs | 60 +++++++++++++++++++++ .../Visual_Studio/Tango.BL/Enumerations/Roles.cs | 6 +++ 12 files changed, 158 insertions(+), 19 deletions(-) (limited to 'Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MainViewVM.cs') diff --git a/Software/DB/TCC/TCC.mdf b/Software/DB/TCC/TCC.mdf index 67f699f61..9840f753b 100644 Binary files a/Software/DB/TCC/TCC.mdf and b/Software/DB/TCC/TCC.mdf differ diff --git a/Software/DB/TCC/TCC_log.ldf b/Software/DB/TCC/TCC_log.ldf index 390749bbf..eeb735214 100644 Binary files a/Software/DB/TCC/TCC_log.ldf and b/Software/DB/TCC/TCC_log.ldf differ diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 79cd947dc..88258bdcf 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 793affcc5..08d1ad4fe 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/ConfigurationViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/ConfigurationViewVM.cs index edccf1c06..0c4b3a0f5 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/ConfigurationViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/ConfigurationViewVM.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Tango.BL.Entities; using Tango.Core.Commands; using Tango.Core.DI; +using Tango.FSE.BL; using Tango.FSE.Common; using Tango.FSE.Common.AutoComplete; using Tango.FSE.Common.SQL; @@ -90,6 +91,12 @@ namespace Tango.FSE.MachineConfiguration.ViewModels private async void ResetCounters() { + if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.FSE_ResetMachineCounters)) + { + await NotificationProvider.ShowError("The current user profile does not allow resetting the machine counters.\nPlease contact your administrator."); + return; + } + if (!MachineProvider.IsPPCAvailable) { await NotificationProvider.ShowError("Resetting the machine counters requires an active connection to this machine."); @@ -121,6 +128,12 @@ namespace Tango.FSE.MachineConfiguration.ViewModels private async void ResetDeviceRegistration() { + if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.FSE_ResetMachineDeviceRegistration)) + { + await NotificationProvider.ShowError("The current user profile does not allow resetting the device registration.\nPlease contact your administrator."); + return; + } + if (!await NotificationProvider.ShowWarningQuestion("Resetting the machine's device registration will allow other panel PCs to perform a machine setup for this machine. Are you sure?", "RESET", "CANCEL")) return; EditingComposition.Machine.IsDeviceRegistered = false; diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/DataStoreViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/DataStoreViewVM.cs index 198f1bd9b..7c1fae7ac 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/DataStoreViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/DataStoreViewVM.cs @@ -114,6 +114,12 @@ namespace Tango.FSE.MachineConfiguration.ViewModels private async void EditItem(DataStoreItemModel item) { + if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.FSE_DataStoreWrite)) + { + await NotificationProvider.ShowError("The current user profile does not allow editing of the data store.\nPlease contact your administrator."); + return; + } + var vm = await NotificationProvider.ShowDialog(new DataStoreItemEditDialogViewVM() { Item = item, EnableTypeChange = !item.IsGlobal }); if (vm.DialogResult) @@ -127,6 +133,12 @@ namespace Tango.FSE.MachineConfiguration.ViewModels private async void AddCollection() { + if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.FSE_DataStoreCreate)) + { + await NotificationProvider.ShowError("The current user profile does not allow creating new data store collections.\nPlease contact your administrator."); + return; + } + var result = await NotificationProvider.ShowInputBox("Add Collection", "Please enter the collection name", MaterialDesignThemes.Wpf.PackIconKind.Collection, null, null, 20, null, null, (input) => { if (DataStore.Collections.ToList().Exists(x => x.Name.ToLower() == input.ToLower())) @@ -157,6 +169,12 @@ namespace Tango.FSE.MachineConfiguration.ViewModels private async void AddItem() { + if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.FSE_DataStoreCreate)) + { + await NotificationProvider.ShowError("The current user profile does not allow creating new data store items.\nPlease contact your administrator."); + return; + } + var result = await NotificationProvider.ShowInputBox("Add Item", "Please enter the item key", MaterialDesignThemes.Wpf.PackIconKind.KeyAdd, null, null, 20, null, null, (input) => { if (SelectedCollection.Items.ToList().Exists(x => x.Key.ToLower() == input.ToLower())) @@ -187,14 +205,26 @@ namespace Tango.FSE.MachineConfiguration.ViewModels } } - private void RemoveCollection(DataStoreCollectionModel collection) + private async void RemoveCollection(DataStoreCollectionModel collection) { + if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.FSE_DataStoreCreate)) + { + await NotificationProvider.ShowError("The current user profile does not allow deleting data store collections.\nPlease contact your administrator."); + return; + } + collection.IsDeleted = true; _collectionsView?.Refresh(); } - private void RemoveItem(DataStoreItemModel item) + private async void RemoveItem(DataStoreItemModel item) { + if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.FSE_DataStoreCreate)) + { + await NotificationProvider.ShowError("The current user profile does not allow deleting data store items.\nPlease contact your administrator."); + return; + } + item.IsDeleted = true; _selectedCollectionView.Refresh(); } @@ -223,6 +253,12 @@ namespace Tango.FSE.MachineConfiguration.ViewModels private async void SaveModel() { + if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.FSE_DataStoreWrite)) + { + await NotificationProvider.ShowError("The current user profile does not allow editing of the data store.\nPlease contact your administrator."); + return; + } + try { using (NotificationProvider.PushTaskItem("Updating data store...")) @@ -272,6 +308,7 @@ namespace Tango.FSE.MachineConfiguration.ViewModels } catch (Exception ex) { + DataStore = null; LogManager.Log(ex, "Error loading data store."); if (await NotificationProvider.ShowWarningQuestion($"Error occurred while trying to load the data store.\n{ex.FlattenMessage()}", "RETRY", "CANCEL")) { @@ -285,6 +322,11 @@ namespace Tango.FSE.MachineConfiguration.ViewModels { base.OnNavigatedTo(); + if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.FSE_DataStoreRead)) + { + return; + } + if (DataStore == null) { await LoadDataStore(); diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MachineViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MachineViewVM.cs index 24a0cbc42..19617c347 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MachineViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MachineViewVM.cs @@ -31,6 +31,19 @@ namespace Tango.FSE.MachineConfiguration.ViewModels get { return _selectedView; } set { + if (value == NavigationView.DataStoreView) + { + if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.FSE_DataStoreRead)) + { + Task.Delay(500).ContinueWith((x) => + { + SelectedView = _selectedView; + NotificationProvider.ShowError("The current user profile does not allow accessing the data store.\nPlease contact your administrator."); + }); + return; + } + } + _selectedView = value; RaisePropertyChangedAuto(); } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MainViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MainViewVM.cs index 5b8ca21ac..250dc1046 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MainViewVM.cs @@ -16,19 +16,22 @@ namespace Tango.FSE.MachineConfiguration.ViewModels { public override void OnApplicationReady() { - InvokeUI(() => + if (CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.FSE_RunConfigurationModule)) { - NavigationManager.MenuItems.Add(new NavigationMenuItem(() => + InvokeUI(() => { - NavigationManager.NavigateTo(); - }) - { - Name = "Configuration", - Index = 8, - Description = "Access to the organization machines configuration and settings", - Image = ResourceHelper.GetImageFromResources("Images/configuration.png"), + NavigationManager.MenuItems.Add(new NavigationMenuItem(() => + { + NavigationManager.NavigateTo(); + }) + { + Name = "Configuration", + Index = 8, + Description = "Access to the organization machines configuration and settings", + Image = ResourceHelper.GetImageFromResources("Images/configuration.png"), + }); }); - }); + } } public async override Task OnApplicationLogout() diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/ConfigurationView.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/ConfigurationView.xaml index fda526d34..f52bdc618 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/ConfigurationView.xaml +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/ConfigurationView.xaml @@ -5,6 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Tango.FSE.MachineConfiguration.Views" xmlns:global="clr-namespace:Tango.FSE.MachineConfiguration" + xmlns:auth="clr-namespace:Tango.FSE.Common.Authorization;assembly=Tango.FSE.Common" xmlns:material="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:vm="clr-namespace:Tango.FSE.MachineConfiguration.ViewModels" xmlns:enumerations="clr-namespace:Tango.BL.Enumerations;assembly=Tango.BL" @@ -31,7 +32,7 @@ - + @@ -112,7 +113,7 @@ - + @@ -131,7 +132,7 @@ - + @@ -156,7 +157,7 @@ - + Head Type diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.UsersAndRoles/ViewModels/UserDetailsViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.UsersAndRoles/ViewModels/UserDetailsViewVM.cs index 0e243e02d..20953faa1 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.UsersAndRoles/ViewModels/UserDetailsViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.UsersAndRoles/ViewModels/UserDetailsViewVM.cs @@ -189,9 +189,10 @@ namespace Tango.FSE.UsersAndRoles.ViewModels { collection.Add(new RoleModel(roles.SingleOrDefault(x => x.RoleEnum == Roles.FSETwineTechnician), Roles.FSETechnician, Roles.FSEAdvancedTechnician)); collection.Add(new RoleModel(roles.SingleOrDefault(x => x.RoleEnum == Roles.FSETwineAdministrator), Roles.FSETechnician, Roles.FSEAdvancedTechnician, Roles.FSEAdministrator, Roles.FSETwineTechnician)); - collection.Add(new RoleModel(roles.SingleOrDefault(x => x.RoleEnum == Roles.FSETwineProcedureDesigner), Roles.FSETechnician)); - collection.Add(new RoleModel(roles.SingleOrDefault(x => x.RoleEnum == Roles.FSETwineProcedurePublisher), Roles.FSETechnician, Roles.FSETwineProcedureDesigner)); - collection.Add(new RoleModel(roles.SingleOrDefault(x => x.RoleEnum == Roles.FSETwineDeveloper), Roles.FSETechnician) { IsVisible = CurrentUser.HasRole(Roles.FSETwineDeveloper) }); + collection.Add(new RoleModel(roles.SingleOrDefault(x => x.RoleEnum == Roles.FSETwineProcedureDesigner), Roles.FSETechnician, Roles.FSEAdvancedTechnician, Roles.FSETwineTechnician)); + collection.Add(new RoleModel(roles.SingleOrDefault(x => x.RoleEnum == Roles.FSETwineProcedurePublisher), Roles.FSETechnician, Roles.FSEAdvancedTechnician, Roles.FSETwineTechnician, Roles.FSETwineProcedureDesigner)); + collection.Add(new RoleModel(roles.SingleOrDefault(x => x.RoleEnum == Roles.FSETwineDataStoreDeveloper), Roles.FSETechnician, Roles.FSEAdvancedTechnician, Roles.FSETwineTechnician)); + collection.Add(new RoleModel(roles.SingleOrDefault(x => x.RoleEnum == Roles.FSETwineDeveloper), Roles.FSETechnician, Roles.FSEAdvancedTechnician, Roles.FSETwineTechnician) { IsVisible = CurrentUser.HasRole(Roles.FSETwineDeveloper) }); } collection.ToList().ForEach(x => x.IsSelected = user.FSERoles.Any(y => y.Code == x.Role.Code)); diff --git a/Software/Visual_Studio/Tango.BL/Enumerations/Permissions.cs b/Software/Visual_Studio/Tango.BL/Enumerations/Permissions.cs index 8591cf826..5bf6095f5 100644 --- a/Software/Visual_Studio/Tango.BL/Enumerations/Permissions.cs +++ b/Software/Visual_Studio/Tango.BL/Enumerations/Permissions.cs @@ -271,5 +271,65 @@ namespace Tango.BL.Enumerations [Description("Allows running a floating procedure project file.")] FSE_RunProcedureProjectFile = 1020, + /// + /// (Allows loading the machine configuration module) + /// + [Description("Allows loading the machine configuration module")] + FSE_RunConfigurationModule = 1021, + + /// + /// (Allows editing of machine provisioning settings) + /// + [Description("Allows editing of machine provisioning settings")] + FSE_ModifyMachineProvisioning = 1022, + + /// + /// (Allows editing of machine update settings) + /// + [Description("Allows editing of machine update settings")] + FSE_ModifyMachineUpdate = 1023, + + /// + /// (Allows editing of machine identity settings) + /// + [Description("Allows editing of machine identity settings")] + FSE_ModifyMachineIdentity = 1024, + + /// + /// (Allows editing of machine hardware settings) + /// + [Description("Allows editing of machine hardware settings")] + FSE_ModifyMachineHardware = 1025, + + /// + /// (Allows viewing data store items) + /// + [Description("Allows viewing data store items")] + FSE_DataStoreRead = 1026, + + /// + /// (Allows writing to data store items) + /// + [Description("Allows writing to data store items")] + FSE_DataStoreWrite = 1027, + + /// + /// (Allows creating data store items and collections) + /// + [Description("Allows creating data store items and collections")] + FSE_DataStoreCreate = 1028, + + /// + /// (Allows resetting the machine counters) + /// + [Description("Allows resetting the machine counters")] + FSE_ResetMachineCounters = 1029, + + /// + /// (Allows resetting the machine device registration) + /// + [Description("Allows resetting the machine device registration")] + FSE_ResetMachineDeviceRegistration = 1030, + } } diff --git a/Software/Visual_Studio/Tango.BL/Enumerations/Roles.cs b/Software/Visual_Studio/Tango.BL/Enumerations/Roles.cs index 5747cfb59..b51477393 100644 --- a/Software/Visual_Studio/Tango.BL/Enumerations/Roles.cs +++ b/Software/Visual_Studio/Tango.BL/Enumerations/Roles.cs @@ -139,6 +139,12 @@ namespace Tango.BL.Enumerations [Description("Twine Developer")] FSETwineDeveloper = 1005, + /// + /// (Twine Data Store Developer) + /// + [Description("Twine Data Store Developer")] + FSETwineDataStoreDeveloper = 1008, + /// /// (Twine Procedure Designer) /// -- cgit v1.3.1