Prechádzať zdrojové kódy

Added ability to export and import specific database profiles
Fixed "blank profile" issue with new databases

frankvandenbos 4 mesiacov pred
rodič
commit
31ff3a6ad3

+ 83 - 43
prs.desktop/App.xaml.cs

@@ -13,6 +13,7 @@ using InABox.Core;
 using InABox.Logging;
 using InABox.Wpf;
 using InABox.WPF;
+using Microsoft.Win32;
 using NDesk.Options;
 using Syncfusion.Licensing;
 using Path = System.IO.Path;
@@ -56,58 +57,97 @@ namespace PRSDesktop
 
         private void AutoDiscover(Dictionary<string, DatabaseSettings> allsettings)
         {
-            var confirm = MessageWindow.ShowYesNo("Try to configure Server Connection Automatically?", "Auto Discover");
-            if (confirm)
-                try
+            var mw = new MessageWindow();
+            mw.Title = "Configure Database";
+            mw.Message =
+                "No PRS Databases found!.\n\n" +
+                "The following options are available:\n" +
+                "- [Scan] Search the local network for PRS databases\n" +
+                "- [Import] bring in a pre-configured connection profile, or\n" +
+                "- [Demo Mode] connect to the Demonstration Database\n\n"+
+                "What would you like to do?";  
+            mw.Buttons.Add(new MessageWindowButton("Scan",(win,args) => ScanForDatabases(args, allsettings), MessageWindowButtonPosition.Left));
+            mw.Buttons.Add(new MessageWindowButton("Import",(win,args) => ImportDatabase(args, allsettings), MessageWindowButtonPosition.Left));
+            mw.Buttons.Add(new MessageWindowButton("Demo Mode",(win,args) => args.Close = true, MessageWindowButtonPosition.Right));
+
+            mw.ShowDialog();
+        }
+        
+        private void ImportDatabase(MessageWindowButtonDelegateArgs args, Dictionary<string, DatabaseSettings> allsettings)
+        {
+            var ofd = new OpenFileDialog();
+            ofd.Filter = "PRS Connection Files (*.prsconnection)|*.prsconnection";
+            if (ofd.ShowDialog() == true)
+            {
+                var profilename = Path.GetFileNameWithoutExtension(ofd.FileName);
+                var text = File.ReadAllText(ofd.FileName);
+                var settings = Serialization.Deserialize<DatabaseSettings>(text);
+                if (settings != null)
+                {
+                    allsettings[profilename] = settings;
+                    new LocalConfiguration<DatabaseSettings>().SaveAll(allsettings);
+                    args.Close = true;
+                }
+                else
                 {
-                    using (new WaitCursor())
+                    MessageBox.Show("Invalid Connection Profile!");
+                }
+            }
+        }
+
+        private void ScanForDatabases(MessageWindowButtonDelegateArgs args, Dictionary<string, DatabaseSettings> allsettings)
+        {
+            try
+            {
+                using (new WaitCursor())
+                {
+                    AutoDiscoverySettings autodiscover;
+                    using (var client = new UdpClient())
                     {
-                        AutoDiscoverySettings autodiscover;
-                        using (var client = new UdpClient())
-                        {
-                            client.Client.SendTimeout = 10000;
-                            client.Client.ReceiveTimeout = 20000;
+                        client.Client.SendTimeout = 10000;
+                        client.Client.ReceiveTimeout = 20000;
 
-                            var requestData = Encoding.ASCII.GetBytes("");
-                            var serverEndPoint = new IPEndPoint(IPAddress.Any, 0);
-                            client.EnableBroadcast = true;
+                        var requestData = Encoding.ASCII.GetBytes("");
+                        var serverEndPoint = new IPEndPoint(IPAddress.Any, 0);
+                        client.EnableBroadcast = true;
 
-                            client.Send(requestData, requestData.Length, new IPEndPoint(IPAddress.Broadcast, 8888));
+                        client.Send(requestData, requestData.Length, new IPEndPoint(IPAddress.Broadcast, 8888));
 
-                            var serverResponseData = client.Receive(ref serverEndPoint);
-                            var serverResponse = Encoding.ASCII.GetString(serverResponseData);
-                            autodiscover = Serialization.Deserialize<AutoDiscoverySettings>(serverResponse);
-                            client.Close();
-                        }
+                        var serverResponseData = client.Receive(ref serverEndPoint);
+                        var serverResponse = Encoding.ASCII.GetString(serverResponseData);
+                        autodiscover = Serialization.Deserialize<AutoDiscoverySettings>(serverResponse);
+                        client.Close();
+                    }
 
-                        var settings = new DatabaseSettings();
-                        settings.IsActive = true;
-                        settings.Logo = autodiscover.Logo;
-                        settings.Protocol = autodiscover.Protocol;
-                        settings.DatabaseType = DatabaseType.Networked;
-                        settings.URLs = autodiscover.URLs;
-                        settings.LibraryLocation = autodiscover.LibraryLocation;
-                        settings.GoogleAPIKey = autodiscover.GoogleAPIKey;
+                    var settings = new DatabaseSettings();
+                    settings.IsActive = true;
+                    settings.Logo = autodiscover.Logo;
+                    settings.Protocol = autodiscover.Protocol;
+                    settings.DatabaseType = DatabaseType.Networked;
+                    settings.URLs = autodiscover.URLs;
+                    settings.LibraryLocation = autodiscover.LibraryLocation;
+                    settings.GoogleAPIKey = autodiscover.GoogleAPIKey;
 
-                        allsettings[autodiscover.Name] = settings;
-                        new LocalConfiguration<DatabaseSettings>(autodiscover.Name).Save(settings);
+                    allsettings[autodiscover.Name] = settings;
+                    new LocalConfiguration<DatabaseSettings>(autodiscover.Name).Save(settings);
 
-                        AutoUpdateSettings = new AutoUpdateSettings
-                        {
-                            Channel = autodiscover.UpdateChannel,
-                            Type = autodiscover.UpdateType,
-                            Location = autodiscover.UpdateLocation,
-                            Elevated = autodiscover.UpdateAdmin
-                        };
-                        new LocalConfiguration<AutoUpdateSettings>().Save(AutoUpdateSettings);
-
-                        MessageWindow.ShowMessage($"Server found at {String.Join(";",autodiscover.URLs)}", "Success");
-                    }
-                }
-                catch
-                {
-                    MessageWindow.ShowMessage("No Server Found", "Not found", image: MessageWindow.WarningImage);
+                    AutoUpdateSettings = new AutoUpdateSettings
+                    {
+                        Channel = autodiscover.UpdateChannel,
+                        Type = autodiscover.UpdateType,
+                        Location = autodiscover.UpdateLocation,
+                        Elevated = autodiscover.UpdateAdmin
+                    };
+                    new LocalConfiguration<AutoUpdateSettings>().Save(AutoUpdateSettings);
+
+                    MessageWindow.ShowMessage($"Server found at {String.Join(";",autodiscover.URLs)}", "Success");
+                    args.Close = true;
                 }
+            }
+            catch
+            {
+                MessageWindow.ShowMessage("No Server Found", "Not found", image: MessageWindow.WarningImage);
+            }
         }
 
         private void MoveDirectory(string[] source, string target)

+ 2 - 0
prs.desktop/Configuration/DataBaseConfiguration.xaml

@@ -116,6 +116,8 @@
                     BorderThickness="0.75,0,0.75,0.75" Background="WhiteSmoke" CornerRadius="0,0,5,5" Padding="5">
                 <DockPanel Margin="5,5,5,0">
                     
+                    <Button x:Name="ExportOne" DockPanel.Dock="Right" Content="Export" Padding="10,0"
+                            Click="ExportOne_Click" Margin="5,0,0,0" />
                     <Button x:Name="CreateLink" DockPanel.Dock="Right" Content="Create Link" Padding="10,0"
                             Click="CreateLink_Click" Margin="5,0,0,0" />
                     <CheckBox x:Name="IsActiveCheck" DockPanel.Dock="Right" Content="Active?" VerticalAlignment="Center"

+ 21 - 0
prs.desktop/Configuration/DataBaseConfiguration.xaml.cs

@@ -759,6 +759,27 @@ namespace PRSDesktop
                 }
             }
         }
+        
+        private void ExportOne_Click(object sender, RoutedEventArgs e)
+        {
+            if (!_settings.TryGetValue(_current, out var settings))
+                return;
+            
+            using (var sfd = new SaveFileDialog())
+            {
+                sfd.Filter = "PRS Connection Files (*.prsconnection)|*.prsconnection";
+                sfd.DefaultExt = "prsconnection";
+                sfd.FileName = $"{_current}.prsconnection";
+                sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
+                var result = sfd.ShowDialog();
+                if (result == System.Windows.Forms.DialogResult.OK && !string.IsNullOrWhiteSpace(sfd.FileName))
+                {
+                    var json = Serialization.Serialize(settings);
+                    File.WriteAllText(sfd.FileName, json);
+                    MessageBox.Show("Connection File created!");
+                }
+            }
+        }
 
         private void Import_Click(object sender, RoutedEventArgs e)
         {

+ 35 - 31
prs.desktop/MainWindow.xaml.cs

@@ -1287,47 +1287,51 @@ public partial class MainWindow : IPanelHostControl
     private void LoadInitialWindow()
     {
         var app = new LocalConfiguration<AppSettings>().Load();
-        if (app.Settings.ContainsKey("CurrentPanel"))
+        var module = app.Settings.ContainsKey("CurrentPanel")
+            ? !string.IsNullOrWhiteSpace(app.Settings["CurrentPanel"])
+                ? app.Settings["CurrentPanel"].Split([" / "], StringSplitOptions.None)
+                : [ "Human Resources", "Task List"]
+            : [ "Human Resources", "Task List"];
+        
+
+        try
         {
-            try
-            {
-                var bFound = false;
-                var module = app.Settings["CurrentPanel"].Split(new[] { " / " }, StringSplitOptions.None);
-                if (module.Length == 2)
-                    foreach (Fluent.RibbonTabItem tab in _ribbon.Tabs)
+            var bFound = false;
+            if (module.Length == 2)
+                foreach (Fluent.RibbonTabItem tab in _ribbon.Tabs)
+                {
+                    if (String.Equals(tab.Header, module.First()))
                     {
-                        if (String.Equals(tab.Header, module.First()))
+                        _ribbon.SelectedTabItem = tab;
+                        foreach (Fluent.RibbonGroupBox bar in tab.Groups)
                         {
-                            _ribbon.SelectedTabItem = tab;
-                            foreach (Fluent.RibbonGroupBox bar in tab.Groups)
+                            foreach (var item in bar.Items)
                             {
-                                foreach (var item in bar.Items)
+                                var button = item as Fluent.Button;
+                                if (button != null && String.Equals(button.Header, module.Last()))
                                 {
-                                    var button = item as Fluent.Button;
-                                    if (button != null && String.Equals(button.Header, module.Last()))
-                                    {
-                                        bFound = true;
-                                        if (button.Command is SimpleCommand command)
-                                            command.Execute(null);
-                                        //button.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
-                                        break;
-                                    }
-                                }
-
-                                if (bFound)
+                                    bFound = true;
+                                    if (button.Command is SimpleCommand command)
+                                        command.Execute(null);
+                                    //button.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
                                     break;
+                                }
                             }
-                        }
 
-                        if (bFound)
-                            break;
+                            if (bFound)
+                                break;
+                        }
                     }
-            }
-            catch (Exception e)
-            {
-                MessageWindow.ShowError($"Unable to load {app.Settings["CurrentPanel"]}", e);
-            }
+
+                    if (bFound)
+                        break;
+                }
         }
+        catch (Exception e)
+        {
+            MessageWindow.ShowError($"Unable to load {app.Settings["CurrentPanel"]}", e);
+        }
+
     }
 
     private void _ribbon_OnLoaded(object sender, RoutedEventArgs e)