/* * show frmMain */ public static void ShowConfiguration() { // initialize new FormConfig FormConfig frmConfig = new FormConfig(); /* * event handler for btn StartServer * first check for configurations and start server */ frmConfig.btnStartServer.Click += (s, e) => { if (ServerController.isPrintServerStarted == false) { /* * if server is not started, check for printer name * if printer name is not set,, stop and let user know * otherwise, start the server, and change the text of the * control button */ if (frmConfig.cmbPrinters.Text == "") { MessageBox.Show("Please select Receipt Printer to continue." , "Receipt Printer Not Configured" , MessageBoxButtons.OK , MessageBoxIcon.Error); } else if (frmConfig.txtPrinterPort.Text == "") { MessageBox.Show("Please set your print server port. Default is 8123." , "Print Server Port not set" , MessageBoxButtons.OK , MessageBoxIcon.Error); } else if (frmConfig.txtServerPort.Text == "") { MessageBox.Show("Please set your web server port. Default is 8000." , "Web Server Port not set" , MessageBoxButtons.OK , MessageBoxIcon.Error); } else { Config.PrinterName = frmConfig.cmbPrinters.Text; Config.PrintServerPort = frmConfig.txtPrinterPort.Text; Config.WebServerPort = frmConfig.txtServerPort.Text; Config.Save(); ServerController.StartPrintServer(); frmConfig.RefreshFormConponentsState(); } } else { /* * if server is started, stop the server and change the Txt of command * button */ ServerController.StopPrintServer(); frmConfig.RefreshFormConponentsState(); } }; // event handler for btn Launch POS frmConfig.btnLaunchPOS.Click += (s, e) => { if (ServerController.isWebServerStarted) { LaunchChromeBrowser(); } else { MessageBox.Show("Local POS is not started. Please restart the program, and download new version of POS and try again." , "POS Not Started" , MessageBoxButtons.OK , MessageBoxIcon.Error); } }; // event handler for btn minimize frmConfig.btnMinimize.Click += (s, e) => { frmConfig.Hide(); frmConfig.Dispose(); }; // init the combo boxes foreach (string printerName in PrinterSettings.InstalledPrinters) { frmConfig.cmbPrinters.Items.Add(printerName); } foreach (string port in SerialPort.GetPortNames()) { frmConfig.cmdDrawers.Items.Add(port); } frmConfig.RefreshFormConponentsState(); // show the form frmConfig.Show(); }
/* * This method is called when program is executed and no othe rinstances is running before * to prevent port conflicting, etc. It will do all initialization and start server itself * if all configuration is set. * * otherwise it will show configuration form (for the first time) */ private static void InitializeApplication(string[] args) { Debug.WriteLine("Application initalization"); /* * This task will act like a Mutex server to listen to any incoming * arguments when user launch the app again with argument. */ // delete log file if needed if (DELETE_LOG_FILE_ON_START) { File.Delete(LOG_FILE); } Task.Run(() => { using (var server = new NamedPipeServerStream(_interprocessID)) { using (var reader = new StreamReader(server)) { using (var writer = new StreamWriter(server)) { // this infinity loop is to receive any thing from the other instance while (true) { server.WaitForConnection(); var incomingArgs = reader.ReadLine().Split('\t'); server.Disconnect(); ProgramArgumentsHelper.HandleArguments(incomingArgs); } } } } }); // Enable Visual Style Application.EnableVisualStyles(); // release the Mutex _appSingletonMaker.ReleaseMutex(); // get App version AppVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion; // handle the initialize argument // since this program will start without any required arguments, we just gonna // comment it out. Or just leave it. The Handler will do nothing anyway ProgramArgumentsHelper.HandleArguments(args); // initialize URI schema, by reregistering the URI schema to the registry URISchemaHelper.InitializeURISchema(); // initialize Logger var logger = Logger.getInstance(); Log = ""; // Add logger Handler here logger.onNewEntry += (s) => { string NewLogEntry = ""; NewLogEntry = "\n[" + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + "] " + s; Log += NewLogEntry + "\n"; Debug.WriteLine(s); }; // Initialize Configuration Config.LoadConfigurations(); // initialize ServerController ServerController.Initialize(); // check for auto start or show configuration if (Config.PrinterName != "" && ServerController.isPrintServerStarted == false) { ServerController.StartPrintServer(); } else { ShowConfiguration(); } // check for web root update //CheckForWebrootUpdates(); if (WebServerController.IsWebrootInstalled()) { WebServerController.StartWebServer(); } // this method will terminate initializing script here // all scripts after this line will be execute on application.exit() call InitializeTrayIconEvents(); TrayIcon.InitializeTrayIcon(); }