/// <summary> /// Command handler /// </summary> private async Task Consumer_Received(object sender, BasicDeliverEventArgs e) { try { if (e.RoutingKey == RoutingAddressMap.LampCommandRoutingKey) { var msg = Deserialize <LampCommandMessage>(e.Body); if (msg.Command == LampCommandType.ClearAll) { keyboard.ClearAllPushButtonsAndLedButtons(); await keyboard.UpdateLampsAsync(); await keyboard.UpdateAllDisplaysAsync(); } else { bool on = msg.Command == LampCommandType.SetOn; foreach (int keyIndex in msg.KeyIndexes) { keyboard.SetPushButtonLamp(keyIndex, on); } await keyboard.UpdateLampsAsync().ConfigureAwait(false); } } else if (e.RoutingKey == RoutingAddressMap.QuickKeyCommandRoutingKey) { var msg = Deserialize <QuickKeyMessage>(e.Body); foreach (var button in msg.Buttons) { keyboard.SetLcdButton(button.Index, button.Color.Convert(), button.Text); } //Update buttons List <int> rowsToUpdate = msg.Buttons.Select(b => b.Index / 8).Distinct().ToList(); if (msg.Buttons.Count == 1) { await keyboard.UpdateOneDisplayAsync(msg.Buttons[0].Index).ConfigureAwait(false); } else if (rowsToUpdate.Count == 1) { await keyboard.UpdateDisplayRowAsync(rowsToUpdate[0]).ConfigureAwait(false); } else { await keyboard.UpdateAllDisplaysAsync().ConfigureAwait(false); } //Need to update lamps to update LCD button colors await keyboard.UpdateLampsAsync().ConfigureAwait(false); } } catch (Exception ex) { Console.WriteLine($"{ex.GetType().Name} occurred while processing message: {ex.Message}"); } finally { //Ack our processed message rabbitChannel.BasicAck(e.DeliveryTag, false); } }