Ejemplo n.º 1
0
        private static void SMSSender(ISession session, Notification message, ConfigParam config, SendResult state)
        {
            object s = null;
            string errorMessage = null, mobile;
            bool error = false;
            string errorCode = string.Empty ;
            foreach (NotificationReceiver receiver in message.Receivers)
            {
               s = null;
                error = false;
                errorMessage = null;
                errorCode = "";
                //合法性检查
                mobile = receiver.PostTo;
                if (!CheckSms(ref mobile))
                {
                    log.ErrorFormat("message {0}, receiver: {1} not send: 无效的手机号码", message.NotifyID, receiver.PostTo);
                    errorMessage = "无效的手机号码";
                    error = true;
                }

                //尝试发送
                if (!error)
                    try
                    {
                        s = _smsService.SendMessage(config.SMSAccount, config.SMSPassword, message.Content, mobile);
                        error =_smsService.ParseSendResult(s,out errorCode, out errorMessage);
                        log.DebugFormat("message {0} sent, receiver: {1}, content: {2}", message.NotifyID, mobile, message.Content);
                    }
                    catch (Exception er)
                    {
                        //发送过程如果发生异常,异常信息将尝试记入数据库
                        error = true;
                        errorMessage = er.Message;
                    }

                //记录发送结果状态
                try
                {
                    session.BeginTransaction();
                    bool success = message.AfterSendDo(receiver, error ? "-99998" : "-99999", errorMessage);
                    session.Commit();
                    if (success) state.SuccessCount++;
                    else state.ErrorCount++;
                }
                catch (Exception er)
                {
                    //如果记录发送结果状态时发生异常,只能将异常信息记入日志文件
                    session.Rollback();
                    state.ErrorCount++;
                    log.ErrorFormat("message: {0}, receiver: {1}, result code: {2}, result error: {3}, exception: {4}", message.NotifyID, receiver.PostTo, error?"-99998":errorCode, errorMessage, er.Message);
                }
            }
            message.AfterSendDo();
        }
Ejemplo n.º 2
0
        private static void MailSender(ISession session, Notification message, ConfigParam config, SendResult state)
        {
            bool   error = false;
            string errorMessage = null, code = null;

            foreach (NotificationReceiver receiver in message.Receivers)
            {
                error        = false;
                errorMessage = "";
                code         = "0";
                //合法性检查
                if (!CheckMail(receiver.PostTo))
                {
                    log.ErrorFormat("message {0}, receiver: {1} not send: 无效的EMail地址", message.NotifyID, receiver.PostTo);
                    errorMessage = "无效的EMail地址";
                    code         = "-99999";
                    error        = true;
                }

                //尝试发送
                if (!error)
                {
                    try
                    {
                        _mailService.Subject  = message.Title;
                        _mailService.HTMLBody = message.Content;
                        _mailService.ClearRecipients();
                        _mailService.AddRecipient(receiver.PostTo, receiver.UserName, null);
                        error        = !_mailService.Send(config.MailServer, false);
                        code         = _mailService.ErrorCode.ToString();
                        errorMessage = _mailService.ErrorMessage + " " + _mailService.Log;
                        _mailService.Close();
                        if (error)
                        {
                            log.ErrorFormat("message {0}, receiver: {1} not send: {2} - {3}", message.NotifyID, receiver.PostTo, _mailService.ErrorCode, _mailService.ErrorMessage);
                        }
                        else
                        {
                            log.DebugFormat("message {0} sent, receiver: {1}", message.NotifyID, receiver.PostTo);
                        }
                    }
                    catch (Exception er)
                    {
                        //发送过程如果发生异常,异常信息将尝试记入数据库
                        error        = true;
                        errorMessage = er.Message;
                        code         = "-99999";
                    }
                }

                //记录发送结果状态
                try
                {
                    session.BeginTransaction();
                    bool success = message.AfterSendDo(receiver, code, errorMessage);
                    session.Commit();
                    if (success)
                    {
                        state.SuccessCount++;
                    }
                    else
                    {
                        state.ErrorCount++;
                    }
                }
                catch (Exception er)
                {
                    //如果记录发送结果状态时发生异常,只能将异常信息记入日志文件
                    session.Rollback();
                    state.ErrorCount++;
                    log.ErrorFormat("message: {0}, receiver: {1}, result code: {2}, result error: {3}, exception: {4}", message.NotifyID, receiver.ReceiverID, code, errorMessage, er.Message);
                }
            }
            message.AfterSendDo();
        }
Ejemplo n.º 3
0
        private static void MailSender(ISession session, Notification message, ConfigParam config, SendResult state)
        {
            bool error = false;
            string errorMessage = null, code = null;
            foreach (NotificationReceiver receiver in message.Receivers)
            {
                error = false;
                errorMessage = "";
                code = "0";
                //合法性检查
                if (!CheckMail(receiver.PostTo))
                {
                    log.ErrorFormat("message {0}, receiver: {1} not send: 无效的EMail地址", message.NotifyID, receiver.PostTo);
                    errorMessage = "无效的EMail地址";
                    code = "-99999";
                    error = true;
                }

                //尝试发送
                if (!error)
                    try
                    {
                        _mailService.Subject = message.Title;
                        _mailService.HTMLBody = message.Content;
                        _mailService.ClearRecipients();
                        _mailService.AddRecipient(receiver.PostTo, receiver.UserName, null);
                        error = !_mailService.Send(config.MailServer, false);
                        code = _mailService.ErrorCode.ToString();
                        errorMessage = _mailService.ErrorMessage + " " + _mailService.Log;
                        _mailService.Close();
                        if (error)
                        {
                            log.ErrorFormat("message {0}, receiver: {1} not send: {2} - {3}", message.NotifyID, receiver.PostTo, _mailService.ErrorCode, _mailService.ErrorMessage);
                        }
                        else
                            log.DebugFormat("message {0} sent, receiver: {1}", message.NotifyID, receiver.PostTo);
                    }
                    catch (Exception er)
                    {
                        //发送过程如果发生异常,异常信息将尝试记入数据库
                        error = true;
                        errorMessage = er.Message;
                        code = "-99999";
                    }

                //记录发送结果状态
                try
                {
                    session.BeginTransaction();
                    bool success = message.AfterSendDo(receiver, code, errorMessage);
                    session.Commit();
                    if (success) state.SuccessCount++;
                    else state.ErrorCount++;
                }
                catch (Exception er)
                {
                    //如果记录发送结果状态时发生异常,只能将异常信息记入日志文件
                    session.Rollback();
                    state.ErrorCount++;
                    log.ErrorFormat("message: {0}, receiver: {1}, result code: {2}, result error: {3}, exception: {4}", message.NotifyID, receiver.ReceiverID, code, errorMessage, er.Message);
                }
            }
            message.AfterSendDo();
        }
Ejemplo n.º 4
0
        private static void SMSSender(ISession session, Notification message, ConfigParam config, SendResult state)
        {
            object s = null;
            string errorMessage = null, mobile;
            bool   error     = false;
            string errorCode = string.Empty;

            foreach (NotificationReceiver receiver in message.Receivers)
            {
                s            = null;
                error        = false;
                errorMessage = null;
                errorCode    = "";
                //合法性检查
                mobile = receiver.PostTo;
                if (!CheckSms(ref mobile))
                {
                    log.ErrorFormat("message {0}, receiver: {1} not send: 无效的手机号码", message.NotifyID, receiver.PostTo);
                    errorMessage = "无效的手机号码";
                    error        = true;
                }

                //尝试发送
                if (!error)
                {
                    try
                    {
                        s     = _smsService.SendMessage(config.SMSAccount, config.SMSPassword, message.Content, mobile);
                        error = _smsService.ParseSendResult(s, out errorCode, out errorMessage);
                        log.DebugFormat("message {0} sent, receiver: {1}, content: {2}", message.NotifyID, mobile, message.Content);
                    }
                    catch (Exception er)
                    {
                        //发送过程如果发生异常,异常信息将尝试记入数据库
                        error        = true;
                        errorMessage = er.Message;
                    }
                }

                //记录发送结果状态
                try
                {
                    session.BeginTransaction();
                    bool success = message.AfterSendDo(receiver, error ? "-99998" : "-99999", errorMessage);
                    session.Commit();
                    if (success)
                    {
                        state.SuccessCount++;
                    }
                    else
                    {
                        state.ErrorCount++;
                    }
                }
                catch (Exception er)
                {
                    //如果记录发送结果状态时发生异常,只能将异常信息记入日志文件
                    session.Rollback();
                    state.ErrorCount++;
                    log.ErrorFormat("message: {0}, receiver: {1}, result code: {2}, result error: {3}, exception: {4}", message.NotifyID, receiver.PostTo, error?"-99998":errorCode, errorMessage, er.Message);
                }
            }
            message.AfterSendDo();
        }