public async Task <IActionResult> GetHq(string path, string panoramaId) { Console.WriteLine("HQ called!"); var tile = await _tileService.GetTile(path, panoramaId, true); var model = Mapper.Map <TileModel>(tile); return(base.File(tile.Stream, model.Source)); }
/// <summary> /// Populates the tile cache for the configured tiled map definition or tile set /// </summary> /// <param name="progress"></param> /// <returns></returns> public TileSeedStats Run(IProgress <TileProgress> progress = null) { var failed = 0; var rendered = 0; var sw = new Stopwatch(); sw.Start(); Action <Action <TileRef>, TileRef> executor = _options.Executor ?? DefaultExecutor; var maxThreads = _options.MaxDegreeOfParallelism; var resId = _walker.ResourceID; var tiles = _walker.GetTileList(); var total = tiles.Length; var interval = 1000; //Every second using (new Timer(_ => progress?.Report(new TileProgress(rendered, total, failed)), null, interval, interval)) { Action <TileRef> fetcher = tile => { try { using (_tileSvc.GetTile(resId, tile.GroupName, tile.Col, tile.Row, tile.Scale)) { Interlocked.Increment(ref rendered); } } catch (Exception ex) { _options.ErrorLogger?.Invoke(tile, ex); Interlocked.Increment(ref failed); } }; if (maxThreads.HasValue) { var popts = new ParallelOptions(); popts.MaxDegreeOfParallelism = maxThreads.Value; Parallel.ForEach(tiles, popts, t => executor(fetcher, t)); } else { Parallel.ForEach(tiles, t => executor(fetcher, t)); } } // And this method blocks! So if we get to this point, everything has been iterated through and // this the tiling run has finished. sw.Stop(); return(new TileSeedStats { ResourceID = resId, TilesRendered = rendered, Duration = sw.Elapsed }); }
/// <summary> /// Renders a single tile /// </summary> /// <param name="ev"></param> /// <param name="tileSvc"></param> /// <param name="row">The row index of the tile</param> /// <param name="col">The column index of the tile</param> /// <param name="scaleindex">The scale index of the tile</param> /// <param name="group">The name of the baselayer group</param> private void RenderTile(EventWaitHandle ev, ITileService tileSvc, long row, long col, int scaleindex, string group) { ev.Reset(); lock (_syncLock) { _raiseEvents.Enqueue(new EventPassing( EventPassing.EventType.Begin, (int)row, (int)col, null, ev )); _event.Set(); } ev.WaitOne(Timeout.Infinite, true); int c = _parent.Config.RetryCount; while (c > 0) { c--; try { if (!_parent.Cancel) { if (_parent.Config.RenderMethod == null) { tileSvc.GetTile(_mapDefinition, group, (int)col, (int)row, scaleindex).Dispose(); //NOXLATE } else { _parent.Config.RenderMethod(_mapDefinition, group, (int)col, (int)row, scaleindex); } } break; } catch (Exception ex) { if (c == 0) { Exception pex = ex; ev.Reset(); EventPassing evobj = new EventPassing( EventPassing.EventType.Error, (int)row, (int)col, ex, ev ); lock (_syncLock) { _raiseEvents.Enqueue(evobj); _event.Set(); } ev.WaitOne(Timeout.Infinite, true); if (evobj.Result == null) { break; } if (pex == evobj.Result) { throw; } else { throw (Exception)evobj.Result; } } } } ev.Reset(); lock (_syncLock) { _raiseEvents.Enqueue(new EventPassing( EventPassing.EventType.Finish, (int)row, (int)col, null, ev )); _event.Set(); } ev.WaitOne(Timeout.Infinite, true); }
/// <summary> /// Renders a single tile /// </summary> /// <param name="ev"></param> /// <param name="tileSvc"></param> /// <param name="row">The row index of the tile</param> /// <param name="col">The column index of the tile</param> /// <param name="scaleindex">The scale index of the tile</param> /// <param name="group">The name of the baselayer group</param> private void RenderTile(EventWaitHandle ev, ITileService tileSvc, long row, long col, int scaleindex, string group) { ev.Reset(); lock (SyncLock) { RaiseEvents.Enqueue(new EventPassing( EventPassing.EventType.Begin, (int)row, (int)col, null, ev )); Event.Set(); } ev.WaitOne(Timeout.Infinite, true); int c = Parent.Config.RetryCount; while (c > 0) { c--; try { if (!Parent.Cancel) if (Parent.Config.RenderMethod == null) tileSvc.GetTile(MapDefinition, group, (int)col, (int)row, scaleindex, "PNG").Dispose(); //NOXLATE else Parent.Config.RenderMethod(MapDefinition, group, (int)col, (int)row, scaleindex); break; } catch (Exception ex) { if (c == 0) { Exception pex = ex; ev.Reset(); EventPassing evobj = new EventPassing( EventPassing.EventType.Error , (int)row, (int)col, ex, ev ); lock (SyncLock) { RaiseEvents.Enqueue(evobj); Event.Set(); } ev.WaitOne(Timeout.Infinite, true); if (evobj.Result == null) break; if (pex == evobj.Result) throw; else throw (Exception)evobj.Result; } } } ev.Reset(); lock (SyncLock) { RaiseEvents.Enqueue(new EventPassing( EventPassing.EventType.Finish, (int)row, (int)col, null, ev )); Event.Set(); } ev.WaitOne(Timeout.Infinite, true); }