Ejemplo n.º 1
0
        protected async override void Work(object argObject)
        {
            FetcherArgs args        = (FetcherArgs)argObject;
            HttpFetcher httpFetcher = new HttpFetcher();
            Page        page        = new Page(new Uri(args.Url, UriKind.RelativeOrAbsolute), args.Parent, args.Url);

            if (Program.Verbose)
            {
                Console.WriteLine($"Fetching: {page.AbsoluteUri}");
            }
            try
            {
                string html = await httpFetcher.FetchBody(page.AbsoluteUri);

                page.Body = html;

                callback(new ParserArgs()
                {
                    Page = page
                });
            } catch (HttpRequestException e)
            {
                Console.WriteLine($"HttpRequestException on page: {page.AbsoluteUri}\n{e.Message}");
            } catch (ArgumentException e)
            {
                Console.WriteLine($"ArgumentException on page: {page.AbsoluteUri}\n{e.Message}");
            }
            base.Work(argObject);
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Collecting data, please wait...");

            var          fetcher = new HttpFetcher();
            const string baseUrl = "https://www.poromaa.com/assignment_data/";
            const string apiUrl  = "transactions.json";

            //Get list with objects
            var data    = fetcher.GetData(baseUrl, apiUrl, args[0], args[1]);
            var balance = Calculation.GetBalance(data);

            Console.Clear();
            Console.WriteLine($"Balance: {balance}");

            Console.ReadKey();
        }
Ejemplo n.º 3
0
        public IFetcher CreateFetcher(bool fakeFetcher, Primitive.Config.IHttpConfig config)
        {
            if (fakeFetcher)
            {
                if (localFetcher is null)
                {
                    localFetcher = new LocalFetcher(config);
                }

                return(localFetcher);
            }
            else
            {
                if (httpFetcher is null)
                {
                    var client = new HttpClientWrapper();
                    httpFetcher = new HttpFetcher(config, client);
                }
                return(httpFetcher);
            }
        }
        public void Should_gracefully_return_empty_string_when_encountering_an_error_code_such_as_404()
        {
            var fetcher = new HttpFetcher();

            Assert.AreEqual("", fetcher.DownloadString("http://services.smeedee.org/This_url_does_not_exist"));
        }