public static void ShutdownApplication(bool showTaskbar = true) { IsAppShuttingDown = true; LocalSetting.Update(); #if !DEMO if (LocalSetting.Values.String["StartBroadcastServer"] != null) { BroadcastServerSocket.Stop(); } BroadcastClientSocket.Stop(); #endif if (TaskManagerServiceHelper.IsStarted) { TaskManagerServiceHelper.IsTaskManagerDisabled = false; } if (ConfigurationManager.UseKeyboardHook) { UserControlManager.Disable(); } if (showTaskbar) { UserControlManager.ShowTaskbar(true); } Logger.WriteLog("Exiting application"); Logger.CloseLog(); TemPOS.MainWindow.Singleton.AllowClose = true; TemPOS.MainWindow.Singleton.Dispatcher.Invoke((Action)(() => { TemPOS.MainWindow.Singleton.Closed += SingletonClosed; TemPOS.MainWindow.Singleton.Close(); })); }
public MainWindow() { if (Singleton != null) { throw new Exception("MainWindow Singleton Exception"); } Singleton = this; AllowClose = false; InitializeComponent(); InitializeSize(); // Timed delayed Show() _showMe.Interval = new TimeSpan(0, 0, 0, 0, 200); _showMe.Tick += showMe_Tick; _showMe.Start(); // Not sure why I put this here, but it doesn't hurt anything LocalSetting.Update(); #if !DEMO // Start the client broadcast server if running locally if (BroadcastServerSocket.IsEnabled) { BroadcastServerSocket.Start(); } // Start the client broadcast client BroadcastClientSocket.Connected += MessageSocket_Connected; BroadcastClientSocket.ReceivedMessage += MessageSocket_ReceivedMessage; BroadcastClientSocket.Start(); #endif // Restore focus if lost LostFocus += MainWindowDialog_LostFocus; }
public IEnumerator SendPing(int port) { ServerAddresses.Clear(); if (BroadcastClientSocket != null) { for (int i = 0; i < NumberOfPings; i++) { foreach (string ipAddress in BroadcastAddresses) { IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse(ipAddress), port); byte[] str = Encoding.ASCII.GetBytes("ping"); try { BroadcastClientSocket.SendTo(str, ipEndPoint); } catch (Exception exception) { Output.WriteLine($"Error sending out a ping to: {ipEndPoint}\n{exception}"); } yield return(new WaitForSeconds(WaitBeforePings)); } } } }
void MessageSocket_ReceivedMessage(object sender, EventArgs e) { var message = sender as string; if (message == null) { return; } if (message.Equals("ServerPortMayHaveChanged")) { // Restart the client BroadcastClientSocket.Stop(); BroadcastClientSocket.Start(); } else if (message.StartsWith("UpdateServerInfo ")) { string[] tokens = message.Split(' '); if (tokens.Length != 3) { return; } LocalSetting.Values.String["UpdateServerPort"] = tokens[2]; LocalSetting.Values.String["UpdateServer"] = tokens[1]; LocalSetting.Update(); } }
void BroadcastServerSocket_StartedListening(object sender, EventArgs e) { if (BroadcastClientSocket.IsConnected) { BroadcastClientSocket.Stop(); } BroadcastClientSocket.Start(); }
public void CloseClient() { if (BroadcastClientSocket != null) { BroadcastClientSocket.Close(); BroadcastClientSocket = null; BroadcastRemoteEndPoint = null; } }
private void DoLogin(string scanCode) { Employee employee = EmployeeManager.LookupByScanCode(scanCode); if (employee == null) { // The debug version will have an exception here if escape-exit is used try { PosDialogWindow.ShowDialog(Types.Strings.LoginLoginIncorrect, Types.Strings.Error); return; } catch { return; } } // Check if logged-in somewhere else if (PosHelper.IsLocked(TableName.Employee, employee.Id)) { #if !DEMO BroadcastClientSocket.SendRemoteLogout(employee.Id); #endif PosHelper.Unlock(TableName.Employee, employee.Id); } // Check if clock-in is required if (!employee.IsClockedIn()) { if (!DoClockIn(employee) && !employee.HasPermission(Permissions.SystemMaintenance)) { return; } } // Proceed with login IsLoggedIn = true; // Clear dead-locks Lock.DeleteAllEmployeeLocks(employee.Id); // Lock the employee to prevent simultaneous logins PosHelper.Lock(TableName.Employee, employee.Id, employee.Id); #if !DEMO // Tell other clients, that this employee just logged in BroadcastClientSocket.SendMessage("LOGIN " + employee.Id); #endif StartAutoLogoutTimer(); if (Login != null) { Login.Invoke(this, new UserLoginEventArgs(employee)); } }
void MessageSocket_Connected(object sender, EventArgs e) { int?terminalNumber = NetworkTools.GetLastLanByte(); if (terminalNumber != null) { BroadcastClientSocket.SendMessage("AppStarted " + terminalNumber.Value); } else { BroadcastClientSocket.SendMessage("AppStarted"); } }
private void SaveOptions() { #if !DEMO StoreSetting.Set("AutoUpdate", (radioButtonAutoUpdateIsEnabled.IsSelected ? 1 : 0)); LocalSetting.Values.String["UpdateServerPort"] = textBoxPort.Text; LocalSetting.Values.String["UpdateServer"] = textBoxServer.Text; LocalSetting.Update(); // Need to notify other clients of this information so they can update // their LocalSetting values BroadcastClientSocket.SendMessage("UpdateServerInfo " + LocalSetting.Values.String["UpdateServer"] + " " + LocalSetting.Values.String["UpdateServerPort"]); #endif }
private void AsyncCallbackBroadcastSocket(IAsyncResult result) { if (BroadcastClientSocket != null) { try { int size = BroadcastClientSocket.EndReceiveFrom(result, ref BroadcastRemoteEndPoint); string address = BroadcastRemoteEndPoint.ToString().Split(':')[0]; if (!ServerAddresses.Contains(address) && !LocalFullAddresses.Contains(address)) { Output.WriteLine($"Got a server address: {address}"); AddNewClient(address); } //Have to keep listening on the same BroadCast socket, due to other broadcast addresses may reply BroadcastClientSocket.BeginReceiveFrom(new byte[1024], 0, 1024, SocketFlags.None, ref BroadcastRemoteEndPoint, new AsyncCallback(AsyncCallbackBroadcastSocket), null); } catch (Exception exception) { Output.WriteLine($"Error in AsyncCallback of Broadcast socket:\n{exception}"); } } }