Пример #1
0
        public async Task GetStatus()
        {
            var count = await HinasukiRepository.GetCount();

            await Clients.Caller.SendAsync("Hinasuki", count);

            await Clients.Caller.SendAsync("UserCount", HinasukiHubValue.UserCount);
        }
Пример #2
0
        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();
        }
Пример #3
0
        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;
        }
Пример #4
0
        public async Task AddCount()
        {
            await HinasukiRepository.AddCount();

            Interlocked.Exchange(ref IsNotify, 1);
        }
Пример #5
0
 public HinasukiHub(HinasukiHubValue hinasukiHubValue, HinasukiRepository hinasukiRepository)
 {
     HinasukiHubValue   = hinasukiHubValue ?? throw new ArgumentNullException(nameof(hinasukiHubValue));
     HinasukiRepository = hinasukiRepository ?? throw new ArgumentNullException(nameof(hinasukiRepository));
 }