Exemple #1
0
        static async Task Main(string[] args)
        {
            Console.Write("Initializing console connection... ");
            keyboard = new KeyboardInterface();
            if (!await keyboard.StartupAsync())
            {
                Console.WriteLine("Failed.  Exiting...");
                return;
            }
            Console.WriteLine("Success");

            keyboard.TBarValueChanged     += Keyboard_TBarValueChanged;
            keyboard.KeyPressed           += Keyboard_KeyPressed;
            keyboard.KeyReleased          += Keyboard_KeyReleased;
            keyboard.RotaryValueChanged   += Keyboard_RotaryValueChanged;
            keyboard.JoystickValueChanged += Keyboard_JoystickValueChanged;
            keyboard.KeyAction            += Keyboard_KeyAction;
            Console.WriteLine("Listening for events");

            Console.WriteLine("Press enter to exit");
            Console.ReadLine();

            Console.WriteLine("Shutting down...");
            await keyboard.ShutdownAsync();
        }
        public async Task <bool> Startup()
        {
            await ShutdownAsync().ConfigureAwait(false);

            IsRunning = true;

            //Startup keyboard
            if (!await keyboard.StartupAsync().ConfigureAwait(false))
            {
                await ShutdownAsync().ConfigureAwait(false);

                return(false);
            }

            //Startup RabbitMQ connection
            rabbitConnection = rabbitMqFactory.CreateConnection();
            rabbitChannel    = rabbitConnection.CreateModel();

            //Send messages on
            rabbitChannel.ExchangeDeclare(RoutingAddressMap.Exchange, RoutingAddressMap.ExchangeType);

            var lampCommandQueue = rabbitChannel.QueueDeclare();

            rabbitChannel.QueueBind(lampCommandQueue.QueueName, RoutingAddressMap.Exchange, RoutingAddressMap.LampCommandRoutingKey);

            var quickKeyCommandQueue = rabbitChannel.QueueDeclare();

            rabbitChannel.QueueBind(quickKeyCommandQueue.QueueName, RoutingAddressMap.Exchange, RoutingAddressMap.QuickKeyCommandRoutingKey);

            consumer           = new AsyncEventingBasicConsumer(rabbitChannel);
            consumer.Received += Consumer_Received;
            rabbitChannel.BasicConsume(lampCommandQueue.QueueName, false, consumer);
            rabbitChannel.BasicConsume(quickKeyCommandQueue.QueueName, false, consumer);

            return(true);
        }