public async Task <bool> SetDeviceState(Device device, DeviceUpdate state) { var events = SetDeviceEvent?.GetInvocationList().ToList(); //Let the last subscription get first dibs events?.Reverse(); var handled = false; var args = new SetDeviceArgs { Device = device, Request = state, }; if (events != null) { foreach (var e in events) { try { handled = await Task.Run(() => (e as SetDeviceStateHandler)?.Invoke(this, args) ?? false); if (handled) { return(args.Success); } } catch (Exception ex) { Console.WriteLine(ex); } } } var handlerList = GetHandlerList(device.Service ?? WebRequestHandler.Identifier); foreach (var handler in handlerList) { handled = await handler.HandleRequest(device, state); if (handled) { return(true); } } return(false); }
public async Task <bool> HandleRequest(Device device, DeviceUpdate request) { try { if (request.DataType != DataTypes.Bool) { return(false); } //TODO: Fixme //var url = device.ad //var resp = await client.GetAsync (request.BoolValue.Value ? device.OnUrl : device.OffUrl); //resp.EnsureSuccessStatusCode (); } catch (Exception ex) { Console.WriteLine(ex); } return(false); }