コード例 #1
0
ファイル: FormConfigTester.cs プロジェクト: wuyouss/V2RayGCon
        private void FormConfigTester_Shown(object sender, System.EventArgs e)
        {
            formTitle = this.Text;

            UpdateServerList();

            tester        = new Model.BaseClass.CoreServer();
            tester.OnLog += LogReceiver;

            setting.OnSettingChange += SettingChange;

            this.FormClosed += (s, a) =>
            {
                tester.OnLog            -= LogReceiver;
                setting.OnSettingChange -= SettingChange;
                tester.StopCoreThen(null);
            };

            Lib.UI.SetFormLocation <FormConfigTester>(this, Model.Data.Enum.FormLocations.BottomLeft);
        }
コード例 #2
0
ファイル: ServerItem.cs プロジェクト: usaweili/V2RayGCon
 public void StopCoreThen(Action next = null)
 {
     Task.Factory.StartNew(() => server.StopCoreThen(next));
 }
コード例 #3
0
ファイル: FormConfigTester.cs プロジェクト: wuyouss/V2RayGCon
 private void btnStop_Click(object sender, EventArgs e)
 {
     tester.StopCoreThen(null);
     this.Text = formTitle;
 }
コード例 #4
0
        public void DoSpeedTestThen(Action next = null)
        {
            void log(string msg)
            {
                SendLog(msg);
                SetStatus(msg);
            }

            void error(string msg)
            {
                log(msg);
                next?.Invoke();
            }

            var port = Lib.Utils.GetFreeTcpPort();

            if (port <= 0)
            {
                error(I18N("GetFreePortFail"));
                return;
            }

            Thread.Sleep(100);

            var cfg = GetDecodedConfig(true);

            if (cfg == null)
            {
                error(I18N("DecodeImportFail"));
                return;
            }

            if (!OverwriteInboundSettings(
                    ref cfg,
                    (int)Model.Data.Enum.ProxyTypes.HTTP,
                    "127.0.0.1",
                    port))
            {
                error(I18N("CoreCantSetLocalAddr"));
                return;
            }

            var url  = StrConst("SpeedTestUrl");
            var text = I18N("Testing") + " ...";

            log(text);
            SendLog(url);

            var speedTester = new Model.BaseClass.CoreServer();

            speedTester.OnLog += OnLogHandler;

            speedTester.RestartCoreThen(cfg.ToString(), null, () =>
            {
                // v2ray-core need a little time to get ready.
                Thread.Sleep(1000);

                var time = Lib.Utils.VisitWebPageSpeedTest(url, port);

                text = string.Format("{0}:{1}",
                                     I18N("VisitWebPageTest"),
                                     time > 0 ? time.ToString() + "ms" : I18N("Timeout"));

                log(text);
                speedTester.StopCoreThen(() =>
                {
                    speedTester.OnLog -= OnLogHandler;
                    next?.Invoke();
                });
            });
        }