Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        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();
            }));
        }
Exemplo n.º 3
0
        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();
            }
        }
 private void radioButtonIsNotUsingKioskMode_SelectionGained(object sender, EventArgs e)
 {
     if (!IsInitialized)
     {
         return;
     }
     radioButtonIsUsingKioskMode.IsSelected   = false;
     LocalSetting.Values.Boolean["KioskMode"] = false;
     LocalSetting.Update();
 }
Exemplo n.º 5
0
 public static void SetPrinterToUnused(string printerName)
 {
     if (printerName.Equals(Strings.Local))
     {
         CloseDevice(activePosPrinterLocal);
         activePosPrinterLocal = null;
         LocalSetting.Values.String["PrinterName"] = null;
     }
     else if (printerName.Equals(Strings.Journal))
     {
         CloseDevice(activePosPrinterJournal);
         activePosPrinterJournal = null;
         LocalSetting.Values.String["PrinterNameJournal"] = null;
     }
     else if (printerName.Equals(Strings.Kitchen1))
     {
         CloseDevice(activePosPrinterKitchen1);
         activePosPrinterKitchen1 = null;
         LocalSetting.Values.String["PrinterNameKitchen1"] = null;
     }
     else if (printerName.Equals(Strings.Kitchen2))
     {
         CloseDevice(activePosPrinterKitchen2);
         activePosPrinterKitchen2 = null;
         LocalSetting.Values.String["PrinterNameKitchen2"] = null;
     }
     else if (printerName.Equals(Strings.Kitchen3))
     {
         CloseDevice(activePosPrinterKitchen3);
         activePosPrinterKitchen3 = null;
         LocalSetting.Values.String["PrinterNameKitchen3"] = null;
     }
     else if (printerName.Equals(Strings.Bar1))
     {
         CloseDevice(activePosPrinterKitchen1);
         activePosPrinterKitchen1 = null;
         LocalSetting.Values.String["PrinterNameKitchen1"] = null;
     }
     else if (printerName.Equals(Strings.Bar2))
     {
         CloseDevice(activePosPrinterKitchen2);
         activePosPrinterKitchen2 = null;
         LocalSetting.Values.String["PrinterNameKitchen2"] = null;
     }
     else if (printerName.Equals(Strings.Bar3))
     {
         CloseDevice(activePosPrinterKitchen3);
         activePosPrinterKitchen3 = null;
         LocalSetting.Values.String["PrinterNameKitchen3"] = null;
     }
     LocalSetting.Update();
 }
Exemplo n.º 6
0
 public static void SetPrinter(string printerTargetName, DeviceInfo deviceInfo)
 {
     if (printerTargetName.Equals(Strings.Local))
     {
         CloseDevice(activePosPrinterLocal);
         LocalSetting.Values.String["PrinterName"] = deviceInfo.Description;
         activePosPrinterLocal = InitializePosPrinter("PrinterName");
     }
     else if (printerTargetName.Equals(Strings.Journal))
     {
         CloseDevice(activePosPrinterJournal);
         LocalSetting.Values.String["PrinterNameJournal"] = deviceInfo.Description;
         activePosPrinterJournal = InitializePosPrinter("PrinterNameJournal");
     }
     else if (printerTargetName.Equals(Strings.Kitchen1))
     {
         CloseDevice(activePosPrinterKitchen1);
         LocalSetting.Values.String["PrinterNameKitchen1"] = deviceInfo.Description;
         activePosPrinterKitchen1 = InitializePosPrinter("PrinterNameKitchen1");
     }
     else if (printerTargetName.Equals(Strings.Kitchen2))
     {
         CloseDevice(activePosPrinterKitchen2);
         LocalSetting.Values.String["PrinterNameKitchen2"] = deviceInfo.Description;
         activePosPrinterKitchen2 = InitializePosPrinter("PrinterNameKitchen2");
     }
     else if (printerTargetName.Equals(Strings.Kitchen3))
     {
         CloseDevice(activePosPrinterKitchen3);
         LocalSetting.Values.String["PrinterNameKitchen3"] = deviceInfo.Description;
         activePosPrinterKitchen3 = InitializePosPrinter("PrinterNameKitchen3");
     }
     else if (printerTargetName.Equals(Strings.Bar1))
     {
         CloseDevice(activePosPrinterKitchen1);
         LocalSetting.Values.String["PrinterNameBar1"] = deviceInfo.Description;
         activePosPrinterKitchen1 = InitializePosPrinter("PrinterNameBar1");
     }
     else if (printerTargetName.Equals(Strings.Bar2))
     {
         CloseDevice(activePosPrinterKitchen2);
         LocalSetting.Values.String["PrinterNameBar2"] = deviceInfo.Description;
         activePosPrinterKitchen2 = InitializePosPrinter("PrinterNameBar2");
     }
     else if (printerTargetName.Equals(Strings.Bar3))
     {
         CloseDevice(activePosPrinterKitchen3);
         LocalSetting.Values.String["PrinterNameBar3"] = deviceInfo.Description;
         activePosPrinterKitchen3 = InitializePosPrinter("PrinterNameBar3");
     }
     LocalSetting.Update();
 }
Exemplo n.º 7
0
        void client_Authenticated(object sender, EventArgs e)
        {
            var client = sender as Srp6ClientSocket;

            if (client == null)
            {
                return;
            }
            client.Disconnected -= client_Disconnected;
            client.Socket.Disconnect();
            LocalSetting.Values.String["IsAuthorized"] = "Yes";
            LocalSetting.Update();
            BeginStartup();
        }
Exemplo n.º 8
0
 private void buttonUpdate_Click(object sender, RoutedEventArgs e)
 {
     if (!IsPersonalInfoHidden)
     {
         LocalSetting.CompanyName             = textBoxCompanyName.Text;
         LocalSetting.ApplicationSerialNumber = textBoxSerialNumber.Text;
     }
     LocalSetting.DatabaseServerName         = textBoxDBServer.Text;
     LocalSetting.DatabaseServerDatabaseName = textBoxDBInitialCatalog.Text;
     LocalSetting.DatabaseServerLoginName    = textBoxDBLogin.Text;
     LocalSetting.DatabaseServerPassword     = textBoxDBPassword.Text;
     LocalSetting.Update();
     Window.GetWindow(this).Close();
 }
        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
        }
Exemplo n.º 10
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            ExitCode               = 0;
            StartupArgs            = e.Args;
            WasLocalSettingReset   = false;
            TemposDesktop          = null;
            IsAppShuttingDown      = false;
            IsUsingDesktop         = false;
            Current.SessionEnding += Current_SessionEnding;


            // Set the current directory to the application path
            // So we don't start-up in the \windows\System32\ folder at windows login
            try
            {
                //System.IO.Directory.SetCurrentDirectory(
                //    System.IO.Path.GetDirectoryName(VistaSecurity.GetExecutablePath())
                //);
                System.IO.Directory.SetCurrentDirectory(
                    System.IO.Path.GetDirectoryName(ResourceAssembly.Location)
                    );
            }
            catch (Exception ex)
            {
                // Ignore, since the original app was in the currect folder, so should
                // the app on the alternate desktop.
                //MessageBox.Show(ex.Message);
            }

#if DEBUG
            if (SpecialStart.IsEnabled)
            {
                LocalSetting.Initialize();
                SpecialStart.Start();
                Process.GetCurrentProcess().Kill();
                return;
            }
#endif
            if ((e.Args.Length == 1) && e.Args[0].Equals("/INSTALLTMA"))
            {
                bool isDone = false;
                LocalSetting.Initialize();
                TaskManagerServiceHelper.InstallFailed += (o, args) =>
                {
                    ExitCode = -1 * TaskManagerServiceHelper.FailCode;
                    isDone   = true;
                };
                TaskManagerServiceHelper.Installed += (o, args) =>
                {
                    TaskManagerServiceHelper.Start();
                };
                TaskManagerServiceHelper.StartFailed += (o, args) =>
                {
                    ExitCode = -2;
                    isDone   = true;
                };
                TaskManagerServiceHelper.Started += (o, args) =>
                {
                    isDone = true;
                };
                TaskManagerServiceHelper.Install();
                while (!isDone)
                {
                    Thread.Sleep(300);
                }
                Current.Shutdown();
                return;
            }

            if ((e.Args.Length == 1) && e.Args[0].Equals("/UNINSTALLTMA"))
            {
                bool isDone = false;
                LocalSetting.Initialize();
                TaskManagerServiceHelper.UninstallFailed += (o, args) =>
                {
                    ExitCode = -1;
                    isDone   = true;
                };
                TaskManagerServiceHelper.Uninstalled += (o, args) =>
                {
                    isDone = true;
                };
                TaskManagerServiceHelper.Uninstall();
                while (!isDone)
                {
                    Thread.Sleep(300);
                }
                Current.Shutdown();
                return;
            }

            if ((e.Args.Length == 1) && e.Args[0].Equals("/STARTTMA"))
            {
                bool isDone = false;
                LocalSetting.Initialize();
                TaskManagerServiceHelper.StartFailed += (o, args) =>
                {
                    ExitCode = -1;
                    isDone   = true;
                };
                TaskManagerServiceHelper.Started += (o, args) =>
                {
                    isDone = true;
                };
                TaskManagerServiceHelper.Start();
                while (!isDone)
                {
                    Thread.Sleep(300);
                }
                Current.Shutdown();
                return;
            }

            if ((e.Args.Length == 1) && e.Args[0].Equals("/STOPTMA"))
            {
                bool isDone = false;
                LocalSetting.Initialize();
                TaskManagerServiceHelper.StopFailed += (o, args) =>
                {
                    ExitCode = -1;
                    isDone   = true;
                };
                TaskManagerServiceHelper.Stopped += (o, args) =>
                {
                    isDone = true;
                };
                TaskManagerServiceHelper.Stop();
                while (!isDone)
                {
                    Thread.Sleep(300);
                }
                Current.Shutdown();
                return;
            }

            if ((e.Args.Length == 1) && e.Args[0].Equals("/STOPSQL"))
            {
                LocalSetting.Initialize();
                if (ServiceHelper.IsSqlServiceRunningLocally)
                {
                    ServiceHelper.StopSqlService(20000);
                }
                if (ServiceHelper.IsSqlBrowserServiceRunningLocally)
                {
                    ServiceHelper.StopSqlBrowserService(20000);
                }
                Thread.Sleep(1000);
                Process.GetCurrentProcess().Kill();
                return;
            }

            if ((e.Args.Length == 1) && e.Args[0].Equals("/STARTSQL"))
            {
                LocalSetting.Initialize();
                if (!ServiceHelper.IsSqlBrowserServiceRunningLocally &&
                    !string.IsNullOrEmpty(LocalSetting.DatabaseServerLoginName))
                {
                    ServiceHelper.StartSqlBrowserService(20000);
                }
                if (!ServiceHelper.IsSqlServiceRunningLocally)
                {
                    ServiceHelper.StartSqlService(20000);
                }
                Thread.Sleep(1000);
                Process.GetCurrentProcess().Kill();
                return;
            }

            // Initialize Local Settings
            WasLocalSettingReset = LocalSetting.Initialize();

            // Some old LocalSettings file doesn't have LocalSetting.Values.Boolean in it, old
            if (LocalSetting.Values.Boolean == null)
            {
                LocalSetting.Reset();
                LocalSetting.Update();
            }

            string desktopName = Desktop.GetDesktopName();
            if (desktopName != null)
            {
                if (LocalSetting.Values.Boolean["KioskMode"] &&
                    desktopName.Contains("Default"))
                {
                    // Relaunch application on the TemposDesktop
                    {
                        TemposDesktop = Desktop.CreateDesktop("TemposDesktop");
                        try
                        {
                            Process protectedProcess =
                                TemposDesktop.CreateProcess(ResourceAssembly.Location);
                            TemposDesktop.Show();
                            protectedProcess.WaitForExit();
                            //TemposDesktop.Close(false);
                        }
                        catch (Exception ex)
                        {
                            if (TemposDesktop != null)
                            {
                                TemposDesktop.Close();
                            }
                            MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace);
                        }
                        Current.Shutdown();
                        return;
                    }
                }

                if (desktopName.Contains("TemposDesktop"))
                {
                    IsUsingDesktop = true;
                    TemposDesktop  = Desktop.GetCurrent();
                }
            }
            if (((desktopName == null) || desktopName.Contains("Default")) &&
                ((e.Args.Length != 1) || !e.Args[0].ToUpper().Equals("/RESTART")))
            {
                if (!IsOnlyProcess())
                {
                    Process.GetCurrentProcess().Kill();
                    return;
                }
            }

#if !DEMO
            Updater.RemoveUpdateDirectory();
#else
            // Just show the Strings.SystemSettings dialog and exit
            if (Keyboard.GetKeyStates(Key.LeftCtrl) != KeyStates.Down)
            {
                return;
            }
            StartupWindow.PromptForConnectionString(true);
            Process.GetCurrentProcess().Kill();
#endif
        }