From fb6127d281025e1d475c68e7d288d8832d6709a1 Mon Sep 17 00:00:00 2001 From: chsakell Date: Tue, 4 Oct 2016 13:24:33 +0300 Subject: [PATCH] remove timer service --- Controllers/HomeController.cs | 62 ------------------------- Core/Timer/ITimerService.cs | 9 ---- Core/Timer/TimerEventArgs.cs | 14 ------ Core/Timer/TimerService.cs | 28 ----------- Core/Timer/TimerServiceConfiguration.cs | 9 ---- Startup.cs | 5 -- appsettings.json | 4 -- 7 files changed, 131 deletions(-) delete mode 100644 Core/Timer/ITimerService.cs delete mode 100644 Core/Timer/TimerEventArgs.cs delete mode 100644 Core/Timer/TimerService.cs delete mode 100644 Core/Timer/TimerServiceConfiguration.cs diff --git a/Controllers/HomeController.cs b/Controllers/HomeController.cs index 3c8d7a5..80320c8 100644 --- a/Controllers/HomeController.cs +++ b/Controllers/HomeController.cs @@ -1,13 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; -using AutoMapper; -using LiveGameFeed.Controllers; -using LiveGameFeed.Core.MvcTimer; using LiveGameFeed.Data.Abstract; -using LiveGameFeed.Data.Repositories; using LiveGameFeed.Hubs; -using LiveGameFeed.Models; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR.Infrastructure; @@ -20,72 +13,17 @@ namespace LiveGameFeed.Controllers private Object lockOb = new Object(); public HomeController(IConnectionManager signalRConnectionManager, - ITimerService timerService, IMatchRepository matchRepository, IFeedRepository feedRepository) : base(signalRConnectionManager) { _matchRepository = matchRepository; _feedRepository = feedRepository; - // timerService.TimerElapsed += _feed_Generate; } public IActionResult Index() { return View(); } - - private async void _feed_Generate(object sender, EventArgs e) - { - TimerEventArgs eventsArgs = e as TimerEventArgs; - System.Diagnostics.Debug.WriteLine("hello from home ApiHubController.cs.."); - lock (this.lockOb) - { - UpdateScores(); - } - //await Clients.All.userConnected(DateTime.Now); - //_coolMessageHubContext.Clients.All.newCpuValue(eventsArgs.Value); - } - - private async void UpdateScores() - { - Random r = new Random(); - bool updateHost = r.Next(0, 2) == 0; - - IEnumerable matches = _matchRepository.GetAll(); - - foreach (var match in matches) - { - if (updateHost) - { - match.HostScore = match.HostScore + 2; - Feed feed = new Feed() - { - Description = "2 points for " + match.Host + "!", - CreatedAt = DateTime.Now, - MatchId = match.Id - }; - - match.Feeds.Add(feed); - } - else - { - match.GuestScore = match.GuestScore + 2; - Feed feed = new Feed() - { - Description = "2 points for " + match.Guest + "!", - CreatedAt = DateTime.Now, - MatchId = match.Id - }; - match.Feeds.Add(feed); - } - - _matchRepository.Commit(); - MatchViewModel _matchVM = Mapper.Map(match); - FeedViewModel _feedVM = Mapper.Map(match.Feeds.Last()); - await Clients.All.updateMatch(_matchVM); - await Clients.Group(match.Id.ToString()).addFeed(_feedVM); - } - } } } \ No newline at end of file diff --git a/Core/Timer/ITimerService.cs b/Core/Timer/ITimerService.cs deleted file mode 100644 index cdf92d9..0000000 --- a/Core/Timer/ITimerService.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace LiveGameFeed.Core.MvcTimer -{ - public interface ITimerService - { - event EventHandler TimerElapsed; - } -} \ No newline at end of file diff --git a/Core/Timer/TimerEventArgs.cs b/Core/Timer/TimerEventArgs.cs deleted file mode 100644 index da581c2..0000000 --- a/Core/Timer/TimerEventArgs.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace LiveGameFeed.Core.MvcTimer -{ - public class TimerEventArgs : EventArgs - { - public TimerEventArgs(int value) - { - Value = value; - } - - public int Value { get; } - } -} \ No newline at end of file diff --git a/Core/Timer/TimerService.cs b/Core/Timer/TimerService.cs deleted file mode 100644 index 82c6108..0000000 --- a/Core/Timer/TimerService.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Threading; -using Microsoft.Extensions.Options; - -namespace LiveGameFeed.Core.MvcTimer -{ - public class TimerService : ITimerService - { - private Timer _timer; - readonly Random _random = new Random(); - public event EventHandler TimerElapsed; - - public TimerService(IOptions options) - { - var optionsTimerServiceConfiguration = options; - _timer = new Timer( - OnTimerElapsed, - null, - optionsTimerServiceConfiguration.Value.DueTime, - optionsTimerServiceConfiguration.Value.Period); - } - - private void OnTimerElapsed(object sender) - { - TimerElapsed?.Invoke(this, new TimerEventArgs(_random.Next(0, 100))); - } - } -} diff --git a/Core/Timer/TimerServiceConfiguration.cs b/Core/Timer/TimerServiceConfiguration.cs deleted file mode 100644 index 418adb8..0000000 --- a/Core/Timer/TimerServiceConfiguration.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace LiveGameFeed.Core.MvcTimer -{ - public class TimerServiceConfiguration - { - public int DueTime { get; set; } - - public int Period { get; set; } - } -} diff --git a/Startup.cs b/Startup.cs index 7390016..150071c 100644 --- a/Startup.cs +++ b/Startup.cs @@ -12,7 +12,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using LiveGameFeed.Core.Mappings; -using LiveGameFeed.Core.MvcTimer; using Newtonsoft.Json.Serialization; using RecurrentTasks; using LiveGameFeed.Core; @@ -41,10 +40,6 @@ namespace LiveGameFeed services.AddSingleton(); services.AddSingleton(); - // Timer service configuration - services.AddSingleton(); - services.Configure(Configuration.GetSection("TimeService")); - // Automapper Configuration AutoMapperConfiguration.Configure(); diff --git a/appsettings.json b/appsettings.json index 4a39375..723c096 100644 --- a/appsettings.json +++ b/appsettings.json @@ -6,9 +6,5 @@ "System": "Information", "Microsoft": "Information" } - }, - "TimeService": { - "DueTime": 10000, - "Period": 10000 } }