/* * 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(); }