Esempio n. 1
0
        public bool WorkerOperation(UserSensitiveMailQueueInfo info)
        {
            ErrorCodeInfo error         = new ErrorCodeInfo();
            string        message       = string.Empty;
            string        resultmessage = string.Empty;
            Guid          transactionid = Guid.NewGuid();
            string        paramstr      = string.Empty;

            paramstr += $"SensitiveID:{info.ID}";
            paramstr += $"||Keywords:{info.Keywords}";
            paramstr += $"||StartTime:{info.StartTime}";
            paramstr += $"||EndTime:{info.EndTime}";
            paramstr += $"||UserID:{info.UserID}";
            bool bResult = true;

            try
            {
                do
                {
                    Log4netHelper.Info($"RemoveSensitiveMail Begin: {paramstr}");
                    CommonProvider          commonProvider = new CommonProvider();
                    DirectoryEntry          userEntry      = new DirectoryEntry();
                    SensitiveMailDBProvider provider       = new SensitiveMailDBProvider();
                    if (!commonProvider.GetADEntryByGuid(info.UserID, out userEntry, out message))
                    {
                        Log4netHelper.Error($"RemoveSensitiveMail GetADEntryByGuid ID:{info.UserID}, Error:{message}");
                        info.Status   = SensitiveMailStatus.Failed;
                        resultmessage = "用户不存在。";
                        provider.UpdateUserSensitiveMailQueue(transactionid, info, resultmessage, out error);
                        bResult = false;
                        break;
                    }
                    string userMail = userEntry.Properties["mail"].Value == null ? "" : Convert.ToString(userEntry.Properties["mail"].Value);
                    ADManagerWebService.ManagerWebService webService = new ADManagerWebService.ManagerWebService();
                    webService.Timeout = -1;
                    if (!webService.RemoveSensitiveMail(transactionid, userMail, info.Keywords, info.StartTime, info.EndTime, out resultmessage, out message))
                    {
                        info.Status = SensitiveMailStatus.Failed;
                        provider.UpdateUserSensitiveMailQueue(transactionid, info, resultmessage, out error);
                        Log4netHelper.Error($"RemoveSensitiveMail ID:{info.ID}, Error:{message}");
                        bResult = false;
                        break;
                    }
                    //记录执行日志
                    info.Status = SensitiveMailStatus.Success;
                    provider.UpdateUserSensitiveMailQueue(transactionid, info, resultmessage, out error);
                    Log4netHelper.Info($"RemoveSensitiveMail End: {paramstr}");
                } while (false);
            }
            catch (Exception ex)
            {
                Log4netHelper.Error("RemoveSensitiveMail异常", paramstr, ex.ToString(), transactionid);
                bResult = false;
            }
            return(bResult);
        }
Esempio n. 2
0
        static void WorkerOperationWait(CancellationTokenSource cts, bool isTimeOut, UserSensitiveMailQueueInfo info)
        {
            SensitiveMailDBProvider provider = new SensitiveMailDBProvider();
            Guid          transactionid      = Guid.NewGuid();
            ErrorCodeInfo error = new ErrorCodeInfo();

            if (isTimeOut)
            {
                Log4netHelper.Error($"Thead TimeOut,ID: {info.ID}");
                info.Status = SensitiveMailStatus.Failed;
                provider.UpdateUserSensitiveMailQueue(transactionid, info, string.Empty, out error);
                cts.Cancel();
            }
        }
Esempio n. 3
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()}");
            }
        }