Ejemplo n.º 1
0
 private void btn_start_Click(object sender, EventArgs e)
 {
     LoadConfig();  //重新加载配置文件
     if (ddns == null)
     {
         ddns = new Ddns(Config.AccessKeyId, Config.AccessKeySecret);
     }
     if (btn_start.Text == "Start")
     {
         if (tb_domain.Text.Split('.').Length <= 2)
         {
             MessageBox.Show("域名格式错误,应该输入以下的域名格式:www.geeiot.net或@.geeiot.net!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         else if (!CheckIP(tb_ip.Text))
         {
             MessageBox.Show("IP格式错误,请重新获取IP!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         if (!ddns.StartDdns(tb_domain.Text, tb_ip.Text))
         {
             MessageBox.Show("启动解析失败,请重试!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         tb_domain.Enabled = false;
         comb_time.Enabled = false;
         btn_start.Text    = "Stop";
     }
     else if (btn_start.Text == "Stop")
     {
         if (!ddns.StopDns())
         {
             MessageBox.Show("停止解析失败,请重试!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         else
         {
             tb_domain.Enabled = true;
             comb_time.Enabled = true;
             btn_start.Text    = "Start";
         }
     }
 }
Ejemplo n.º 2
0
        private bool LoadConfig()
        {
            try
            {
                if (IsStart)
                {
                    //Save Config
                    Form_Main_FormClosing(null, null);
                }

                //读取配置文件
                if (!Config.ReadConfig())
                {
                    if (!Config.SaveConfig())
                    {
                        return(false);
                    }
                }
                //实例化类
                ddns           = null;
                ddns           = new Ddns(Config.AccessKeyId, Config.AccessKeySecret);
                ddns.WriteLog += ShowLog;
                ddns.ShowIp   += ShowIp;
                //设置Combbox
                if (CombValue.Contains(Config.SpanTime.ToString()))
                {
                    int index = CombValue.IndexOf(Config.SpanTime.ToString());
                    comb_time.SelectedIndex = index;
                }
                else
                {
                    comb_time.SelectedIndex = 0;
                }
                tb_domain.Text = Config.Domain;
                return(true);
            }
            catch
            {
                return(false);
            }
        }