示例#1
0
        public void Test_SubGridSpatialAffinityKey_ToStringSegment()
        {
            Guid ID = Guid.NewGuid();
            ISubGridSpatialAffinityKey key = new SubGridSpatialAffinityKey(SubGridSpatialAffinityKey.DEFAULT_SPATIAL_AFFINITY_VERSION_NUMBER_TICKS, ID, new SubGridCellAddress(12345678, 34567890), 123456, 789012);

            Assert.Equal($"{ID}-1-12345678-34567890-123456-789012", key.ToString());
        }
示例#2
0
        /// <summary>
        /// Removes a spatial stream from the persistent store identified by its spatial descriptor attributes
        /// </summary>
        public FileSystemErrorStatus RemoveSpatialStreamFromPersistentStore(Guid dataModelId,
                                                                            string streamName,
                                                                            int subGridX, int subGridY,
                                                                            long segmentStartDateTicks,
                                                                            long segmentEndDateTicks,
                                                                            long version,
                                                                            FileSystemStreamType streamType)
        {
            try
            {
                var cacheKey = new SubGridSpatialAffinityKey(version, dataModelId, subGridX, subGridY, segmentStartDateTicks, segmentEndDateTicks);

                try
                {
                    SpatialCache(streamType).Remove(cacheKey);
                }
                catch (KeyNotFoundException)
                {
                    return(FileSystemErrorStatus.GranuleDoesNotExist);
                }

                ImmutableProxy?.RemoveSpatialStreamFromPersistentStore(dataModelId, streamName, subGridX, subGridY, segmentStartDateTicks, segmentEndDateTicks, version, streamType);

                return(FileSystemErrorStatus.OK);
            }
            catch (Exception e)
            {
                _log.LogError(e, "Exception occurred:");

                return(FileSystemErrorStatus.UnknownFailureRemovingFileFromFS);
            }
        }
示例#3
0
        public void Test_SubGridSpatialAffinityKey_NullConstructor()
        {
            ISubGridSpatialAffinityKey key = new SubGridSpatialAffinityKey();

            Assert.True(key.ProjectUID == Guid.Empty && key.SubGridX == 0 && key.SubGridY == 0 && key.SegmentStartDateTicks == 0 && key.SegmentEndDateTicks == 0,
                        "Default constructor sub grid spatial affinity key produced unexpected result");
        }
示例#4
0
        public async Task <CellPassesResponse> ExecuteAsync(CellPassesRequestArgument_ApplicationService arg)
        {
            var result = new CellPassesResponse()
            {
                ReturnCode = CellPassesReturnCode.Error
            };

            if (arg.Filters?.Filters != null && arg.Filters.Filters.Length > 0)
            {
                // Prepare the filters for use in cell passes operations. Failure to prepare any filter results in this request terminating
                if (!arg.Filters.Filters.Select(x => FilterUtilities.PrepareFilterForUse(x, arg.ProjectID)).All(x => x == RequestErrorStatus.OK))
                {
                    return(new CellPassesResponse {
                        ReturnCode = CellPassesReturnCode.FailedToPrepareFilter
                    });
                }
            }

            var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(arg.ProjectID);

            if (siteModel == null)
            {
                _log.LogError($"Failed to locate site model {arg.ProjectID}");
                return(result);
            }

            if (!arg.CoordsAreGrid)
            {
                //WGS84 coords need to be converted to NEE
                var pointToConvert = new XYZ(arg.Point.X, arg.Point.Y, 0);
                arg.Point       = DIContext.Obtain <ICoreXWrapper>().LLHToNEE(siteModel.CSIB(), pointToConvert.ToCoreX_XYZ(), CoreX.Types.InputAs.Radians).ToTRex_XYZ();
                result.Northing = arg.Point.Y;
                result.Easting  = arg.Point.X;
            }

            var existenceMap = siteModel.ExistenceMap;

            // Determine the on-the-ground cell
            siteModel.Grid.CalculateIndexOfCellContainingPosition(arg.Point.X,
                                                                  arg.Point.Y,
                                                                  out var otgCellX,
                                                                  out var otgCellY);

            if (!existenceMap[otgCellX >> SubGridTreeConsts.SubGridIndexBitsPerLevel, otgCellY >> SubGridTreeConsts.SubGridIndexBitsPerLevel])
            {
                result.ReturnCode = CellPassesReturnCode.NoDataFound;
                return(result);
            }

            var computeArg      = new CellPassesRequestArgument_ClusterCompute(arg.ProjectID, arg.Point, otgCellX, otgCellY, arg.Filters);
            var requestCompute  = new CellPassesRequest_ClusterCompute();
            var affinityKey     = new SubGridSpatialAffinityKey(SubGridSpatialAffinityKey.DEFAULT_SPATIAL_AFFINITY_VERSION_NUMBER_TICKS, arg.ProjectID, otgCellX, otgCellY);
            var responseCompute = await requestCompute.ExecuteAsync(computeArg, affinityKey);

            result.ReturnCode = responseCompute.ReturnCode;
            result.CellPasses = responseCompute.CellPasses;

            return(result);
        }
示例#5
0
        public void Test_SubGridSpatialAffinityKey_CellAddressAndSegmentConstructor()
        {
            Guid ID = Guid.NewGuid();
            ISubGridSpatialAffinityKey key = new SubGridSpatialAffinityKey(2, ID, new SubGridCellAddress(12345678, 34567890), 123456, 789012);

            Assert.True(key.Version == 2 && key.ProjectUID == ID && key.SubGridX == 12345678 && key.SubGridY == 34567890 && key.SegmentStartDateTicks == 123456 && key.SegmentEndDateTicks == 789012,
                        "Cell address constructor sub grid spatial affinity key produced unexpected result");
        }
示例#6
0
        public void Test_SubGridSpatialAffinityKey_CellAddressConstructor()
        {
            Guid ID = Guid.NewGuid();
            ISubGridSpatialAffinityKey key = new SubGridSpatialAffinityKey(SubGridSpatialAffinityKey.DEFAULT_SPATIAL_AFFINITY_VERSION_NUMBER_TICKS, ID, new SubGridCellAddress(12345678, 34567890));

            Assert.True(key.Version == 1 && key.ProjectUID == ID && key.SubGridX == 12345678 && key.SubGridY == 34567890 && key.SegmentStartDateTicks == -1 && key.SegmentEndDateTicks == -1,
                        "Cell address constructor sub grid spatial affinity key produced unexpected result");
        }
示例#7
0
        /// <summary>
        /// Supports writing a spatial data stream to the persistent store via the grid cache.
        /// </summary>
        public FileSystemErrorStatus WriteSpatialStreamToPersistentStore(Guid dataModelId,
                                                                         string streamName,
                                                                         int subGridX, int subGridY,
                                                                         long segmentStartDateTicks, long segmentEndDateTicks,
                                                                         long version,
                                                                         FileSystemStreamType streamType,
                                                                         MemoryStream mutableStream,
                                                                         object source)
        {
            try
            {
                var cacheKey = new SubGridSpatialAffinityKey(version, dataModelId, subGridX, subGridY, segmentStartDateTicks, segmentEndDateTicks);

                using (var compressedStream = MemoryStreamCompression.Compress(mutableStream))
                {
                    var spatialCache = SpatialCache(streamType);
                    if (_log.IsTraceEnabled())
                    {
                        _log.LogInformation($"Putting key:{cacheKey} in {spatialCache.Name}, size:{mutableStream.Length} -> {compressedStream.Length}, ratio:{(compressedStream.Length / (1.0 * mutableStream.Length)) * 100}%");
                    }
                    spatialCache.Put(cacheKey, new SerialisedByteArrayWrapper(compressedStream.ToArray()));
                }

                // Convert the stream to the immutable form and write it to the immutable storage proxy
                try
                {
                    if (Mutability == StorageMutability.Mutable && ImmutableProxy != null)
                    {
                        PerformSpatialImmutabilityConversion(mutableStream, ImmutableProxy.SpatialCache(streamType), cacheKey, streamType, source);
                    }
                }
                catch (Exception e)
                {
                    _log.LogError(e, $"Exception performing mutability conversion in {nameof(WriteSpatialStreamToPersistentStore)}");
                    return(FileSystemErrorStatus.MutableToImmutableConversionError);
                }

                return(FileSystemErrorStatus.OK);
            }
            catch (Exception e)
            {
                _log.LogError(e, $"Exception writing spatial stream {streamName} to persistent store");
                return(FileSystemErrorStatus.UnknownErrorWritingToFS);
            }
        }
示例#8
0
        /// <summary>
        /// Supports reading a stream of spatial data from the persistent store via the grid cache
        /// </summary>
        public FileSystemErrorStatus ReadSpatialStreamFromPersistentStore(Guid dataModelId,
                                                                          string streamName,
                                                                          int subGridX, int subGridY,
                                                                          long segmentStartDateTicks,
                                                                          long segmentEndDateTicks,
                                                                          long version,
                                                                          FileSystemStreamType streamType,
                                                                          out MemoryStream stream)
        {
            stream = null;

            try
            {
                var cacheKey = new SubGridSpatialAffinityKey(version, dataModelId, subGridX, subGridY, segmentStartDateTicks, segmentEndDateTicks);

                //Log.LogInformation($"Getting key:{streamName}");

                try
                {
                    using var ms    = new MemoryStream(SpatialCache(streamType).Get(cacheKey).Bytes);
                    stream          = MemoryStreamCompression.Decompress(ms);
                    stream.Position = 0;
                }
                catch (KeyNotFoundException)
                {
                    return(FileSystemErrorStatus.GranuleDoesNotExist);
                }

                return(FileSystemErrorStatus.OK);
            }
            catch (Exception e)
            {
                _log.LogError(e, "Exception occurred:");

                stream = null;
                return(FileSystemErrorStatus.UnknownErrorReadingFromFS);
            }
        }
示例#9
0
        /// <summary>
        /// Executor that implements requesting and rendering sub grid information to create the cell datum
        /// </summary>
        public async Task <CellPassesResponse> ExecuteAsync(CellPassesRequestArgument_ClusterCompute arg, SubGridSpatialAffinityKey key)
        {
            Log.LogInformation($"Performing Execute for DataModel:{arg.ProjectID}");

            var result = new CellPassesResponse {
                ReturnCode = CellPassesReturnCode.Error
            };

            var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(arg.ProjectID);

            if (siteModel == null)
            {
                Log.LogError($"Failed to locate site model {arg.ProjectID}");
                return(result);
            }

            var existenceMap = siteModel.ExistenceMap;
            var utilities    = DIContext.Obtain <IRequestorUtilities>();
            var requestors   = utilities.ConstructRequestors(null, siteModel, arg.Overrides, arg.LiftParams,
                                                             utilities.ConstructRequestorIntermediaries(siteModel, arg.Filters, true, GridDataType.CellPasses),
                                                             AreaControlSet.CreateAreaControlSet(),
                                                             existenceMap);

            // Get the sub grid relative cell location
            var cellX = arg.OTGCellX & SubGridTreeConsts.SubGridLocalKeyMask;
            var cellY = arg.OTGCellY & SubGridTreeConsts.SubGridLocalKeyMask;

            // Reach into the sub-grid request layer and retrieve an appropriate sub-grid
            var cellOverrideMask = new SubGridTreeBitmapSubGridBits(SubGridBitsCreationOptions.Unfilled);

            cellOverrideMask.SetBit(cellX, cellY);
            requestors[0].CellOverrideMask = cellOverrideMask;

            var thisSubGridOrigin            = new SubGridCellAddress(arg.OTGCellX, arg.OTGCellY);
            var requestSubGridInternalResult = requestors[0].RequestSubGridInternal(thisSubGridOrigin, true, true);

            if (requestSubGridInternalResult.requestResult != ServerRequestResult.NoError)
            {
                if (requestSubGridInternalResult.requestResult == ServerRequestResult.SubGridNotFound)
                {
                    result.ReturnCode = CellPassesReturnCode.NoDataFound;
                }
                else
                {
                    Log.LogError($"Request for sub grid {thisSubGridOrigin} request failed with code {requestSubGridInternalResult.requestResult}");
                }
                return(result);
            }

            if (!(requestSubGridInternalResult.clientGrid is ClientCellProfileAllPassesLeafSubgrid grid))
            {
                Log.LogError($"Request for sub grid {thisSubGridOrigin} request failed due the grid return type being incorrect. Expected {typeof(ClientCellProfileAllPassesLeafSubgrid).Name}, but got {requestSubGridInternalResult.clientGrid.GetType().Name}");
                return(result);
            }

            var cell = grid.Cells[cellX, cellY];

            if (cell.TotalPasses > 0)
            {
                result.ReturnCode = CellPassesReturnCode.DataFound;
                for (var idx = 0; idx < cell.TotalPasses; idx++)
                {
                    var cellPass = cell.CellPasses[idx];
                    result.CellPasses.Add(cellPass);
                }
            }
            else
            {
                result.ReturnCode = CellPassesReturnCode.NoDataFound;
            }

            return(result);
        }
示例#10
0
        /// <summary>
        /// Executor that implements requesting and rendering sub grid information to create the cell datum
        /// </summary>
        public async Task <CellDatumResponse_ClusterCompute> ExecuteAsync(CellDatumRequestArgument_ClusterCompute arg, SubGridSpatialAffinityKey key)
        {
            Log.LogInformation($"Performing Execute for DataModel:{arg.ProjectID}, Mode={arg.Mode}");

            var result = new CellDatumResponse_ClusterCompute {
                ReturnCode = CellDatumReturnCode.UnexpectedError
            };

            var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(arg.ProjectID);

            if (siteModel == null)
            {
                Log.LogError($"Failed to locate site model {arg.ProjectID}");
                return(result);
            }

            IDesignWrapper cutFillDesign = null;

            if (arg.ReferenceDesign != null && arg.ReferenceDesign.DesignID != Guid.Empty)
            {
                var design = siteModel.Designs.Locate(arg.ReferenceDesign.DesignID);
                if (design == null)
                {
                    throw new ArgumentException($"Design {arg.ReferenceDesign.DesignID} not a recognized design in project {arg.ProjectID}");
                }
                cutFillDesign = new DesignWrapper(arg.ReferenceDesign, design);
            }

            await GetProductionData(siteModel, cutFillDesign, result, arg);

            return(result);
        }