示例#1
0
 private void RegisterEventHandler()
 {
     PPPoE.PPPoEDialSuccessEvent += (s, e) =>
     {
         Notify("拨号成功,IP: " + e.Message);
         window.dialBtn.Invoke((MethodInvoker)(() =>
         {
             window.dialBtn.Text = "断开";
         }));
         IsConnected = true;
         DialerConfig.SaveConfig();
     };
     PPPoE.PPPoEHangupSuccessEvent += (s, e) =>
     {
         Notify("断开成功");
         window.dialBtn.Invoke((MethodInvoker)(() =>
         {
             window.dialBtn.Text = "拨号";
         }));
         IsConnected = false;
     };
     PPPoE.PPPoEDialFailEvent                += (s, e) => Notify(e.Message);
     PPPoE.PPPoEHangupFailEvent              += (s, e) => Notify("断开失败");
     HeartBeatProxy.HeartbeatExited          += (s, code) => Notify($"心跳停止({code})");
     NetworkCheck.InnerNetworkCheckFailed    += (s, e) => Notify("InnerNetworkCheckFailed");
     NetworkCheck.OuterNetworkCheckFailed    += (s, e) => Notify("OuterNetworkCheckFailed");
     NetworkCheck.OuterNetworkCheckSuccessed += (s, e) => { };
 }
示例#2
0
        /// <summary>
        ///     拨号
        /// </summary>
        private void Dial()
        {
            // 不想写Command

            if (string.IsNullOrEmpty(UserName))
            {
                Notify("请输入账户");
                return;
            }

            if (string.IsNullOrEmpty(Password))
            {
                Notify("请输入密码");
                return;
            }

            //开始拨号
            Notify("开始拨号");

            //Enable = false;
            DialBtnEnable = false; //拿出,不应该在Task

            new Task(() =>
            {
                try
                {
                    //后台保存
                    DialerConfig.SaveConfig();
                    Model.Authenticator.Authenticate();
                }
                catch (Exception e)
                {
                    Notify(e.Message);
                    Log4Net.WriteLog(e.Message, e);
                }
                //Enable = true;
            }).Start();
        }
 /// <summary>
 ///     将要关闭的事件
 ///     处理关闭前的工作
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void MetroWindow_Closing(object sender, CancelEventArgs e)
 {
     View.Hangup();
     DialerConfig.SaveConfig();
     Model.Utils.DialerUpdater.StopCheckUpdateTimer();
 }
示例#4
0
        /// <summary>
        /// 发送运行统计
        /// </summary>
        public static void SendAnalyze()
        {
            RestClient client = new RestClient("https://api2.bmob.cn");

            //填充用户信息
            AnalyzeData data = new AnalyzeData();

            if (!DialerConfig.isFeedback)
            {
                data.Username = "******";
            }
            else
            {
                MD5    md5      = new MD5CryptoServiceProvider();
                byte[] mdResult = md5.ComputeHash(Encoding.Default.GetBytes(DialerConfig.username));
                data.Username = ToHexString(mdResult, mdResult.Length);
            }
            data.CampusZone = (int)DialerConfig.zone;
            data.Version    = Version.GetVersion();

            try
            {
                //发送/更新用户信息
                if (DialerConfig.guid == "")
                {
                    RestRequest request = new RestRequest("/1/classes/analyze", Method.POST); //post
                    request.AddHeader("X-Bmob-Application-Id", "6402f2d047a6728395bc8df1f918b340");
                    request.AddHeader("X-Bmob-REST-API-Key", "a0069d330057d662b7a1af4245e8f882");
                    request.AddJsonBody(data);
                    IRestResponse <ObjId> objId = client.Execute <ObjId>(request);
                    if (objId.ResponseStatus == ResponseStatus.Completed)
                    {
                        DialerConfig.guid = objId.Data.objectId;
                        DialerConfig.SaveConfig();
                    }
                }
                else
                {
                    //update
                    RestRequest request = new RestRequest($"/1/classes/analyze/{DialerConfig.guid}", Method.PUT);
                    request.AddHeader("X-Bmob-Application-Id", "6402f2d047a6728395bc8df1f918b340");
                    request.AddHeader("X-Bmob-REST-API-Key", "a0069d330057d662b7a1af4245e8f882");
                    request.AddHeader("Content-Type", "application/json");
                    request.AddJsonBody(data);
                    IRestResponse <ObjId> response = client.Execute <ObjId>(request);
                    if (response.ResponseStatus == ResponseStatus.Completed)
                    {
                        if (response.Data.code == 101)
                        {
                            DialerConfig.guid = "";
                            DialerConfig.SaveConfig();
                            SendAnalyze();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log4Net.WriteLog(e.Message, e);
            }
        }