public async Task GetStatus() { var count = await HinasukiRepository.GetCount(); await Clients.Caller.SendAsync("Hinasuki", count); await Clients.Caller.SendAsync("UserCount", HinasukiHubValue.UserCount); }
public HinasukiHubValue(HinasukiRepository hinasukiRepository, IHubContext <HinasukiHub> hinasukiHubContext) { HinasukiRepository = hinasukiRepository ?? throw new ArgumentNullException(nameof(hinasukiRepository)); HinasukiHubContext = hinasukiHubContext ?? throw new ArgumentNullException(nameof(hinasukiHubContext)); NotifyTimer = new System.Timers.Timer() { AutoReset = true, Interval = 100, }; NotifyTimer.Elapsed += NotifyTimer_Elapsed; NotifyTimer.Start(); }
private async void NotifyTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (IsNotify == 0) { return; } var count = await HinasukiRepository.GetCount(); if (OldCount == count) { Interlocked.Exchange(ref IsNotify, 0); return; } await HinasukiHubContext.Clients.All.SendAsync("Hinasuki", count); OldCount = count; }
public async Task AddCount() { await HinasukiRepository.AddCount(); Interlocked.Exchange(ref IsNotify, 1); }
public HinasukiHub(HinasukiHubValue hinasukiHubValue, HinasukiRepository hinasukiRepository) { HinasukiHubValue = hinasukiHubValue ?? throw new ArgumentNullException(nameof(hinasukiHubValue)); HinasukiRepository = hinasukiRepository ?? throw new ArgumentNullException(nameof(hinasukiRepository)); }