Пример #1
0
        private void Completed(object sender, AsyncCompletedEventArgs e)
        {
            //MessageBox.Show("Download completed!");
            string filepath = ((System.Net.WebClient)(sender)).QueryString["filepath"];
            int    id       = int.Parse(((System.Net.WebClient)(sender)).QueryString["SearchResultItem.id"]);

            textBox1.Text += "download completed: " + filepath + System.Environment.NewLine;

            // Open the text file using a stream reader.
            using (StreamReader sr = new StreamReader(filepath))
            {
                // Read the stream to a string, and write the string to the console.
                String line = sr.ReadToEnd();
                SupportSLRDataSetTableAdapters.SearchResultItemTableAdapter searchResultItemTableAdapter = new SupportSLRDataSetTableAdapters.SearchResultItemTableAdapter();
                SupportSLRDataSet.SearchResultItemRow searchResultItemRow = supportSLRDataSet.SearchResultItem.FindByid(id);
                searchResultItemRow.endnote_content = line;
                searchResultItemTableAdapter.Update(supportSLRDataSet.SearchResultItem);
                searchResultItemTableAdapter.Dispose();
            }
        }
Пример #2
0
        private void SearchSpringerLink()
        {
            string basicURL          = textBox3.Text;
            string querystring       = textBox2.Text;
            string titleLocator      = textBox4.Text;
            string basicURLforResult = "http://link.springer.com/";

            int  page      = 1;
            int  page_end  = 1;
            int  numResult = 1;
            bool hasPages  = true;

            page     = int.Parse(textBox5.Text);
            page_end = int.Parse(textBox6.Text);

            while (hasPages)
            {
                string resultsFromSearch = string.Empty;
                try
                {
                    resultsFromSearch = GetContentFromURL(String.Format(basicURL, page) + querystring);
                }
                catch (Exception ex)
                {
                    textBox1.Text += "Error on: " + String.Format(basicURL, page) + querystring + System.Environment.NewLine;
                }

                if (resultsFromSearch != string.Empty)
                {
                    List <string> listResults = resultsFromSearch.Split(new string[] { titleLocator }, StringSplitOptions.None).ToList();
                    hasPages = false;
                    foreach (string result in listResults)
                    {
                        string resultTrim = result.Trim();
                        if (resultTrim.StartsWith("href="))
                        {
                            hasPages = true;

                            string token01   = "href=\"";
                            string urlResult = resultTrim.Substring(resultTrim.IndexOf(token01) + token01.Length, resultTrim.IndexOf("\">") - token01.Length);

                            string contentResult = string.Empty;
                            contentResult = GetContentFromURL(basicURLforResult + urlResult).Trim();

                            SupportSLRDataSetTableAdapters.SearchResultItemTableAdapter searchResultItemTableAdapter = new SupportSLRDataSetTableAdapters.SearchResultItemTableAdapter();
                            SupportSLRDataSet.SearchResultItemRow newSearchResultItemRow = supportSLRDataSet.SearchResultItem.NewSearchResultItemRow();
                            newSearchResultItemRow.fk_QueryDataSourceRound_id = 9; // (int)comboBox1.SelectedValue;
                            newSearchResultItemRow.url           = urlResult;
                            newSearchResultItemRow.page_content  = contentResult;
                            newSearchResultItemRow.errors_onload = string.Empty;

                            // Create Id to reference on downloaded file names
                            supportSLRDataSet.SearchResultItem.Rows.Add(newSearchResultItemRow);
                            searchResultItemTableAdapter.Update(supportSLRDataSet.SearchResultItem);

                            // Find and download Endnote file (enw)
                            try
                            {
                                FindDownloadEndnoteFile(newSearchResultItemRow, contentResult, numResult, basePathSpringerLink);
                            }
                            catch (Exception ex)
                            {
                                newSearchResultItemRow.errors_onload += "FindDownloadEndnoteFile: " + ex.Message + ex.Source + System.Environment.NewLine;
                            }

                            // Find properties of the result (title, abstract, keywords, year, pages, data source type)
                            try
                            {
                                FindProperties(newSearchResultItemRow, contentResult);
                            }
                            catch (Exception ex)
                            {
                                newSearchResultItemRow.errors_onload += "FindProperties: " + ex.Message + ex.Source + System.Environment.NewLine;
                            }

                            searchResultItemTableAdapter.Update(supportSLRDataSet.SearchResultItem);
                            searchResultItemTableAdapter.Dispose();

                            numResult++;
                        }
                    }
                    page++;

                    if (page > page_end)
                    {
                        hasPages = false;
                    }
                }
            }
        }
Пример #3
0
        private void SearchScienceDirect()
        {
            string basicURL     = textBox3.Text;
            string querystring  = textBox2.Text;
            string titleLocator = textBox4.Text;

            int  page      = 1;
            int  page_end  = 1;
            int  numResult = 1;
            bool hasPages  = true;

            page     = int.Parse(textBox5.Text);
            page_end = int.Parse(textBox6.Text);


            while (hasPages)
            {
                string resultsFromSearch = string.Empty;
                string url = String.Format(basicURL + querystring, page - 2);

                try
                {
                    resultsFromSearch = GetContentFromURL(url);
                }
                catch (Exception ex)
                {
                    textBox1.Text += "Error on: " + url + System.Environment.NewLine;
                }

                if (resultsFromSearch != string.Empty)
                {
                    List <string> listResults = resultsFromSearch.Split(new string[] { titleLocator }, StringSplitOptions.None).ToList();
                    hasPages = false;

                    foreach (string result in listResults)
                    {
                        string resultTrim = result.Trim();
                        if (resultTrim.Contains(">"))
                        {
                            resultTrim = resultTrim.Substring(resultTrim.IndexOf(">") + 1);
                        }

                        if (resultTrim.StartsWith("<H2>"))
                        {
                            hasPages = true;

                            string token01   = "href=\"";
                            string urlResult = resultTrim.Substring(resultTrim.IndexOf(token01) + token01.Length);
                            urlResult = urlResult.Substring(0, urlResult.IndexOf("\""));

                            string contentResult = string.Empty;
                            contentResult = GetContentFromURL(urlResult).Trim();

                            SupportSLRDataSetTableAdapters.SearchResultItemTableAdapter searchResultItemTableAdapter = new SupportSLRDataSetTableAdapters.SearchResultItemTableAdapter();
                            SupportSLRDataSet.SearchResultItemRow newSearchResultItemRow = supportSLRDataSet.SearchResultItem.NewSearchResultItemRow();
                            newSearchResultItemRow.fk_QueryDataSourceRound_id = 8; //(int)comboBox1.SelectedValue;
                            newSearchResultItemRow.url           = urlResult;
                            newSearchResultItemRow.page_content  = contentResult;
                            newSearchResultItemRow.errors_onload = string.Empty;

                            // Create Id to reference on downloaded file names
                            supportSLRDataSet.SearchResultItem.Rows.Add(newSearchResultItemRow);
                            searchResultItemTableAdapter.Update(supportSLRDataSet.SearchResultItem);

                            /*
                             * Not done because on the first page of the results it iss possible to export all results in a single file (to be used afterwards to cite in Word)
                             * // Find and download Endnote file (enw)
                             * try
                             * {
                             *  FindDownloadEndnoteFile(newSearchResultItemRow, contentResult, numResult, basePathSpringerLink);
                             * }
                             * catch (Exception ex)
                             * {
                             *  newSearchResultItemRow.errors_onload += "FindDownloadEndnoteFile: " + ex.Message + ex.Source + System.Environment.NewLine;
                             * }
                             */


                            // Find properties of the result (title, abstract, keywords, year, pages, data source type)
                            try
                            {
                                FindProperties(newSearchResultItemRow, contentResult);
                            }
                            catch (Exception ex)
                            {
                                newSearchResultItemRow.errors_onload += "FindProperties: " + ex.Message + ex.Source + System.Environment.NewLine;
                            }

                            searchResultItemTableAdapter.Update(supportSLRDataSet.SearchResultItem);
                            searchResultItemTableAdapter.Dispose();

                            numResult++;
                        }
                    }
                }

                page++;

                if (page > page_end)
                {
                    hasPages = false;
                }
            }
        }
Пример #4
0
        private void ReprocessSearchScienceDirect()
        {
            string basicURL     = textBox3.Text;
            string querystring  = textBox2.Text;
            string titleLocator = textBox4.Text;

            int  page      = 1;
            int  page_end  = 1;
            int  numResult = 1;
            bool hasPages  = true;

            page     = int.Parse(textBox5.Text);
            page_end = int.Parse(textBox6.Text);

            List <string> lstUrls = new List <string>();

            //lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S0196064403008217");
            lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S1386505606002000");
            //lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S1072751501007694");
            //lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S0169260700001358");
            lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S1386505615000660");
            lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S0146000509001104");
            lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S0196064408018982");
            lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S0140673613621509");
            lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S0029655408001589");
            lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S1072751507006953");
            lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S0140673609603159");
            lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S1471491414000628");
            lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S0196064411015502");
            lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S1072751512004474");
            lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S0002817714623369");
            lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S1386505605000730");
            lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S1473309909701768");
            lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S0196655304003645");
            lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S1932227511000449");
            lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S0033350616000093");
            lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S0736467912010980");
            lstUrls.Add("http://www.sciencedirect.com/science/article/pii/S1067991X14000765");

            foreach (string url in lstUrls)
            {
                string contentResult = string.Empty;
                contentResult = GetContentFromURL(url).Trim();

                SupportSLRDataSetTableAdapters.SearchResultItemTableAdapter searchResultItemTableAdapter = new SupportSLRDataSetTableAdapters.SearchResultItemTableAdapter();
                SupportSLRDataSet.SearchResultItemRow newSearchResultItemRow = supportSLRDataSet.SearchResultItem.NewSearchResultItemRow();
                newSearchResultItemRow.fk_QueryDataSourceRound_id = 2; //(int)comboBox1.SelectedValue;
                newSearchResultItemRow.url           = url;
                newSearchResultItemRow.page_content  = contentResult;
                newSearchResultItemRow.errors_onload = string.Empty;

                // Create Id to reference on downloaded file names
                supportSLRDataSet.SearchResultItem.Rows.Add(newSearchResultItemRow);
                searchResultItemTableAdapter.Update(supportSLRDataSet.SearchResultItem);

                // Find properties of the result (title, abstract, keywords, year, pages, data source type)
                try
                {
                    FindProperties(newSearchResultItemRow, contentResult);
                }
                catch (Exception ex)
                {
                    newSearchResultItemRow.errors_onload += "FindProperties: " + ex.Message + ex.Source + System.Environment.NewLine;
                }

                searchResultItemTableAdapter.Update(supportSLRDataSet.SearchResultItem);
                searchResultItemTableAdapter.Dispose();

                numResult++;
            }
        }
Пример #5
0
        private void SearchWiley()
        {
            string basicURL     = textBox3.Text;
            string querystring  = textBox2.Text;
            string titleLocator = textBox4.Text;

            int  page      = 1;
            int  page_end  = 1;
            int  numResult = 1;
            bool hasPages  = true;

            page     = int.Parse(textBox5.Text);
            page_end = int.Parse(textBox6.Text);


            while (hasPages)
            {
                string resultsFromSearch = string.Empty;
                string url = String.Format(basicURL + querystring, (page - 1) * 20 + 1);
                url = url.Replace("&amp;", "&");

                try
                {
                    resultsFromSearch = GetContentFromURL(url);
                }
                catch (Exception ex)
                {
                    textBox1.Text += "Error on: " + url + System.Environment.NewLine;
                }

                if (resultsFromSearch != string.Empty)
                {
                    List <string> listResults = resultsFromSearch.Split(new string[] { titleLocator }, StringSplitOptions.None).ToList();
                    listResults.RemoveAt(0);
                    hasPages = false;

                    foreach (string result in listResults)
                    {
                        string resultTrim = result.Trim();

                        hasPages = true;

                        string token01   = "href=\"";
                        string urlResult = resultTrim.Substring(resultTrim.IndexOf(token01) + token01.Length);
                        urlResult = basicURL + urlResult.Substring(0, urlResult.IndexOf("\"")).Replace("&lt;", "%3C").Replace("&gt;", "%3E");

                        string contentResult = string.Empty;
                        contentResult = GetContentFromURL(urlResult).Trim();

                        SupportSLRDataSetTableAdapters.SearchResultItemTableAdapter searchResultItemTableAdapter = new SupportSLRDataSetTableAdapters.SearchResultItemTableAdapter();
                        SupportSLRDataSet.SearchResultItemRow newSearchResultItemRow = supportSLRDataSet.SearchResultItem.NewSearchResultItemRow();
                        newSearchResultItemRow.fk_QueryDataSourceRound_id = 12; //(int)comboBox1.SelectedValue;
                        newSearchResultItemRow.url           = urlResult;
                        newSearchResultItemRow.page_content  = contentResult;
                        newSearchResultItemRow.errors_onload = string.Empty;

                        // Create Id to reference on downloaded file names
                        supportSLRDataSet.SearchResultItem.Rows.Add(newSearchResultItemRow);
                        searchResultItemTableAdapter.Update(supportSLRDataSet.SearchResultItem);

                        // Find properties of the result (title, abstract, keywords, year, pages, data source type)
                        try
                        {
                            FindProperties(newSearchResultItemRow, contentResult);
                        }
                        catch (Exception ex)
                        {
                            newSearchResultItemRow.errors_onload += "FindProperties: " + ex.Message + ex.Source + System.Environment.NewLine;
                        }

                        searchResultItemTableAdapter.Update(supportSLRDataSet.SearchResultItem);
                        searchResultItemTableAdapter.Dispose();

                        numResult++;
                    }
                }

                page++;

                if (page > page_end)
                {
                    hasPages = false;
                }
            }
        }
Пример #6
0
        private void SearchScopus()
        {
            string filepath    = textBox3.Text;
            string typeLocator = textBox4.Text;

            string resultsFromFile = string.Empty;

            try
            {
                resultsFromFile = GetContentFromFile(filepath);
            }
            catch (Exception ex)
            {
                textBox1.Text += "Error on: " + filepath + Environment.NewLine;
            }

            List <string> listResults = resultsFromFile.Split(new string[] { typeLocator }, StringSplitOptions.None).ToList();

            listResults.RemoveAt(0);

            foreach (string result in listResults)
            {
                string resultTrim = result.Trim();

                SupportSLRDataSetTableAdapters.SearchResultItemTableAdapter searchResultItemTableAdapter = new SupportSLRDataSetTableAdapters.SearchResultItemTableAdapter();
                SupportSLRDataSet.SearchResultItemRow newSearchResultItemRow = supportSLRDataSet.SearchResultItem.NewSearchResultItemRow();
                newSearchResultItemRow.fk_QueryDataSourceRound_id = 11; //(int)comboBox1.SelectedValue;

                string line_break = "\n";

                string temp = resultTrim;
                string type = temp.Substring(0, temp.IndexOf(line_break)).Trim();
                type = (type == "JOUR") ? "Journal" : (type == "CONF") ? "Conference proceeding" : "Book Section";
                temp = temp.Substring(temp.IndexOf(line_break));

                string temp2 = "TI  - ";
                temp = temp.Substring(temp.IndexOf(temp2) + temp2.Length);
                string title = temp.Substring(0, temp.IndexOf(line_break)).Trim();

                string pages = string.Empty;
                temp2 = "SP  - ";
                if (temp.Contains(temp2))
                {
                    temp  = temp.Substring(temp.IndexOf(temp2) + temp2.Length);
                    pages = temp.Substring(0, temp.IndexOf(line_break)).Trim();

                    temp2  = "EP  - ";
                    temp   = temp.Substring(temp.IndexOf(temp2) + temp2.Length);
                    pages += "-" + temp.Substring(0, temp.IndexOf(line_break)).Trim();
                }

                temp2 = "PY  - ";
                temp  = temp.Substring(temp.IndexOf(temp2) + temp2.Length);
                string year = temp.Substring(0, temp.IndexOf(line_break)).Trim();

                temp2 = "UR  - ";
                temp  = temp.Substring(temp.IndexOf(temp2) + temp2.Length);
                string url = temp.Substring(0, temp.IndexOf(line_break)).Trim();

                newSearchResultItemRow.type             = type;
                newSearchResultItemRow.title            = title;
                newSearchResultItemRow.pages            = pages;
                newSearchResultItemRow.date_publication = year;
                newSearchResultItemRow.url = url;

                supportSLRDataSet.SearchResultItem.Rows.Add(newSearchResultItemRow);
                searchResultItemTableAdapter.Update(supportSLRDataSet.SearchResultItem);

                try
                {                 // Search by title in Google
                    string query   = "\"" + title + "\"";
                    var    client  = new SearchClient(query);
                    string content = string.Empty;

                    foreach (var hit in client.Query())
                    {
                        string urlResult = hit.CleanUri.ToString();
                        try
                        {
                            content = GetContentFromURL(urlResult);
                        }
                        catch (Exception ex)
                        {
                            textBox1.Text += "Error on: " + url + Environment.NewLine;
                        }

                        //if (!content.StartsWith("%PDF") && content.ToLower().Contains("abstract"))
                        break;
                    }

                    newSearchResultItemRow.page_content = content;
                }
                catch (Exception ex)
                {
                    textBox1.Text += "Error on Googling: " + ex.Message + Environment.NewLine;
                }

                newSearchResultItemRow.errors_onload = string.Empty;

                searchResultItemTableAdapter.Update(supportSLRDataSet.SearchResultItem);
                searchResultItemTableAdapter.Dispose();
            }
        }