Example #1
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);
     }
 }
Example #2
0
        public static int TimeOut = 200;//超时设置成200ms

        public static LocalParams GetLocalParams()
        {
            LocalParams ps = new LocalParams();

            try
            {
                string        exePath = Assembly.GetExecutingAssembly().Location;
                Configuration config  = ConfigurationManager.OpenExeConfiguration(exePath);
                if (config != null)
                {
                    if (config.AppSettings.Settings.Count > 0)
                    {
                        string ip = config.AppSettings.Settings["IP"].Value;
                        if (!string.IsNullOrEmpty(ip))
                        {
                            ps.IP = ip;
                        }
                        string mark = config.AppSettings.Settings["Mask"].Value;
                        if (!string.IsNullOrEmpty(mark))
                        {
                            ps.Mark = mark;
                        }
                        string gateWay = config.AppSettings.Settings["GateWay"].Value;
                        if (!string.IsNullOrEmpty(gateWay))
                        {
                            ps.GateWay = gateWay;
                        }
                        string timeOut = config.AppSettings.Settings["PingTimeOut"].Value;
                        if (!string.IsNullOrEmpty(timeOut))
                        {
                            try { ps.PingTimeOut = Convert.ToInt32(timeOut); }
                            catch { ps.PingTimeOut = 200; }
                        }
                        string scanerCount = config.AppSettings.Settings["ScanerCount"].Value;
                        if (!string.IsNullOrEmpty(scanerCount))
                        {
                            try { ps.ScanerCount = Convert.ToInt32(scanerCount); }
                            catch { ps.ScanerCount = 8; }
                        }
                    }
                }
            }
            catch
            {
                return(ps);
            }

            return(ps);
        }