/// <summary> /// Raises the MessageReceived event. /// </summary> /// <param name="args"></param> void OnMessageReceived(RnetMessageEventArgs args) { Contract.Requires(args != null); if (MessageReceived != null) MessageReceived(this, args); }
/// <summary> /// Raises the MessageSent event. /// </summary> /// <param name="args"></param> void OnMessageSent(RnetMessageEventArgs args) { Contract.Requires(args != null); if (MessageSent != null) MessageSent(this, args); }
/// <summary> /// Invoked when a message is sent. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> void Client_MessageSent(object sender, RnetMessageEventArgs args) { SynchronizationContext.Post(i => OnMessageSent(args), null); }
/// <summary> /// Invoked when a message arrives. /// </summary> /// <param name="args"></param> async void OnClientMessageReceived(RnetMessageEventArgs args) { Contract.Requires(args != null); // client is stopped, ignore any trailing events if (State != RnetBusState.Started) return; // unknown var message = args.Message; if (message == null) return; // find device from which the message originated var device = GetOrCreateDevice(message.SourceDeviceId) as RnetRemoteDevice; if (device != null) { // device has been seen device.Activate(); // destined to us if (message.TargetDeviceId == LocalDevice.DeviceId) await device.SentMessage(message); // destined to all devices if (message.TargetDeviceId == RnetDeviceId.AllDevices) await device.SentMessage(message); // destined to all devices on our zone if (message.TargetDeviceId.KeypadId == RnetKeypadId.AllZone && message.TargetDeviceId.ZoneId == LocalDevice.DeviceId.ZoneId) await device.SentMessage(message); } OnMessageReceived(args); }
/// <summary> /// Raises the MessageReceived event. /// </summary> /// <param name="args"></param> void OnMessageReceived(RnetMessageEventArgs args) { Contract.Requires<ArgumentNullException>(args != null); Contract.Requires<NullReferenceException>(args.Message != null); RnetTraceSource.Default.TraceEvent(TraceEventType.Verbose, -1, "RnetClient:OnMessageReceived Message={0}", args.Message); if (MessageReceived != null) MessageReceived(this, args); }