private void OnEvent(BackendEvent newEvent) { if (newEvent is BackendEventError) { var error = newEvent as BackendEventError; if (error.Policy == ErrorPolicyType.Deactivate) { try { var accounts = new Accounts(); var account = accounts[error.Id]; if (account != null) { account.persistantState = AccountState.Disabled; account.forceDisabled = true; } } catch { } } } if (_notifier != null) { // Returns true if user relevant if (_notifier.Push(newEvent)) { newEvent.Persist = true; } } _events.Enqueue(newEvent); }
private void OnProcessBackendEvent() { try { if (_blocked) { _newRequest = true; } else { _blocked = true; { BackendEvent newEvent = null; do { newEvent = GetBackendEvent(); if (newEvent == null) { break; } if (newEvent is BackendEventWindows) { OnBackendEventWindows(newEvent as BackendEventWindows); } if (newEvent is BackendEventMessage) { OnBackendEventMessage(newEvent as BackendEventMessage); } if (newEvent is BackendEventRequest) { OnBackendEventRequest(newEvent as BackendEventRequest); } if (newEvent is BackendEventState) { OnBackendEventState(newEvent as BackendEventState); } if (newEvent is BackendEventLog) { OnBackendEventLog(newEvent as BackendEventLog); } if (newEvent is BackendEventError) { OnBackendEventError(newEvent as BackendEventError); } }while (newEvent != null); } _blocked = false; if (_newRequest) { _newRequest = false; OnProcessBackendEvent(); } } } catch (Exception uiEx) { UIError(uiEx); } }
private async void TTNTrackerMessageIncomming(Object _1, BackendEvent e) => await Task.Run(() => { Tuple <String, String> json = this.ConvertTrackerJson(e.Message); if (json != null) { this.mqtt.Send(json.Item1, json.Item2); Console.WriteLine("Mqtt ->: on " + json.Item1 + " set " + json.Item2); } });
protected override void Backend_MessageIncomming(Object sender, BackendEvent mqtt) { try { JsonData d = JsonMapper.ToObject(mqtt.Message); PositionModel.Instance.ParseMqttJson(d, (String)mqtt.From); CameraModel.Instance.ParseMqttJson(d, (String)mqtt.From); SensorModel.Instance.ParseMqttJson(d, (String)mqtt.From); } catch (Exception e) { Helper.WriteError("Backend_MessageIncomming(): " + e.Message + "\n\n" + e.StackTrace); } }