Ejemplo n.º 1
0
        private void ProcessMessage(MessageEventArgs e)
        {
            string fromDevice = e.FromDevice;
            string dataName   = e.Name;

            const string CONNECTION = "Connection";

            if (e.SendingDevice.Equals(Devices.SERVER) && e.Parameter.ToString().StartsWith(CONNECTION))
            {
                HandleConnectionMessage(e);
            }

            DeviceModel sendingDeviceModel = deviceModels.FirstOrDefault(x => x.Name == e.SendingDevice);

            if (sendingDeviceModel != null)
            {
                sendingDeviceModel.HandleSentMessageEvent();
            }

            DeviceModel receivingDeviceModel = deviceModels.FirstOrDefault(x => x.Name == e.ReceivingDevice || x.Name == e.ToDevice);

            if (receivingDeviceModel != null)
            {
                receivingDeviceModel.HandleReceivedMessageEvent();
            }

            if (fromDevice.Equals(Devices.RASPBERRY_PI_B))
            {
                HandleRaspberryPiBMessage(e);
            }
            else if (fromDevice.Equals(Devices.PHOTON_A) || fromDevice.Equals(Devices.PHOTON_B) || fromDevice.Equals(Devices.PHOTON_C))
            {
                HandlePhotonsMessage(e);
            }
        }