private async Task <UIWebResponse> HandleUIRequestAsync(UIWebRequest request) { if (dispatcher == null) { throw new Exception("No dispacher"); } UIWebResponse response = null; await dispatcher.RunAsync(CoreDispatcherPriority.High, () => { response = MainModel.HandleWebRequest(request); }); return(response); }
public UIWebResponse HandleWebRequest(UIWebRequest request) { if (request.AlarmOn != null) { IsAlarmEnabled = request.AlarmOn.Value; } if (request.SirenOn != null) { if (request.SirenOn.Value) { System.Diagnostics.Debug.WriteLine("UIWebRequest.SirenOn"); } else { StopAlarmSound(); } } if (request.Sector0TriggerEnabled != null) { Sector0.AlarmTriggerEnabled = request.Sector0TriggerEnabled.Value; } var alarmTriggerEvents = AlarmTriggerEvents.Take(10).Select(model => { return(new UIWebResponseEvent() { Description = model.Description }); }).ToList(); return(new UIWebResponse() { AlarmOn = IsAlarmEnabled, Sector0TriggerEnabled = Sector0.AlarmTriggerEnabled, Sector0Value = Sector0.LongValue, Movement0Value = Movement0.LongValue, RssiValue = Rssi.LongValue, SirenOn = IsAlarmActive, ClientsConnected = clients.Count, AlarmTriggerEvents = alarmTriggerEvents }); }
async Task <WebResponse> HandleHttpPostRequest(WebResponse request) { var uiReq = UIWebRequest.Deserialize(request.Content); var uiRes = await HandleUIRequestAsync(uiReq); WebResponse response = new WebResponse(); response.Headers = new Dictionary <string, string>() { { "Content-Type", "application/json" }, }; MemoryStream stream = new MemoryStream(); uiRes.Serialize(stream); response.Content = stream; return(response); }