예제 #1
0
        public static async Task HttpDownLoadRecordTask(string url, string path, CancellationTokenSource cts)
        {
            var instance   = new HttpDownLoad(url, path, true);
            var ctsEndTask = new CancellationTokenSource();

            cts.Token.Register(() =>
            {
                if (!ctsEndTask.IsCancellationRequested)
                {
                    ctsEndTask.Cancel();
                }
            });
            ctsEndTask.Token.Register(() => { instance.Stop(); });

            try
            {
                await instance.Start();

                ctsEndTask.Cancel();
            }
            catch
            {
                // ignored
            }
        }
예제 #2
0
        public void HttpDownLoadTest()
        {
            var recorder = new BilibiliLiveRecorder(3);

            Assert.ThrowsExceptionAsync <ArgumentException>(async() => { await recorder.GetLiveUrl(); }).Wait();

            recorder.Refresh().Wait();

            var urls      = Task.Run(recorder.GetLiveUrl).Result.ToArray();
            var urlNumber = urls.Length;

            Assert.IsTrue(urlNumber > 1);

            var          url      = urls[0];
            const string path     = @"D:\Downloads\test.flv";
            var          instance = new HttpDownLoad(url, path, true);

            Task.Run(async() =>
            {
                await instance.Start();
            });
            Thread.Sleep(10000);
            instance.Stop();
        }