|
@@ -32,6 +32,7 @@ using InABox.DynamicGrid;
|
|
|
using InABox.Mail;
|
|
|
using InABox.Core.Reports;
|
|
|
using InABox.IPC;
|
|
|
+using InABox.Rpc;
|
|
|
using InABox.Scripting;
|
|
|
using InABox.WPF;
|
|
|
using NAudio.Wave;
|
|
@@ -58,7 +59,6 @@ using Pen = System.Drawing.Pen;
|
|
|
using PixelFormat = System.Drawing.Imaging.PixelFormat;
|
|
|
using Role = Comal.Classes.Role;
|
|
|
using SortDirection = InABox.Core.SortDirection;
|
|
|
-using ValidationResult = InABox.Clients.ValidationResult;
|
|
|
using PRSDesktop.Components.Spreadsheet;
|
|
|
using InABox.Wpf.Reports;
|
|
|
|
|
@@ -75,6 +75,8 @@ namespace PRSDesktop
|
|
|
|
|
|
private static PipeServer<string>? _client;
|
|
|
|
|
|
+ private IRpcClientTransport? _transport;
|
|
|
+
|
|
|
private WaveIn? _audio;
|
|
|
private bool _audioMuted;
|
|
|
private MemoryStream? _audioStream;
|
|
@@ -143,7 +145,7 @@ namespace PRSDesktop
|
|
|
ClientFactory.Notifications.AddHandler<Notification>(ReceiveNotification);
|
|
|
ClientFactory.RegisterMailer(EmailType.IMAP, typeof(IMAPMailer));
|
|
|
ClientFactory.RegisterMailer(EmailType.Exchange, typeof(ExchangeMailer));
|
|
|
- ClientFactory.OnLog += (_, message) => { Logger.Send(LogType.Information, ClientFactory.UserID, message); };
|
|
|
+ ClientFactory.OnLog += (type, userid, message, parameters) => Logger.Send(LogType.Information, ClientFactory.UserID, message, parameters);
|
|
|
ClientFactory.OnRequestError += ClientFactory_OnRequestError;
|
|
|
|
|
|
HotKeyManager.Initialize();
|
|
@@ -163,20 +165,24 @@ namespace PRSDesktop
|
|
|
|
|
|
case DatabaseType.Networked:
|
|
|
|
|
|
- //var url = App.DatabaseSettings.URLs.FirstOrDefault() ?? "localhost:8000";
|
|
|
- //ClientFactory.SetClientType(typeof(RPCClient<>), Platform.Wpf, CoreUtils.GetVersion(), () => new RPCClientSocketTransport(url));
|
|
|
+ var url = App.DatabaseSettings.URLs.FirstOrDefault() ?? "localhost:8000";
|
|
|
+ _transport = new RpcClientSocketTransport(url);
|
|
|
+ _transport.OnClose += TransportConnectionLost;
|
|
|
+ ClientFactory.SetClientType(typeof(RpcClient<>), Platform.Wpf, CoreUtils.GetVersion(), _transport );
|
|
|
|
|
|
- var url = RestClient<User>.Ping(App.DatabaseSettings.URLs, out DatabaseInfo info);
|
|
|
- ClientFactory.SetClientType(typeof(RestClient<>), Platform.Wpf, CoreUtils.GetVersion(),
|
|
|
- url, true);
|
|
|
+ //var url = RestClient<User>.Ping(App.DatabaseSettings.URLs, out DatabaseInfo info);
|
|
|
+ //ClientFactory.SetClientType(typeof(RestClient<>), Platform.Wpf, CoreUtils.GetVersion(),
|
|
|
+ // url, true);
|
|
|
break;
|
|
|
|
|
|
case DatabaseType.Local:
|
|
|
- //var pipe = DatabaseServerProperties.GetPipeName(App.DatabaseSettings.LocalServerName);
|
|
|
- //ClientFactory.SetClientType(typeof(RPCClient<>), Platform.Wpf, CoreUtils.GetVersion(),
|
|
|
- // () => new RPCClientPipeTransport(pipe));
|
|
|
- ClientFactory.SetClientType(typeof(IPCClient<>), Platform.Wpf, CoreUtils.GetVersion(),
|
|
|
- DatabaseServerProperties.GetPipeName(App.DatabaseSettings.LocalServerName));
|
|
|
+ var pipename = DatabaseServerProperties.GetPipeName(App.DatabaseSettings.LocalServerName);
|
|
|
+ _transport = new RpcClientPipeTransport(pipename);
|
|
|
+ _transport.OnClose += TransportConnectionLost;
|
|
|
+ ClientFactory.SetClientType(typeof(RpcClient<>), Platform.Wpf, CoreUtils.GetVersion(),
|
|
|
+ _transport );
|
|
|
+ // ClientFactory.SetClientType(typeof(IPCClient<>), Platform.Wpf, CoreUtils.GetVersion(),
|
|
|
+ // DatabaseServerProperties.GetPipeName(App.DatabaseSettings.LocalServerName));
|
|
|
break;
|
|
|
}
|
|
|
|
|
@@ -207,8 +213,8 @@ namespace PRSDesktop
|
|
|
CheckForUpdates();
|
|
|
|
|
|
Exception? startupException = null;
|
|
|
- Exception? loginException = null;
|
|
|
- ValidationResult? loginStatus = null;
|
|
|
+ //Exception? loginException = null;
|
|
|
+ ValidationStatus? loginStatus = null;
|
|
|
|
|
|
Progress.ShowModal("Loading PRS", progress =>
|
|
|
{
|
|
@@ -304,10 +310,10 @@ namespace PRSDesktop
|
|
|
|
|
|
if (startupException != null)
|
|
|
MessageBox.Show(startupException.Message);
|
|
|
- else if (loginException != null)
|
|
|
- MessageBox.Show(loginException.Message);
|
|
|
+ //else if (loginException != null)
|
|
|
+ // MessageBox.Show(loginException.Message);
|
|
|
|
|
|
- if (DoLogin(App.DatabaseSettings.Autologin) == ValidationResult.VALID)
|
|
|
+ if (DoLogin(App.DatabaseSettings.Autologin) == ValidationStatus.VALID)
|
|
|
{
|
|
|
AfterLogin();
|
|
|
}
|
|
@@ -323,7 +329,7 @@ namespace PRSDesktop
|
|
|
|
|
|
Progress.ShowModal("Starting Up", progress =>
|
|
|
{
|
|
|
- if (loginStatus == ValidationResult.VALID && DatabaseType == DatabaseType.Standalone)
|
|
|
+ if (loginStatus == ValidationStatus.VALID && DatabaseType == DatabaseType.Standalone)
|
|
|
{
|
|
|
progress.Report("Starting Scheduler");
|
|
|
scheduler.Start();
|
|
@@ -331,6 +337,34 @@ namespace PRSDesktop
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ private void TransportConnectionLost(IRpcTransport transport, RpcTransportCloseArgs e)
|
|
|
+ {
|
|
|
+ if ((transport is IRpcClientTransport client))
|
|
|
+ {
|
|
|
+ Dispatcher.Invoke(() => {
|
|
|
+ Progress.ShowModal("Reconnecting", (progress) =>
|
|
|
+ {
|
|
|
+ DateTime lost = DateTime.Now;
|
|
|
+ while (!client.IsConnected())
|
|
|
+ {
|
|
|
+ progress.Report($"Connection lost - ({(DateTime.Now - lost):hh\\:mm})");
|
|
|
+ try
|
|
|
+ {
|
|
|
+ Logger.Send(LogType.Error,ClientFactory.UserID,"Reconnecting - ({0:hh\\:mm})",DateTime.Now - lost);
|
|
|
+ client.Connect();
|
|
|
+ if (client.IsConnected())
|
|
|
+ ClientFactory.Validate(ClientFactory.SessionID);
|
|
|
+ }
|
|
|
+ catch (System.Exception e1)
|
|
|
+ {
|
|
|
+ Logger.Send(LogType.Error,ClientFactory.UserID,$"Reconnect Failed: {e1.Message}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private bool _loggingOut = false;
|
|
|
|
|
|
private void ClientFactory_OnRequestError(RequestException e)
|
|
@@ -1420,9 +1454,9 @@ namespace PRSDesktop
|
|
|
|
|
|
#region Login Management
|
|
|
|
|
|
- private ValidationResult? DoLogin(bool autoLogin)
|
|
|
+ private ValidationStatus? DoLogin(bool autoLogin)
|
|
|
{
|
|
|
- ValidationResult? result = null;
|
|
|
+ ValidationStatus? result = null;
|
|
|
if (autoLogin)
|
|
|
{
|
|
|
if (App.DatabaseSettings.LoginType == LoginType.UserID)
|
|
@@ -1437,22 +1471,22 @@ namespace PRSDesktop
|
|
|
MessageBox.Show("Error connecting to server.\nPlease check the server URL and port number.");
|
|
|
result = null;
|
|
|
}
|
|
|
- if (result == ValidationResult.INVALID)
|
|
|
+ if (result == ValidationStatus.INVALID)
|
|
|
{
|
|
|
MessageBox.Show("Unable to Login with User ID: " + App.DatabaseSettings.UserID);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if (result != ValidationResult.VALID)
|
|
|
+ if (result != ValidationStatus.VALID)
|
|
|
{
|
|
|
- var login = new PinLogin(CoreUtils.GetVersion(), result ?? ValidationResult.INVALID);
|
|
|
+ var login = new PinLogin(CoreUtils.GetVersion(), result ?? ValidationStatus.INVALID);
|
|
|
if (login.ShowDialog() == true)
|
|
|
{
|
|
|
- result = ValidationResult.VALID;
|
|
|
+ result = ValidationStatus.VALID;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return result ?? ValidationResult.INVALID;
|
|
|
+ return result ?? ValidationStatus.INVALID;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -1519,6 +1553,7 @@ namespace PRSDesktop
|
|
|
|
|
|
private void LoadCurrentEmployee()
|
|
|
{
|
|
|
+
|
|
|
var me = new Client<Employee>().Query(
|
|
|
new Filter<Employee>(x => x.UserLink.ID).IsEqualTo(ClientFactory.UserGuid),
|
|
|
new Columns<Employee>(x => x.ID).Add(x => x.Email).Add(x=>x.Name)
|
|
@@ -1590,7 +1625,7 @@ namespace PRSDesktop
|
|
|
MessageBox.Show(message);
|
|
|
}
|
|
|
|
|
|
- if (DoLogin(false) == ValidationResult.VALID)
|
|
|
+ if (DoLogin(false) == ValidationStatus.VALID)
|
|
|
{
|
|
|
AfterLogin();
|
|
|
}
|
|
@@ -2734,8 +2769,30 @@ namespace PRSDesktop
|
|
|
return _timesheets.Rows.Any(r => r.Get<TimeSheet, DateTime>(c => c.Date).Date < DateTime.Today);
|
|
|
}
|
|
|
|
|
|
+ private void ShutDownTransport()
|
|
|
+ {
|
|
|
+ if (_transport != null)
|
|
|
+ {
|
|
|
+ _transport.OnClose -= TransportConnectionLost;
|
|
|
+ if (_transport.IsConnected())
|
|
|
+ _transport.Disconnect();
|
|
|
+ _transport = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void Window_Unloaded(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
+ ShutDownTransport();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void RibbonWindow_Closed(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+
|
|
|
+ ShutDownTransport();
|
|
|
+
|
|
|
+ DisconnectRecorderNotes();
|
|
|
+ Application.Current.Shutdown();
|
|
|
}
|
|
|
|
|
|
//private bool _closingFromSystemMenu = false;
|
|
@@ -2764,6 +2821,9 @@ namespace PRSDesktop
|
|
|
if (!CoreUtils.GetVersion().Equals("???"))
|
|
|
if (station.ID != Guid.Empty)
|
|
|
ExecuteLogout();
|
|
|
+
|
|
|
+ ShutDownTransport();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void FinalizeAutoTimesheet()
|
|
@@ -2791,11 +2851,6 @@ namespace PRSDesktop
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void RibbonWindow_Closed(object sender, EventArgs e)
|
|
|
- {
|
|
|
- DisconnectRecorderNotes();
|
|
|
- Application.Current.Shutdown();
|
|
|
- }
|
|
|
|
|
|
#region Notifications + Heartbeat
|
|
|
|
|
@@ -4086,7 +4141,7 @@ namespace PRSDesktop
|
|
|
|
|
|
private void LoginButton_OnClick(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- if (DoLogin(false) == ValidationResult.VALID)
|
|
|
+ if (DoLogin(false) == ValidationStatus.VALID)
|
|
|
AfterLogin();
|
|
|
}
|
|
|
|