コード例 #1
0
        private void InitializeConnector(Dictionary <string, string> parameters)
        {
            string protocol;
            string port;

            bool   testConfig = false;
            string lanConfig  = null;
            string testConfigString;

            if (!parameters.TryGetValue("/P", out port))
            {
                port = "8889";// default
            }
            string certPath = null;

            if (!parameters.TryGetValue("/C", out certPath))
            {
                protocol = "ws";// default
            }
            else
            {
                protocol = "wss";
            }
            if (!parameters.TryGetValue("/T", out testConfigString))
            {
                testConfig = false;
            }
            else
            {
                testConfig = true; //
            }
            parameters.TryGetValue("/L", out lanConfig);


            server = new WebSocketServer(protocol + "://127.0.0.1:" + port);
            if (certPath != null)
            {
                server.Certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(certPath);
            }
            CloverDeviceConfiguration config = null;

            if (testConfig)
            {
                config = new TestCloverDeviceConfiguration();
            }
            else if (lanConfig != null)
            {
                int loc = lanConfig.IndexOf(':');
                if (loc == -1)
                {
                    throw new InvalidDataException("invalid lan host. arguments must be '/L <hostname>:<port>'");
                }
                try
                {
                    string lanHostname = lanConfig.Substring(0, loc);
                    string lanPortStr  = lanConfig.Substring(loc + 1);
                    int    lanPort     = int.Parse(lanPortStr);
                    if (lanPort < 0 || lanPort > 65535)
                    {
                        throw new InvalidDataException("Invalid port. must be between 1 and 65535");
                    }
                    config = new WebSocketCloverDeviceConfiguration(lanHostname, lanPort, getPOSNameAndVersion(), Debug, Timer);
                }
                catch (FormatException fe)
                {
                    throw new InvalidDataException("invalid port: " + lanConfig.Substring(loc + 1));
                }
            }
            else
            {
                config = new USBCloverDeviceConfiguration(null, getPOSNameAndVersion(), Debug, Timer);
            }

            cloverConnector = new CloverConnector(config);
            cloverConnector.InitializeConnection();
            cloverConnector.AddCloverConnectorListener(connectorListener);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            string startFilePath = "c:/clover/SaleRequest.txt";

            //testFile
            //string startFilePath = "c:/users/bryanc/Desktop/test.txt";


            ICloverConnector          cloverConnector;
            CloverDeviceConfiguration USBConfig = new USBCloverDeviceConfiguration("__deviceID__", "com.Fromuth.BC.tech", false, 1);

            cloverConnector = new CloverConnector(USBConfig);
            cloverConnector.AddCloverConnectorListener(new YourListener(cloverConnector));
            cloverConnector.InitializeConnection();

            Logging log = new Logging("CloverLog");

            log.WriteMessage("Clover Program Started");

            DateTime timeStamp = DateTime.Now;

            Thread.Sleep(5000);
            do
            {
                if (cloverConnector.IsReady && !isBusy)
                {
                    try
                    {
                        //output a clover isConnected file
                        if (File.Exists("c:/clover/isConnected.txt"))
                        {
                            File.WriteAllText("c:/clover/isConnected.txt", DateTime.Now.ToString());
                        }
                        else
                        {
                            File.Create("c:/clover/isConnected.txt");
                            File.WriteAllText("c:/clover/isConnected.txt", DateTime.Now.ToString());
                        }


                        //If the SaleRequest is made, proceed, else keep repeatig loop.
                        if (File.Exists(startFilePath) && !isBusy)
                        {
                            isBusy = true;

                            string startFileText = File.ReadAllText(startFilePath);
                            //File.Delete(startFilePath);
                            //File.Move(startFilePath, "c:/clover/clover-request-sale-file.txt");
                            string[] startFileContent = startFileText.Split('\t');
                            switch (startFileContent[0].ToLower())
                            {
                            case "SALE":
                            case "Sale":
                            case "sale":
                            {
                                //StartOrder(cloverConnector);
                                StartSale(cloverConnector, startFileContent[1], Int32.Parse(startFileContent[2]));
                                break;
                            }

                            case "mrefund":
                            case "MREFUND":
                            case "MRefund":
                            case "refund":
                            {
                                StartRefund(cloverConnector, startFileContent[1], Int32.Parse(startFileContent[2]));
                                break;
                            }

                            case "fdrefund":
                            case "FDREFUND":
                            case "FDRefund":
                            {
                                StartDirectRefund(cloverConnector, startFileContent[1], startFileContent[2]);
                                break;
                            }

                            case "pdrefund":
                            case "PDREFUND":
                            case "PDRefund":
                            {
                                StartDirectRefund(cloverConnector, startFileContent[1], startFileContent[2], Int32.Parse(startFileContent[3]));
                                break;
                            }

                            case "cancel":
                            case "CANCEL":
                            case "Cancel":
                            {
                                cloverConnector.ShowMessage("Transaction Canceled by the cashier.");
                                Thread.Sleep(1500);
                                cloverConnector.ShowWelcomeScreen();
                                break;
                            }

                            default:
                            {
                                cloverConnector.ShowMessage("Invalid Response");
                                Thread.Sleep(3000);
                                cloverConnector.ShowWelcomeScreen();
                                break;
                            }
                            }

                            //File.Delete(startFilePath);
                        }
                        Thread.Sleep(5000);
                    }catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        log.WriteError(ex.Message);
                        isBusy = false;

                        Thread.Sleep(5000);
                    }
                }
            } while (true);
        }