Exemplo n.º 1
0
        public void RunAndWait()
        {
            ThreadPool.QueueUserWorkItem(QueueFiller);
            for (int i = 0; i < _parent.Config.ThreadCount; i++)
            {
                ThreadPool.QueueUserWorkItem(ThreadRender);
            }

            bool completed = false;

            while (!completed)
            {
                EventPassing eventToRaise = null;
                while (true)
                {
                    lock (_syncLock)
                    {
                        if (_raiseEvents.Count > 0)
                        {
                            eventToRaise = _raiseEvents.Dequeue();
                        }
                    }

                    if (eventToRaise == null)
                    {
                        //No more events
                        break;
                    }
                    else
                    {
                        switch (eventToRaise.Type)
                        {
                        case EventPassing.EventType.Begin:
                            _parent.InvokeBeginRendering(
                                _invoker,
                                _group,
                                _scale,
                                eventToRaise.Row,
                                eventToRaise.Col);
                            break;

                        case EventPassing.EventType.Finish:
                            _parent.InvokeFinishRendering(
                                _invoker,
                                _group,
                                _scale,
                                eventToRaise.Row,
                                eventToRaise.Col);
                            break;

                        case EventPassing.EventType.Error:
                            eventToRaise.Result = _parent.InvokeError(
                                _invoker,
                                _group,
                                _scale,
                                eventToRaise.Row,
                                eventToRaise.Col,
                                eventToRaise.Exception);
                            break;

                        default:
                            //Not translated, because it is an internal error that should never happen
                            throw new Exception("Bad event type");     //NOXLATE
                        }
                        eventToRaise.Event.Set();
                        eventToRaise = null;
                    }
                }

                lock (_syncLock)
                {
                    if (_completeFlag == 0 && _raiseEvents.Count == 0)
                    {
                        completed = true;
                    }
                }

                if (!completed)
                {
                    _event.WaitOne(5 * 1000, true);
                }
            }
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <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);
        }