public void DeviceFound(IADevice iaDevice, bool ownDevice) { PairableDevice pairableDevice = new PairableDevice { Identifier = iaDevice.Name, PairingState = PairingState.NotPaired }; FindDeviceWidthAndHeight(iaDevice); if (iaDevice.SupportedRoutes.Contains(Routes.GetLocationRoute)) { IARequest request = new IARequest(Routes.GetLocationRoute); IntAirAct.SendRequest(request, iaDevice, delegate(IAResponse response, Exception error) { if (response == null || response.StatusCode == 404) { // Device has no location } else if (response.StatusCode == 200) { IntermediatePoint intermediatePoint = response.BodyAs <IntermediatePoint>(); Point result = intermediatePoint.ToPoint(); Device localDevice = locator.Devices.Find(d => d.Identifier.Equals(iaDevice.Name)); if (localDevice != null) { localDevice.Location = result; response.StatusCode = 201; // created } else { response.StatusCode = 404; // not found } } }); } locator.Devices.Add(pairableDevice); if (DeviceAdded != null) { DeviceAdded(this, pairableDevice); } }
/// <summary> /// Handle a request with updated location for a device. /// </summary> /// <param name="request">IntAirAct Request</param> /// <param name="response">IntAirAct Response</param> public void UpdateDeviceLocation(IARequest request, IAResponse response) { IntermediatePoint intermediatePoint = request.BodyAs <IntermediatePoint>(); Point result = intermediatePoint.ToPoint(); String name = request.Parameters["identifier"]; Device localDevice = locator.Devices.Find(d => d.Identifier.Equals(name)); if (localDevice != null) { localDevice.Location = result; response.StatusCode = 201; // created } else { response.StatusCode = 404; // not found } }