Beispiel #1
0
        /// <summary>
        /// Запускает таймер.
        /// </summary>
        public void Run()
        {
            while (true)
            {
                //признак, устанавливаемый при возникновении ошибки обработки.
                bool hasError = false;
                try
                {
                    //сбрасываем текущий контекст выполнения.
                    RuntimeContext.ResetCurrent();

                    //создаём и запускаем экземпляр сервиса.
                    ISkyService service = this.CreateService();
                    if (service == null)
                    {
                        throw new Exception("Failed to get instance of the ISkyService.");
                    }
                    service.Run();
                }
                catch (Exception ex)
                {
                    //устанавливаем признак наличия ошибки.
                    hasError = true;

                    //записываем ошибку в лог.
                    WriteErrorLog(ex, this.LogName);
                }
                finally
                {
                    //при наличии ошибки, увеличиваем интервал таймера до 30 секунд, чтобы не забивать лог ошибок.
                    if (hasError)
                    {
                        Thread.Sleep(30000);
                    }

                    //при наличии необработанных ошибок в порождённых потоков обработки, приостанавливаем на 30 сек, чтобы не забивать лог.
                    else if (HasUnhandledExecutionError)
                    {
                        //приостанавливаем работу.
                        Thread.Sleep(30000);

                        //сбрасываем идентификатор основного потока, если установлена соответствующая директива из порождённого потока обработки.
                        HasUnhandledExecutionError = false;
                    }

                    //при отсутствии ошибок выполняем таймер с частотой в 1 секунду.
                    else
                    {
                        Thread.Sleep(1000);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Initializes the input manager.
        /// </summary>
        public override void Initialize()
        {
            Logger.Trace("init()");

            // import required services.
            this._world                 = (IWorld)this.Game.Services.GetService(typeof(IWorld));
            this._player                = (IPlayer)this.Game.Services.GetService(typeof(IPlayer));
            this._graphicsManager       = (IGraphicsManager)this.Game.Services.GetService(typeof(IGraphicsManager));
            this._cameraController      = (ICameraControlService)this.Game.Services.GetService(typeof(ICameraControlService));
            this._ingameDebuggerService = (IInGameDebuggerService)this.Game.Services.GetService(typeof(IInGameDebuggerService));
            this._fogger                = (IFogger)this.Game.Services.GetService(typeof(IFogger));
            this._skyService            = (ISkyService)this.Game.Services.GetService(typeof(ISkyService));
            this._chunkCache            = (IChunkCache)this.Game.Services.GetService(typeof(IChunkCache));
            this._bloomService          = (IBloomService)this.Game.Services.GetService(typeof(IBloomService));

            // get current mouse & keyboard states.
            this._previousKeyboardState = Keyboard.GetState();
            this._previousMouseState    = Mouse.GetState();

            base.Initialize();
        }
Beispiel #3
0
        /// <summary>
        /// Initializes the input manager.
        /// </summary>
        public override void Initialize()
        {
            Logger.Trace("init()");

            // import required services.
            this._world = (IWorld) this.Game.Services.GetService(typeof (IWorld));
            this._player = (IPlayer) this.Game.Services.GetService(typeof (IPlayer));
            this._graphicsManager = (IGraphicsManager) this.Game.Services.GetService(typeof (IGraphicsManager));
            this._cameraController = (ICameraControlService) this.Game.Services.GetService(typeof (ICameraControlService));
            this._ingameDebuggerService =(IInGameDebuggerService) this.Game.Services.GetService(typeof (IInGameDebuggerService));
            this._fogger = (IFogger) this.Game.Services.GetService(typeof (IFogger));
            this._skyService = (ISkyService) this.Game.Services.GetService(typeof (ISkyService));
            this._chunkCache = (IChunkCache) this.Game.Services.GetService(typeof (IChunkCache));
            this._bloomService = (IBloomService) this.Game.Services.GetService(typeof (IBloomService));

            // get current mouse & keyboard states.
            this._previousKeyboardState = Keyboard.GetState();
            this._previousMouseState = Mouse.GetState();

            base.Initialize();
        }