Ejemplo n.º 1
0
 private void OnTimerStart(object sender, RoutedEventArgs e)
 {
     if (_timerService.IsActive)
     {
         _timerService.Stop();
     }
     TimerStatesStore.CurrentState = TimerStatesStore.States.Work;
     TimerTickProgress.Maximum     = TimerValuesStore.Timelapse;
     ActivityDataGrid.AddRow((int)TimerValuesStore.Timelapse, BaseStatesStore.IsWork);
     ActivityManager.Create(TimerValuesStore.Timelapse, BaseStatesStore.IsWork);
     _timerService.Set(TimerValuesStore.Timelapse, TimerValuesStore.TickInterval);
     _timerService.Start();
 }
Ejemplo n.º 2
0
        public async Task TimerCmd(params string[] input)
        {
            if (input[0] == "start")
            {
                TimeSpan repeat = TimeSpan.Zero;
                if (input.Length >= 3 && !string.IsNullOrEmpty(input[2]))
                {
                    repeat = TimeSpan.Parse(input[2]);
                }

                TimeSpan due = new TimeSpan(0, 5, 0);
                if (!string.IsNullOrEmpty(input[1]))
                {
                    due = TimeSpan.Parse(input[1]);
                }

                await _service.Start(Context.User.Mention, Context.Channel, due, repeat);
            }
            else if (input[0] == "stop")
            {
                await _service.Stop(Context.User.Mention, Context.Channel);
            }
            else
            {
                await ReplyAsync("Usage: !timer start/stop h:mm:ss");
            }
        }
Ejemplo n.º 3
0
        public void TimerTest_Normal()
        {
            var timer = new TimerService {
                Interval = TimeSpan.FromMilliseconds(100)
            };
            var beforeTime    = DateTime.Now;
            var notifications = new List <TimeSpan>();

            timer.Elapsed += (sender, e) =>
            {
                // 開始前時間からの経過時間を保持しておく
                notifications.Add(DateTime.Now - beforeTime);
            };
            timer.Start();
            // タイマーを動作させるため、スレッドをスリープさせる
            System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(1000));
            timer.Stop();

            // スレッドスイッチのオーバーヘッドがあるため、スリープ時間をIntervalで割った数分きっかり
            // 通知が来たりしない。
            // インターバル100[ms]で、待機時間が1000[ms]の為、8回以上通知が来ていれば良いものとする
            Assert.IsTrue(8 < notifications.Count);

            // Intervalの±20%の間に収まっていれば良いものとする
            for (int i = 0; i < notifications.Count - 1; i++)
            {
                Assert.IsTrue(TimeSpan.FromMilliseconds(100 * 0.8) < (notifications[i + 1] - notifications[i]));
                Assert.IsTrue((notifications[i + 1] - notifications[i]) < TimeSpan.FromMilliseconds(100 * 1.2));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Raised when the client disconnects from Discord.
        /// <para>
        /// Stops the <see cref="TimerService"/> and logs that the client has disconnected along with exception information.
        /// </para>
        /// </summary>
        /// <param name="e">The exception thrown on disconnect.</param>
        /// <returns>No object or value is returned by this method when it completes.</returns>
        private Task DisconnectedEventHandler(Exception e)
        {
            Console.WriteLine(
                $"\n{DateTime.Now}\nCLIENT DISCONNECTED\nMessage: {e.Message}\n---STACK TRACE---\n{e.StackTrace}\n\n");
            _timerService.Stop();

            return(Task.CompletedTask);
        }
Ejemplo n.º 5
0
        public void TimerService_TimerStoppedBeforeStarted_ThrowsException()
        {
            // Arrange
            var unitUnderTest = new TimerService();

            // Act/Assert
            Assert.Throws <InvalidOperationException>(() => unitUnderTest.Stop());
        }
Ejemplo n.º 6
0
 private void ExecuteStop(object obj)
 {
     TimerService.Stop();
     _applicationStateService.Save();
     _applicationStateService.CurrentState.ActiveTaskState = TimerState.Stopped;
     TaskCommands.TaskIdle.Execute(TaskName);
     TaskCommands.SaveTaskStart.Execute(TimeEntry);
     Update();
 }
Ejemplo n.º 7
0
        public void TimerTest_Resume()
        {
            var timer = new TimerService {
                Interval = TimeSpan.FromMilliseconds(100)
            };

            timer.Start();
            timer.Stop();
            TimerTest_Normal();
        }
Ejemplo n.º 8
0
        public void TimerService_ShouldRunNewTimer_OnRunNewTimer()
        {
            var timerService = new TimerService();
            var settingsMock = new Mock <ISimulationSettings>();

            settingsMock.Setup(s => s.IncomingFlights).Returns(new Mock <List <Flight> >().Object);
            settingsMock.Setup(s => s.OutgoingFlights).Returns(new Mock <List <Flight> >().Object);
            settingsMock.Setup(s => s.Multiplier).Returns(1);

            timerService.SetSettings(settingsMock.Object);

            timerService.RunNewTimer();
            Thread.Sleep(2000);
            timerService.Stop();

            timerService.GetTimeSinceSimulationStart().TotalMilliseconds.ShouldBeGreaterThan(2000);

            timerService.RunNewTimer();
            timerService.Stop();
            timerService.GetTimeSinceSimulationStart().TotalMilliseconds.ShouldBeLessThan(2000);
        }
Ejemplo n.º 9
0
        private static void Main()
        {
            var fileClient    = new FileClient();
            var consoleClient = new ConsloleClient();
            var timerService  = new TimerService();

            timerService.OnOneSecond += (sender, args) => consoleClient.WriteToConsole(args.EventInfo);
            timerService.OnOneSecond += (sender, args) => fileClient.WriteToFile(args.EventInfo);

            timerService.Start();

            Thread.Sleep(20000);
            timerService.Stop();
        }
Ejemplo n.º 10
0
        public void TimerService_TimerStopped_IsRunning()
        {
            // Arrange
            var unitUnderTest = new TimerService();

            unitUnderTest.Start(100);
            unitUnderTest.Pause();
            unitUnderTest.Resume();

            // Act
            unitUnderTest.Stop();

            // Arrange
            Assert.IsFalse(unitUnderTest.IsRunning);
        }
Ejemplo n.º 11
0
        public void TimerService_TimerStopped_NoEventThrown()
        {
            // Arrange
            var timerElapsedEvent = new AutoResetEvent(false);
            var unitUnderTest     = new TimerService();

            unitUnderTest.Elapsed += (sender, args) => timerElapsedEvent.Set();
            unitUnderTest.Start(100);

            // Act
            unitUnderTest.Stop();
            timerElapsedEvent.Reset();

            // Assert
            Assert.IsFalse(timerElapsedEvent.WaitOne(200), "Did not expected Elapsed event");
        }
Ejemplo n.º 12
0
 public async Task fmstoptimerAsync()
 {
     if (await _adminService.HasCommandAccessAsync(Context.User, UserType.Admin))
     {
         try
         {
             _timer.Stop();
             await ReplyAsync("Timer stopped");
         }
         catch (Exception e)
         {
             _logger.LogError(e.Message, Context.Message.Content, Context.User.Username, Context.Guild?.Name, Context.Guild?.Id);
             await ReplyAsync("The timer service cannot be loaded. Please wait for the bot to fully load.");
         }
     }
 }
Ejemplo n.º 13
0
 /// <summary>
 ///
 /// </summary>
 void HandleTimerCmd()
 {
     if (!_timerService.Enabled)
     {
         _timerService.Start();
         StartBtnText = "Stop Timer";
         elapsedTime  = 0;
     }
     else
     {
         _timerService.Stop();
         StartBtnText = "Start Timer";
         AddEntry();
     }
     IsRunning = _timerService.Enabled;
 }
Ejemplo n.º 14
0
        public void TimerService_ShouldShouldReturnSameTimeSinceStart_FromBothMethods()
        {
            var timerService = new TimerService();
            var settingsMock = new Mock <ISimulationSettings>();

            settingsMock.Setup(s => s.IncomingFlights).Returns(new Mock <List <Flight> >().Object);
            settingsMock.Setup(s => s.OutgoingFlights).Returns(new Mock <List <Flight> >().Object);
            settingsMock.Setup(s => s.Multiplier).Returns(1);

            timerService.SetSettings(settingsMock.Object);

            timerService.Start();
            Thread.Sleep(2000);
            timerService.Stop();

            timerService.GetTicksSinceSimulationStart().ShouldBeInRange(timerService.GetTimeSinceSimulationStart().Ticks - 5, timerService.GetTimeSinceSimulationStart().Ticks + 5);
        }
Ejemplo n.º 15
0
 public async Task StopCmd(string name)
 {
     _service.Stop(name);
     await ReplyAsync($"{name} timer stopped.");
 }
Ejemplo n.º 16
0
        public static void Main(string[] args)
        {
            //挂载全局异常处理
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            if (GCSettings.IsServerGC)
            {
                Console.WriteLine("GC优化已开启");
            }

            var config = Configure.Inst;

            if (!config.Load())
            {
                return;
            }

            int workerCount = config.workerCount + noTableWorkerCount;

            dbSvc.Start(config.dbConnectStr, workerCount);
            dbHelper.Start();
            workerMgr.Start(workerCount);
            if (!server.Start(config.serverPort, 10000))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("端口:{0}被占用,请按任意键退出", config.serverPort);
                Console.ResetColor();
                Console.ReadKey();
                return;
            }
            moduleManager.Start();
            timerSvc.Start();

            Console.WriteLine("游戏服务器启动完毕,端口:{0}", config.serverPort);

            //Thread thread = new Thread(ClearMemoryThreadProc);
            //thread.IsBackground = true;
            //thread.Start();

            while (true)
            {
                var key = Console.ReadKey();

                if (key.Key == ConsoleKey.S)
                {
                    Console.WriteLine("");
                    Console.WriteLine("当前连接数:{0} 连接池存量:{1}",
                                      server.connectNum, server.GetSessionPoolCount());
                    Console.WriteLine("支持游戏:{0}", Configure.Inst.supportGames);
                }
                if (key.Key == ConsoleKey.T)
                {
                    Configure.Inst.isShowStat = !Configure.Inst.isShowStat;

                    Console.WriteLine("");
                    if (Configure.Inst.isShowStat)
                    {
                        Console.WriteLine("已打开统计信息显示");
                    }
                    else
                    {
                        Console.WriteLine("已关闭统计信息显示");
                    }
                }
                if (key.Key == ConsoleKey.C)
                {
                    Console.Clear();
                }
                if (key.Key == ConsoleKey.Q)
                {
                    break;
                }
                if (key.Key == ConsoleKey.R)
                {
                    Console.WriteLine("");
                    moduleManager.gameModule.LoadAllConfigs();
                }
                if (key.Key == ConsoleKey.D1)
                {
                    Console.WriteLine("");
                    moduleManager.gameModule.SetAllGameIsShowInfo(true);
                    Console.WriteLine("已打开游戏内信息显示");
                }
                if (key.Key == ConsoleKey.D2)
                {
                    Console.WriteLine("");
                    moduleManager.gameModule.SetAllGameIsShowInfo(false);
                    Console.WriteLine("已关闭游戏内信息显示");
                }
                //if(key.Key == ConsoleKey.W)
                //{
                //    dbHelper.LogPlayGame(@"D:\Work\ChessServers\bin\GameServer\Games\Br1", "test", "12312414", "阿拉丁", 0, 100, new JObject());
                //    dbHelper.LogGame(@"D:\Work\ChessServers\bin\GameServer\Games\Br1", "test", "阿拉丁", 0, 100, new JObject());
                //}

                Thread.Sleep(100);
            }

            timerSvc.Stop();
            moduleManager.Stop();
            server.Stop();
            workerMgr.Stop();
            dbHelper.Stop();
            dbSvc.Stop();
        }
Ejemplo n.º 17
0
        public static void Main(string[] args)
        {
            //挂载全局异常处理
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            if (GCSettings.IsServerGC)
            {
                Console.WriteLine("GC优化已开启");
            }

            var config = Configure.Inst;

            if (!config.Load())
            {
                return;
            }

            dbSvc.Start(config.dbConnectStr, config.workerCount + 1);
            dbHelper.Start();
            workerMgr.Start(config.workerCount);
            if (!server.Start(config.serverPort, 10000))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("端口:{0}被占用,请按任意键退出", config.serverPort);
                Console.ResetColor();
                Console.ReadKey();
                return;
            }
            moduleManager.Start();
            timerSvc.Start();

            Console.WriteLine("大厅服务器启动完毕,端口:{0}", config.serverPort);

            while (true)
            {
                var key = Console.ReadKey();

                if (key.Key == ConsoleKey.S)
                {
                    Console.WriteLine("");
                    Console.WriteLine("当前连接数:{0} 连接池存量:{1}",
                                      server.connectNum, server.GetSessionPoolCount());
                }
                if (key.Key == ConsoleKey.T)
                {
                    Configure.Inst.isShowStat = !Configure.Inst.isShowStat;

                    Console.WriteLine("");
                    if (Configure.Inst.isShowStat)
                    {
                        Console.WriteLine("已打开统计信息显示");
                    }
                    else
                    {
                        Console.WriteLine("已关闭统计信息显示");
                    }
                }
                if (key.Key == ConsoleKey.C)
                {
                    Console.Clear();
                }
                if (key.Key == ConsoleKey.Q)
                {
                    break;
                }

                Thread.Sleep(100);
            }

            timerSvc.Stop();
            moduleManager.Stop();
            server.Stop();
            workerMgr.Stop();
            dbHelper.Stop();
            dbSvc.Stop();
        }
Ejemplo n.º 18
0
 public void  Stop()
 {
     myTimerService.Stop(this);
 }
Ejemplo n.º 19
0
        public void TimerTest_StopBeforeStart()
        {
            var timer = new TimerService();

            timer.Stop();
        }