Example #1
0
        public async Task Run()
        {
            await Task.Run(() =>
            {
                var driver  = AppContext.Resolve <ChromeDriver>();
                var links   = new List <string>(20);
                var estates = new List <RealEstate>(20);

                for (var i = From; i <= To; ++i)
                {
                    try
                    {
                        estates.Clear();

                        //driver.Navigate().GoToUrl($"https://www.nekretnine.rs/stambeni-objekti/lista/po-stranici/10/stranica/{i}/?order={Order}");
                        driver.Navigate().GoToUrl($"https://www.nekretnine.rs/stambeni-objekti/kuce/lista/po-stranici/10/stranica/{i}/");

                        links.Clear();
                        foreach (var offer in driver.FindElementsByXPath(OfferXPath))
                        {
                            links.Add(offer.GetAttribute("href"));
                        }

                        foreach (var link in links)
                        {
                            var estate = Scraper.Scrape(link);
                            estates.Add(estate);
                        }

                        PageCompleted?.Invoke(i, estates);
                    }
                    catch (Exception ex) { PageError?.Invoke(i, ex); }
                }
            });
        }
Example #2
0
        public void MakeRequest(Uri address)
        {
            // emulate request
            System.Threading.Thread.Sleep(1000);
            bool loaded = (new Random().Next(100) <= 40) ? true : false;

            if (loaded)
            {
                // notify client code
                PageLoad?.Invoke(this, new EventArgs());
                Ready = true;
            }
            else
            {
                PageError?.Invoke(this, new EventArgs());
                Ready = true;
            }
        }
Example #3
0
        internal override void OnMessage(string method, JsonElement?serverParams)
        {
            switch (method)
            {
            case "close":
                Closed?.Invoke(this, EventArgs.Empty);
                break;

            case "crash":
                Crashed?.Invoke(this, EventArgs.Empty);
                break;

            case "domcontentloaded":
                DOMContentLoaded?.Invoke(this, EventArgs.Empty);
                break;

            case "load":
                Load?.Invoke(this, EventArgs.Empty);
                break;

            case "bindingCall":
                BindingCall?.Invoke(
                    this,
                    new BindingCallEventArgs
                {
                    BidingCall = serverParams?.GetProperty("binding").ToObject <BindingCallChannel>(Connection.GetDefaultJsonSerializerOptions()).Object,
                });
                break;

            case "route":
                Route?.Invoke(
                    this,
                    new RouteEventArgs
                {
                    Route   = serverParams?.GetProperty("route").ToObject <RouteChannel>(Connection.GetDefaultJsonSerializerOptions()).Object,
                    Request = serverParams?.GetProperty("request").ToObject <RequestChannel>(Connection.GetDefaultJsonSerializerOptions()).Object,
                });
                break;

            case "popup":
                Popup?.Invoke(this, new PageChannelPopupEventArgs
                {
                    Page = serverParams?.GetProperty("page").ToObject <PageChannel>(Connection.GetDefaultJsonSerializerOptions()).Object,
                });
                break;

            case "pageError":
                PageError?.Invoke(this, serverParams?.GetProperty("error").GetProperty("error").ToObject <PageErrorEventArgs>(Connection.GetDefaultJsonSerializerOptions()));
                break;

            case "fileChooser":
                FileChooser?.Invoke(this, serverParams?.ToObject <FileChooserChannelEventArgs>(Connection.GetDefaultJsonSerializerOptions()));
                break;

            case "frameAttached":
                FrameAttached?.Invoke(this, new FrameEventArgs(serverParams?.GetProperty("frame").ToObject <FrameChannel>(Connection.GetDefaultJsonSerializerOptions()).Object));
                break;

            case "frameDetached":
                FrameDetached?.Invoke(this, new FrameEventArgs(serverParams?.GetProperty("frame").ToObject <FrameChannel>(Connection.GetDefaultJsonSerializerOptions()).Object));
                break;

            case "dialog":
                Dialog?.Invoke(this, new DialogEventArgs(serverParams?.GetProperty("dialog").ToObject <DialogChannel>(Connection.GetDefaultJsonSerializerOptions()).Object));
                break;

            case "console":
                Console?.Invoke(this, new ConsoleEventArgs(serverParams?.GetProperty("message").ToObject <ConsoleMessage>(Connection.GetDefaultJsonSerializerOptions())));
                break;

            case "request":
                Request?.Invoke(this, new RequestEventArgs {
                    Request = serverParams?.GetProperty("request").ToObject <RequestChannel>(Connection.GetDefaultJsonSerializerOptions()).Object
                });
                break;

            case "requestFinished":
                RequestFinished?.Invoke(this, new RequestEventArgs {
                    Request = serverParams?.GetProperty("request").ToObject <RequestChannel>(Connection.GetDefaultJsonSerializerOptions()).Object
                });
                break;

            case "requestFailed":
                RequestFailed?.Invoke(this, serverParams?.ToObject <PageChannelRequestFailedEventArgs>(Connection.GetDefaultJsonSerializerOptions()));
                break;

            case "response":
                Response?.Invoke(this, new ResponseEventArgs {
                    Response = serverParams?.GetProperty("response").ToObject <ResponseChannel>(Connection.GetDefaultJsonSerializerOptions()).Object
                });
                break;

            case "download":
                Download?.Invoke(this, new DownloadEventArgs()
                {
                    Download = serverParams?.GetProperty("download").ToObject <DownloadChannel>(Connection.GetDefaultJsonSerializerOptions()).Object
                });
                break;

            case "worker":
                Worker?.Invoke(
                    this,
                    new WorkerChannelEventArgs
                {
                    WorkerChannel = serverParams?.GetProperty("worker").ToObject <WorkerChannel>(Connection.GetDefaultJsonSerializerOptions()),
                });
                break;
            }
        }
        internal override void OnMessage(string method, JsonElement?serverParams)
        {
            switch (method)
            {
            case "close":
                Closed?.Invoke(this, EventArgs.Empty);
                break;

            case "crash":
                Crashed?.Invoke(this, EventArgs.Empty);
                break;

            case "domcontentloaded":
                DOMContentLoaded?.Invoke(this, EventArgs.Empty);
                break;

            case "load":
                Load?.Invoke(this, EventArgs.Empty);
                break;

            case "bindingCall":
                BindingCall?.Invoke(
                    this,
                    new() { BindingCall = serverParams?.GetProperty("binding").ToObject <BindingCallChannel>(Connection.DefaultJsonSerializerOptions).Object });
                break;

            case "route":
                var route   = serverParams?.GetProperty("route").ToObject <RouteChannel>(Connection.DefaultJsonSerializerOptions).Object;
                var request = serverParams?.GetProperty("request").ToObject <RequestChannel>(Connection.DefaultJsonSerializerOptions).Object;
                Route?.Invoke(
                    this,
                    new() { Route = route, Request = request });
                break;

            case "popup":
                Popup?.Invoke(this, new() { Page = serverParams?.GetProperty("page").ToObject <PageChannel>(Connection.DefaultJsonSerializerOptions).Object });
                break;

            case "pageError":
                PageError?.Invoke(this, serverParams?.GetProperty("error").GetProperty("error").ToObject <SerializedError>(Connection.DefaultJsonSerializerOptions));
                break;

            case "fileChooser":
                FileChooser?.Invoke(this, serverParams?.ToObject <FileChooserChannelEventArgs>(Connection.DefaultJsonSerializerOptions));
                break;

            case "frameAttached":
                FrameAttached?.Invoke(this, serverParams?.GetProperty("frame").ToObject <FrameChannel>(Connection.DefaultJsonSerializerOptions).Object);
                break;

            case "frameDetached":
                FrameDetached?.Invoke(this, serverParams?.GetProperty("frame").ToObject <FrameChannel>(Connection.DefaultJsonSerializerOptions).Object);
                break;

            case "dialog":
                Dialog?.Invoke(this, serverParams?.GetProperty("dialog").ToObject <DialogChannel>(Connection.DefaultJsonSerializerOptions).Object);
                break;

            case "console":
                Console?.Invoke(this, serverParams?.GetProperty("message").ToObject <ConsoleMessage>(Connection.DefaultJsonSerializerOptions));
                break;

            case "webSocket":
                WebSocket?.Invoke(this, serverParams?.GetProperty("webSocket").ToObject <WebSocketChannel>(Connection.DefaultJsonSerializerOptions).Object);
                break;

            case "download":
                Download?.Invoke(this, serverParams?.ToObject <PageDownloadEvent>(Connection.DefaultJsonSerializerOptions));
                break;

            case "video":
                Video?.Invoke(this, new() { Artifact = serverParams?.GetProperty("artifact").ToObject <ArtifactChannel>(Connection.DefaultJsonSerializerOptions).Object });
                break;

            case "worker":
                Worker?.Invoke(
                    this,
                    new() { WorkerChannel = serverParams?.GetProperty("worker").ToObject <WorkerChannel>(Connection.DefaultJsonSerializerOptions) });
                break;
            }
        }