/// <summary> /// derived class must implement to handle Post request /// </summary> protected override HttpServiceResponse ProcessPostRequest(HttpServiceContext context) { BaseServiceNode service = _service as BaseServiceNode; if (service == null) { return(CreateResponseForBadRequest(context, Name, $"PostNotSupported {context.Context.Request.Url.AbsoluteUri}")); } string dataName = nameof(BaseServiceNode.Status); if (context.UnmatchedSegments?.Count > 0 && string.Equals(dataName, context.UnmatchedSegments[0], StringComparison.OrdinalIgnoreCase)) { SensorStatusData data = null; string json = GetFromRequestStream(context.Context.Request); try { data = JsonConvert.DeserializeObject <SensorStatusData>(json); } catch (Exception err) { return(CreateResponseForBadRequest(context, Name, $"InvalidData {json}")); } service.SetStatus(data.SensorRate, data.IsOn); return(CreateSuccessResponse(context, Name, 200)); } return(CreateResponseForBadRequest(context, Name, $"InvalidPostRequestPath {context.Context.Request.Url.AbsoluteUri}")); }
private bool Subscribe(SubscriptionItem item, HttpTargetSite target) { bool ok = false; WireData data = null; BaseServiceNode serviceNode = _service.Children .Where((IIotNode node) => string.Equals(node.Id, item.Node, StringComparison.OrdinalIgnoreCase)).FirstOrDefault() as BaseServiceNode; if (serviceNode != null) { if (string.IsNullOrEmpty(item.Data)) { serviceNode.Subscribe(target); ok = true; } else { data = serviceNode.GetData <WireData>(item.Data); if (data != null) { data.Subscribe(target); ok = true; } } } return(ok); }
/// <summary> /// stop all sensors /// </summary> public void StopAll() { foreach (IotNode node in Children) { BaseServiceNode sensor = node as BaseServiceNode; if (sensor == null) { continue; } sensor.Stop(); } }
/// <summary> /// start all sensors /// </summary> public void StartAll(SensorRate rate = SensorRate.Medium) { foreach (IotNode node in Children) { BaseServiceNode sensor = node as BaseServiceNode; if (sensor == null) { continue; } sensor.Status.SensorRate = rate; sensor.Start(); } }