Exemple #1
0
        public ResultList MSASConnectFetch(Uri URL)
        {
            WebClient wc = new WebClient();

            wc.Proxy = WebProxy.GetDefaultProxy();

            ResultList resList = new ResultList();


            var data = " ";

            try
            {
                data = wc.DownloadString(URL);
                //Console.WriteLine(data);
            }
            catch (Exception e)
            {
                //TabPage.displayError("MS Also blocking Dude !!! YY !!!!");
                return(null);
            }
            JObject obj = JObject.Parse(data);

            int paperCount = 0;

            if (obj["d"]["Publication"]["Result"].Count() == 0)
            {
                //TabPage.displayError("No Results");
                return(null);
            }
            int total = (int)obj["d"]["Publication"]["TotalItem"];

            Console.WriteLine("sdfsd" + total);
            resList.setCount(total);
            while (paperCount < obj["d"]["Publication"]["Result"].Count())
            {
                Result result = new Result();
                Paper  p      = new Paper();



                String title = (String)obj["d"]["Publication"]["Result"][paperCount]["Title"];
                p.settitle(title);

                String content = (String)obj["d"]["Publication"]["Result"][paperCount]["Abstract"];
                p.setdescription(content);
                int authorCount = 0;

                String authors = "";

                while (authorCount < obj["d"]["Publication"]["Result"][paperCount]["Author"].Count() && authorCount < 5)
                {
                    authors += (String)obj["d"]["Publication"]["Result"][paperCount]["Author"][authorCount]["FirstName"] + " ";

                    if ((String)obj["d"]["Publication"]["Result"][paperCount]["Author"][authorCount]["MiddleName"] != "")
                    {
                        authors += (String)obj["d"]["Publication"]["Result"][paperCount]["Author"][authorCount]["MiddleName"] + " " + (String)obj["d"]["Publication"]["Result"][paperCount]["Author"][authorCount]["LastName"] + " , ";
                    }
                    else
                    {
                        authors += (String)obj["d"]["Publication"]["Result"][paperCount]["Author"][authorCount]["LastName"] + " , ";
                    }

                    authorCount++;
                }

                p.setYear((int)obj["d"]["Publication"]["Result"][paperCount]["Year"]);
                p.setauthors(authors);

                //if (obj["d"]["Publication"]["Result"][paperCount]["Conference"] != null)
                //  p.setConferenceUrl(((String)(obj["d"]["Publication"]["Result"][paperCount]["Conference"][0])));


                int citations = Convert.ToInt32((String)obj["d"]["Publication"]["Result"][paperCount]["CitationCount"]);
                p.setnumCitations(citations);

                String url = "";

                if (obj["d"]["Publication"]["Result"][paperCount]["FullVersionURL"].Count() > 0)
                {
                    url = (String)obj["d"]["Publication"]["Result"][paperCount]["FullVersionURL"][0];
                }


                if (url != "")
                {
                    Uri titleURL = new Uri(url);
                    p.seturl(titleURL);
                }
                else
                {
                    p.seturl(null);
                }
                int id = (int)obj["d"]["Publication"]["Result"][paperCount]["ID"];
                p.setid(id);
                paperCount++;

                result.addPaper(p);
                resList.Add(result);
            }
            return(resList);
        }
Exemple #2
0
        public Result GSConnect(Uri URL)
        {
            //Console.WriteLine(URL.ToString());


            String       strResponse = this.GSTryConnect(URL);
            HtmlDocument document    = new HtmlDocument();

            document.Load(new StringReader(strResponse));

            String resTitle     = "";
            String resAuthor    = "";
            String resContent   = "";
            String resCite      = "";
            String resLink      = "";
            String profileLink  = "";
            String resTitleLink = "";

            Result result = new Result();



            HtmlNode testNode = document.DocumentNode.SelectSingleNode("//div[@id='gs_ccl']/p[@class='gs_med']");

            if (testNode != null)
            {
                TabPage.displayError("No Results Found ! Please Try Again!!!");
                return(null);
            }



            testNode = document.DocumentNode.SelectSingleNode("//div[@class='gs_r']/div[@class='gs_ri']");
            if (testNode != null)
            {
                foreach (HtmlNode startNode in document.DocumentNode.SelectNodes("//div[@class='gs_r']/div[@class='gs_ri']"))
                {
                    Paper paper = new Paper();

                    HtmlNode titleNode = startNode.SelectSingleNode("h3[@class='gs_rt']");

                    resTitle = titleNode.InnerText;
                    paper.settitle(resTitle);

                    HtmlNode authorLinkNode = titleNode.SelectSingleNode("a[@href]");

                    resTitleLink = authorLinkNode.Attributes["href"].Value;

                    paper.seturl(new Uri(resTitleLink));

                    HtmlNode authorNode = startNode.SelectSingleNode("div[@class='gs_a']");


                    resAuthor = authorNode.InnerText;
                    paper.setauthors(resAuthor);


                    HtmlNode contentNode = startNode.SelectSingleNode("div[@class='gs_rs']");

                    if (contentNode != null)
                    {
                        resContent = contentNode.InnerText;
                        if (resContent != null)
                        {
                            paper.setdescription(resContent);
                        }
                    }


                    HtmlNode citeNode = startNode.SelectSingleNode("div[@class='gs_fl']");

                    int numCite;
                    if (citeNode != null)
                    {
                        HtmlNode citeInfoNode = citeNode.SelectSingleNode("a[@href]");

                        resCite = citeInfoNode.InnerText;
                        if (resCite.Contains("Cited by"))
                        {
                            resCite = resCite.Replace("Cited by ", "");
                            numCite = Convert.ToInt32(resCite);
                            paper.setnumCitations(numCite);
                            resLink = citeInfoNode.Attributes["href"].Value;

                            paper.setcitationsUrl(resLink);
                        }
                        else
                        {
                            numCite = 0;
                            paper.setnumCitations(numCite);
                        }
                    }
                    else
                    {
                        numCite = 0;
                        paper.setnumCitations(numCite);
                    }


                    result.addPaper(paper);
                }
                return(result);
            }

            else
            {
                //TabPage.displayError("GS Blocking!!!");
                return(null);
            }
        }