Example #1
0
        async void _timer_Elapsed(object sender, EventArgs e)
        {
            if (CurrentService == null || CurrentService.ExpirationDate == default(DateTime))
            {
                return;
            }

            CurrentService.RestDuration -= _timer.Interval / 1000.0 / 60.0;

            var diff          = CurrentService.ExpirationDate.Subtract(DateTime.Now);
            var otherServices = _billing.GetActiveUserServices()
                                .Where(s => s != CurrentService && s.Plugin == CurrentService.Plugin && (s.RestDuration > 0 || s.Duration == -1));

            if (CurrentService.RestDuration <= 0)
            {
                _timer.Stop();
                try
                {
                    if (_item != null)
                    {
                        var s = await _billing.GetServiceForItemAsync(CurrentService.Plugin, _item);

                        if (s != null)
                        {
                            CurrentService = s;
                            _timer.Start();
                            return;
                        }
                    }
                    else
                    {
                        var s2 = await _billing.GetServiceAsync(CurrentService.Plugin);

                        if (s2 != null)
                        {
                            CurrentService = s2;
                            _timer.Start();
                            return;
                        }
                    }
                    var h = ServiceExpired;
                    h?.Invoke(this, CurrentService);
                }
                catch
                {
                    _timer.Start();
                }
                return;
            }

            if (otherServices.Any())
            {
                return;
            }


            if (CurrentService.RestDuration <= 20)
            {
                if (_n30min)
                {
                    return;
                }
                ShowPopup(CurrentService.ExpirationDate);
                _n30min = true;
            }
            else if (CurrentService.RestDuration <= 120)
            {
                if (_n1Hour)
                {
                    return;
                }
                ShowPopup(CurrentService.ExpirationDate);
                _n1Hour = true;
            }
        }