Просмотр исходного кода

Converted LogikalSettings and V6Settings to IGlobalConfigurationSettings
V6 and Logikal Clients now update license usages when accessing data

frogsoftware 9 месяцев назад
Родитель
Сommit
a116a4028e

+ 2 - 1
prs.classes/Entities/Logikal/LogikalSettings.cs

@@ -1,4 +1,5 @@
 using System;
+using InABox.Configuration;
 using InABox.Core;
 
 namespace Comal.Classes
@@ -10,7 +11,7 @@ namespace Comal.Classes
         NotApproved
     }
 
-    public class LogikalSettings : Entity, IRemotable, IPersistent, ILicense<LogikalLicense>
+    public class LogikalSettings : BaseObject, IGlobalConfigurationSettings
     {
         [FileNameEditor]
         [EditorSequence(1)]

+ 14 - 0
prs.classes/Entities/Logikal/LogikalUsage.cs

@@ -0,0 +1,14 @@
+using InABox.Clients;
+using InABox.Core;
+
+namespace Comal.Classes
+{
+    
+    public class LogikalUsage : Entity, IRemotable, IPersistent, ILicense<LogikalLicense>
+    {
+        public static void Increment()
+        {
+            Client.Save(new LogikalUsage(),"");
+        }
+    }
+}

+ 3 - 3
prs.classes/Entities/V6/V6Settings.cs

@@ -1,12 +1,12 @@
 using System;
 using System.Collections.Generic;
-using InABox.Clients;
+using InABox.Configuration;
 using InABox.Core;
 
 namespace Comal.Classes
 {
-    
-    public class V6Settings : Entity, IRemotable, IPersistent, ILicense<V6License>
+    // As of v8.20 this has been migrated from an Entity to GlobalConfiguration for 
+    public class V6Settings : BaseObject, IGlobalConfigurationSettings
     {
         [TextBoxEditor]
         [EditorSequence(1)]

+ 13 - 0
prs.classes/Entities/V6/V6Usage.cs

@@ -0,0 +1,13 @@
+using InABox.Clients;
+using InABox.Core;
+
+namespace Comal.Classes
+{
+    public class V6Usage : Entity, IRemotable, IPersistent, ILicense<V6License>
+    {
+        public static void Increment()
+        {
+            Client.Save(new V6Usage(),"");
+        }
+    }
+}

+ 38 - 0
prs.classes/SecurityDescriptors/Logikal_Descriptors.cs

@@ -0,0 +1,38 @@
+using InABox.Core;
+
+namespace Comal.Classes.SecurityDescriptors
+{
+    
+    
+    [Caption("Edit Logikal Settings")]
+    public class EditLogikalSettings : EnabledSecurityDescriptor<LogikalLicense>
+    { 
+    }
+    
+    [Caption("Import Projects from Logikal")]
+    public class ImportLogikalProjects : EnabledSecurityDescriptor<LogikalLicense>
+    { 
+    }
+
+    [Caption("Import Bills of Materials from Logikal")]
+    public class ImportLogikalBillsOfMaterials : EnabledSecurityDescriptor<LogikalLicense>
+    { 
+    }
+    
+    [Caption("Import Requisitions from Logikal")]
+    public class ImportLogikalRequisitions : EnabledSecurityDescriptor<LogikalLicense>
+    { 
+    }
+    
+    [Caption("Import Approved Designs from Logikal")]
+    public class ImportApprovedLogikalDesigns : EnabledSecurityDescriptor<LogikalLicense>
+    { 
+    }
+    
+    [Caption("Import Unapproved Designs from Logikal")]
+    public class ImportUnapprovedLogikalDesigns : EnabledSecurityDescriptor<LogikalLicense>
+    { 
+    }
+
+    
+}

+ 14 - 0
prs.classes/SecurityDescriptors/V6_Descriptors.cs

@@ -0,0 +1,14 @@
+using InABox.Core;
+
+namespace Comal.Classes.SecurityDescriptors
+{
+    [Caption("Edit V6 Settings")]
+    public class EditV6Settings : EnabledSecurityDescriptor<V6License>
+    { 
+    }
+    
+    [Caption("Import Projects from V6")]
+    public class ImportV6Projects : EnabledSecurityDescriptor<V6License>
+    { 
+    }
+}

+ 9 - 2
prs.desktop/Panels/Jobs/BillOfMaterials/JobBillOfMaterialsGrid.cs

@@ -4,10 +4,13 @@ using System.Threading;
 using System.Windows;
 using System.Windows.Controls;
 using Comal.Classes;
+using Comal.Classes.SecurityDescriptors;
 using InABox.Clients;
+using InABox.Configuration;
 using InABox.Core;
 using InABox.DynamicGrid;
 using InABox.Wpf;
+using InABox.WPF;
 
 namespace PRSDesktop
 {
@@ -90,6 +93,8 @@ namespace PRSDesktop
             result.Job.Synchronise(Master ?? new Job());
             return result;
         }
+
+        private LogikalSettings? _logikalSettings;
         
         protected override void DoAdd(bool openEditorOnDirectEdit = false)
         {
@@ -105,7 +110,8 @@ namespace PRSDesktop
             //     menu.Items.Add(item);
             // }
 
-            if (Security.CanView<LogikalSettings>())
+            _logikalSettings ??= new GlobalConfiguration<LogikalSettings>().Load();
+            if (_logikalSettings.ImportBillOfMaterials && Security.IsAllowed<ImportLogikalBillsOfMaterials>())
             {
                 var _c = new LogikalClient();
                 if (_c.Settings.ImportBillOfMaterials)
@@ -113,7 +119,8 @@ namespace PRSDesktop
                     menu ??= new ContextMenu();
                     var item = new MenuItem()
                     {
-                        Header = "Import from Logikal"
+                        Header = "Import from Logikal",
+                        Icon = new Image() { Source = PRSDesktop.Resources.logikal.AsBitmapImage() }
                     };
                     item.Click += ImportFromLogikal;
                     menu.Items.Add(item);

+ 14 - 13
prs.desktop/Panels/Jobs/ProjectsGrid.cs

@@ -5,10 +5,12 @@ using System.Threading;
 using System.Windows;
 using System.Windows.Controls;
 using Comal.Classes;
+using Comal.Classes.SecurityDescriptors;
 using InABox.Clients;
 using InABox.Configuration;
 using InABox.Core;
 using InABox.DynamicGrid;
+using InABox.WPF;
 
 namespace PRSDesktop;
 
@@ -229,30 +231,29 @@ public class ProjectsGrid : DynamicDataGrid<Job>
     protected override void DoAdd(bool openEditorOnDirectEdit = false)
     {
         ContextMenu? menu = null;
-        if (Security.CanView<V6Settings>())
+        if (Security.IsAllowed<ImportV6Projects>())
         {
             menu ??= new ContextMenu();
             var item = new MenuItem()
             {
-                Header = "Import from V6"
+                Header = "Import from V6",
+                Icon = new Image() { Source = PRSDesktop.Resources.v6.AsBitmapImage() }
             };
             item.Click += ImportFromV6;
             menu.Items.Add(item);
         }
 
-        if (Security.CanView<LogikalSettings>())
+        _logikalSettings ??= new GlobalConfiguration<LogikalSettings>().Load();
+        if (_logikalSettings.ImportJobs && Security.IsAllowed<ImportLogikalProjects>())
         {
-            var _c = new LogikalClient();
-            if (_c.Settings.ImportJobs)
+            menu ??= new ContextMenu();
+            var item = new MenuItem()
             {
-                menu ??= new ContextMenu();
-                var item = new MenuItem()
-                {
-                    Header = "Import from Logikal"
-                };
-                item.Click += ImportFromLogikal;
-                menu.Items.Add(item);
-            }
+                Header = "Import from Logikal",
+                Icon = new Image() { Source = PRSDesktop.Resources.logikal.AsBitmapImage() }
+            };
+            item.Click += ImportFromLogikal;
+            menu.Items.Add(item);
         }
 
         if (menu != null)

+ 27 - 27
prs.desktop/Setups/SystemSetupActions.cs

@@ -2,10 +2,13 @@ using System;
 using System.Collections.Generic;
 using System.Linq;
 using Comal.Classes;
+using Comal.Classes.SecurityDescriptors;
 using InABox.Clients;
+using InABox.Configuration;
 using InABox.Core;
 using InABox.DynamicGrid;
 using InABox.Wpf;
+using V6Settings = Comal.Classes.V6Settings;
 
 namespace PRSDesktop;
 
@@ -187,35 +190,32 @@ public static class SystemSetupActions
 
     public static void ERPStatuses(IPanelHost host)
     {
-        host.CreateSetupActionIfCanView<LogikalSettings>("Logikal Settings", PRSDesktop.Resources.logikal, (action) =>
-        {
-            var logikal = Client.Query(
-                    new Filter<LogikalSettings>().All(),
-                    Columns.All<LogikalSettings>()
-                ).Rows
-                .FirstOrDefault()?
-                .ToObject<LogikalSettings>() ?? new LogikalSettings();
-            var grid = new LogikalSettingsGrid();
-            if (grid.EditItems(new LogikalSettings[] { logikal }))
+        host.CreateSetupActionIf(
+            "Logikal Settings", 
+            PRSDesktop.Resources.logikal, 
+            (action) =>
             {
-                Client.Save(logikal, "Updated Settings");
-            }
-        });
+                var _logikalSettings = new GlobalConfiguration<LogikalSettings>().Load();
+                _logikalSettings.CheckSQL();
+                var _logikalSettingsGrid = new LogikalSettingsGrid();
+                if (_logikalSettingsGrid.EditItems(new LogikalSettings[] { _logikalSettings }))
+                    new GlobalConfiguration<LogikalSettings>().Save(_logikalSettings);
+            },
+            Security.IsAllowed<EditLogikalSettings>()
+        );
         
-        host.CreateSetupActionIfCanView<V6Settings>("V6 Settings", PRSDesktop.Resources.v6, (action) =>
-        {
-            var v6 = Client.Query(
-                    new Filter<V6Settings>().All(),
-                    Columns.All<V6Settings>()
-                ).Rows
-                .FirstOrDefault()?
-                .ToObject<V6Settings>() ?? new V6Settings();
-            v6.CheckSQL();
-            var grid = new V6SettingsGrid();
-            if (grid.EditItems(new V6Settings[] { v6 }))
+        host.CreateSetupActionIf(
+            "V6 Settings", 
+            PRSDesktop.Resources.v6, 
+            (action) =>
             {
-                Client.Save(v6, "Updated Settings");
-            }
-        });
+                var _v6Settings = new GlobalConfiguration<V6Settings>().Load();
+                _v6Settings.CheckSQL();
+                var grid = new V6SettingsGrid();
+                if (grid.EditItems(new V6Settings[] { _v6Settings }))
+                    new GlobalConfiguration<V6Settings>().Save(_v6Settings);
+            },
+            Security.IsAllowed<EditV6Settings>()
+        );
     }
 }

+ 4 - 12
prs.desktop/Utils/LogikalUtils/LogikalClient.cs

@@ -8,6 +8,7 @@ using Comal.Classes;
 using H.Formatters;
 using H.Pipes;
 using InABox.Clients;
+using InABox.Configuration;
 using InABox.Core;
 using InABox.Logikal;
 using Newtonsoft.Json;
@@ -38,17 +39,8 @@ public class LogikalClient : IDisposable
     
     public LogikalClient()
     {
-        
-        Settings = Client
-            .Query(
-                new Filter<LogikalSettings>().All(),
-                Columns.All<LogikalSettings>(),
-                null,
-                CoreRange.Database(1)
-            )
-            .ToObjects<LogikalSettings>()
-            .FirstOrDefault()
-        ?? new LogikalSettings();
+
+        Settings = new GlobalConfiguration<LogikalSettings>().Load();
         
         var _basedirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) ?? "";
         var _logikalapp = System.IO.Path.Combine(_basedirectory, "PRSLogikal", "PRSLogikal.exe");
@@ -194,6 +186,7 @@ public class LogikalClient : IDisposable
 
     public LogikalResponse Connect()
     {
+        LogikalUsage.Increment();
         Ready = false;
         var _request = new LogikalConnectRequest()
         {
@@ -256,7 +249,6 @@ public class LogikalClient : IDisposable
     {
         if (!Ready)
             return NOTLOGGEDIN;
-
         var _request = new LogikalProjectRequest(projectid);
         var _result = Send(_request);
         return _result;

+ 5 - 15
prs.desktop/Utils/MicrosoftSQL/V6Utils/V6Client.cs

@@ -8,6 +8,7 @@ using System.Linq;
 using System.Text;
 using Comal.Classes;
 using InABox.Clients;
+using InABox.Configuration;
 using InABox.Core;
 using InABox.Dxf;
 using Syncfusion.Windows.Tools.Controls;
@@ -20,15 +21,9 @@ public class V6Client : MicrosoftSQLClient
 
     public V6Client()
     {
-        Settings = Client.Query(
-                new Filter<V6Settings>().All(),
-                Columns.All<V6Settings>(),
-                null,
-                CoreRange.Database(1)
-            )
-            .ToObjects<V6Settings>()
-            .FirstOrDefault()
-        ?? new V6Settings();
+        V6Usage.Increment();
+
+        Settings = new GlobalConfiguration<V6Settings>().Load();
         Settings.CheckSQL();
     }
 
@@ -219,10 +214,7 @@ public class V6Client : MicrosoftSQLClient
 
         return _result;
     }
-
-
-
-
+    
     public List<V6Labour> GetLabour(int number, string variation, int? quoteitem = null)
     {
         try
@@ -297,7 +289,6 @@ public class V6Client : MicrosoftSQLClient
         _result.Finish = GetString(row, nameof(V6Profile.Finish));
         return _result;
     }
-
     
     public List<V6Component> GetComponents(int number, string variation, int? quoteitem = null)
     {
@@ -336,7 +327,6 @@ public class V6Client : MicrosoftSQLClient
         return _result;
     }
     
-    
     public List<V6Glass> GetGlass(int number, string variation, int? quoteitem = null)
     {
         try

+ 1 - 1
prs.desktop/prsdesktop.iss

@@ -8,7 +8,7 @@
 #define public Dependency_Path_NetCoreCheck "dependencies\"
 
 #define MyAppName "PRS Desktop"
-#define MyAppVersion "8.19"
+#define MyAppVersion "8.20"
 #define MyAppPublisher "PRS Digital"
 #define MyAppURL "https://www.prs-software.com.au"
 #define MyAppExeName "PRSDesktop.exe"

+ 1 - 1
prs.licensing/PRSLicensing.iss

@@ -8,7 +8,7 @@
 #define public Dependency_Path_NetCoreCheck "dependencies\"
 
 #define MyAppName "PRS Licensing"
-#define MyAppVersion "8.19"
+#define MyAppVersion "8.20"
 #define MyAppPublisher "PRS Digital"
 #define MyAppURL "https://www.prs-software.com.au"
 #define MyAppExeName "PRSLicensing.exe"

+ 1 - 1
prs.server/PRSServer.iss

@@ -8,7 +8,7 @@
 #define public Dependency_Path_NetCoreCheck "dependencies\"
 
 #define MyAppName "PRS Server"
-#define MyAppVersion "8.19"
+#define MyAppVersion "8.20"
 #define MyAppPublisher "PRS Digital"
 #define MyAppURL "https://www.prs-software.com.au"
 #define MyAppExeName "PRSServer.exe"

+ 1 - 0
prs.shared/Database Update Scripts/DatabaseUpdateScripts.cs

@@ -49,5 +49,6 @@ public static class DatabaseUpdateScripts
         DataUpdater.RegisterUpdateScript<Update_7_77>();
         DataUpdater.RegisterUpdateScript<Update_8_02>();
         DataUpdater.RegisterUpdateScript<Update_8_04>();
+        DataUpdater.RegisterUpdateScript<Update_8_20>();
     }
 }

+ 1 - 1
prs.shared/Database Update Scripts/Update_8_14.cs → prs.shared/Database Update Scripts/Update_8_14_Unused.cs

@@ -4,7 +4,7 @@ using InABox.Database;
 
 namespace PRS.Shared.Database_Update_Scripts;
 
-internal class Update_8_14 : DatabaseUpdateScript
+internal class Update_8_14_Unused : DatabaseUpdateScript
 {
 
     private static readonly int CHUNK_SIZE = 500;

+ 41 - 0
prs.shared/Database Update Scripts/Update_8_20.cs

@@ -0,0 +1,41 @@
+using Comal.Classes;
+using InABox.Configuration;
+using InABox.Core;
+using InABox.Database;
+
+namespace PRS.Shared.Database_Update_Scripts;
+
+internal class Update_8_20 : DatabaseUpdateScript
+{
+    
+    public override VersionNumber Version => new(8, 20);
+    
+    public override bool Update()
+    {
+        var _provider = DbFactory.NewProvider(Logger.Main);
+        MigrateSettings<V6Settings>(_provider);
+        MigrateSettings<LogikalSettings>(_provider);
+        return true;
+    }
+
+    private static void MigrateSettings<T>(IProvider provider) where T : BaseObject, new()
+    {
+        var _table = provider.Query<T>($"select * from {typeof(T).Name.Split('.').Last()}");
+        if (_table != null)
+        {
+            var _entity = _table.Rows.FirstOrDefault()?.ToObject<T>();
+            if (_entity != null)
+            {
+                var _config = new GlobalSettings()
+                {
+                    Section = typeof(T).Name.Split('.').Last(),
+                    Key = "",
+                    Contents = Serialization.Serialize(_entity)
+                };
+                provider.Save(_config);
+            }
+            provider.DropTable<T>();
+        }
+    }
+    
+ }

+ 19 - 0
prs.stores/LogikalUsageStore.cs

@@ -0,0 +1,19 @@
+using Comal.Classes;
+using InABox.Core;
+using InABox.Database;
+
+namespace PRSStores;
+
+public class LogikalUsageStore : Store<LogikalUsage>
+{
+    
+    protected override void OnSave(LogikalUsage[] entities, ref string auditnote)
+    {
+        UpdateUserTracking(typeof(LogikalUsage), UserTrackingAction.Write);
+    }
+
+    protected override void OnSave(LogikalUsage entity, ref string auditnote)
+    {
+        UpdateUserTracking(typeof(LogikalUsage), UserTrackingAction.Write);
+    }
+}

+ 19 - 0
prs.stores/V6UsageStore.cs

@@ -0,0 +1,19 @@
+using Comal.Classes;
+using InABox.Core;
+using InABox.Database;
+
+namespace PRSStores;
+
+public class V6UsageStore : Store<V6Usage>
+{
+    
+    protected override void OnSave(V6Usage[] entities, ref string auditnote)
+    {
+        UpdateUserTracking(typeof(V6Usage), UserTrackingAction.Write);
+    }
+
+    protected override void OnSave(V6Usage entity, ref string auditnote)
+    {
+        UpdateUserTracking(typeof(V6Usage), UserTrackingAction.Write);
+    }
+}