예제 #1
0
 public override void Invoke()
 {
     if ((Execute || ExecuteOnLoad && Wrapper.LoadedFrame) && !WasExecuted(Wrapper.BrowserId))
     {
         OnBeforeExecute?.Invoke(this, Wrapper);
         Operation(Wrapper);
         Executed.UpdateGeneric(Wrapper.BrowserId, true);
         OnAfterExecute?.Invoke(this, Wrapper);
     }
 }
        /// <summary>
        /// Executes a task
        /// </summary>
        public virtual void Execute()
        {
            OnBeforeExecute?.Invoke(this, new EventArgs());
            const int maxTries     = 3;
            var       queuedEmails = _queuedEmailService.SearchEmails(null, null, null, null,
                                                                      true, true, maxTries, false, 0, 500);

            foreach (var queuedEmail in queuedEmails)
            {
                var bcc = string.IsNullOrWhiteSpace(queuedEmail.Bcc)
                            ? null
                            : queuedEmail.Bcc.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                var cc = string.IsNullOrWhiteSpace(queuedEmail.CC)
                            ? null
                            : queuedEmail.CC.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                try
                {
                    _emailSender.SendEmail(_emailAccountService.GetEmailAccountById(queuedEmail.EmailAccountId),
                                           queuedEmail.Subject,
                                           queuedEmail.Body,
                                           queuedEmail.From,
                                           queuedEmail.FromName,
                                           queuedEmail.To,
                                           queuedEmail.ToName,
                                           queuedEmail.ReplyTo,
                                           queuedEmail.ReplyToName,
                                           bcc,
                                           cc);

                    queuedEmail.SentOnUtc = DateTime.UtcNow;
                }
                catch (Exception exc)
                {
                    _logger.Error($"Error sending e-mail. {exc.Message}", exc);
                }
                finally
                {
                    queuedEmail.SentTries += 1;
                    _queuedEmailService.UpdateQueuedEmail(queuedEmail);
                }
            }
            OnAfterExecute?.Invoke(this, new EventArgs());
        }
예제 #3
0
        private void Execute(object state)
        {
            if (!_started)
            {
                return;
            }
            if (null != OnBeforeExecute)
            {
                OnBeforeExecute.Invoke(this);
            }
            var t          = ExecuteWorker();
            var normaltime = false;

            try{
                normaltime = t.Wait(WaitInterval);
            }
            catch {
            }

            if (null != OnComplete)
            {
                OnComplete.Invoke(this);
            }

            if (t.IsFaulted || !normaltime)
            {
                var ex = t.Exception ?? new Exception("timeout");
                AfterError(ex);
            }
            else
            {
                if (null != OnSuccess)
                {
                    OnSuccess.Invoke(this);
                }
                _timer = new Timer(Execute, true, AfterSuccessInterval, Timeout.Infinite);
            }
        }