예제 #1
0
        public void Enqueue(int bandNo, LevelId level)
        {
            string key = _cacheNameHelper.GetResourceKey(bandNo, level.No);

            if (_readFileStreams.ContainsKey(key))
            {
                return;
            }
            BandLevelTask task = new BandLevelTask();

            task.BandNo = bandNo;
            task.Level  = level;
            _bandLevelQueue.Enqueue(task);
        }
예제 #2
0
        private unsafe void DoBandLevelTask(BandLevelTask bandLevelTask)
        {
            _isDoingLargerTask = true;
            try
            {
                string fname = _cacheNameHelper.GetCacheFilename(_cacheFolder, bandLevelTask.BandNo, bandLevelTask.Level.No);
                using (FileStream fs = new FileStream(fname, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
                {
                    using (BinaryWriter bw = new BinaryWriter(fs))
                    {
                        IRasterBand band   = _dataProvider.GetRasterBand(bandLevelTask.BandNo);
                        int         tCount = bandLevelTask.Level.Tiles.Length;
                        TileId[]    tiles  = bandLevelTask.Level.Tiles;
                        TileId      tile;
                        LevelId     lv   = bandLevelTask.Level;
                        byte[]      data = new byte[_tileBufferSize];
                        fixed(byte *ptr = data)
                        {
                            IntPtr buffer = new IntPtr(ptr);

                            for (int i = 0; i < tCount; i++)
                            {
                                tile = tiles[i];
                                band.Read(
                                    (int)(_tileSize * tile.Col / lv.Scale),
                                    (int)(_tileSize * tile.Row / lv.Scale),
                                    (int)(tile.Width / lv.Scale),
                                    (int)(tile.Height / lv.Scale),
                                    buffer, _dataProvider.DataType, tile.Width, tile.Height);
                                bw.Write(data);
                                //
                                if (_needPauseLargerTask)
                                {
                                    Console.WriteLine("需要暂停长任务。");
                                    _needPauseLargerTask = false;
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                _isDoingLargerTask = false;
            }
        }
예제 #3
0
 void Application_Idle(object sender, EventArgs e)
 {
     //return;
     if (_bandLevelQueue.Count > 0)
     {
         BandLevelTask task = _bandLevelQueue.Dequeue();
         task.FileName = _cacheNameHelper.GetCacheFilename(_cacheFolder, task.BandNo, task.Level.No);
         //将任务插入到读取栈
         _taskStack.Push(task);
     }
     else
     {
         if (_workerIsFinisehd)
         {
             _isStarted = false;
             Start();
         }
     }
 }