/// <summary>
        /// Starts Web Server and notify user.
        /// This method does not check for webroot installation in Cache folder
        /// make sure you check for webroot installation by using IsWebrootInstalled()
        /// method with a true returned before calling this function to prevent any error
        /// </summary>
        public static void StartWebServer()
        {
            return;

            //WebSocketSharp.Server.HttpServer a = new WebSocketSharp.Server.HttpServer(port: Convert.ToInt32(Config.WebServerPort));
            //a.DocumentRootPath = CacheDirectory;
            //a.Start();
            string prefixes = "http://localhost:" + Config.WebServerPort + "/";

            WebServer = new SMFileServer(CacheDirectory, prefixes);


            TrayIcon.NotifyUser("Web Server Started", "Web Server started and ready to use.");
            isWebServerStarted = true;
        }
Esempio n. 2
0
 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();
     });
 }
        public static void StartPrintServer()
        {
            StartRawPrinterService();
            StartCOMPortDrawerService();


            // start Web Socket print Server in a new thread
            //PrintServerThread = new Thread(StartWebSocketServer);
            //PrintServerThread.Start();

            //if (PrintServerThread.ThreadState == ThreadState.Running)
            //{
            //    TrayIcon.NotifyUser("Print Server Started", "Print server has been started and ready to take messages");
            //    isPrintServerStarted = true;
            //}

            WSSServer           = new WebSocketServer(IPAddress.Any, Convert.ToInt16(Config.PrintServerPort));
            WSSServer.Log.File  = "log.txt";
            WSSServer.Log.Level = LogLevel.Debug;

            WSSServer.AddWebSocketService <SalonManager.Classes.WebSocketServerControllers.Printing>("/");                       // default, legacy module
            WSSServer.AddWebSocketService <CommunicationServerBehavior>("/communication");                                       // legacy communication module - acts like a chat server
            WSSServer.AddWebSocketService <SalonManager.Classes.WebSocketServerControllers.RawPrinterDirect>("/raw-printers");   // access to raw printers using ?m=printername
            WSSServer.AddWebSocketService <SalonManager.Classes.WebSocketServerControllers.Communication>("/comm");              // another communication
            WSSServer.AddWebSocketService <SalonManager.Classes.WebSocketServerControllers.Utility>("/utility");                 // utility to access system wise function such as list printers name, etc.

            WSSServer.Log.Debug("Server started");

            WSSServer.KeepClean = false;

            try
            {
                WSSServer.Start();
                TrayIcon.NotifyUser("Print Server Started", "Print server has been started and ready to take messages");
                isPrintServerStarted = true;
            }
            catch (Exception e)
            {
                MessageBox.Show(@"Another application is listening to port " + Config.PrintServerPort + ".\nChange your port number and try again", "Print Server can not start", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 4
0
        /*
         * 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();
        }