// Need to obtain 1 polygon which this device (DeviceTRN) lat/long lies within public ProjectDataResult GetIntersectingProjectsForDevice(GetProjectUidsRequest request, DeviceData device, out int errorCode) { errorCode = 0; var deviceProjects = new ProjectDataResult(); if (device == null || string.IsNullOrEmpty(device.CustomerUID) || string.IsNullOrEmpty(device.DeviceUID)) { return(deviceProjects); } // returns whatever the cws rules mandate, and any conditions in projectSvc e.g. non-archived and 3dp-enabled type try { deviceProjects = _deviceProxy.GetProjectsForDevice(device.DeviceUID, _mergedCustomHeaders).Result; _log.LogDebug($"{nameof(GetIntersectingProjectsForDevice)}: deviceProjects {JsonConvert.SerializeObject(deviceProjects)}"); if (deviceProjects?.Code != 0 || !deviceProjects.ProjectDescriptors.Any()) { errorCode = 48; return(deviceProjects); } var intersectingProjects = new ProjectDataResult(); foreach (var project in deviceProjects.ProjectDescriptors) { if (project.ProjectType.HasFlag(CwsProjectType.AcceptsTagFiles) && !project.IsArchived) { if (!request.HasLatLong && request.HasNE && request.Northing != null && request.Easting != null) { var convertedLL = this.ConvertNEtoLL(project.ProjectUID, request.Northing.Value, request.Easting.Value).Result; if (convertedLL != null) { request.Longitude = convertedLL.ConversionCoordinates[0].X; request.Latitude = convertedLL.ConversionCoordinates[0].Y; } } if (request.HasLatLong && PolygonUtils.PointInPolygon(project.ProjectGeofenceWKT, request.Latitude, request.Longitude)) { intersectingProjects.ProjectDescriptors.Add(project); } } } if (!intersectingProjects.ProjectDescriptors.Any()) { errorCode = 44; } return(intersectingProjects); } catch (Exception e) { throw new ServiceException(HttpStatusCode.InternalServerError, TagFileProcessingErrorResult.CreateTagFileProcessingErrorResult(false, ContractExecutionStatesEnum.InternalProcessingError, 17, "device", e.Message)); } }
public async Task <ProjectData> GetProject(string projectUid) { if (string.IsNullOrEmpty(projectUid)) { return(null); } try { return(await _projectProxy.GetProject(projectUid, _mergedCustomHeaders)); } catch (Exception e) { throw new ServiceException(HttpStatusCode.InternalServerError, TagFileProcessingErrorResult.CreateTagFileProcessingErrorResult(false, ContractExecutionStatesEnum.InternalProcessingError, 17, "project", e.Message)); } }
// Need to obtain cws: DeviceTRN public async Task <DeviceData> GetDevice(string serialNumber) { if (string.IsNullOrEmpty(serialNumber)) { return(null); } try { return(await _deviceProxy.GetDevice(serialNumber, _mergedCustomHeaders)); } catch (Exception e) { throw new ServiceException(HttpStatusCode.InternalServerError, TagFileProcessingErrorResult.CreateTagFileProcessingErrorResult(false, ContractExecutionStatesEnum.InternalProcessingError, 17, "device", e.Message)); } }
public async Task <int> GetDeviceLicenses(string customerUid) { if (string.IsNullOrEmpty(customerUid)) { return(0); } try { return((await _cwsAccountClient.GetDeviceLicenses(new Guid(customerUid), _mergedCustomHeaders))?.Total ?? 0); } catch (Exception e) { throw new ServiceException(HttpStatusCode.InternalServerError, TagFileProcessingErrorResult.CreateTagFileProcessingErrorResult(false, ContractExecutionStatesEnum.InternalProcessingError, 17, "cwsAccount", e.Message)); } }
public async Task <CoordinateConversionResult> ConvertNEtoLL(string projectUid, double northing, double easting) { var request = new CoordinateConversionRequest(new Guid(projectUid), TwoDCoordinateConversionType.NorthEastToLatLon, new[] { new TwoDConversionCoordinate(easting, northing) }); try { var result = await _tRexCompactionDataProxy.SendDataPostRequest <CoordinateConversionResult, CoordinateConversionRequest>(request, "/coordinateconversion", _mergedCustomHeaders); _log.LogDebug($"{nameof(ConvertNEtoLL)}: CoordinateConversionRequest {JsonConvert.SerializeObject(request)} CoordinateConversionResult {JsonConvert.SerializeObject(result)}"); // This could be done in the CoreX.Wrapper, if the TRex request pipeline exposed the CoreX.Types.ReturnAs type. // TRex returns the coordinates in radians, all future uses here assume degrees, must convert. var mutatedCoordinates = new TwoDConversionCoordinate[result.ConversionCoordinates.Length]; for (var i = 0; i < result.ConversionCoordinates.Length; i++) { var point = result.ConversionCoordinates[i]; mutatedCoordinates[i] = new TwoDConversionCoordinate(point.X.LonRadiansToDegrees(), point.Y.LatRadiansToDegrees()); } result.SetConversionCoordinates(mutatedCoordinates); if (result?.ConversionCoordinates == null || result.ConversionCoordinates.Length != 1 || result.ConversionCoordinates[0].X < -180 || result.ConversionCoordinates[0].X > 180 || result.ConversionCoordinates[0].Y < -90 || result.ConversionCoordinates[0].Y > 90) { return(null); } return(result); } catch (Exception e) { throw new ServiceException(HttpStatusCode.InternalServerError, TagFileProcessingErrorResult.CreateTagFileProcessingErrorResult(false, ContractExecutionStatesEnum.InternalProcessingError, 17, "tRex", e.Message)); } }