private static void InitializeTrayIconEvents() { TrayIcon.AddEventHandler(TrayIcon.EventType.ShowMainWindow, (s, e) => { ShowConfiguration(); }); TrayIcon.AddEventHandler(TrayIcon.EventType.DoubleClick, (s, e) => { ShowConfiguration(); }); TrayIcon.AddEventHandler(TrayIcon.EventType.About, (s, e) => { ShowAbout(); }); TrayIcon.AddEventHandler(TrayIcon.EventType.CheckUpdates, (s, e) => { if (WebServerController.CheckForUpdates() == false) { MessageBox.Show("You are running the latest version of Point of Sale."); } }); TrayIcon.AddEventHandler(TrayIcon.EventType.Log, (s, e) => { ShowLog(); }); }
/// <summary> /// Parse a single argument. If that argument takes another sub argument, it will take it and /// return the numbe rof arguments it took. /// </summary> /// <param name="parts"></param> /// <param name="i"></param> /// <returns></returns> private static int ParseProgramArgumentSingle(ref string[] parts, int i) { int _requiredArguments = 0; // how many part we will take to fulfill this command argument switch (parts[i].ToLower()) { case "showlog": Program.ShowLog(); _requiredArguments = 0; break; case "start": if (parts.Length < i + 2) { MessageBox.Show("Invalid START command.\nUsage: START SERVER|WEB"); } if (parts[i + 1].ToLower() == "server" && !PrintServerController.isPrintServerStarted) { PrintServerController.StartPrintServer(); } else if (parts[i + 1].ToLower() == "web" && !WebServerController.isWebServerStarted) { WebServerController.StartWebServer(); } _requiredArguments = 1; break; case "stop": if (parts.Length < i + 2) { MessageBox.Show("Invalid STOP command.\nUsage: STOP SERVER|WEB"); } if (parts[i + 1].ToLower() == "server" && PrintServerController.isPrintServerStarted) { PrintServerController.StopPrintServer(); } else if (parts[i + 1].ToLower() == "web" && WebServerController.isWebServerStarted) { WebServerController.StopWebServer(); } _requiredArguments = 1; break; } return(++_requiredArguments); }
/** * check for web root updates */ public static void CheckForWebrootUpdates() { WebServerController.CheckForUpdates(); }
/* * 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(); }