|
@@ -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)
|