Ejemplo n.º 1
0
        async Task storeAllTenders()
        {
            //denotes the tender page for use in this method
            int i = 1;

            while (isNextAvailable != false)
            {
                string httpTask = await Task.Run <string>(() => getPageData(nextUrl));

                i = i + 1;

                var httpResult = httpTask.ToString();

                //Small data extraction to get "Next" and "Previous" page hyperlinks
                var htmlDoc = new HtmlDocument();
                htmlDoc.LoadHtml(httpResult);

                //Extract tender data from the response
                var tenderItems = await Task.Run <Object>(() => DataExtraction.getTenderPage(htmlDoc));

                saveToTenderDb((List <tenderItem>)tenderItems, i);
            }

            List <tenderItem> dbtenders = await Task.Run <List <tenderItem> >(() => retrieveTenderFromDatabase(2));

            if (dbtenders.Count > 0)
            {
                //nextPage.IsVisible = true;
            }
            //await WaitAndExecuteUpdateTenders(10800000, storeAllTenders);
        }
Ejemplo n.º 2
0
        async void onPreviousPageTapped(object sender, EventArgs eventArgs)
        {
            activityIndicator.IsVisible = true;
            activityIndicator.IsRunning = true;
            //Sending HTTP request to obtain the second tender page data
            string httpTask = await Task.Run <string>(() => HttpRequestHandler.GetRequest(previousUrl, false));

            var httpResult = httpTask.ToString();

            //Small data extraction to get "Next" and "Previous" page hyperlinks
            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(httpResult);
            var aNodes = htmlDoc.DocumentNode.SelectNodes("//a");

            isNextAvailable     = false;
            isPreviousAvailable = false;

            foreach (var aNode in aNodes)
            {
                if (aNode.InnerHtml == "Previous")
                {
                    previousUrl         = "http://www2.sesco.com.my/etender/notice/" + aNode.Attributes["href"].Value;
                    isPreviousAvailable = true;
                }
                else if (aNode.InnerHtml == "Next")
                {
                    nextUrl         = "http://www2.sesco.com.my/etender/notice/" + aNode.Attributes["href"].Value;
                    isNextAvailable = true;
                }
            }

            //Extract tender data from the response
            var tenderItems = await Task.Run <Object>(() => DataExtraction.getTenderPage(htmlDoc));

            //var tenders = DataExtraction.getWebData(httpResult, "tender");
            //List<tenderItem> tenderItems = (List<tenderItem>)tenders;

            listView.ItemsSource  = (List <tenderItem>)tenderItems;
            listView.ItemTemplate = dataTemplate;

            if (isPreviousAvailable)
            {
                previousPage.IsVisible = true;
            }
            else
            {
                previousPage.IsVisible = false;
            }

            if (isNextAvailable)
            {
                nextPage.IsVisible = true;
            }
            else
            {
                nextPage.IsVisible = false;
            }
            activityIndicator.IsVisible = false;
            activityIndicator.IsRunning = false;
        }