コード例 #1
0
        public void RemoveSensitiveMailQueue()
        {
            Guid     transactionid = new Guid();
            int      removeSensitiveMailServiceSleepTime = Convert.ToInt32(Common.ConfigHelper.ConfigInstance["removeSensitiveMailServiceSleepTime"]);
            TimeSpan sensitiveMailQueueTimeOut           = TimeSpan.FromSeconds(Convert.ToInt32(Common.ConfigHelper.ConfigInstance["sensitiveMailQueueTimeOut"]));
            int      sensitiveMailQueueCount             = Convert.ToInt32(Common.ConfigHelper.ConfigInstance["sensitiveMailQueueCount"]);

            AdminInfo     adminInfo = new AdminInfo();
            ErrorCodeInfo error     = new ErrorCodeInfo();
            string        message   = string.Empty;

            try
            {
                do
                {
                    string snkey = ConfigHelper.ConfigInstance["SNKey"];
                    //if (ValidatorHelper.CheckSNKey(snkey))
                    //{
                    List <SensitiveMailInfo> sensitiveMails = new List <SensitiveMailInfo>();
                    SensitiveMailDBProvider  provider       = new SensitiveMailDBProvider();
                    UserProvider             userProvider   = new UserProvider();
                    //1.先获取已提交的敏感邮件 2.更新子队列全部执行完成的主数据的状态 3.
                    if (provider.GetSubmitSensitiveMailQueueList(transactionid, out sensitiveMails, out error))
                    {
                        //拆分Ou在子队列总添加用户
                        for (int i = 0; i < sensitiveMails.Count; i++)
                        {
                            SensitiveMailInfo sensitiveMailInfo = sensitiveMails[i];
                            if (!AddUserSensitiveMailQueue(transactionid, sensitiveMailInfo, out error))
                            {
                                continue;
                            }
                            sensitiveMailInfo.Status = SensitiveMailStatus.Executing;
                            provider.UpdateSensitiveMailStatus(transactionid, adminInfo, sensitiveMailInfo, out error);
                        }
                    }

                    //根据线程数量获取需要提交队列的数据
                    List <UserSensitiveMailQueueInfo> queueInfos = new List <UserSensitiveMailQueueInfo>();
                    provider.GetUserSensitiveMailQueueList(transactionid, out queueInfos, out error);
                    if (queueInfos.Count > 0)
                    {
                        Task <string[]> parent = new Task <string[]>(state =>
                        {
                            string[] result = new string[queueInfos.Count];
                            //创建并启动子任务
                            for (int i = 0; i < queueInfos.Count; i++)
                            {
                                UserSensitiveMailQueueInfo queueInfo = queueInfos[i];
                                queueInfo.Status = SensitiveMailStatus.Executing;
                                provider.UpdateUserSensitiveMailQueue(transactionid, queueInfo, string.Empty, out error);
                                var cts = new CancellationTokenSource();
                                new Task(() => { WorkerOperation(queueInfo); }, TaskCreationOptions.AttachedToParent).Start();
                            }
                            return(result);
                        }, "");
                        //任务处理完成后执行的操作
                        parent.ContinueWith(t =>
                        {
                        });
                        //启动父任务
                        parent.Start();
                    }
                    //}
                    //等待任务结束 Wait只能等待父线程结束,没办法等到父线程的ContinueWith结束
                    Thread.Sleep(TimeSpan.FromSeconds(removeSensitiveMailServiceSleepTime));
                } while (removeSensitiveMailServiceSleepTime > 0);
            }
            catch (Exception ex)
            {
                Log4netHelper.Error($"RemoveSensitiveMailQueue Exception: {ex.ToString()}");
            }
        }
コード例 #2
0
        public bool ExecuteSensitiveMail(Guid transactionid, AdminInfo admin, SensitiveMailInfo sensitiveMailInfo, out string strJsonResult)
        {
            bool result = true;

            strJsonResult = string.Empty;
            ErrorCodeInfo error    = new ErrorCodeInfo();
            string        message  = string.Empty;
            string        paramstr = string.Empty;

            paramstr += $"AdminID:{admin.UserID}";
            paramstr += $"||AdminAccount:{admin.UserAccount}";
            paramstr += $"||ID:{sensitiveMailInfo.ID}";

            string funname = "ExecuteSensitiveMail";

            try
            {
                do
                {
                    SensitiveMailDBProvider provider = new SensitiveMailDBProvider();
                    if (!provider.GetSensitiveMailInfo(transactionid, admin, ref sensitiveMailInfo, out error))
                    {
                        strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                        LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                        result = false;
                        break;
                    }

                    if (sensitiveMailInfo.Status == SensitiveMailStatus.Executing || sensitiveMailInfo.Status == SensitiveMailStatus.Submit)
                    {
                        error.Code    = ErrorCode.SensitiveMailExecute;
                        strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                        LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                        result = false;
                        break;
                    }
                    sensitiveMailInfo.Status    = SensitiveMailStatus.Submit;
                    sensitiveMailInfo.ExecuteID = transactionid;
                    if (!provider.UpdateSensitiveMailStatus(transactionid, admin, sensitiveMailInfo, out error))
                    {
                        strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                        LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                        result = false;
                        break;
                    }
                    error.Code = ErrorCode.None;
                    LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), true, transactionid);
                    strJsonResult = JsonHelper.ReturnJson(true, Convert.ToInt32(error.Code), error.Info);

                    #region 操作日志
                    LogInfo operateLog = new LogInfo();
                    operateLog.AdminID       = admin.UserID;
                    operateLog.AdminAccount  = admin.UserAccount;
                    operateLog.RoleID        = admin.RoleID;
                    operateLog.ClientIP      = _clientip;
                    operateLog.OperateResult = true;
                    operateLog.OperateType   = "执行敏感邮件规则";
                    operateLog.OperateLog    = $"{admin.UserAccount}于{DateTime.Now}执行敏感邮件规则。" +
                                               $"名称:{sensitiveMailInfo.Name}," +
                                               $"关键字:{sensitiveMailInfo.Keywords}," +
                                               $"开始时间:{sensitiveMailInfo.StartTime}," +
                                               $"结束时间:{sensitiveMailInfo.EndTime}";
                    LogManager.AddOperateLog(transactionid, operateLog);
                    #endregion

                    result = true;
                } while (false);
            }
            catch (Exception ex)
            {
                error.Code = ErrorCode.Exception;
                LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                LoggerHelper.Error("SensitiveMailManager调用ExecuteSensitiveMail异常", paramstr, ex.ToString(), transactionid);
                strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                result        = false;
            }
            return(result);
        }