Example #1
0
 /// <summary>
 /// 回滚事务
 /// </summary>
 protected void RollBack()
 {
     if (TranHelper != null)
     {
         TranHelper.RollBack();
     }
 }
Example #2
0
        protected override void OnException(ExceptionContext filterContext)
        {
            //标记异常已处理
            filterContext.ExceptionHandled = true;
            if (TranHelper != null && Tran != null)
            {
                TranHelper.RollBack();
            }

            #region 日志记录
            ErrorBLL.Instance.Log(filterContext.Exception.ToString());
            #endregion

            // 跳转到错误页
            //TempData["message"] = "异常:" + filterContext.Exception.Message + ";异常Trace:" + filterContext.Exception.StackTrace;
            //bool gettitle = Request.Url.AbsoluteUri.ToLower().Contains("gettitle=1");
            //if (!gettitle)
            //    filterContext.Result = new RedirectResult(Url.Action("Index", "ErrorPages"));
        }
Example #3
0
        /// <summary>
        /// 处理每个帖子的优秀答题者(按最多点赞来)(---每24小时刷新一次---)
        /// </summary>
        private void NiceAnswer()
        {
            Thread t = new Thread(() =>
            {
                //计划每天凌晨3点执行吧
                DateTime now = DateTime.Now;
                int hours    = 0;
                if (now.Hour > 3)
                {
                    hours = 27 - now.Hour;
                    Thread.Sleep(hours * 60 * 60 * 1000);
                }

                var coinSource = CoinSourceEnum.NiceAnswer.GetHashCode();
                while (true)
                {
                    List <_QuestionInfo> questions = QuestionBLL.Instance.GetALLQuestion();
                    questions.ForEach(question =>
                    {
                        if (question.CommentCount > 1)
                        {
                            _Comment niceComment = QuestionBLL.Instance.GetNiceComment(question.QuestionId, question.BestAnswerId);
                            if (niceComment != null)
                            {
                                if (question.NiceAnswerId != niceComment.CommentId)
                                {
                                    TranHelper tranHelper = new TranHelper();
                                    try
                                    {
                                        if (SqlHelper.ExecuteSql(tranHelper.Tran, System.Data.CommandType.Text, "update Question set NiceAnswerId={0} where QuestionId={1}".FormatWith(niceComment.CommentId, question.QuestionId)) > 0)
                                        {
                                            int coin           = Convert.ToInt32(question.Coin);
                                            int coinType       = Convert.ToInt32(question.CoinType);
                                            long commentUserId = Convert.ToInt64(niceComment.CommentUserID);
                                            if (coinType != 0)
                                            {
                                                //判断是否已赠送过积分
                                                if (!ScoreCoinLogBLL.Instance.HasGiveScore(commentUserId, question.QuestionId, coinType, coinSource, tranHelper.Tran))
                                                {
                                                    //未赠送过,则赠送积分
                                                    if (UserExtBLL.Instance.AddScore(commentUserId, coin * 7 / 10, coinType, tranHelper.Tran))
                                                    {
                                                        if (ScoreCoinLogBLL.Instance.Log(coin * 7 / 10, coinType, CoinSourceEnum.NiceAnswer, commentUserId, niceComment.UserName, tranHelper.Tran, question.QuestionId))
                                                        {
                                                            tranHelper.Commit();
                                                        }
                                                        else
                                                        {
                                                            tranHelper.RollBack();
                                                        }
                                                        tranHelper.Dispose();
                                                    }
                                                    else
                                                    {
                                                        tranHelper.RollBack();
                                                        tranHelper.Dispose();
                                                    }
                                                }
                                                else
                                                {
                                                    tranHelper.RollBack();
                                                    tranHelper.Dispose();
                                                }
                                            }
                                            else
                                            {
                                                tranHelper.Commit();
                                            }
                                        }
                                        else
                                        {
                                            tranHelper.RollBack();
                                            tranHelper.Dispose();
                                        }
                                    }
                                    catch
                                    {
                                        tranHelper.RollBack();
                                        tranHelper.Dispose();
                                    }
                                    finally
                                    {
                                        //Thread.Sleep(1 * 10 * 1000);
                                    }
                                }
                            }
                        }
                    });
                    Thread.Sleep(24 * 60 * 60 * 1000);
                }
            });

            t.IsBackground = true;
            t.Start();
        }