Exemplo n.º 1
0
        public async Task <IClientLeafSubGrid> ExecuteAsync(ISurfaceElevationPatchArgument arg) => Execute(arg); // Task.Run(() => Execute(arg));

        public IClientLeafSubGrid Execute(ISurfaceElevationPatchArgument arg)
        {
            if (arg.SurveyedSurfacePatchType > SurveyedSurfacePatchType.CompositeElevations)
            {
                return(null);
            }

            var cachingSupported = arg.SurveyedSurfacePatchType != SurveyedSurfacePatchType.CompositeElevations && _cache != null;

            // Check the item is available in the cache
            if (cachingSupported && _cache?.Get(arg.OTGCellBottomLeftX, arg.OTGCellBottomLeftY) is IClientLeafSubGrid cacheResult)
            {
                return(_cache.ExtractFromCachedItem(cacheResult, arg.ProcessingMap, arg.SurveyedSurfacePatchType));
            }

            SubGridTreeBitmapSubGridBits savedMap = null;

            // Always request the full sub grid from the surveyed surface engine unless composite elevations are requested
            if (cachingSupported)
            {
                savedMap          = arg.ProcessingMap;
                arg.ProcessingMap = SubGridTreeBitmapSubGridBits.FullMask;
            }

            var subGridInvalidationVersion = cachingSupported ? _cache.InvalidationVersion : 0;

            var executor = new CalculateSurfaceElevationPatch();

            _sitemodel ??= DIContext.ObtainRequired <ISiteModels>().GetSiteModel(arg.SiteModelID);
            _designFiles ??= DIContext.ObtainRequired <IDesignFiles>();
            _surveyedSurfaces ??= _sitemodel.SurveyedSurfaces;

            var clientResult = executor.Execute(_sitemodel, arg.OTGCellBottomLeftX, arg.OTGCellBottomLeftY,
                                                arg.CellSize, arg.SurveyedSurfacePatchType, arg.IncludedSurveyedSurfaces,
                                                _designFiles, _surveyedSurfaces, arg.ProcessingMap);

            if (clientResult != null)
            {
                // For now, only cache non-composite elevation sub grids
                if (cachingSupported)
                {
                    _cache?.Add(clientResult, subGridInvalidationVersion);
                }

                if (savedMap != null)
                {
                    clientResult = _cache.ExtractFromCachedItem(clientResult, savedMap, arg.SurveyedSurfacePatchType);
                }
            }

            return(clientResult);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Invokes the surface elevation patch computation function on the server nodes the request has been sent to
        /// </summary>
        public ISerialisedByteArrayWrapper Invoke(ISurfaceElevationPatchArgument arg)
        {
            try
            {
                var executor = new CalculateSurfaceElevationPatch();

                var siteModel = DIContext.ObtainRequired <ISiteModels>().GetSiteModel(arg.SiteModelID);

                if (siteModel == null)
                {
                    _log.LogWarning($"Failed to get site model with ID {arg.SiteModelID}");
                    return(new SerialisedByteArrayWrapper(null));
                }

                var result = executor.Execute(siteModel, arg.OTGCellBottomLeftX, arg.OTGCellBottomLeftY,
                                              arg.CellSize, arg.SurveyedSurfacePatchType, arg.IncludedSurveyedSurfaces,
                                              DIContext.ObtainRequired <IDesignFiles>(),
                                              siteModel.SurveyedSurfaces,
                                              arg.ProcessingMap);

                byte[] resultAsBytes = null;
                if (result != null)
                {
                    try
                    {
                        resultAsBytes = result.ToBytes();
                    }
                    finally
                    {
                        DIContext.Obtain <IClientLeafSubGridFactory>().ReturnClientSubGrid(ref result);
                    }
                }

                return(new SerialisedByteArrayWrapper(resultAsBytes));
            }
            catch (Exception e)
            {
                _log.LogError(e, "Exception requesting surveyed surface elevation patch");
                return(new SerialisedByteArrayWrapper(null));
            }
        }