CloverWindowsSDKREST.CloverRESTService.OnStart C# (CSharp) Метод

OnStart() защищенный Метод

protected OnStart ( string args ) : void
args string
Результат void
        protected override void OnStart(string[] args)
        {
            string logSource = "_TransportEventLog";
            if (!EventLog.SourceExists(logSource))
                EventLog.CreateEventSource(logSource, logSource);

            EventLogTraceListener myTraceListener = new EventLogTraceListener(logSource);

            // Add the event log trace listener to the collection.
            Trace.Listeners.Add(myTraceListener);

            if (args.Length > 0)
            {
                if (((ICollection<string>)args).Contains("-debug"))
                {
                    Debug = true;
                }

                if (((ICollection<string>)args).Any(a => a.Contains("-timer")))
                {
                    IEnumerable<string> timerStrings = ((ICollection<string>)args).Where(a => a.Contains("-timer"));
                    if (timerStrings.Count() == 1)
                    {
                        try {
                            string timerString = timerStrings.First();
                            int index = timerString.IndexOf('=');
                            string timerSeconds = timerString.Substring(index + 1);
                            Timer = Convert.ToInt32(timerSeconds);
                        } catch (Exception e)
                        {
                            Timer = 1;
                            EventLog.WriteEntry(SERVICE_NAME, "Error parsing the -timer command line argument.  Setting timer to 1 second.");
                        }
                    }
                }
            }

            EventLog.WriteEntry(SERVICE_NAME, "Starting...");
            Dictionary<string, string> argsMap = new Dictionary<string, string>();
            for (int i = 1; i < args.Length; i++)
            {
                argsMap.Add(args[i - 1], args[i++]);
            }

            // only allow localhost
            string listenAddress = null;
            if (!argsMap.TryGetValue("/P", out listenAddress))
            {
                listenAddress = "http://127.0.0.1:8181/";
                listenAddress = "8181";
            }

            ServiceEndpoints endpoints = new ServiceEndpoints();

            string callbackEndpoint = null;
            if (!argsMap.TryGetValue("/C", out callbackEndpoint))
            {
                callbackEndpoint = "http://localhost:8182/CloverCallback";
            }

            server = new CloverRESTServer("localhost", listenAddress, "http");// "127.0.0.1", listenAddress, "http");
            CloverRESTConnectorListener connectorListener = new CloverRESTConnectorListener();
            Console.WriteLine("callback endpoint: " + callbackEndpoint);
            connectorListener.RestClient = new RestSharp.RestClient(callbackEndpoint);
            server.ForwardToClientListener = connectorListener;
            string webSocketEndpoint = null;
            if(argsMap.TryGetValue("/L", out webSocketEndpoint))
            {
                string[] tokens = webSocketEndpoint.Split(new char[]{':'});
                if(tokens.Length != 2) {
                    throw new Exception("Invalid host and port. must be <hostname>:<port>");
                }
                string hostname = tokens[0];
                int port = int.Parse(tokens[1]);
                server.CloverConnector = new CloverConnector(new WebSocketCloverDeviceConfiguration(hostname, port, getPOSNameAndVersion(), Debug, Timer));
            }
            else
            {
                server.CloverConnector = new CloverConnector(new USBCloverDeviceConfiguration(null, getPOSNameAndVersion(), Debug, Timer));
            }
            server.CloverConnector.InitializeConnection();
            server.CloverConnector.AddCloverConnectorListener(connectorListener);
            StartRESTListener();
            server.OnAfterStart += new ToggleServerHandler(this.OnServerStart);
            server.OnStop += new ToggleServerHandler(this.OnServerStop);
        }