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/MachineViewVM.cs | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MachineViewVM.cs (limited to 'Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MachineViewVM.cs') 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 new file mode 100644 index 000000000..cbd6c1cf1 --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MachineViewVM.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using Tango.FSE.Common; +using Tango.FSE.Common.Navigation; +using Tango.FSE.MachineConfiguration.Messages; +using static Tango.FSE.MachineConfiguration.ViewModels.MachineViewVM; + +namespace Tango.FSE.MachineConfiguration.ViewModels +{ + public class MachineViewVM : ConfigurationViewModel, INavigationObjectReceiver + { + public class NavigationObject + { + public String MachineSerialNumber { get; set; } + } + + public enum NavigationView + { + ConfigurationView, + DataStoreView, + } + + private NavigationView _selectedView; + public NavigationView SelectedView + { + get { return _selectedView; } + set + { + _selectedView = value; + RaisePropertyChangedAuto(); + } + } + + private Machine _machine; + public Machine Machine + { + get { return _machine; } + set { _machine = value; RaisePropertyChangedAuto(); } + } + + public void OnNavigatedToWithObject(NavigationObject obj) + { + SelectedView = NavigationView.ConfigurationView; + LoadMachine(obj.MachineSerialNumber); + } + + private async void LoadMachine(String serialNumber) + { + using (NotificationProvider.PushTaskItem("Loading machine configuration...")) + { + Machine = await Services.MachinesService.GetMachineFull(serialNumber); + RaiseMessage(new MachineLoadedMessage() { Machine = Machine }); + } + } + } +} -- 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/MachineViewVM.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/MachineViewVM.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 From cd5006f765c65482033d671095f34453acfc416b Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Wed, 18 Nov 2020 18:06:13 +0200 Subject: DataStore improvements. --- .../Tango.DataStore.EF/EFDataStoreCollection.cs | 10 ++ .../Tango.DataStore.Editing/DataStoreItemModel.cs | 8 +- .../Tango.FSE.MachineConfiguration.csproj | 8 +- .../ViewModelLocator.cs | 6 +- .../ViewModels/ConfigurationViewVM.cs | 144 --------------- .../ViewModels/DataStoreViewVM.cs | 2 +- .../ViewModels/MachineViewVM.cs | 4 +- .../ViewModels/SettingsViewVM.cs | 144 +++++++++++++++ .../Views/ConfigurationView.xaml | 196 --------------------- .../Views/ConfigurationView.xaml.cs | 28 --- .../Views/MachineView.xaml | 2 +- .../Views/SettingsView.xaml | 196 +++++++++++++++++++++ .../Views/SettingsView.xaml.cs | 28 +++ .../DataStore/DefaultDataStoreProvider.cs | 2 - .../DataStore/DefaultDataStoreService.cs | 2 + 15 files changed, 398 insertions(+), 382 deletions(-) delete mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/ConfigurationViewVM.cs create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/SettingsViewVM.cs delete mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/ConfigurationView.xaml delete mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/ConfigurationView.xaml.cs create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/SettingsView.xaml create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/SettingsView.xaml.cs (limited to 'Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MachineViewVM.cs') diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.EF/EFDataStoreCollection.cs b/Software/Visual_Studio/DataStore/Tango.DataStore.EF/EFDataStoreCollection.cs index c42935368..c1b45e37f 100644 --- a/Software/Visual_Studio/DataStore/Tango.DataStore.EF/EFDataStoreCollection.cs +++ b/Software/Visual_Studio/DataStore/Tango.DataStore.EF/EFDataStoreCollection.cs @@ -33,6 +33,16 @@ namespace Tango.DataStore.EF { using (var db = ObservablesContext.CreateDefault()) { + var globalItem = db.GlobalDataStoreItems.FirstOrDefault(x => x.CollectionName == Name && x.Key == key); + + if (globalItem != null) + { + if (globalItem.DataType != (int)type) + { + throw new InvalidOperationException("A global data store item exists with the same key, but different data type."); + } + } + DataStoreItem item = db.DataStoreItems.SingleOrDefault(x => x.CollectionName == Name && x.Key == key); if (item == null) diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.Editing/DataStoreItemModel.cs b/Software/Visual_Studio/DataStore/Tango.DataStore.Editing/DataStoreItemModel.cs index 3b1741395..8f00a0ec6 100644 --- a/Software/Visual_Studio/DataStore/Tango.DataStore.Editing/DataStoreItemModel.cs +++ b/Software/Visual_Studio/DataStore/Tango.DataStore.Editing/DataStoreItemModel.cs @@ -53,7 +53,13 @@ namespace Tango.DataStore.Editing public String FormattedValue { - get { return this.ToString().ToOneLine(); } + get + { + var value = this.ToString(); + + if (value != null) return value.ToOneLine(); + return null; + } } public string Guid { 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 1a820ae3c..6e48f0ee7 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 @@ -98,13 +98,13 @@ - + - - ConfigurationView.xaml + + SettingsView.xaml DataStoreView.xaml @@ -227,7 +227,7 @@ Designer MSBuild:Compile - + MSBuild:Compile Designer diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModelLocator.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModelLocator.cs index 187565ca4..b924868b2 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModelLocator.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModelLocator.cs @@ -18,7 +18,7 @@ namespace Tango.FSE.MachineConfiguration TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); - TangoIOC.Default.Register(); + TangoIOC.Default.Register(); TangoIOC.Default.Register(); } @@ -46,11 +46,11 @@ namespace Tango.FSE.MachineConfiguration } } - public static ConfigurationViewVM ConfigurationViewVM + public static SettingsViewVM SettingsViewVM { get { - return TangoIOC.Default.GetInstance(); + return TangoIOC.Default.GetInstance(); } } 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 deleted file mode 100644 index 0c4b3a0f5..000000000 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/ConfigurationViewVM.cs +++ /dev/null @@ -1,144 +0,0 @@ -using System; -using System.Collections.Generic; -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.BL; -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 - { - [TangoInject] - private IRemoteSqlProvider RemoteSqlProvider { get; set; } - - private MachineEditingComposition _editingComposition; - public MachineEditingComposition EditingComposition - { - get { return _editingComposition; } - set { _editingComposition = value; RaisePropertyChangedAuto(); } - } - - public RelayCommand SaveCommand { get; set; } - public RelayCommand ResetCountersCommand { get; set; } - public RelayCommand ResetDeviceRegistrationCommand { get; set; } - - private List _sites; - public List Sites - { - get { return _sites; } - set { _sites = value; RaisePropertyChangedAuto(); } - } - - private Site _selectedSite; - public Site SelectedSite - { - get { return _selectedSite; } - set { _selectedSite = value; RaisePropertyChangedAuto(); } - } - - public ConfigurationViewVM() - { - RegisterForMessage(OnEditingCompositionLoaded); - SaveCommand = new RelayCommand(SaveConfiguration); - ResetCountersCommand = new RelayCommand(ResetCounters); - ResetDeviceRegistrationCommand = new RelayCommand(ResetDeviceRegistration); - } - - private void OnEditingCompositionLoaded(EditingCompositionLoadedMessage msg) - { - using (NotificationProvider.PushTaskItem("Loading machine configuration...")) - { - EditingComposition = msg.EditingComposition; - EditingComposition.Machine.ForceVersionUpdateChanged += (x, value) => { if (value) EditingComposition.Machine.SuspendVersionUpdate = false; }; - EditingComposition.Machine.SuspendVersionUpdateChanged += (x, value) => { if (value) EditingComposition.Machine.ForceVersionUpdate = false; }; - EditingComposition.Machine.OrganizationChanged -= OnMachine_OrganizationChanged; - EditingComposition.Machine.OrganizationChanged += OnMachine_OrganizationChanged; - OnMachine_OrganizationChanged(EditingComposition.Machine, EditingComposition.Machine.Organization); - } - } - - private void OnMachine_OrganizationChanged(object sender, Organization organization) - { - var sites = organization.Sites.ToList(); - sites.Insert(0, new Site() { Guid = null, Name = "NONE", ID = -1 }); - Sites = sites; - SelectedSite = Sites.FirstOrDefault(x => x.Guid == EditingComposition.Machine.SiteGuid); - - if (SelectedSite == null) - { - SelectedSite = Sites.First(); - } - } - - private async void SaveConfiguration() - { - using (NotificationProvider.PushTaskItem("Saving machine configuration...")) - { - EditingComposition.Machine.SiteGuid = SelectedSite.Guid; - EditingComposition = await Services.MachineConfigurationService.SaveMachineEditingComposition(EditingComposition); - await NotificationProvider.ShowSuccess("Machine configuration saved successfully."); - } - } - - 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."); - 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 (!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; - EditingComposition.Machine.DeviceId = null; - EditingComposition.Machine.DeviceName = null; - } - } -} 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 ef708afd3..d8bd8791a 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 @@ -120,7 +120,7 @@ namespace Tango.FSE.MachineConfiguration.ViewModels return; } - var vm = await NotificationProvider.ShowDialog(new DataStoreItemEditDialogViewVM() { Item = item, EnableTypeChange = !item.IsGlobal }); + var vm = await NotificationProvider.ShowDialog(new DataStoreItemEditDialogViewVM() { Item = item, EnableTypeChange = !item.IsGlobal && item.GlobalItem == null }); if (vm.DialogResult) { 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 19617c347..dd2430415 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 @@ -21,7 +21,7 @@ namespace Tango.FSE.MachineConfiguration.ViewModels public enum NavigationView { - ConfigurationView, + SettingsView, DataStoreView, } @@ -58,7 +58,7 @@ namespace Tango.FSE.MachineConfiguration.ViewModels public void OnNavigatedToWithObject(NavigationObject obj) { - SelectedView = NavigationView.ConfigurationView; + SelectedView = NavigationView.SettingsView; LoadMachine(obj.MachineGuid); } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/SettingsViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/SettingsViewVM.cs new file mode 100644 index 000000000..ed2cbd714 --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/SettingsViewVM.cs @@ -0,0 +1,144 @@ +using System; +using System.Collections.Generic; +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.BL; +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 SettingsViewVM : FSEViewModel + { + [TangoInject] + private IRemoteSqlProvider RemoteSqlProvider { get; set; } + + private MachineEditingComposition _editingComposition; + public MachineEditingComposition EditingComposition + { + get { return _editingComposition; } + set { _editingComposition = value; RaisePropertyChangedAuto(); } + } + + public RelayCommand SaveCommand { get; set; } + public RelayCommand ResetCountersCommand { get; set; } + public RelayCommand ResetDeviceRegistrationCommand { get; set; } + + private List _sites; + public List Sites + { + get { return _sites; } + set { _sites = value; RaisePropertyChangedAuto(); } + } + + private Site _selectedSite; + public Site SelectedSite + { + get { return _selectedSite; } + set { _selectedSite = value; RaisePropertyChangedAuto(); } + } + + public SettingsViewVM() + { + RegisterForMessage(OnEditingCompositionLoaded); + SaveCommand = new RelayCommand(SaveConfiguration); + ResetCountersCommand = new RelayCommand(ResetCounters); + ResetDeviceRegistrationCommand = new RelayCommand(ResetDeviceRegistration); + } + + private void OnEditingCompositionLoaded(EditingCompositionLoadedMessage msg) + { + using (NotificationProvider.PushTaskItem("Loading machine configuration...")) + { + EditingComposition = msg.EditingComposition; + EditingComposition.Machine.ForceVersionUpdateChanged += (x, value) => { if (value) EditingComposition.Machine.SuspendVersionUpdate = false; }; + EditingComposition.Machine.SuspendVersionUpdateChanged += (x, value) => { if (value) EditingComposition.Machine.ForceVersionUpdate = false; }; + EditingComposition.Machine.OrganizationChanged -= OnMachine_OrganizationChanged; + EditingComposition.Machine.OrganizationChanged += OnMachine_OrganizationChanged; + OnMachine_OrganizationChanged(EditingComposition.Machine, EditingComposition.Machine.Organization); + } + } + + private void OnMachine_OrganizationChanged(object sender, Organization organization) + { + var sites = organization.Sites.ToList(); + sites.Insert(0, new Site() { Guid = null, Name = "NONE", ID = -1 }); + Sites = sites; + SelectedSite = Sites.FirstOrDefault(x => x.Guid == EditingComposition.Machine.SiteGuid); + + if (SelectedSite == null) + { + SelectedSite = Sites.First(); + } + } + + private async void SaveConfiguration() + { + using (NotificationProvider.PushTaskItem("Saving machine configuration...")) + { + EditingComposition.Machine.SiteGuid = SelectedSite.Guid; + EditingComposition = await Services.MachineConfigurationService.SaveMachineEditingComposition(EditingComposition); + await NotificationProvider.ShowSuccess("Machine configuration saved successfully."); + } + } + + 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."); + 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 (!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; + EditingComposition.Machine.DeviceId = null; + EditingComposition.Machine.DeviceName = null; + } + } +} 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 deleted file mode 100644 index f52bdc618..000000000 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/ConfigurationView.xaml +++ /dev/null @@ -1,196 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - Activate Windows License - - - - License Key - - - - - - Setup Team Viewer - - - - - Activate Disk Protection - - - - - Use Firmware Emulator (Demo Machine) - - - - - - Device Registration - - - - - - Registered: - - - - - Device ID: - - - - - Device Name: - - - - - - - - - - - - - Machine Counters - - - - - - Total Dye Time: - - - - - Total Dye Meters: - - - - - - - - - - - - - - - Disable Firmware Upgrade - - - - - Force Version Update - - - - - Suspend Version Update - - - - - - - - - Serial Number - - - - - Name - - - - - Organization - - - - - Site - - - - - - - - - Head Type - - - - - Hardware Version - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/ConfigurationView.xaml.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/ConfigurationView.xaml.cs deleted file mode 100644 index d25948d2c..000000000 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/ConfigurationView.xaml.cs +++ /dev/null @@ -1,28 +0,0 @@ -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.FSE.MachineConfiguration.Views -{ - /// - /// Interaction logic for MachineDataStoreView.xaml - /// - public partial class ConfigurationView : UserControl - { - public ConfigurationView() - { - InitializeComponent(); - } - } -} 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 ca6470db3..d33966e18 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 @@ -35,7 +35,7 @@ - + diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/SettingsView.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/SettingsView.xaml new file mode 100644 index 000000000..88df5a0b3 --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/SettingsView.xaml @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + Activate Windows License + + + + License Key + + + + + + Setup Team Viewer + + + + + Activate Disk Protection + + + + + Use Firmware Emulator (Demo Machine) + + + + + + Device Registration + + + + + + Registered: + + + + + Device ID: + + + + + Device Name: + + + + + + + + + + + + + Machine Counters + + + + + + Total Dye Time: + + + + + Total Dye Meters: + + + + + + + + + + + + + + + Disable Firmware Upgrade + + + + + Force Version Update + + + + + Suspend Version Update + + + + + + + + + Serial Number + + + + + Name + + + + + Organization + + + + + Site + + + + + + + + + Head Type + + + + + Hardware Version + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/SettingsView.xaml.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/SettingsView.xaml.cs new file mode 100644 index 000000000..bdf8d904d --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/SettingsView.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.FSE.MachineConfiguration.Views +{ + /// + /// Interaction logic for MachineDataStoreView.xaml + /// + public partial class SettingsView : UserControl + { + public SettingsView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/DataStore/DefaultDataStoreProvider.cs b/Software/Visual_Studio/FSE/Tango.FSE.UI/DataStore/DefaultDataStoreProvider.cs index 9dbfec1db..14cf4c7c4 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/DataStore/DefaultDataStoreProvider.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/DataStore/DefaultDataStoreProvider.cs @@ -226,8 +226,6 @@ namespace Tango.FSE.UI.DataStore { foreach (var item in collection.Items) { - - if (item.IsGlobal) { globals.Add(new SaveModel() { CollectionName = collection.Name, Item = item }); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/DataStore/DefaultDataStoreService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/DataStore/DefaultDataStoreService.cs index 41fb21498..4d2e9c1df 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/DataStore/DefaultDataStoreService.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/DataStore/DefaultDataStoreService.cs @@ -121,6 +121,7 @@ namespace Tango.PPC.Common.DataStore [ExternalBridgeRequestHandlerMethod(typeof(RemoteDataStoreDeleteRequest), RequestHandlerLoggingMode.LogRequestName)] public async Task OnRemoteDataStoreDeleteRequest(RemoteDataStoreDeleteRequest request, String token, ExternalBridgeReceiver receiver) { + throw new InvalidOperationException("Deleting from the data store is not allowed."); GetManager().GetCollection(request.Collection).Delete(request.Key); await receiver.SendGenericResponse(new RemoteDataStoreDeleteResponse(), token); } @@ -128,6 +129,7 @@ namespace Tango.PPC.Common.DataStore [ExternalBridgeRequestHandlerMethod(typeof(RemoteDataStoreDeleteAllRequest), RequestHandlerLoggingMode.LogRequestName)] public async Task OnRemoteDataStoreDeleteAllRequest(RemoteDataStoreDeleteAllRequest request, String token, ExternalBridgeReceiver receiver) { + throw new InvalidOperationException("Deleting from the data store is not allowed."); GetManager().GetCollection(request.Collection).DeleteAll(); await receiver.SendGenericResponse(new RemoteDataStoreDeleteAllResponse(), token); } -- cgit v1.3.1 From 466340a97f8a158570f84fc12238101ca9c124ec Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 19 Nov 2020 01:46:41 +0200 Subject: Data store improvements. Added line number to logs viewer. Added DataStore Create Write Global permission. Added FSE application path to "Path" environment variable for dsUtil. Completed dsUtil. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 22675456 -> 22675456 bytes .../Advanced Installer Projects/FSE Installer.aip | 52 ++++++-- .../DataStore/Tango.DataStore.CLI/DataStoreUtil.cs | 131 +++++++++++++++++++++ .../Tango.DataStore.CLI/DataStoreUtilSettings.cs | 15 +++ .../DataStore/Tango.DataStore.CLI/Options.cs | 21 +++- .../DataStore/Tango.DataStore.CLI/Program.cs | 66 +---------- .../Tango.DataStore.CLI/Tango.DataStore.CLI.csproj | 6 + .../ViewModels/DataStoreViewVM.cs | 14 +-- .../ViewModels/MachineViewVM.cs | 2 +- .../Help/proc-doc.chm | Bin 245435 -> 245437 bytes .../Views/LogFileTabView.xaml | 5 +- .../FSE/Tango.FSE.UI/Properties/AssemblyInfo.cs | 3 +- .../FSE/Tango.FSE.UI/Tango.FSE.UI.csproj | 4 + .../Tango.BL/Enumerations/Permissions.cs | 12 +- .../Controllers/DataStoreController.cs | 20 +++- 16 files changed, 255 insertions(+), 96 deletions(-) create mode 100644 Software/Visual_Studio/DataStore/Tango.DataStore.CLI/DataStoreUtil.cs create mode 100644 Software/Visual_Studio/DataStore/Tango.DataStore.CLI/DataStoreUtilSettings.cs (limited to 'Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MachineViewVM.cs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index b80bbc9b0..58fbcac47 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 b06dad7d5..981698cbd 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/Advanced Installer Projects/FSE Installer.aip b/Software/Visual_Studio/Advanced Installer Projects/FSE Installer.aip index dc6557505..86a02fb0f 100644 --- a/Software/Visual_Studio/Advanced Installer Projects/FSE Installer.aip +++ b/Software/Visual_Studio/Advanced Installer Projects/FSE Installer.aip @@ -63,6 +63,8 @@ + + @@ -303,8 +305,10 @@ - - + + + + @@ -314,6 +318,7 @@ + @@ -361,6 +366,7 @@ + @@ -372,10 +378,10 @@ - - - - + + + + @@ -755,16 +761,27 @@ + + + + + + + + + + + + + + + + + - - - - - - @@ -927,6 +944,9 @@ + + + @@ -1246,13 +1266,19 @@ + - + + + + + + diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/DataStoreUtil.cs b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/DataStoreUtil.cs new file mode 100644 index 000000000..b18476e3f --- /dev/null +++ b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/DataStoreUtil.cs @@ -0,0 +1,131 @@ +using ConsoleTables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Cryptography; +using Tango.DataStore.Web; +using Tango.Settings; +using Tango.Web; + +namespace Tango.DataStore.CLI +{ + public class DataStoreConsole + { + public void Get(GetOptions options) + { + try + { + ApplyAutoLogin(options); + + if (options.MachineSerialNumber != null) + { + Console.WriteLine($"Retrieving data store values for '{options.MachineSerialNumber}'..."); + } + else + { + Console.WriteLine("Retrieving global data store values..."); + } + + var client = CreateClient(options.Email, options.Password, options.Environment); + + var items = client.Get(options.MachineSerialNumber, options.Collection, options.Key).ToList(); + + ConsoleTable table = new ConsoleTable("COLLECTION", "KEY", "DATA TYPE", "PROTO TYPE", "STATE", "GLOBAL", "LOCAL"); + + foreach (var item in items) + { + table.AddRow(item.Collection, item.Key, item.DataType, item.ProtoMessageType != MessageType.None ? item.ProtoMessageType.ToString() : null, item.Type, item.GlobalValue.ToStringSafe().ToOneLine(), item.LocalValue.ToStringSafe().ToOneLine()); + } + + Console.WriteLine(); + Console.WriteLine("DATA STORE RESULTS:"); + Console.WriteLine(); + + table.Write(); + } + catch (Exception ex) + { + Console.WriteLine(ex.FlattenMessage()); + } + } + + public void Put(PutOptions options) + { + try + { + ApplyAutoLogin(options); + + if (options.MachineSerialNumber != null) + { + Console.WriteLine($"Storing data store value for '{options.MachineSerialNumber}'..."); + } + else + { + Console.WriteLine("Storing global data store value..."); + } + + var client = CreateClient(options.Email, options.Password, options.Environment); + + if (options.DataType == Web.DataType.Proto) + { + options.Value = options.Value.ToStringOrEmpty().Replace("'", "\""); + } + + client.Put(new DataStoreWebPutItem() + { + Collection = options.Collection, + Key = options.Key, + DataType = options.DataType, + MachineSerialNumber = options.MachineSerialNumber, + ProtoMessageType = options.ProtoMessageType, + Value = options.Value + }); + + Console.WriteLine($"Item '{options.Key}' stored successfully."); + } + catch (Exception ex) + { + Console.WriteLine(ex.FlattenMessage()); + } + } + + public void AutoLogin(LoginConfig options) + { + MachineLevelCryptographer crypt = new MachineLevelCryptographer(); + var settings = SettingsManager.Default.GetOrCreate(); + settings.Email = options.Email; + settings.Password = crypt.Encrypt(options.Password); + settings.Save(); + } + + private void ApplyAutoLogin(OptionsBase options) + { + if (options.Email == null && options.Password == null) + { + MachineLevelCryptographer crypt = new MachineLevelCryptographer(); + var settings = SettingsManager.Default.GetOrCreate(); + options.Email = settings.Email; + options.Password = crypt.Decrypt(settings.Password); + } + } + + private DataStoreClient CreateClient(String email, String password, DeploymentSlot slot) + { + String token = String.Empty; + + HttpClient http = new HttpClient(); + DataStoreClient dsClient = new DataStoreClient(slot.ToAddress(), http); + var response = dsClient.Login(new LoginRequest() + { + Email = email, + Password = password, + }); + http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", response.Token); + + return dsClient; + } + } +} diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/DataStoreUtilSettings.cs b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/DataStoreUtilSettings.cs new file mode 100644 index 000000000..58380d231 --- /dev/null +++ b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/DataStoreUtilSettings.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Settings; + +namespace Tango.DataStore.CLI +{ + public class DataStoreUtilSettings : SettingsBase + { + public String Email { get; set; } + public String Password { get; set; } + } +} diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Options.cs b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Options.cs index 150756671..fd91a5722 100644 --- a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Options.cs +++ b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Options.cs @@ -4,16 +4,17 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.DataStore.Web; using Tango.Web; namespace Tango.DataStore.CLI { public class OptionsBase { - [Option(longName: "email", HelpText = "Email address.", Required = true)] + [Option(longName: "email", HelpText = "Email address.")] public String Email { get; set; } - [Option(longName: "password", HelpText = "Password.", Required = true)] + [Option(longName: "password", HelpText = "Password.")] public String Password { get; set; } [Option(longName: "env", HelpText = "The target environment.", Required = true)] @@ -45,7 +46,23 @@ namespace Tango.DataStore.CLI [Option(longName: "key", HelpText = "New or existing item key", Required = true)] public String Key { get; set; } + [Option(longName: "data-type", HelpText = "Item data type", Required = true)] + public Web.DataType DataType { get; set; } + + [Option(longName: "proto-type", HelpText = "Protobuf message type when data-type is 'Proto'.")] + public MessageType ProtoMessageType { get; set; } + [Option(longName: "value", HelpText = "Item value", Required = true)] public String Value { get; set; } } + + [Verb("login-config", HelpText = "Stores the specified credentials for use with the --auto-login flag.")] + public class LoginConfig + { + [Option(longName: "email", HelpText = "Email address.")] + public String Email { get; set; } + + [Option(longName: "password", HelpText = "Password.")] + public String Password { get; set; } + } } diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs index db4f54620..85dfbb0bb 100644 --- a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs +++ b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs @@ -19,7 +19,7 @@ namespace Tango.DataStore.CLI { var console = new DataStoreConsole(); - var result = Parser.Default.ParseArguments(args) + var result = Parser.Default.ParseArguments(args) .WithParsed((options) => { console.Get(options); @@ -28,6 +28,10 @@ namespace Tango.DataStore.CLI { console.Put(options); }) + .WithParsed((options) => + { + console.AutoLogin(options); + }) .WithNotParsed((errors) => { @@ -41,64 +45,4 @@ namespace Tango.DataStore.CLI } } } - - public class DataStoreConsole - { - public void Get(GetOptions options) - { - try - { - if (options.MachineSerialNumber != null) - { - Console.WriteLine($"Retrieving data store values for '{options.MachineSerialNumber}'..."); - } - else - { - Console.WriteLine("Retrieving global data store values..."); - } - - var client = CreateClient(options.Email, options.Password, options.Environment); - - var items = client.Get(options.MachineSerialNumber, options.Collection, options.Key).ToList(); - - ConsoleTable table = new ConsoleTable("COLLECTION", "KEY", "DATA TYPE", "STATE", "GLOBAL", "LOCAL"); - - foreach (var item in items) - { - table.AddRow(item.Collection, item.Key, item.DataType, item.Type, item.GlobalValue.ToStringSafe().ToOneLine(), item.LocalValue.ToStringSafe().ToOneLine()); - } - - Console.WriteLine(); - Console.WriteLine("DATA STORE RESULTS:"); - Console.WriteLine(); - - table.Write(); - } - catch (Exception ex) - { - Console.WriteLine(ex.FlattenMessage()); - } - } - - public void Put(PutOptions options) - { - - } - - private DataStoreClient CreateClient(String email, String password, DeploymentSlot slot) - { - String token = String.Empty; - - HttpClient http = new HttpClient(); - DataStoreClient dsClient = new DataStoreClient(slot.ToAddress(), http); - var response = dsClient.Login(new LoginRequest() - { - Email = "roy@twine-s.com", - Password = "1Creativity", - }); - http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", response.Token); - - return dsClient; - } - } } diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Tango.DataStore.CLI.csproj b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Tango.DataStore.CLI.csproj index 28aab4ef7..42b0b95dc 100644 --- a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Tango.DataStore.CLI.csproj +++ b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Tango.DataStore.CLI.csproj @@ -63,6 +63,8 @@ + + @@ -85,6 +87,10 @@ {e4927038-348d-4295-aaf4-861c58cb3943} Tango.PMR + + {d8f1ad85-526a-4f50-b6dc-d437af63d8d8} + Tango.Settings + {5001990f-977b-48ff-b217-0236a5022ad8} Tango.Web 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 d8bd8791a..46f388461 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,7 +114,7 @@ namespace Tango.FSE.MachineConfiguration.ViewModels private async void EditItem(DataStoreItemModel item) { - if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.FSE_DataStoreWrite)) + if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.DataStoreWrite)) { await NotificationProvider.ShowError("The current user profile does not allow editing of the data store.\nPlease contact your administrator."); return; @@ -133,7 +133,7 @@ namespace Tango.FSE.MachineConfiguration.ViewModels private async void AddCollection() { - if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.FSE_DataStoreCreate)) + if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.DataStoreCreate)) { await NotificationProvider.ShowError("The current user profile does not allow creating new data store collections.\nPlease contact your administrator."); return; @@ -174,7 +174,7 @@ namespace Tango.FSE.MachineConfiguration.ViewModels private async void AddItem() { - if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.FSE_DataStoreCreate)) + if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.DataStoreCreate)) { await NotificationProvider.ShowError("The current user profile does not allow creating new data store items.\nPlease contact your administrator."); return; @@ -217,7 +217,7 @@ namespace Tango.FSE.MachineConfiguration.ViewModels private async void RemoveCollection(DataStoreCollectionModel collection) { - if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.FSE_DataStoreCreate)) + if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.DataStoreCreate)) { await NotificationProvider.ShowError("The current user profile does not allow deleting data store collections.\nPlease contact your administrator."); return; @@ -229,7 +229,7 @@ namespace Tango.FSE.MachineConfiguration.ViewModels private async void RemoveItem(DataStoreItemModel item) { - if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.FSE_DataStoreCreate)) + if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.DataStoreCreate)) { await NotificationProvider.ShowError("The current user profile does not allow deleting data store items.\nPlease contact your administrator."); return; @@ -263,7 +263,7 @@ namespace Tango.FSE.MachineConfiguration.ViewModels private async void SaveModel() { - if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.FSE_DataStoreWrite)) + if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.DataStoreWrite)) { await NotificationProvider.ShowError("The current user profile does not allow editing of the data store.\nPlease contact your administrator."); return; @@ -332,7 +332,7 @@ namespace Tango.FSE.MachineConfiguration.ViewModels { base.OnNavigatedTo(); - if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.FSE_DataStoreRead)) + if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.DataStoreRead)) { return; } 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 dd2430415..fd953a0b8 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 @@ -33,7 +33,7 @@ namespace Tango.FSE.MachineConfiguration.ViewModels { if (value == NavigationView.DataStoreView) { - if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.FSE_DataStoreRead)) + if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.DataStoreRead)) { Task.Delay(500).ContinueWith((x) => { diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures.Documentation/Help/proc-doc.chm b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures.Documentation/Help/proc-doc.chm index 8777b5768..ef7ec26c0 100644 Binary files a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures.Documentation/Help/proc-doc.chm and b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures.Documentation/Help/proc-doc.chm differ diff --git a/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Views/LogFileTabView.xaml b/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Views/LogFileTabView.xaml index 8f06dac0d..92064f9fd 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Views/LogFileTabView.xaml +++ b/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Views/LogFileTabView.xaml @@ -16,7 +16,7 @@ Background="{StaticResource FSE_PrimaryBackgroundDarkBrush}" Foreground="{StaticResource FSE_PrimaryForegroundBrush}"> - + @@ -24,6 +24,7 @@ + @@ -34,7 +35,7 @@ - + diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/Properties/AssemblyInfo.cs b/Software/Visual_Studio/FSE/Tango.FSE.UI/Properties/AssemblyInfo.cs index fa70e630e..964eb990b 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/Properties/AssemblyInfo.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/Properties/AssemblyInfo.cs @@ -8,5 +8,4 @@ using System.Windows; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Tango FSE")] -[assembly: AssemblyVersion("1.1.1.0")] - +[assembly: AssemblyVersion("1.1.1.0")] diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/Tango.FSE.UI.csproj b/Software/Visual_Studio/FSE/Tango.FSE.UI/Tango.FSE.UI.csproj index 4b4d46a78..2a79629a3 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/Tango.FSE.UI.csproj +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/Tango.FSE.UI.csproj @@ -601,6 +601,10 @@ + + {6189b8c3-7af9-43dd-8a61-a8a05f526f62} + Tango.DataStore.CLI + {208C8BD8-72C6-4E3C-ACAA-351091A2ACC7} Tango.PPC.Shared diff --git a/Software/Visual_Studio/Tango.BL/Enumerations/Permissions.cs b/Software/Visual_Studio/Tango.BL/Enumerations/Permissions.cs index 5bf6095f5..51e98f6f4 100644 --- a/Software/Visual_Studio/Tango.BL/Enumerations/Permissions.cs +++ b/Software/Visual_Studio/Tango.BL/Enumerations/Permissions.cs @@ -305,19 +305,19 @@ namespace Tango.BL.Enumerations /// (Allows viewing data store items) /// [Description("Allows viewing data store items")] - FSE_DataStoreRead = 1026, + DataStoreRead = 1026, /// /// (Allows writing to data store items) /// [Description("Allows writing to data store items")] - FSE_DataStoreWrite = 1027, + DataStoreWrite = 1027, /// /// (Allows creating data store items and collections) /// [Description("Allows creating data store items and collections")] - FSE_DataStoreCreate = 1028, + DataStoreCreate = 1028, /// /// (Allows resetting the machine counters) @@ -331,5 +331,11 @@ namespace Tango.BL.Enumerations [Description("Allows resetting the machine device registration")] FSE_ResetMachineDeviceRegistration = 1030, + /// + /// (Allows creating creating and editing the global data store) + /// + [Description("Allows creating creating and editing the global data store")] + DataStoreCreateWriteGlobal = 1031, + } } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/DataStoreController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/DataStoreController.cs index 0d35bd776..383a59850 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/DataStoreController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/DataStoreController.cs @@ -62,6 +62,11 @@ namespace Tango.MachineService.Controllers throw new AuthenticationException("Your account has been disabled. Please contact your administrator."); } + if (!user.HasPermission(Permissions.DataStoreRead)) + { + throw new AuthenticationException("You are not authorized to access the data store."); + } + var token = WebToken.CreateNew(MachineServiceConfig.JWT_TOKEN_SECRET, new TokenObject() { UserGuid = user.Guid, @@ -81,7 +86,7 @@ namespace Tango.MachineService.Controllers { try { - if (!RequestToken.Object.Permissions.Contains(Permissions.FSE_DataStoreRead)) + if (!RequestToken.Object.Permissions.Contains(Permissions.DataStoreRead)) { throw CreateHttpException(new AuthenticationException("The current user was not authorized to read from the data store."), HttpStatusCode.Unauthorized); } @@ -150,9 +155,9 @@ namespace Tango.MachineService.Controllers { try { - if (!RequestToken.Object.Permissions.Contains(Permissions.FSE_DataStoreWrite)) + if (!RequestToken.Object.Permissions.Contains(Permissions.DataStoreWrite)) { - throw CreateHttpException(new AuthenticationException("The current user was not authorized to write to the data store."), HttpStatusCode.BadRequest); + throw CreateHttpException(new AuthenticationException("The current user was not authorized to write to the data store."), HttpStatusCode.Unauthorized); } if (item.Collection == null || item.Key == null) @@ -177,7 +182,7 @@ namespace Tango.MachineService.Controllers if (dbItem == null) { - if (!RequestToken.Object.Permissions.Contains(Permissions.FSE_DataStoreCreate)) + if (!RequestToken.Object.Permissions.Contains(Permissions.DataStoreCreate)) { throw CreateHttpException(new AuthenticationException("The current user was not authorized to create new items on the data store."), HttpStatusCode.Unauthorized); } @@ -197,11 +202,16 @@ namespace Tango.MachineService.Controllers } else { + if (!RequestToken.Object.Permissions.Contains(Permissions.DataStoreCreateWriteGlobal)) + { + throw CreateHttpException(new AuthenticationException("The current user was not authorized to write to the global data store."), HttpStatusCode.Unauthorized); + } + GlobalDataStoreItem dbItem = db.GlobalDataStoreItems.FirstOrDefault(x => x.CollectionName == item.Collection && x.Key == item.Key); if (dbItem == null) { - if (!RequestToken.Object.Permissions.Contains(Permissions.FSE_DataStoreCreate)) + if (!RequestToken.Object.Permissions.Contains(Permissions.DataStoreCreate)) { throw CreateHttpException(new AuthenticationException("The current user was not authorized to create new items on the data store."), HttpStatusCode.Unauthorized); } -- cgit v1.3.1