void GetNearestDeviceInView(IARequest request, IAResponse response) { String deviceIdentifier = request.Parameters["identifier"]; // Find the associated device in the Current Devices Device observer = locator.Devices.Find(d => d.Identifier.Equals(deviceIdentifier)); if (observer == null) { //TODO: Should we use distinct status codes for distinct failure types here? response.StatusCode = 404; return; } // Find the nearest device that we observe Device nearestDevice = locator.GetNearestDeviceInView(observer); if (nearestDevice == null) { response.StatusCode = 404; return; } // Prepare the device for serialization IntermediateDevice intermediateDevice = PairableDevice.GetCompleteIntermediateDevice(nearestDevice); if (intermediateDevice == null) { response.StatusCode = 404; return; } response.SetBodyWith(intermediateDevice); }
void GetNearestDeviceInRange(IARequest request, IAResponse response) { String deviceIdentifier = request.Parameters["identifier"]; double range = Double.Parse(request.Parameters["range"]); // Find the associated device in the Current Devices Device observer = locator.Devices.Find(d => d.Identifier.Equals(deviceIdentifier)); if (observer == null) { response.StatusCode = 404; return; } Device nearestDevice = locator.GetNearestDeviceWithinRange(observer, range); if (nearestDevice == null) { response.StatusCode = 404; return; } IntermediateDevice intermediateDevice = PairableDevice.GetCompleteIntermediateDevice(nearestDevice); if (intermediateDevice == null) { response.StatusCode = 404; return; } // Respond with the device response.SetBodyWith(intermediateDevice); }
/// <summary> /// Handle a request for information about a device /// </summary> /// <param name="request"></param> /// <param name="response"></param> void GetDevice(IARequest request, IAResponse response) { String deviceIdentifier = request.Parameters["identifier"]; // Find the associated device in the Current Devices Device device = locator.Devices.Find(d => d.Identifier.Equals(deviceIdentifier)); if (device == null) { response.StatusCode = 404; return; } // Get the intermediateDevice for serialization IntermediateDevice intermediateDevice = PairableDevice.GetCompleteIntermediateDevice(device); if (intermediateDevice == null) { //TODO: Should this status code be different, to reflect that the device exists but couldn't be returned due to incompleteness? response.StatusCode = 404; return; } // Respond with the device response.SetBodyWith(intermediateDevice); }