Esempio n. 1
0
 private void ConnectAP_Completed(object sender, RunWorkerCompletedEventArgs e)
 {
     try
     {
         object[] res = (object[])e.Result;
         if ((bool)res[0])//连接成功
         {
             List <string> ips = GeneralMethod.GetLocalIPS();
             localIP                = ips[0];
             ip_begin_h.Text        = ips[0].Substring(0, ips[0].LastIndexOf('.') + 1);
             ip_end_h.Text          = ips[0].Substring(0, ips[0].LastIndexOf('.') + 1);
             btn_scan.IsEnabled     = true;
             btn_connect.Content    = "网络已连接";
             btn_connect.IsEnabled  = false;
             btn_ok.IsEnabled       = true;
             btn_connect.Foreground = new SolidColorBrush(Colors.Green);
         }
         else//连接失败
         {
             LogManager.Insert(this, "ConnectAP_Completed", res[1].ToString());
             MsgBox.ShowV2(res[1].ToString(), MsgBoxType.Error, this);
             btn_scan.IsEnabled    = false;
             btn_ok.IsEnabled      = false;
             btn_connect.IsEnabled = true;
         }
     }
     catch (Exception ex)
     {
         string errMsg = "";
         if (ex.InnerException != null)
         {
             errMsg = ex.Message + "(" + ex.InnerException.Message + ")";
         }
         else
         {
             errMsg = ex.Message;
         }
         LogManager.Insert(this, "ConnectAP_Completed", errMsg);
         MsgBox.ShowV2(errMsg, MsgBoxType.Error, this);
     }
     finally
     {
         if (sender != null)//捕获异常后手动关闭线程
         {
             BackgroundWorker worker = sender as BackgroundWorker;
             if (worker.WorkerSupportsCancellation && !worker.CancellationPending)
             {
                 worker.CancelAsync();
             }
             worker.Dispose();
         }
         if (waitBox != null)
         {
             waitBox.Close();
         }
     }
 }
Esempio n. 2
0
 private void MainWindow_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         LocalParams lps      = GeneralMethod.GetLocalParams();
         string[]    ipss     = new string[] { lps.IP };
         string[]    marks    = new string[] { lps.Mark };
         string[]    gateWays = new string[] { "192.168.0.1" };
         APManager.SetIPAddress(ipss, marks, gateWays, null);
         btn_ok.IsEnabled = false;
         if (!File.Exists(SystemSettings.ConfigPath))//未初始化
         {
             btn_scan.IsEnabled = false;
         }
         else
         {
             SystemSettings config = SystemSettings.Read();
             if (config != null)
             {
                 ShowConfig(config);
             }
             //如果网络已经连接
             string errMsg = "";
             if (APManager.ConnectToSSID(config.APUser, config.APPass,
                                         out errMsg))
             {
                 List <string> ips = GeneralMethod.GetLocalIPS();
                 localIP                = ips[0];
                 ip_begin_h.Text        = ips[0].Substring(0, ips[0].LastIndexOf('.') + 1);
                 ip_end_h.Text          = ips[0].Substring(0, ips[0].LastIndexOf('.') + 1);
                 btn_scan.IsEnabled     = true;
                 btn_connect.Content    = "网络已连接";
                 btn_connect.Foreground = new SolidColorBrush(Colors.Green);
                 btn_connect.IsEnabled  = false;
             }
             else
             {
                 btn_scan.IsEnabled = false;
                 btn_ok.IsEnabled   = false;
                 LogManager.Insert(this, "MainWindow_Loaded", "网络连接异常,请重新连接!");
                 MsgBox.ShowV2("网络连接异常,请重新连接!", MsgBoxType.Error, this);
             }
         }
     }
     catch (Exception ex)
     {
         LogManager.Insert(this, "MainWindow_Loaded", ex.Message);
         MsgBox.ShowV2(ex.Message, MsgBoxType.Error, this);
     }
 }