示例#1
0
        // retrieve global and per-instance tile packs
        public async Task RefreshLayers()
        {
            // we don't want to do this more than once at the same time so we will need to track that.

            // stop watching for filesystem changes while we download
            watcher.EnableRaisingEvents = false;

            // check for map packs first.
            _logger.LogDebug("Starting Refreshing layers");

            var packs = await PackContainer.List();

            foreach (var pack in packs)
            {
                var thispackfile = Path.Combine(CurrentOptions.PackPath, pack);
                if (await PackContainer.GetIfNewer(pack, thispackfile))
                {
                    // extract pack to appropriate places
                    using (var zip = ZipFile.OpenRead(thispackfile))
                    {
                        foreach (var entry in zip.Entries)
                        {
                            var fn  = Path.GetFileName(entry.FullName);
                            var ext = Path.GetExtension(fn);
                            if (ext.Equals(".json"))
                            {
                                var style = Path.Combine(CurrentOptions.StylePath, fn);
                                if (NeedToExtract(style, entry.Length))
                                {
                                    _logger.LogDebug($"Extracting {style}.");
                                    entry.ExtractToFile(style, true);
                                }
                            }

                            if (ext.Equals(".mbtiles"))
                            {
                                var tile = Path.Combine(CurrentOptions.TilePath, fn);
                                if (NeedToExtract(tile, entry.Length))
                                {
                                    _logger.LogDebug($"Extracting {tile}.");
                                    entry.ExtractToFile(tile, true);
                                    OpenService(tile);
                                }
                            }
                        }
                    }
                }
            }

            // see if there's any new standalone map layers
            _logger.LogDebug("Checking for standalone layers");

            var mbtiles = await TileContainer.List();

            foreach (var mbtile in mbtiles)
            {
                var thismbtile = Path.Combine(CurrentOptions.TilePath, mbtile);
                if (await PackContainer.GetIfNewer(mbtile, thismbtile))
                {
                    OpenService(thismbtile);
                }
            }

            // reenable watching for filesystem changes
            watcher.EnableRaisingEvents = true;

            _logger.LogDebug("Ending Refreshing layers");
        }