Mycroft.Dispatcher.Run C# (CSharp) Method

Run() public method

public Run ( ) : void
return void
        public void Run()
        {
            Server.ClientConnected += HandleNewClientConnection;
            Server.Start();

            Log.Debug("Dispatcher running");

            Command currentCmd;
            while (true)
            {
                // The preempt stack should only be added to
                // from a command. Because of this, if the DispatchPreemptStack is empty
                // then we can ignore the preempt stack and block until the
                // next command is available through the standard queue.
                if (!DispatchPreemptStack.TryTake(out currentCmd))
                {
                    currentCmd = DispatchQueue.Take();
                }
                // Issue all the commands o/
                Server.Issue(currentCmd);
                MessageArchive.Issue(currentCmd);
                Registry.Issue(currentCmd);
                this.Issue(currentCmd);
            }
        }

Usage Example

Example #1
0
        static void Main(string[] args)
        {
            Log = Logger.GetInstance();

            Log.Info("Starting up");

            TcpServer server = null;

            if(UsingTls(args))
            {
                Log.Info("Using TLS");
                X509Certificate2 cert = null;
                var foundCert = TryGetX509Certificate(args, out cert);

                // We have a certificate, so create the server
                if (foundCert)
                {
                    server = new TlsServer(IPAddress.Any, DEFAULT_PORT, cert);
                }
            }
            else
            {
                Log.Warning("Not using TLS");
                //insecure version
                server = new TcpServer(IPAddress.Any, DEFAULT_PORT);
            }

            // If we can't start the server, we can't run anything
            if(server == null)
            {
                Log.Error("Could not start the server");
                Environment.Exit(1);
            }

            // All systems go, start the server
            var registry = new Registry();
            var MessageArchive = new MessageArchive();
            var dispatcher = new Dispatcher(server, registry, MessageArchive);
            dispatcher.Run();
        }