Ejemplo n.º 1
0
        public async Task <GeofenceDataSingleResult> UpsertBoundary(string projectUid, [FromBody] BoundaryRequest request)
        {
            Log.LogInformation(
                $"{ToString()}.{nameof(UpsertBoundary)}: CustomerUID={CustomerUid} BoundaryRequest: {JsonConvert.SerializeObject(request)}");

            var requestFull = BoundaryRequestFull.Create(
                CustomerUid,
                IsApplication,
                await GetProject(projectUid),
                GetUserId,
                request);

            requestFull.Validate(ServiceExceptionHandler);
            requestFull.Request.BoundaryPolygonWKT = GeofenceValidation.MakeGoodWkt(requestFull.Request.BoundaryPolygonWKT);

            var getResult = await BoundaryHelper.GetProjectBoundaries(
                Log, ServiceExceptionHandler,
                projectUid, _projectRepository, _geofenceRepository).ConfigureAwait(false);

            if (getResult.GeofenceData.Any(g => request.Name.Equals(g.GeofenceName, StringComparison.OrdinalIgnoreCase)))
            {
                ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 62);
            }

            var executor = RequestExecutorContainer.Build <UpsertBoundaryExecutor>(ConfigStore, Logger,
                                                                                   ServiceExceptionHandler, _geofenceRepository, _projectRepository, ProjectProxy);
            var result = await executor.ProcessAsync(requestFull) as GeofenceDataSingleResult;

            Log.LogInformation(
                $"{ToString()}.UpsertBoundary Completed: resultCode: {result?.Code} result: {JsonConvert.SerializeObject(result)}");
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes the 'Get Custom Boundaries' Request for a project
        /// </summary>
        protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item)
        {
            var request = CastRequestObjectTo <BaseRequestFull>(item, 52);

            if (request == null)
            {
                return(null);
            }

            var boundaries  = new List <GeofenceData>();
            var projectRepo = (IProjectRepository)auxRepository;

            Task <GeofenceDataListResult> boundariesTask = null;

            //Task<List<GeofenceData>> favoritesTask = null;
            //Task<List<GeofenceData>> associatedTask = null;
            try
            {
                //a) Custom boundaries
                boundariesTask = BoundaryHelper.GetProjectBoundaries(
                    log, serviceExceptionHandler, request.ProjectUid, projectRepo, (IGeofenceRepository)Repository);
                //b) favorite geofences that overlap project

                // geofence and UnifiedProd services are not available to ccss
                //favoritesTask =
                //  GeofenceProxy.GetFavoriteGeofences(request.CustomerUid, request.UserUid, request.CustomHeaders);
                ////c) unified productivity associated geofences
                //associatedTask = UnifiedProductivityProxy.GetAssociatedGeofences(request.ProjectUid, request.CustomHeaders);

                await Task.WhenAll(boundariesTask /*, favoritesTask, associatedTask */);
            }
            catch (Exception e)
            {
                log.LogError(e, "Failed to retrieve all boundaries");
            }

            try
            {
                if (boundariesTask != null && !boundariesTask.IsFaulted && boundariesTask.Result != null)
                {
                    boundaries.AddRange(boundariesTask.Result.GeofenceData);
                }
                //if (associatedTask != null && !associatedTask.IsFaulted && associatedTask.Result != null)
                //  boundaries.AddRange(associatedTask.Result);
                //if (favoritesTask != null && !favoritesTask.IsFaulted && favoritesTask.Result != null)
                //{
                //  //Find out which favorite geofences overlap project boundary
                //  var overlappingGeofences =
                //    (await projectRepo.DoPolygonsOverlap(request.ProjectGeometryWKT,
                //      favoritesTask.Result.Select(g => g.GeometryWKT))).ToList();
                //  for (var i = 0; i < favoritesTask.Result.Count; i++)
                //  {
                //    if (overlappingGeofences[i])
                //      boundaries.Add(favoritesTask.Result[i]);
                //  }
                //}
            }
            catch (Exception ex)
            {
                log.LogError(ex, "Failed to aggregate all boundaries");
            }

            //Remove any duplicates
            boundaries = boundaries.Distinct(new DistinctGeofenceComparer()).ToList();

            return(new GeofenceDataListResult
            {
                GeofenceData = boundaries.ToImmutableList()
            });
        }