public void Start(ITimeHolder timeHolder) { _timer = new Timer((e) => { timeHolder.Time = DateTime.UtcNow; }, null, TimeSpan.Zero, TimeSpan.FromSeconds(1)); }
private async void Sync(ITimeHolder timeHolder) { var temp = await _webAPI.GetTimeAsync(); if (Math.Abs((temp - timeHolder.Time).TotalSeconds) > 10) { timeHolder.Time = temp; } }
public void Start(ITimeHolder timeHolder) { var counter = 0; _timer = new Timer((e) => { if (counter % 5 == 0) { Sync(timeHolder); } timeHolder.Time = timeHolder.Time.AddSeconds(1); counter++; }, null, TimeSpan.Zero, TimeSpan.FromSeconds(1)); }
public async Task InvokeAsync(HttpContext context, ITimeHolder timeholder) { var currentTime = DateTimeOffset.UtcNow; if (currentTime.Hour > 8 && currentTime.Hour < 16) { timeholder.Memorize(currentTime); BeforeGoingToNextMiddleware(context); await _next.Invoke(context); ReturningFromNextMiddleware(context); } }
public WeatherForecastController(ILogger <WeatherForecastController> logger, ITimeHolder timeHolder) { _logger = logger; _timeHolder = timeHolder; }