Esempio n. 1
0
        public void PutTile <T>(TileIdentify tile, int bandNo, T[] buffer)
        {
            long id = long.Parse(bandNo.ToString() + tile.TileNo.ToString());

            if (_cachedFiles.Contains(id))
            {
                return;
            }
            string fname = GetTileBufferFileName(tile, bandNo);
            int    len   = tile.Width * tile.Height * DataTypeHelper.SizeOf(_dataProvider.DataType);

            byte[]   dstBuffer = new byte[len];
            GCHandle srcHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            GCHandle dstHandle = GCHandle.Alloc(dstBuffer, GCHandleType.Pinned);

            try
            {
                WinAPI.MemoryCopy(dstHandle.AddrOfPinnedObject(), srcHandle.AddrOfPinnedObject(), len);
tryAgainLine:
                try
                {
                    File.WriteAllBytes(fname, dstBuffer);
                }
                catch (DirectoryNotFoundException)//缓存目录被删除
                {
                    Directory.CreateDirectory(_fDir);
                    goto tryAgainLine;
                }
                catch (IOException ioex)
                {
                    if (ioex.Message.Contains("磁盘空间"))
                    {
                        FileDiskCacheManagerFactory.TryFreeDiskspace(_fDir);
                    }
                    return;
                }
                _cachedFiles.Add(id);
            }
            finally
            {
                srcHandle.Free();
                dstHandle.Free();
            }
        }
Esempio n. 2
0
 private void ActiveFileDiskCacheManager()
 {
     _fileDiskCacheManager = FileDiskCacheManagerFactory.Active(_dataProvider);
     _enableDiskCache      = _fileDiskCacheManager != null;
 }