public void Start()
 {
     if (_worker != null)
     {
         _worker.Start();
     }
     TryDoFails();
     _source.EnumerateTileRange(_mapConfig.LastTile,
                                (zoom) =>
     {
         _tilePathBuilder.BuildZoomFold(zoom, _mapConfig.OffsetZoom);
     },
                                (tile) =>
     {
         _worker.TryQueue(new TileCoordWrap
         {
             Tile      = tile,
             OnSuccess = null,
             OnFailed  = (tile1, ex) =>
             {
                 _failsProvider.Insert(tile1);
                 Console.WriteLine(ex.Message);
             },
             OnFinally = (tile2) =>
             {
                 _mapConfig.LastTile = tile2;
                 if (_currTileIndex == TotalTile)
                 {
                     _mapConfig.Save();
                     OnFinished();
                 }
             }
         });
     });
 }
        public void Start()
        {
            if (_worker != null)
            {
                _worker.Start();
            }
            //重试失败的瓦片;
            TryDoFails();

            //从最后一次的瓦片开始下载瓦片
            _source.EnumerateTileRange(_mapConfig.Result.LastTile,
                                       (tile) =>
            {
                _worker.TryQueue(new TileCoordWrap
                {
                    Tile      = tile,
                    OnSuccess = (tile1) => {
                        Interlocked.Increment(ref _successTileIndex);
                        Task.Run(() =>
                        {
                            OnTileLoaded(tile1);
                        });
                    },
                    OnFailed = (tile1, ex) =>
                    {
                        _failsStrategy.Insert(tile1);
                        Console.WriteLine(string.Format("Tile : zoom :  {0} x: {1} y :{2},有异常:{3}", tile1.Zoom, tile1.X,
                                                        tile1.Y, ex.Message));
                    },
                    OnFinally = (tile2) =>
                    {
                        lock (this)
                        {
                            if (_currTileIndex >= TotalTile)
                            {
                                Task.Run(() =>
                                {
                                    var msg = string.Format("{瓦片下载完成... 完成情况:{0}/{1},失败:{2}!", _successTileIndex, TotalTile, FailTiles);
                                    OnFinished(msg);
                                });
                            }
                        }
                    }
                });
            });
        }