コード例 #1
0
ファイル: Mailer.cs プロジェクト: jango2015/SendEmail
        /// <summary>
        /// 开始群发邮件
        /// </summary>
        /// <param name="msg">通知消息</param>
        /// <param name="done">完成执行</param>
        public void Start(Action<string> msg = null, Pub.Class.Action done = null)
        {
            exit = false;
            uiMsg = msg; uiDone = done;
            thread = new Thread(() => {
                smtpList = SmtpListHelper.SelectListByAll();
                sendSetting = SendSettingHelper.SelectByID(1);
                templateList = HtmlTemplateHelper.SelectListByAll().Where(p => p.Status == 0).ToList();

                sendStart();
            });
            thread.IsBackground = true;
            thread.Start();
        }
コード例 #2
0
ファイル: Mailer.cs プロジェクト: yh200212121212/SendEmail
        /// <summary>
        /// 开始群发邮件
        /// </summary>
        /// <param name="msg">通知消息</param>
        /// <param name="done">完成执行</param>
        public void Start(Action <string> msg = null, Pub.Class.Action done = null)
        {
            exit   = false;
            uiMsg  = msg; uiDone = done;
            thread = new Thread(() => {
                smtpList     = SmtpListHelper.SelectListByAll();
                sendSetting  = SendSettingHelper.SelectByID(1);
                templateList = HtmlTemplateHelper.SelectListByAll().Where(p => p.Status == 0).ToList();

                sendStart();
            });
            thread.IsBackground = true;
            thread.Start();
        }
コード例 #3
0
ファイル: NetHelper.cs プロジェクト: yh200212121212/SendEmail
        /// <summary>
        /// 更换IP
        /// </summary>
        /// <param name="netType">0表示路由 1表示拨号连接</param>
        /// <param name="msg">通知输出消息</param>
        /// <param name="done">完成时执行</param>
        /// <param name="index">第几次执行</param>
        /// <returns></returns>
        public static string ChangeIP(int netType, Action <string> msg = null, Pub.Class.Action done = null, int index = 0)
        {
            string name = GetNetName(netType);

            setting = SendSettingHelper.SelectByID(1);

            if (setting.IsNull())
            {
                if (!msg.IsNull())
                {
                    msg("请修改发送设置!");
                }
                if (!done.IsNull())
                {
                    done();
                }
                return("");
            }
            else
            {
                if (index == setting.MaxRetryCount)
                {
                    if (!done.IsNull())
                    {
                        done();
                    }
                    return("");
                }
                if (!msg.IsNull())
                {
                    msg((index + 1).ToString());
                }

                //清空多少分钟前的历史IP
                if (Data.Pool("ConnString").DBType == "SqlServer")
                {
                    "delete from IpHistory where CreateTime < DateAdd(MINUTE , -{0}, getdate())".FormatWith(setting.DeleteInterval).ToSQL().ToExec();
                }
                else if (Data.Pool("ConnString").DBType == "SQLite" || Data.Pool("ConnString").DBType == "MonoSQLite")
                {
                    "delete from IpHistory where datetime(CreateTime) < datetime('now','localtime', '-{0} minute')".FormatWith(setting.DeleteInterval).ToSQL().ToExec();
                }
                if (!msg.IsNull())
                {
                    msg("正在重启" + name + "......");
                }
                IController connect;
                switch (netType)
                {
                case 1: connect = new ModelController(); break;

                case 2: connect = new TianYiController(); break;

                default: connect = new RouteController(); break;
                }
                string error = connect.Reset();
                if (!error.IsNullEmpty())
                {
                    if (!msg.IsNull())
                    {
                        msg("重启" + name + "失败:" + error);
                    }
                    return(ChangeIP(netType, msg, done, index + 1));
                }
                else
                {
                    if (!msg.IsNull())
                    {
                        msg("已重启" + name + ",正在检测是否联网......");
                    }
                    bool isTrue = NetHelper.CheckNetwork(msg);
                    if (!isTrue)
                    {
                        return(ChangeIP(netType, msg, done, index + 1));
                    }

                    if (!msg.IsNull())
                    {
                        msg("已联接网络,正在获取IP......");
                    }
                    string ip = IPHelper.GetIpFast();

                    if (!msg.IsNull())
                    {
                        msg("获取到IP:" + ip);
                    }
                    if (IpHistoryHelper.IsExistByID(ip))
                    {
                        if (!msg.IsNull())
                        {
                            msg("检测到IP:" + ip + "最近已使用!");
                        }
                        return(ChangeIP(netType, msg, done, index + 1));
                    }
                    else
                    {
                        IpHistoryHelper.Insert(new IpHistory()
                        {
                            IP = ip, CreateTime = DateTime.Now.ToDateTime().ToDateTime()
                        });
                    };
                    return(ip);
                }
            }
        }
コード例 #4
0
        public static void TestIPStart(Action <string> msg, Pub.Class.Action done)
        {
            IList <IpSetting> list = IpSettingHelper.SelectListByAll();

            if (list.Count == 0)
            {
                msg("请设置需要获取IP的网址!"); return;
            }
            msg("共有{0}个获取IP的网址!".FormatWith(list.Count));
            if (!ex.IsNull())
            {
                ex.SetAll();
            }

            ex = new ThreadEx();
            list.Do((p, i) => {
                ex.QueueWorkItem(new System.Threading.WaitCallback(o => {
                    IpSetting setting = (IpSetting)o;
                    string ip         = string.Empty;
                    try {
                        string data     = string.Empty;
                        string name     = setting.DataEncode.IfNullOrEmpty("utf-8");
                        Encoding coding = Encoding.GetEncoding(name);
                        data            = GetRemoteHtmlCode(setting.IPUrl, coding);
                        if (data.Trim().IsNullEmpty())
                        {
                            msg("{0},error - 请检查网址{1}是否正确!".FormatWith(i + 1, setting.IPUrl));
                        }
                        else
                        {
                            if (setting.IPRegex.IsNullEmpty())                               //允许正则为空
                            {
                                if (data.IsNullEmpty())
                                {
                                    msg("{0},error - 网址{1}无法匹配IP:{2}".FormatWith(i + 1, setting.IPUrl, data));
                                }
                                else
                                {
                                    msg("{0},ok - 网址{1}获取的IP是:{2}".FormatWith(i + 1, setting.IPUrl, data));
                                }
                            }
                            else
                            {
                                string begin = setting.IPRegex.Substring(0, setting.IPRegex.IndexOf("(")).Replace("\\", "");
                                string end   = setting.IPRegex.Substring(setting.IPRegex.IndexOf(")") + 1).Replace("\\", "");

                                if (begin.IsNullEmpty() || end.IsNullEmpty())
                                {
                                    msg("{0},error - 请检查网址{1}的正则是否正确:{2}".FormatWith(i + 1, setting.IPUrl, setting.IPRegex));
                                }
                                else
                                {
                                    ip = data.GetMatchingValues(setting.IPRegex, begin, end).Join(",");
                                    if (ip.IsNullEmpty())
                                    {
                                        msg("{0},error - 网址{1}无法匹配IP:{2}".FormatWith(i + 1, setting.IPUrl, data));
                                    }
                                    else
                                    {
                                        msg("{0},ok - 网址{1}获取的IP是:{2}".FormatWith(i + 1, setting.IPUrl, ip));
                                    }
                                }
                            }
                        }
                    } catch (Exception e) {
                        msg("{0},error - 获取网址{1}数据出错:{2}".FormatWith(i + 1, setting.IPUrl, e.Message));
                        return;
                    }
                }), p);
            });
            ex.WaitAllComplete();
            done();
        }
コード例 #5
0
 /// <summary>
 /// 开始群发邮件
 /// </summary>
 /// <param name="msg"></param>
 /// <param name="done"></param>
 public static void Start(Action <string> msg = null, Pub.Class.Action done = null)
 {
     ServicePointManager.DefaultConnectionLimit = 10000;
     mailer.Start(msg, done);
 }