Beispiel #1
0
        public List <string> RequestPointsRegionsKeys(Pair topLeftCorner,
                                                      Pair bottomRightCorner,
                                                      int zoomLevel,
                                                      string username,
                                                      string dataSet)
        {
            //todo: cache the header
            PointsDataSetHeader dataSetHeader = this.userRepository.GetDatasetHeader(username, dataSet);

            if (dataSetHeader == null)
            {
                throw new ApplicationException($"User do not have a dataset with name {dataSet}");
            }

            //set the requested latitude and longitude coordinates of corners in the available limits of the dataset
            var topLeftIndexes = this.dataPointsRegionSource.GetRegionIndexes(
                topLeftCorner.Item1 <(dataSetHeader.MaximumLatitude ?? 90m) ? topLeftCorner.Item1 : dataSetHeader.MaximumLatitude ?? 90m,
                                     topLeftCorner.Item2> (dataSetHeader.MinimumLongitude ?? -180m) ? topLeftCorner.Item2 : dataSetHeader.MinimumLongitude ?? -180m,
                zoomLevel);

            var bottomRightIndexes = this.dataPointsRegionSource.GetRegionIndexes(
                bottomRightCorner.Item1 > (dataSetHeader.MinimumLatitude ?? -90m) ? bottomRightCorner.Item1 : (dataSetHeader.MinimumLatitude ?? -90m),
                bottomRightCorner.Item2 < (dataSetHeader.MaximumLongitude ?? 180m) ? bottomRightCorner.Item2 : (dataSetHeader.MaximumLongitude ?? 180m),
                zoomLevel);

            return(PointsCacheManager.GetKeys(topLeftIndexes, bottomRightIndexes, zoomLevel, dataSetHeader.ID));
        }
        private static List <string> getCacheKeys(Tuple <int, int> from, Tuple <int, int> to, int zoomLevel, int datasetId, out List <Region> requiredPoints)
        {
            List <string> result = new List <string>();

            requiredPoints = new List <Region>();

            for (int i = from.Item1; i <= to.Item1; i += 1)
            {
                for (int j = from.Item2; j <= to.Item2; j += 1)
                {
                    string key        = generateKey(i, j, zoomLevel, datasetId);
                    var    cacheValue = MemoryCache.Default.Get(key);

                    //if the key was not found as entry in cache, request the points and create an entry
                    //which is identified as 'creating'
                    if (cacheValue == null)
                    {
                        requiredPoints.Add(new Region(i, j, zoomLevel));

                        PointsCacheManager.Create(i, j, zoomLevel, datasetId);
                    }
                    else
                    {
                        result.Add(key);
                    }
                }
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Returns data points regions which are inside a specific area of screen for a zoom level.
        /// Limits unit of measure with latitude/longitude.
        /// Points zones source is Cassandra
        /// </summary>
        /// <param name="topLeftCorner"></param>
        /// <param name="bottomRightCorner"></param>
        /// <param name="username"></param>
        /// <param name="dataSet"></param>
        /// <param name="cachedRegions">A list of regions keys which are cached on browser</param>
        /// <param name="callback"></param>
        /// <returns></returns>
        public void RequestDomainPointsRegions(Pair topLeftCorner,
                                               Pair bottomRightCorner,
                                               int zoomLevel,
                                               string username,
                                               string dataSet,
                                               string[] cachedRegions,
                                               Action <IEnumerable <PointBase>, string> callback)
        {
            //todo: cache the header
            PointsDataSetHeader datasetHeader = this.userRepository.GetDatasetHeader(username, dataSet);

            if (datasetHeader == null)
            {
                throw new ApplicationException($"User do not have a dataset with name {dataSet}");
            }

            //set the requested latitude and longitude coordinates of corners in the available limits of the dataset
            var topLeftIndexes = this.dataPointsRegionSource.GetRegionIndexes(
                topLeftCorner.Item1 <(datasetHeader.MaximumLatitude ?? 90m) ? topLeftCorner.Item1 : datasetHeader.MaximumLatitude ?? 90m,
                                     topLeftCorner.Item2> (datasetHeader.MinimumLongitude ?? -180m) ? topLeftCorner.Item2 : datasetHeader.MinimumLongitude ?? -180m,
                zoomLevel);

            var bottomRightIndexes = this.dataPointsRegionSource.GetRegionIndexes(
                bottomRightCorner.Item1 > (datasetHeader.MinimumLatitude ?? -90m) ? bottomRightCorner.Item1 : (datasetHeader.MinimumLatitude ?? -90m),
                bottomRightCorner.Item2 < (datasetHeader.MaximumLongitude ?? 180m) ? bottomRightCorner.Item2 : (datasetHeader.MaximumLongitude ?? 180m),
                zoomLevel);

            var serverCachedRegions = PointsCacheManager.Get(topLeftIndexes,
                                                             bottomRightIndexes,
                                                             zoomLevel,
                                                             datasetHeader.ID,
                                                             cachedRegions,
                                                             out List <Coordinates> requiredRegions);

            if (requiredRegions != null)
            {
                Parallel.ForEach(requiredRegions, coordinate =>
                {
                    try
                    {
                        var result = this.dataPointsRepository.GetRegion(datasetHeader.ID, coordinate.Item1, coordinate.Item2, zoomLevel);

                        string regionKey = null;
                        if (result != null)
                        {
                            regionKey = PointsCacheManager.Write(coordinate.Item1, coordinate.Item2, coordinate.Item3, datasetHeader.ID, result.Points);
                        }

                        callback(result == null ? new List <PointBase>() : result.Points, regionKey);
                    }
                    catch (Exception exception)
                    {
                        CoreContainers.LogsRepository.LogError(exception, Core.Database.Logs.LogTrigger.Domain);

                        //if a error ocurs, the created entry must be deleted from the cache

                        PointsCacheManager.Remove(coordinate.Item1, coordinate.Item2, coordinate.Item3, datasetHeader.ID);
                    }
                });
            }

            foreach (var pointsZonePair in serverCachedRegions)
            {
                callback(pointsZonePair.Item1, pointsZonePair.Item2);
            }
        }