コード例 #1
0
        public static async Task <GeofenceDataListResult> GetProjectBoundaries(
            ILogger log, IServiceExceptionHandler serviceExceptionHandler,
            string projectUid, IProjectRepository projectRepository, IGeofenceRepository geofenceRepository)
        {
            IEnumerable <Geofence> geofences = null;

            try
            {
                var associations = await projectRepository
                                   .GetAssociatedGeofences(projectUid)
                                   .ConfigureAwait(false);

                var projectGeofences = associations.ToList();
                if (projectGeofences.Any())
                {
                    geofences = await geofenceRepository
                                .GetGeofences(projectGeofences.Select(a => a.GeofenceUID.ToString()))
                                .ConfigureAwait(false);
                }
            }
            catch (Exception e)
            {
                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 49, e.Message);
            }

            // may be none, return success and empty list
            return(new GeofenceDataListResult
            {
                GeofenceData = (geofences ?? new List <Geofence>())
                               .Select(x => AutoMapperUtility.Automapper.Map <GeofenceData>(x))
                               .ToImmutableList()
            });
        }
コード例 #2
0
        /// <summary>
        /// Hydrates the filterJson string with the boundary data and uses the MasterData Models filter model to do so - to isolate logic there
        /// </summary>
        public static async Task <string> HydrateJsonWithBoundary(/*IGeofenceProxy geofenceProxy, */ IGeofenceRepository geofenceRepository,
                                                                  ILogger log, IServiceExceptionHandler serviceExceptionHandler, FilterRequestFull filterRequestFull)
        {
            var filterTempForHydration = filterRequestFull.FilterModel(serviceExceptionHandler);

            //If no polygon boundary return original filter JSON
            if (string.IsNullOrEmpty(filterTempForHydration?.PolygonUid))
            {
                return(filterRequestFull.FilterJson);
            }

            //Get polygon boundary to add to filter
            Geofence filterBoundary = null;
            string   methodName     = null;

            try
            {
                if (!filterTempForHydration.PolygonType.HasValue ||
                    filterTempForHydration.PolygonType.Value == GeofenceType.Filter)
                {
                    methodName     = "geofenceRepository.GetGeofence";
                    filterBoundary = await geofenceRepository.GetGeofence(filterTempForHydration.PolygonUid);
                }

                // favorite and assoicated geofences N/A and geofenceSvc not available to ccss
                //if (filterBoundary == null)
                //{
                //  //Get geofence from geofence service. It could be a favorite or an associated geofence.
                //  methodName = "geofenceProxy.GetGeofenceForCustomer";
                //  var geofence = await geofenceProxy.GetGeofenceForCustomer(
                //    filterRequestFull.CustomerUid, filterTempForHydration.PolygonUid, filterRequestFull.CustomHeaders);
                //  if (geofence != null)
                //    filterBoundary = AutoMapperUtility.Automapper.Map<Geofence>(geofence);
                //}
            }
            catch (Exception e)
            {
                log.LogError(e, $"{nameof(HydrateJsonWithBoundary)}: {methodName} failed with exception. projectUid:{filterRequestFull.ProjectUid} boundaryUid:{filterTempForHydration.PolygonUid}");
                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 41, e.Message);
            }

            if (filterBoundary == null)
            {
                log.LogError(
                    $"{nameof(HydrateJsonWithBoundary)}: boundary not found, or not valid: projectUid:{filterRequestFull.ProjectUid} boundaryUid:{filterTempForHydration.PolygonUid}. boundaryType: {filterTempForHydration.PolygonType} returned no boundary match");
                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 40);
            }

            //Add polygon boundary to filter and convert back to JSON
            var polygonPoints = GetPointsFromWkt(filterBoundary.GeometryWKT);

            if (polygonPoints.Count == 0)
            {
                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 45);
            }
            filterTempForHydration.AddBoundary(filterBoundary.GeofenceUID, filterBoundary.Name, polygonPoints, filterBoundary.GeofenceType);

            string newFilterJson = null;

            try
            {
                newFilterJson = JsonConvert.SerializeObject(filterTempForHydration);
            }
            catch (Exception e)
            {
                log.LogError(e, $"{nameof(HydrateJsonWithBoundary)}: {nameof(HydrateJsonWithBoundary)} failed with exception. projectUid:{filterRequestFull.ProjectUid}. boundaryUid:{filterTempForHydration.PolygonUid}");
                // todo normally we incude e.Message. is e.GetBaseException.message specific to Json exception?
                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 43, e.GetBaseException().Message);
            }

            if (string.IsNullOrEmpty(newFilterJson))
            {
                log.LogError(
                    $"{nameof(HydrateJsonWithBoundary)}: {nameof(HydrateJsonWithBoundary)} failed. projectUid:{filterRequestFull.ProjectUid}. boundaryUid:{filterTempForHydration.PolygonUid}.");
                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 44);
            }

            log.LogInformation(
                $"{nameof(HydrateJsonWithBoundary)}: succeeded: projectUid:{filterRequestFull.ProjectUid}. boundaryUid:{filterTempForHydration.PolygonUid}.");
            return(newFilterJson);
        }