private void LnStateStateChanged(object sender, StateMessage e) { if (StateChanged != null) { if (ui.InvokeRequired) { ui.BeginInvoke(new EventHandler <StateMessage>(LnStateStateChanged), sender, e); } else { StateChanged.Fire(this, e); } } }
private void ChangeState(RealTimeState newState) { State = newState; stateTime = Time.CurrentTime.Now; StateChanged.Fire(newState); }
/// <summary> /// Process a loconet message and update the state accordingly. /// </summary> private bool ProcessMessage(byte[] message, Message decoded) { var response = Response.Decode(message); lastPreviewMessageTime = DateTime.Now; SwitchState sw = null; lock (stateLock) { var inpRep = response as InputReport; var swRep = response as SwitchReport; var peerXferResponse = response as PeerXferResponse; if (inpRep != null) { //var item = GetItem(inpRep.Address); } else if (swRep != null) { sw = GetSwitch(swRep.Address); if (sw.Direction != swRep.SensorLevel) { // State change sw.Direction = swRep.SensorLevel; Monitor.PulseAll(stateLock); } else { return(false); } } else if (peerXferResponse != null) { if (peerXferResponse.SvAddress == 0) { if (peerXferResponse.IsSourcePC) { if (peerXferResponse.IsDestinationBroadcast) { // Query request locoIOs.Clear(); LocoIOQuery.Fire(this); } } else { var entry = new LocoIO(peerXferResponse.Source, peerXferResponse.LocoIOVersion); if (!locoIOs.ContainsKey(entry.Address)) { locoIOs[entry.Address] = entry; LocoIOFound.Fire(this, new LocoIOEventArgs(entry)); } } } } } // Notify listeners if (sw != null) { StateChanged.Fire(this, new StateMessage(sw)); } return(false); }