예제 #1
0
 public void SetState(int id, MailSendingState result)
 {
     using (var db = GetDb())
         using (var tx = db.BeginTransaction())
         {
             if (result == MailSendingState.Sended)
             {
                 var d = new SqlDelete("notify_info").Where("notify_id", id);
                 db.ExecuteNonQuery(d);
             }
             else
             {
                 if (result == MailSendingState.Error)
                 {
                     var q        = new SqlQuery("notify_info").Select("attempts").Where("notify_id", id);
                     var attempts = db.ExecuteScalar <int>(q);
                     if (NotifyServiceCfg.MaxAttempts <= attempts + 1)
                     {
                         result = MailSendingState.FatalError;
                     }
                 }
                 var u = new SqlUpdate("notify_info")
                         .Set("state", (int)result)
                         .Set("attempts = attempts + 1")
                         .Set("modify_date", DateTime.UtcNow)
                         .Where("notify_id", id);
                 db.ExecuteNonQuery(u);
             }
             tx.Commit();
         }
 }
예제 #2
0
 public void SetState(int id, MailSendingState result)
 {
     using var scope = ServiceProvider.CreateScope();
     using var db    = scope.ServiceProvider.GetService <DbOptionsManager>().Get(dbid);
     using var tx    = db.BeginTransaction();
     if (result == MailSendingState.Sended)
     {
         var d = new SqlDelete("notify_info").Where("notify_id", id);
         db.ExecuteNonQuery(d);
     }
     else
     {
         if (result == MailSendingState.Error)
         {
             var q        = new SqlQuery("notify_info").Select("attempts").Where("notify_id", id);
             var attempts = db.ExecuteScalar <int>(q);
             if (NotifyServiceCfg.Process.MaxAttempts <= attempts + 1)
             {
                 result = MailSendingState.FatalError;
             }
         }
         var u = new SqlUpdate("notify_info")
                 .Set("state", (int)result)
                 .Set("attempts = attempts + 1")
                 .Set("modify_date", DateTime.UtcNow)
                 .Where("notify_id", id);
         db.ExecuteNonQuery(u);
     }
     tx.Commit();
 }
예제 #3
0
        public void SetState(int id, MailSendingState result)
        {
            using var scope     = ServiceProvider.CreateScope();
            using var dbContext = scope.ServiceProvider.GetService <DbContextManager <NotifyDbContext> >().Get(dbid);
            using var tx        = dbContext.Database.BeginTransaction();

            if (result == MailSendingState.Sended)
            {
                var d = dbContext.NotifyInfo.Where(r => r.NotifyId == id).FirstOrDefault();
                dbContext.NotifyInfo.Remove(d);
                dbContext.SaveChanges();
            }
            else
            {
                if (result == MailSendingState.Error)
                {
                    var attempts = dbContext.NotifyInfo.Where(r => r.NotifyId == id).Select(r => r.Attempts).FirstOrDefault();
                    if (NotifyServiceCfg.Process.MaxAttempts <= attempts + 1)
                    {
                        result = MailSendingState.FatalError;
                    }
                }

                var info = dbContext.NotifyInfo
                           .Where(r => r.NotifyId == id)
                           .ToList();

                foreach (var i in info)
                {
                    i.State      = (int)result;
                    i.Attempts  += 1;
                    i.ModifyDate = DateTime.UtcNow;
                }

                dbContext.SaveChanges();
            }

            tx.Commit();
        }
예제 #4
0
 public void SetState(int id, MailSendingState result)
 {
     using (var db = GetDb())
     using (var tx = db.BeginTransaction())
     {
         if (result == MailSendingState.Sended)
         {
             var d = new SqlDelete("notify_info").Where("notify_id", id);
             db.ExecuteNonQuery(d);
             if (NotifyServiceCfg.DeleteSendedMessages)
             {
                 d = new SqlDelete("notify_queue").Where("notify_id", id);
                 db.ExecuteNonQuery(d);
             }
         }
         else
         {
             if (result == MailSendingState.Error)
             {
                 var q = new SqlQuery("notify_info").Select("attempts").Where("notify_id", id);
                 var attempts = db.ExecuteScalar<int>(q);
                 if (NotifyServiceCfg.MaxAttempts <= attempts + 1)
                 {
                     result = MailSendingState.FatalError;
                 }
             }
             var u = new SqlUpdate("notify_info")
                 .Set("state", (int)result)
                 .Set("attempts = attempts + 1")
                 .Set("modify_date", DateTime.UtcNow)
                 .Where("notify_id", id);
             db.ExecuteNonQuery(u);
         }
         tx.Commit();
     }
 }