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(); })); }
private void BadLicenseShutdown(bool showDialog = true) { if (showDialog) { PosDialogWindow.ShowDialog( Strings.YouHaveNotEnteredAValidCompanyNameAndorSerialNumber, Strings.Error); } UserControlManager.ShowTaskbar(true); Application.Current.Shutdown(); }
private void Startup() { #if !DEMO // Handle an invalid license if ((LocalSetting.Values.String["IsAuthorized"] == null) || !LocalSetting.Values.String["IsAuthorized"].Equals("Yes")) { // Display the Strings.LocalsettingEditor if (PromptForConnectionString(false)) { if (!string.IsNullOrEmpty(LocalSetting.CompanyName) && !string.IsNullOrEmpty(LocalSetting.ApplicationSerialNumber)) { // Check for access to the update server var client = new Srp6ClientSocket( LocalSetting.CompanyName, LocalSetting.ApplicationSerialNumber); client.ConnectFailed += client_ConnectFailed; client.Disconnected += client_Disconnected; client.Authenticated += client_Authenticated; client.Start(); return; } } BadLicenseShutdown(); } else #endif { #if !DEMO if ((App.StartupArgs.Length == 1) && App.StartupArgs[0].ToLower().Equals(@"/update")) { PosDialogWindow window = GeneralSettingsUpdateControl.CreateInDefaultWindow(); GeneralSettingsUpdateControl control = window.DockedControl as GeneralSettingsUpdateControl; Hide(); window.ShowDialog(); UserControlManager.ShowTaskbar(true); Application.Current.Shutdown(); return; } #endif PosDialogWindow.SetStartupWindow(this); BeginStartup(); } }
private void CheckDatabaseConnection() { if (!EnsureDatabaseConnection()) { Dispatcher.Invoke((Action)(() => { if (PromptForChanges()) { new Thread(CheckDatabaseConnection).Start(); } else { UserControlManager.ShowTaskbar(true); Application.Current.Shutdown(); } })); } else { Dispatcher.Invoke((Action)(DoFinishInstall)); } }
/// <summary> /// Called when all startup conditions have been meet. The database is now /// accessible as well. /// </summary> private void FinalStartUp() { if ((_notification != null) && _notification.IsLoaded && _notification.IsVisible) { _notification.Close(); } // Disable AlwaysUseDefaults which was being used prior to this... ConfigurationManager.AlwaysUseDefaults = false; // Task Manager Protection // SettingManager.SetStoreSetting("DontDisableTaskManager", 0); int?isDisabled = SettingManager.GetInt32("DontDisableTaskManager"); if (isDisabled.HasValue && (isDisabled.Value == 1)) { BeginStartup(); return; } if (!TaskManagerServiceHelper.IsInstalled) { if (PosDialogWindow.ShowDialog(Types.Strings.DoYouWantToInstallTheTaskManagerAccessService, Types.Strings.InstallService, DialogButtons.YesNo, false) == DialogButton.Yes) { new Thread(TaskManagerServiceHelper.InstallThread).Start(); } } else if (!TaskManagerServiceHelper.IsStarted) { if (PosDialogWindow.ShowDialog(Types.Strings.DoYouWantToStartTheTaskManagerAccessService, Types.Strings.StartService, DialogButtons.YesNo, false) == DialogButton.Yes) { new Thread(TaskManagerServiceHelper.StartThread).Start(); } } else { TaskManagerServiceHelper.IsTaskManagerDisabled = true; } // Install the SQL Assembly (if one is pending installation) if (Updater.InstallSQLAssembly()) { #if DEBUG PosDialogWindow.ShowDialog("New SQL Assembly Installed", Types.Strings.Information); #endif } // Apply any required database patches at runtime SqlServerSetup.ApplyDatabasePatches(); // Check to make sure the model classes and the tables match if (!DataModelBase.ValidateDatabase()) { #if DEBUG string results = DataModelBase.InvalidDatabaseReport(); PosDialogWindow.ShowDialog( results, "Invalid Database Report"); #else PosDialogWindow.ShowDialog( Strings.TheDatabaseDesignCurrentlyBeingUsedIsIncorrectForThisVersionOfTempos, Strings.StartupError); #endif UserControlManager.ShowTaskbar(true); Application.Current.Shutdown(); return; } // Enable user control UserControlManager.Enable(ConfigurationManager.UseKeyboardHook); UserControlManager.ShowTaskbar(false); // Start-up MainWindow Show(); _mainWindow = new MainWindow(); _mainWindow.Show(); }
void Current_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { e.Handled = true; // Stop the auto-logoof timer LoginControl.StopAutoLogoutTimer(); // Close all database connections DataModelBase.CloseAll(); #if !DEMO // Send the exception to the upgrade server Updater.StartCrashReport(e.Exception); #endif // Save the exception, serialized to the AppData folder try { DateTime now = DateTime.Now; string rootDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path.DirectorySeparatorChar + "TemPOS"; if (!Directory.Exists(rootDirectory)) { Directory.CreateDirectory(rootDirectory); } string path = rootDirectory + Path.DirectorySeparatorChar + "crashdata-" + now.Year + now.Month.ToString("D2") + now.Day.ToString("D2") + "-" + now.Hour.ToString("D2") + now.Minute.ToString("D2") + now.Second.ToString("D2") + ".bin"; using (FileStream fileStream = new FileStream(path, FileMode.CreateNew)) { byte[] serialData = e.Exception.SerializeObject(); using (BinaryWriter writer = new BinaryWriter(fileStream)) { writer.Write(serialData); } } } catch { } // Display the exception message DisplayExceptionDialog(e.Exception); // Remove employee table lock (that prevents simultaneous login) if (SessionManager.ActiveEmployee != null) { PosHelper.Unlock(TableName.Employee, SessionManager.ActiveEmployee.Id); } // Close this app if (_mainWindow != null) { _mainWindow.AllowClose = true; _mainWindow.Close(); } // Disable user control crap if (ConfigurationManager.UseKeyboardHook) { UserControlManager.Disable(); } UserControlManager.ShowTaskbar(true); #if !DEBUG if (PastRestartPoint) { // Restart application Process.Start(Application.ResourceAssembly.Location, "/RESTART"); App.SwitchToDefaultDesktopOnClose = false; } else { App.SwitchToDefaultDesktopOnClose = true; } #else App.SwitchToDefaultDesktopOnClose = true; #endif // Shutdown current application Application.Current.Shutdown(); Process.GetCurrentProcess().Kill(); }