Przeglądaj źródła

Updating platforms from strings to enum.

Kenric Nugteren 2 lat temu
rodzic
commit
4391531a9a

+ 3 - 3
prs.desktop/MainWindow.xaml.cs

@@ -168,19 +168,19 @@ namespace PRSDesktop
             switch (DatabaseType)
             {
                 case DatabaseType.Standalone:
-                    ClientFactory.SetClientType(typeof(LocalClient<>), "Wpf", CoreUtils.GetVersion());
+                    ClientFactory.SetClientType(typeof(LocalClient<>), Platform.Desktop, CoreUtils.GetVersion());
                     DbFactory.ColorScheme = App.DatabaseSettings.ColorScheme;
                     DbFactory.Logo = App.DatabaseSettings.Logo;
                     break;
                 
                 case DatabaseType.Networked:
                     var url = RestClient<User>.Ping(App.DatabaseSettings.URLs, out DatabaseInfo info);
-                    ClientFactory.SetClientType(typeof(RestClient<>), "Wpf", CoreUtils.GetVersion(), 
+                    ClientFactory.SetClientType(typeof(RestClient<>), Platform.Desktop, CoreUtils.GetVersion(), 
                         url, true);
                     break;
                 
                 case DatabaseType.Local:
-                    ClientFactory.SetClientType(typeof(PipeIPCClient<>), "Wpf", CoreUtils.GetVersion(), 
+                    ClientFactory.SetClientType(typeof(PipeIPCClient<>), Platform.Desktop, CoreUtils.GetVersion(), 
                         DatabaseServerProperties.GetPipeName(App.DatabaseSettings.LocalServerName));
                     break;
             }

+ 3 - 3
prs.server/Engines/Database/DatabaseEngine.cs

@@ -90,7 +90,7 @@ namespace PRSServer
             var user = CredentialsCache.Validate(session);
             if (user == null)
                 return Array.Empty<Notification>();
-            var store = DbFactory.FindStore<Notification>(user.ID, user.UserID, "", "");
+            var store = DbFactory.FindStore<Notification>(user.ID, user.UserID, default(Platform), "");
             return store.Query(
                 new Filter<Notification>(x => x.Employee.UserLink.ID).IsEqualTo(user.ID)
                     .And(x => x.Closed).IsEqualTo(DateTime.MinValue),
@@ -117,7 +117,7 @@ namespace PRSServer
 
         private void ConfigureNotifier()
         {
-            Notify.Notifier?.AddPollHandler(PollNotifications);
+            Notify.AddPollHandler(PollNotifications);
         }
 
         public override void Run()
@@ -279,7 +279,7 @@ namespace PRSServer
                     notification.Employee.ID = employee.ID;
                     notification.Title = "HTTPS Certificate expires soon";
                     notification.Description = message;
-                    DbFactory.FindStore<Notification>(employee.UserLink.ID, employee.UserLink.UserID, "", "").Save(notification, "");
+                    DbFactory.FindStore<Notification>(employee.UserLink.ID, employee.UserLink.UserID, default(Platform), "").Save(notification, "");
                 }
                 else
                 {

+ 1 - 1
prs.server/Engines/GPS/GPSEngine.cs

@@ -226,7 +226,7 @@ namespace PRSServer
             CoreUtils.RegisterClasses();
             ComalUtils.RegisterClasses();
 
-            ClientFactory.SetClientType(typeof(PipeIPCClient<>), "GPSServer", Version, DatabaseServerProperties.GetPipeName(Properties.Server));
+            ClientFactory.SetClientType(typeof(PipeIPCClient<>), Platform.GPSEngine, Version, DatabaseServerProperties.GetPipeName(Properties.Server));
             CheckConnection();
 
             DMFactory.Initialise(Properties.DumpFormat, Properties.DumpFile);

+ 1 - 1
prs.server/Engines/Scheduler/ScheduleEngine.cs

@@ -33,7 +33,7 @@ namespace PRSServer
                     Logger.Send(LogType.Error, "", "Server is blank!");
                     return;
                 }
-                ClientFactory.SetClientType(typeof(PipeIPCClient<>), "Scheduler", Version, DatabaseServerProperties.GetPipeName(Properties.Server));
+                ClientFactory.SetClientType(typeof(PipeIPCClient<>), Platform.SchedulerEngine, Version, DatabaseServerProperties.GetPipeName(Properties.Server));
                 CheckConnection();
 
                 Logger.Send(LogType.Information, "", "Starting Scheduler: ");

+ 1 - 1
prs.server/Engines/WebEngine/WebEngine.cs

@@ -29,7 +29,7 @@ namespace PRSServer
                 Logger.Send(LogType.Error, "", "Server is blank!");
                 return;
             }
-            ClientFactory.SetClientType(typeof(PipeIPCClient<>), "WebEngine", Version, DatabaseServerProperties.GetPipeName(Properties.Server));
+            ClientFactory.SetClientType(typeof(PipeIPCClient<>), Platform.WebEngine, Version, DatabaseServerProperties.GetPipeName(Properties.Server));
 
             Logger.Send(LogType.Information, "", "Registering Classes");
 

+ 3 - 3
prs.server/Forms/ServerGrid.cs

@@ -1028,7 +1028,7 @@ namespace PRSServer
                         currentServerURL = url;
                         currentServerPort = port;
                         currentServerName = null;
-                        ClientFactory.SetClientType(typeof(RestClient<>), "PRSServer", CoreUtils.GetVersion(), url, port, true);
+                        ClientFactory.SetClientType(typeof(RestClient<>), Platform.Server, CoreUtils.GetVersion(), url, port, true);;
 
                         // override the need to provide credentials when configuring the database
                         ClientFactory.SetBypass();
@@ -1088,7 +1088,7 @@ namespace PRSServer
                         currentServerPort = null;
                         currentServerURL = null;
                         currentServerName = pipeName;
-                        ClientFactory.SetClientType(typeof(PipeIPCClient<>), "PRSServer", CoreUtils.GetVersion(), pipeName);
+                        ClientFactory.SetClientType(typeof(PipeIPCClient<>), Platform.Server, CoreUtils.GetVersion(), pipeName);
                         using (new WaitCursor())
                         {
                             if (!Client.Ping())
@@ -1145,7 +1145,7 @@ namespace PRSServer
 
                 if (!DbFactory.IsProviderSet || DbFactory.Provider is not SQLiteProvider sql || sql.URL != properties.FileName)
                 {
-                    ClientFactory.SetClientType(typeof(LocalClient<>), "PRSServer", CoreUtils.GetVersion(), "");
+                    ClientFactory.SetClientType(typeof(LocalClient<>), Platform.Server, CoreUtils.GetVersion(), "");
                     Progress.ShowModal("Configuring database", (progress) =>
                     {
                         DbFactory.Stores = CoreUtils.TypeList(

+ 39 - 0
prs.shared/DatabaseUpdateScripts.cs

@@ -10,6 +10,7 @@ using System.Threading.Tasks;
 using Syncfusion.Windows.Tools.Controls;
 using System.Diagnostics.CodeAnalysis;
 using System.Reflection;
+using FastReport.Utils;
 
 namespace PRS.Shared
 {
@@ -24,6 +25,7 @@ namespace PRS.Shared
             DataUpdater.RegisterUpdateScript("6.43", Update_6_43);
             DataUpdater.RegisterUpdateScript("7.00", Update_7_00);
             DataUpdater.RegisterUpdateScript("7.06", Update_7_06);
+            DataUpdater.RegisterUpdateScript("7.14", Update_7_14);
         }
 
         private static Dictionary<string, Tuple<string, string>> _6_31_module_map = new()
@@ -531,5 +533,42 @@ namespace PRS.Shared
             Logger.Send(LogType.Information, "", "Finished updating Deletions");
             return true;
         }
+
+        /// <summary>
+        /// Updating Wpf and Timebench fields to use Platform.DesktopVersion and Platform.MobileVersion
+        /// </summary>
+        /// <returns></returns>
+        private static bool Update_7_14()
+        {
+            Logger.Send(LogType.Information, "", "Converting User.Wpf, User.Timebench -> User.Platform.DesktopVersion, User.Platform.MobileVersion");
+
+            Logger.Send(LogType.Information, "", "Loading Wpf, Timebench properties");
+            var props = DbFactory.Provider.Query<CustomProperty>(new Filter<CustomProperty>(x => x.Name).InList("Wpf", "TimeBench"))
+                .Rows.Select(x => x.ToObject<CustomProperty>()).ToArray();
+            DatabaseSchema.Load(props);
+
+            var columns = new Columns<User>(x => x.ID);
+            columns.Add("Wpf", "TimeBench");
+
+            var users = DbFactory.Provider.Query<User>(
+                new Filter<User>().All(),
+                columns).ToObjects<User>().ToList();
+            foreach(var user in users)
+            {
+                if(user.UserProperties.Dictionary.TryGetValue("Wpf", out var wpf))
+                {
+                    user.Platform.DesktopVersion = wpf?.Value?.ToString() ?? "";
+                }
+                if (user.UserProperties.Dictionary.TryGetValue("TimeBench", out var timebench))
+                {
+                    user.Platform.MobileVersion = timebench?.Value?.ToString() ?? "";
+                }
+            }
+            DbFactory.Provider.Save<User>(users);
+
+            Logger.Send(LogType.Information, "", "Finished updating user versions");
+
+            return true;
+        }
     }
 }

+ 21 - 8
prs.stores/BaseStore.cs

@@ -12,7 +12,7 @@ namespace Comal.Stores
     public class UserPlatform
     {
         public string UserID { get; set; }
-        public string Platform { get; set; }
+        public Platform Platform { get; set; }
         public string Version { get; set; }
     }
 
@@ -49,7 +49,7 @@ namespace Comal.Stores
 
         private void CheckPlatformVersion()
         {
-            if (string.IsNullOrEmpty(UserID) || string.IsNullOrEmpty(Platform) || string.IsNullOrEmpty(Version))
+            if (string.IsNullOrEmpty(UserID) || string.IsNullOrEmpty(Version))
                 return;
 
             var platform = PlatformCache.Platforms.FirstOrDefault(x => x.UserID.Equals(UserID) && x.Platform.Equals(Platform));
@@ -62,16 +62,29 @@ namespace Comal.Stores
             if (!platform.Version.Equals(Version))
             {
                 platform.Version = Version;
-                var prop = DatabaseSchema.Property(typeof(User), Platform);
-                if (prop != null && prop.Getter() != null && prop.Setter() != null)
+
+                if(Platform == Platform.Desktop || Platform == Platform.Mobile)
                 {
                     var user = Provider.Load(new Filter<User>(x => x.UserID).IsEqualTo(UserID)).FirstOrDefault();
-                    if (user != null)
+                    if(user is not null)
                     {
-                        var value = prop.Getter().Invoke(user);
-                        if (!Version.Equals(value))
+                        var current = Platform switch
+                        {
+                            Platform.Desktop => user.Platform.DesktopVersion,
+                            Platform.Mobile => user.Platform.MobileVersion,
+                            _ => ""
+                        };
+                        if (!Version.Equals(current))
                         {
-                            prop.Setter().Invoke(user, Version);
+                            switch (Platform)
+                            {
+                                case Platform.Desktop:
+                                    user.Platform.DesktopVersion = Version;
+                                    break;
+                                case Platform.Mobile:
+                                    user.Platform.MobileVersion = Version;
+                                    break;
+                            }
                             Provider.Save(user);
                         }
                     }