예제 #1
0
        public async Task <SlideShowDetails> GetSlideShowDetailsAsync(string id)
        {
            SlideShowDetails slideShowDetails = null;

            slideShowDetails = await _theHinduClient.GetSlideShowDetailsAsync(id);

            if (slideShowDetails != null)
            {
                if (slideShowDetails.SlideDetails == null)
                {
                    slideShowDetails.SlideDetails = new List <Slidedetail>();
                    await DatabaseOperations.GetInstance().AddSlideShowAsync(slideShowDetails);
                }
            }
            return(slideShowDetails);
        }
예제 #2
0
        public async Task <SlideShowDetails> GetSlideShowDetailsAsync(string id)
        {
            var slideShowDetails = new SlideShowDetails();

            slideShowDetails.Id = id;

            var articleDescription = await GetArticleDescriptionAsync(id);

            if (!string.IsNullOrEmpty(articleDescription))
            {
                var document = new HtmlDocument();
                document.LoadHtml(articleDescription);

                try
                {
                    var pageNumberNode = document.DocumentNode.SelectSingleNode("//div[@class='wx-articlePageNavBar-pageNumber']");
                    if (pageNumberNode != null)
                    {
                        if (!string.IsNullOrEmpty(pageNumberNode.InnerText))
                        {
                            string[] delimiterChars = { "/" };
                            var      numbers        = pageNumberNode.InnerText.Split(delimiterChars, StringSplitOptions.None);
                            if (numbers.Length == 1)
                            {
                                slideShowDetails.Count = int.Parse(numbers[0]);
                            }
                            else if (numbers.Length == 2)
                            {
                                slideShowDetails.Count = int.Parse(numbers[1]);
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    if (Debugger.IsAttached)
                    {
                        Debug.WriteLine("WinSourceClient:" + exception);
                    }
                }
                try
                {
                    var nextImageNode = document.DocumentNode.SelectSingleNode("//a[@class='nextbox']");
                    if (nextImageNode != null)
                    {
                        var url = "http://m.thehindu.com" + nextImageNode.Attributes.AsQueryable().First(o => o.Name.ToLower() == "href").Value;
                        if (url.ToLower().Contains("?image="))
                        {
                            slideShowDetails.Url = url.Substring(0, url.ToLower().IndexOf("?image="));
                        }
                        else
                        {
                            slideShowDetails.Url = url;
                        }
                    }
                }
                catch (Exception exception)
                {
                    if (Debugger.IsAttached)
                    {
                        Debug.WriteLine("WinSourceClient:" + exception);
                    }
                }
            }
            return(slideShowDetails);
        }