Exemple #1
0
        /// <summary>
        /// Returns the elevation cache entry (first searches the local cache, then the azure cache and finally loads the file from blob storage if it was not cached).
        /// </summary>
        /// <param name="fileName">Name of the file that is being cached.</param>
        /// <param name="isArcData">if set to <c>true</c> [is arc data].</param>
        /// <returns>Returns the cache entry (null if no entry was found)</returns>
        private ElevationCacheEntry GetElevationEntry(string fileName, bool isArcData)
        {
            ElevationCacheEntry entry = null;

            // First check local cache
            if (this.localCache.ContainsKey(fileName))
            {
                entry = this.localCache[fileName];
                entry.RefreshCacheDetails();

                return(entry);
            }

            if (this.azureCache != null)
            {
                // Not in local cache, so check azure cache
                entry = this.azureCache.Get(fileName) as ElevationCacheEntry;
                if (entry != null)
                {
                    this.localCache[fileName] = entry;
                    entry.RefreshCacheDetails();
                }
            }

            // Not in local or azure cache, so read from azure storage
            this.Add(fileName, isArcData);

            if (this.localCache.ContainsKey(fileName))
            {
                entry = this.localCache[fileName];
            }

            return(entry);
        }
Exemple #2
0
        /// <summary>
        /// Adds the specified file to the cache (in memory)
        /// </summary>
        /// <param name="filename">File to be cached in memory</param>
        public void Add(string filename)
        {
            string logMethodName = "ElevationCache.Add (filename -> " + filename;

            bool   cacheSizeExceeded = false;
            string dataDirectory     = Utils.Configuration["dataDirectory"];

            try
            {
                //// Check to see if the cache size has exceeded
                cacheSizeExceeded = this.GetMemoryUsage() >= this.maxLocalCacheSize;

                if (cacheSizeExceeded)
                {
                    this.CleanupLocalCache();
                }

                byte[] fileContents = null;

                // Insert file contents into the cache
                if (!this.localCache.ContainsKey(filename))
                {
                    try
                    {
                        fileContents = (byte[])this.TerrainDalc.LoadTerrainFile(filename, dataDirectory, this.cacheElementSize);
                    }
                    catch (Exception ex)
                    {
                        this.Logger.Log(TraceEventType.Critical, LoggingMessageId.PropagationTileNotFound, string.Format("Tile Not Found for filename -> {0}", filename));
                        this.Logger.Log(TraceEventType.Critical, LoggingMessageId.PropagationException, ex.ToString());
                        fileContents = new byte[this.cacheElementSize];
                    }

                    ElevationCacheEntry newEntry = new ElevationCacheEntry(fileContents);
                    this.localCache.Add(filename, newEntry);

                    // Also add to azure cache.
                    if (this.azureCache != null)
                    {
                        // Since we just read this value from blog storage, lets also put it in azure cache.
                        this.azureCache.Put(filename, newEntry);
                    }
                }
            }
            catch (Exception ex)
            {
                // We've hit a tile in Canada. We don't care about such a tile
                // We hit a tile that does not exist for any Country in the system.
                this.Logger.Log(TraceEventType.Error, LoggingMessageId.ElevationGlobUnsupportedTileId, logMethodName);
                this.Logger.Log(TraceEventType.Error, LoggingMessageId.ElevationGlobUnsupportedTileId, ex.ToString());
            }
        }
Exemple #3
0
        /// <summary>
        /// Returns bytes at the specified indices
        /// </summary>
        /// <param name="fileName">File Name</param>
        /// <returns>cache object</returns>
        public object ReadCachedData(string fileName)
        {
            ElevationCacheEntry entry = this.GetElevationEntry(fileName);

            return(entry.Data);
        }