示例#1
0
        private void Fetch(TileInfo tileInfo)
        {
            try
            {
                var data = _tileSource.Provider.GetTile(tileInfo);
                _fileCache.Add(tileInfo.Index, data);

                _fileCache.AddWorldFile(tileInfo, _tileSource.Schema.GetTileHeight("0"), _tileSource.Schema.GetTileHeight("0"),
                                        _tileSource.Schema.Format);
            }
            catch (Exception)
            {
            }
        }
示例#2
0
        private void FetchAsync(TileInfo tileInfo)
        {
            ThreadPool.QueueUserWorkItem(
                source =>
            {
                Exception error = null;
                Tile <T> tile   = null;

                try
                {
                    if (_tileSource != null)
                    {
                        byte[] data = _tileSource.Provider.GetTile(tileInfo);
                        _fileCache.Add(tileInfo.Index, data);

                        _fileCache.AddWorldFile(tileInfo, _tileSource.Schema.GetTileHeight("0"), _tileSource.Schema.GetTileHeight("0"),
                                                _tileSource.Schema.Format);
                        tile = new Tile <T> {
                            Data = data, Info = tileInfo
                        };
                    }
                }
                catch (Exception ex)     //This may seem a bit weird. We catch the exception to pass it as an argument. This is because we are on a worker thread here, we cannot just let it fall through.
                {
                    error = ex;
                }

                lock (_tilesInProgress)
                {
                    if (_tilesInProgress.Contains(tileInfo.Index))
                    {
                        _tilesInProgress.Remove(tileInfo.Index);
                    }
                }

                _waitHandle.Set();
                if (DataChanged != null && !_isAborted)
                {
                    DataChanged(this, new DataChangedEventArgs <T>(error, false, tile));
                }
            });
        }