예제 #1
0
        /// <summary>
        /// Retrieve the required Elevation Files for the set of co-ordinates and add any new files to the cache
        /// </summary>
        /// <param name="elevationFiles"></param>
        private ElevationFile[] GetOrCreateRequiredFilesInCache(DecimalGeoCoordinate[] coordinates)
        {
            var filenames = ParseFilenamesFromCoordinates(coordinates);

            var requiredFiles = new List <ElevationFile>();

            foreach (var filename in filenames)
            {
                ElevationFile newFile = null;

                if (!_cache.TryGetValue(filename, out newFile))
                {
                    var filePath = Path.Combine(_elevationDataPath, filename);

                    if (!System.IO.File.Exists(filePath))
                    {
                        throw new FileNotFoundException($"Dataset '{filename}' is not available.");
                    }

                    newFile = _elevationFileReader.LoadFile(filePath);

                    _cache.Set(filename, newFile);
                }

                requiredFiles.Add(newFile);
            }

            return(requiredFiles.ToArray());
        }
예제 #2
0
        /// <summary>
        /// Retrieve the required Elevation Files for the set of co-ordinates and add any new files to the cache
        /// </summary>
        /// <param name="coordinates"></param>
        private ElevationFile[] GetOrCreateRequiredFilesInCache(DecimalGeoCoordinate[] coordinates)
        {
            var filenames = ParseFilenamesFromCoordinates(coordinates);

            var requiredFiles = new List <ElevationFile>();

            foreach (var filename in filenames)
            {
                ElevationFile newFile = null;

                if (!_cache.TryGetValue(filename, out newFile))
                {
                    var filePath = Path.Combine(_elevationDataPath, filename);

                    if (!System.IO.File.Exists(filePath))
                    {
                        throw new FileNotFoundException($"Dataset '{filename}' is not available.");
                    }

                    newFile = _elevationFileReader.LoadFile(filePath);

                    // TODO : Add to config / update to a sensible option.
                    var cacheOptions = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromMinutes(1));

                    _cache.Set(filename, newFile, cacheOptions);
                }

                requiredFiles.Add(newFile);
            }

            return(requiredFiles.ToArray());
        }