Exemple #1
0
        public async Task Process()
        {
            Sources = _accessor.HttpContext.Request.Form["source[]"];

            if (Sources == null || Sources.Length == 0)
            {
                await WriteJson(new
                {
                    state = "参数错误:没有指定抓取源"
                });

                return;
            }
            //Crawlers = Sources.Select( x => _crawler.Fetch(x)).ToArray();
            //var temp = Sources.Select(async x =>
            // {
            //     return await _crawler.Fetch(x);
            // });
            //foreach (var item in temp)
            //{
            //    this.Crawlers.Add(await item);
            //}
            await WriteJson(new
            {
                state = "SUCCESS",
                //list = temp.Select(async x => {
                //    var item = await x;
                //    return new
                //    {
                //        state = item.State,
                //        source = item.SourceUrl,
                //        url = item.ServerUrl
                //    };
                //}),
                list = Sources.Select(async x => {
                    var item = await _crawler.Fetch(x);
                    return(new
                    {
                        state = item.State,
                        source = item.SourceUrl,
                        url = item.ServerUrl
                    });
                }),
            });
        }