public static async Task <int> QueryGuru(
            [ActivityTrigger] DurableActivityContext ctx,
            TraceWriter log)
        {
            var arguments  = ctx.GetInput <Tuple <string, string> >();
            var searchargs = arguments.Item1.Split(':');

            if (searchargs.Length != 2)
            {
                throw new ArgumentException("Activity.QueryGuru: Expected search query to be in format <query>:<type>");
            }

            var query   = searchargs[0];
            var type    = searchargs[1];
            var cookies = CookieConverter.DecodeCookie(arguments.Item2);

            var browser = await Puppeteer.ConnectAsync(new ConnectOptions { BrowserWSEndpoint = Constants.BrowserWSEndpoint });

            var page = await browser.NewPageAsync();

            await page.SetCookieAsync(cookies);

            var search = new UIAction.NavigateSearch(query, type);
            var pages  = await search.RunAsync(page);

            browser.Disconnect();
            return(pages);
        }
Exemple #2
0
        public static async Task <WorkerResult> RetrievePageContent(
            [ActivityTrigger] DurableActivityContext ctx,
            TraceWriter log)
        {
            var arguments  = ctx.GetInput <Tuple <string, string, int, string, int> >();
            var searchargs = arguments.Item1.Split(':');

            if (searchargs.Length != 2)
            {
                throw new ArgumentException("Activity.QueryGuru: Expected search query to be in format <query>:<type>");
            }

            var query      = searchargs[0];
            var type       = searchargs[1];
            var cookies    = CookieConverter.DecodeCookie(arguments.Item2);
            var pagenumber = arguments.Item3;
            var config     = JsonConvert.DeserializeObject <ConfigSection>(arguments.Item4);
            var totalpages = arguments.Item5;

            var browser = await Puppeteer.ConnectAsync(new ConnectOptions { BrowserWSEndpoint = Constants.BrowserWSEndpoint });

            var page = await browser.NewPageAsync();

            await page.SetCookieAsync(cookies);

            var search = new UIAction.NavigateSearch(query, type, true);
            await search.RunAsync(page);

            var collect = new UIAction.NavigateCollect(pagenumber, ctx.InstanceId, ctx.InstanceId, config);
            var result  = await collect.RunAsync(page);

            // page is closed implicitly
            try
            {
                browser.Disconnect();
            }
            catch { }
            var customresult = new WorkerResult {
                html = result, suburb = query, totalpages = totalpages, page = pagenumber
            };

            return(customresult);
        }