mirror of
https://github.com/chsakell/aspnet-core-signalr-angular.git
synced 2025-12-22 17:27:48 +00:00
added timer service to home controller
This commit is contained in:
15
Core/Mappings/AutoMapperConfiguration.cs
Normal file
15
Core/Mappings/AutoMapperConfiguration.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using AutoMapper;
|
||||
|
||||
namespace LiveGameFeed.Core.Mappings
|
||||
{
|
||||
public class AutoMapperConfiguration
|
||||
{
|
||||
public static void Configure()
|
||||
{
|
||||
Mapper.Initialize(x =>
|
||||
{
|
||||
x.AddProfile<DomainToViewModelMappingProfile>();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Core/Mappings/DomainToViewModelMappingProfile.cs
Normal file
14
Core/Mappings/DomainToViewModelMappingProfile.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using AutoMapper;
|
||||
using LiveGameFeed.Models;
|
||||
|
||||
namespace LiveGameFeed.Core.Mappings
|
||||
{
|
||||
public class DomainToViewModelMappingProfile : Profile
|
||||
{
|
||||
protected override void Configure()
|
||||
{
|
||||
Mapper.CreateMap<Match, MatchViewModel>();
|
||||
Mapper.CreateMap<Feed, FeedViewModel>();
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Core/Timer/ITimerService.cs
Normal file
9
Core/Timer/ITimerService.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace LiveGameFeed.Core.MvcTimer
|
||||
{
|
||||
public interface ITimerService
|
||||
{
|
||||
event EventHandler TimerElapsed;
|
||||
}
|
||||
}
|
||||
14
Core/Timer/TimerEventArgs.cs
Normal file
14
Core/Timer/TimerEventArgs.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace LiveGameFeed.Core.MvcTimer
|
||||
{
|
||||
public class TimerEventArgs : EventArgs
|
||||
{
|
||||
public TimerEventArgs(int value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public int Value { get; }
|
||||
}
|
||||
}
|
||||
28
Core/Timer/TimerService.cs
Normal file
28
Core/Timer/TimerService.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
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<TimerServiceConfiguration> 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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Core/Timer/TimerServiceConfiguration.cs
Normal file
9
Core/Timer/TimerServiceConfiguration.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace LiveGameFeed.Core.MvcTimer
|
||||
{
|
||||
public class TimerServiceConfiguration
|
||||
{
|
||||
public int DueTime { get; set; }
|
||||
|
||||
public int Period { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user