Exemple #1
0
        long RunSpeedTestWorker(
            string speedTestableConfig,
            string title,
            string testUrl,
            int testPort,
            EventHandler <VgcApis.Models.Datas.StrEvent> logDeliever)
        {
            var speedTester = new V2RayGCon.Lib.V2Ray.Core(setting)
            {
                title = title
            };

            if (logDeliever != null)
            {
                speedTester.OnLog += logDeliever;
            }

            speedTester.WaitForToken();
            try
            {
                speedTester.RestartCore(speedTestableConfig);
            }
            finally
            {
                speedTester.ReleaseToken();
            }

            long testResult = Lib.Utils.VisitWebPageSpeedTest(testUrl, testPort);

            speedTester.WaitForTokenHurry();
            try
            {
                speedTester.StopCore();
            }
            finally
            {
                speedTester.ReleaseToken();
            }

            if (logDeliever != null)
            {
                speedTester.OnLog -= logDeliever;
            }
            return(testResult);
        }
Exemple #2
0
        long RunSpeedTestWorker(
            string rawConfig,
            string title,
            string testUrl,
            int testTimeout,
            bool isUseCache,
            bool isInjectSpeedTestTpl,
            bool isInjectActivateTpl,
            EventHandler <VgcApis.Models.Datas.StrEvent> logDeliever)
        {
            var port            = VgcApis.Libs.Utils.GetFreeTcpPort();
            var speedTestConfig = CreateSpeedTestConfig(
                rawConfig, port, isUseCache, isInjectSpeedTestTpl, isInjectActivateTpl);

            if (string.IsNullOrEmpty(speedTestConfig))
            {
                logDeliever?.Invoke(this, new VgcApis.Models.Datas.StrEvent(I18N.DecodeImportFail));
                return(long.MaxValue);
            }

            var url = string.IsNullOrEmpty(testUrl) ?
                      VgcApis.Models.Consts.Webs.GoogleDotCom :
                      testUrl;

            var speedTester = new V2RayGCon.Lib.V2Ray.Core(setting)
            {
                title = title
            };

            if (logDeliever != null)
            {
                speedTester.OnLog += logDeliever;
            }

            speedTester.WaitForToken();
            try
            {
                speedTester.RestartCore(speedTestConfig);
            }
            finally
            {
                speedTester.ReleaseToken();
            }

            long testResult = Lib.Utils.VisitWebPageSpeedTest(url, port, testTimeout);

            speedTester.WaitForTokenHurry();
            try
            {
                speedTester.StopCore();
            }
            finally
            {
                speedTester.ReleaseToken();
            }

            if (logDeliever != null)
            {
                speedTester.OnLog -= logDeliever;
            }
            return(testResult);
        }