/// <summary> /// Raise the MessageReceived event. /// </summary> /// <param name="e">Event arguments (if null the event is cancelled).</param> protected override void OnMessageReceived(MessageReceivedEventArgs e) { if (e == null) return; var dataType = TypeMap.ContainsKey(e.JsonMessage.Key) ? TypeMap[e.JsonMessage.Key] : null; if (dataType != null) { var typedMessage = (TypedMessage)Activator.CreateInstance(dataType); typedMessage.Fill(e.JsonMessage); e.TypedMessage = typedMessage; } base.OnMessageReceived(e); }
private void MessageReceived(MessageReceivedEventArgs e) { if (e.DataType == typeof(SlotCollection)) { _slotCollection = (SlotCollection)e.TypedMessage; foreach (var slot in _slotCollection) { _messageConnection.SendCommand(String.Format(CultureInfo.InvariantCulture, Constants.FahClientSlotOptions, slot.Id)); } _settingsModel.RefreshSlots(_slotCollection); } else if (e.DataType == typeof(SlotOptions)) { var options = (SlotOptions)e.TypedMessage; if (options.MachineId.HasValue) { var slot = _slotCollection.FirstOrDefault(x => x.Id == options.MachineId); if (slot != null) { slot.SlotOptions = options; _settingsModel.RefreshSlots(_slotCollection); } } } }
/// <summary> /// Raise the MessageUpdated event. /// </summary> /// <param name="e">Event arguments (if null the event is cancelled).</param> protected virtual void OnMessageReceived(MessageReceivedEventArgs e) { if (e == null) return; var handler = MessageReceived; if (handler != null) { handler(this, e); } }