private void ChangeUiNextTimeRead()
 {
     Execute.OnUIThread(() => {
         isReadNow = false;
         NotifyOfPropertyChange(nameof(this.CanReadMailsCommand));
         nextTimeReadInt = TimeUnixService.Timestamp() + ReadInterval;
         NextTimeRead    = TimeUnixService.TimeStamToStr(nextTimeReadInt);
         LastTimeRead    = TimeUnixService.TimeStamToStr(TimeUnixService.Timestamp());
         NotifyOfPropertyChange(nameof(this.NextTimeRead));
         NotifyOfPropertyChange(nameof(this.LastTimeRead));
     });
 }
Esempio n. 2
0
        private void MakePause()
        {
            try
            {
                Random rnd = new Random();
                //set values at first start
                if (nextChangeInterval == 0)
                {
                    nextChangeInterval = TimeUnixService.Timestamp() + ChangeIntTime;
                }
                if (nextDopPause == 0)
                {
                    nextDopPause = TimeUnixService.Timestamp() + DopPauseTime;
                }

                //change interval
                if (nextChangeInterval < TimeUnixService.Timestamp())
                {
                    var inter = PauseIntervals.Where(a => a.Start > CurrentInterval.Start).OrderByDescending(st => st.Start).FirstOrDefault();
                    if (inter != null)
                    {
                        CurrentInterval = inter;
                    }
                    _logger.InfoSender($"Change pause interval {CurrentInterval.Start} - {CurrentInterval.Finish}");
                    nextChangeInterval = TimeUnixService.Timestamp() + ChangeIntTime;
                }

                //set pause value
                int pause = rnd.Next(CurrentInterval.Start, CurrentInterval.Finish);

                //add dop pause to main pause
                if (nextDopPause < TimeUnixService.Timestamp())
                {
                    var tmp = rnd.Next(DopPauseInterval.Start, DopPauseInterval.Finish);
                    pause       += tmp;
                    nextDopPause = TimeUnixService.Timestamp() + DopPauseTime;
                    _logger.InfoSender($"Add dop pause {tmp}");
                }
                _logger.InfoSender($"Set pause {pause} sec");

                //make pause
                Thread.Sleep(pause * 1000);
            }
            catch (Exception ex)
            {
                _logger.ErrorSender($"Block MakePause error {ex.Message}");
                throw ex;
            }
        }
 private void ReadService()
 {
     isReadServiceWork = true;
     _logger.InfoReader("Start read service");
     NotifyOfPropertyChange(nameof(this.CanStartReadServiceCommand));
     NotifyOfPropertyChange(nameof(this.CanStopReadServiceCommand));
     Task.Run(() => {
         while (isReadServiceWork)
         {
             if (nextTimeReadInt < TimeUnixService.Timestamp())
             {
                 if (!isReadNow)
                 {
                     ReadMailsCommand();
                 }
             }
             Thread.Sleep(5000);
         }
         NotifyOfPropertyChange(nameof(this.CanStartReadServiceCommand));
         NotifyOfPropertyChange(nameof(this.CanStopReadServiceCommand));
     });
 }