void GetOffsetAngle(IARequest request, IAResponse response) { // Find the device String deviceIdentifier = request.Parameters["identifier"]; Device requestingDevice = locator.Devices.Find(d => d.Identifier == deviceIdentifier); // Device Does Not Exist if (requestingDevice == null) { response.StatusCode = 404; // not found return; } if (requestingDevice.Location.HasValue && locator.Trackers[0].Location.HasValue) { Point requestingDeviceLocation = requestingDevice.Location.Value; Point offsetLocation = locator.Trackers[0].Location.Value; double angle = Util.AngleBetweenPoints(requestingDeviceLocation, offsetLocation); response.SetBodyWith(angle); //response.SetBodyWith(90); } else { // Device doesn't have location response.StatusCode = 400; } }
/// <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); }
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); }
void GetDevicesInView(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) { response.StatusCode = 404; return; } // Get the devices in view, and convert them for serialization List<Device> devicesInView = locator.GetDevicesInView(observer); List<IntermediateDevice> intDevices = PairableDevice.GetCompleteIntermediateDevicesList(devicesInView); if (intDevices.Count == 0) { response.StatusCode = 404; return; } response.SetBodyWith(intDevices); }
void GetDevicesInRange(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 device = locator.Devices.Find(d => d.Identifier.Equals(deviceIdentifier)); if (device == null) { response.StatusCode = 404; return; } List<Device> devicesInView = locator.GetDevicesWithinRange(device, range); List<IntermediateDevice> intermediateDevices = PairableDevice.GetCompleteIntermediateDevicesList(devicesInView); if (intermediateDevices.Count == 0) { response.StatusCode = 404; return; } // Respond with the device response.SetBodyWith(intermediateDevices); }
/// <summary> /// Return All Devices known to the Locator /// </summary> /// <param name="request"></param> /// <param name="response"></param> void GetDevices(IARequest request, IAResponse response) { List<IntermediateDevice> intermediateDevices = PairableDevice.GetCompleteIntermediateDevicesList(locator.Devices); if (intermediateDevices.Count == 0) { response.StatusCode = 404; } else { response.SetBodyWith(intermediateDevices); } }