Beispiel #1
0
        private void SearchButton_Click(object sender, EventArgs e)
        {
            // Companies
            // Financial Organizations
            String entity      = EntityCombo.Text == "Companies"? "company":"financial-organization";
            String querystring = "";



            if (NameTextBox.Text != "")  // then create a  query
            {
                querystring = "query=" + NameTextBox.Text + "&entity=" + entity + (checkBoxTags.Checked ?"&field=tag_list":"&field=name");

                CrunchBaseConnect cbc = new CrunchBaseConnect();
                DiagnosticTimer.StartTimer("SearchCrunch");
                List <cbSearchResults> myresults = cbc.SearchResults(querystring);
                resultslist = myresults;
                SearchResultsGrid.DataSource       = myresults;
                SearchResultsGrid.Columns[0].Width = 8 * 20;
                SearchResultsGrid.Columns[1].Width = 8 * 20;
                SearchResultsGrid.Columns[2].Width = 8 * 12;
                SearchResultsGrid.Columns[3].Width = 8 * 60;
                DiagnosticTimer.StopTimer("SearchCrunch");
            }
        }
Beispiel #2
0
        private void InsertResultsButton_Click(object sender, EventArgs e)
        {
            DiagnosticTimer.StartTimer("InsertResults");
            List <cbSearchResults> sgrid = SearchResultsGrid.DataSource as List <cbSearchResults>;

            object[,] spread = new object[sgrid.Count + 1, 4];
            spread[0, 0]     = "name";
            spread[0, 1]     = "permalink";
            spread[0, 2]     = "namespace";
            spread[0, 3]     = "overview";
            for (int i = 0; i < sgrid.Count; i++)
            {
                spread[i + 1, 0] = sgrid[i].name;
                spread[i + 1, 1] = sgrid[i].permalink;
                spread[i + 1, 2] = sgrid[i].Namespace;
                spread[i + 1, 3] = sgrid[i].overview;
            }
            var curr       = Globals.ThisAddIn.Application.ActiveSheet;
            var startCell  = Globals.ThisAddIn.Application.ActiveCell;
            var endCell    = curr.Cells[startCell.Row + sgrid.Count, startCell.Column + 3];
            var writeRange = curr.Range[startCell, endCell];

            DiagnosticTimer.StartTimer("WriteGridToExcel");
            writeRange.Value2            = spread;
            writeRange.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignTop;
            DiagnosticTimer.StartTimer("FormatExcelGrid");
            writeRange.RowHeight = 14;
            // set the width of name and permalink columns to 140 pixels
            var startcol = startCell;
            var endcol   = curr.Cells[endCell.Row, startCell.Column + 1];
            var setcols  = curr.Range[startcol, endcol].ColumnWidth = 20;

            // set width of permalink to 10
            startcol = curr.Cells[startCell.Row, startCell.Column + 2];
            endcol   = curr.Cells[endCell.Row, startCell.Column + 2];
            setcols  = curr.Range[startcol, endcol].ColumnWidth = 10;
            // set overview to 60

            startcol = curr.Cells[startCell.Row, startCell.Column + 3];
            endcol   = curr.Cells[endCell.Row, startCell.Column + 3];
            setcols  = curr.Range[startcol, endcol].ColumnWidth = 60;
            DiagnosticTimer.StopTimer("FormatExcelGrid");
            DiagnosticTimer.StopTimer("WriteGridToExcel");
            DiagnosticTimer.StopTimer("InsertResults");
            DiagnosticTimer.WriteAllTimersDiag();
        }
        public List <cbSearchResults> SearchResults(string querystring)
        {
            CrunchJsonStream sr         = new CrunchJsonStream();
            string           jsonStream = sr.GetJsonSearch(querystring);

            if (jsonStream != null)
            {
                try
                {
                    DiagnosticTimer.StartTimer("firstpage");
                    JavaScriptSerializer ser = new JavaScriptSerializer();
                    //with the stream, now deserialize into the Crunchbase object
                    ResultsPage Results = ser.Deserialize <ResultsPage>(jsonStream);
                    DiagnosticTimer.StopTimer("firstpage");
                    // we got the first page create a big list of all the pages
                    if (Results.total < 11)
                    { // no extra pages
                        return(Results.results);
                    }
                    else //get the other pages
                    {
                        bool ShowProgress = Results.total > 60 ? true : false;
                        SearchingCrunchBaseProgressForm progressdialog = new SearchingCrunchBaseProgressForm();
                        if (ShowProgress) // put up the dialog
                        {
                            progressdialog.TotalFound    = Results.total;
                            progressdialog.Retireved     = 10;
                            progressdialog.EstimatedTime = new TimeSpan(DiagnosticTimer.GetTimerTimeSpan("firstpage").Ticks *(Results.total));
                            progressdialog.Show();
                        }

                        List <cbSearchResults> allresults = Results.results;
                        for (int i = 2; i < (Results.total / 10) + 1; i++)
                        {
                            jsonStream = sr.GetJsonSearch(querystring + "&page=" + i.ToString());
                            if (jsonStream != null)
                            {
                                try
                                {
                                    ser = new JavaScriptSerializer();
                                    //with the stream, now deserialize into the Crunchbase object
                                    Results = ser.Deserialize <ResultsPage>(jsonStream);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine("Oops, the exception {0} happened with {1}", e.ToString(), querystring);
                                    return(null);
                                }
                                allresults.AddRange(Results.results);
                                if (ShowProgress)
                                {
                                    progressdialog.Retireved     = i * 10;
                                    progressdialog.EstimatedTime = new TimeSpan(DiagnosticTimer.GetTimerTimeSpan("firstpage").Ticks *(Results.total - i));
                                    progressdialog.Update();
                                    if (progressdialog.Canceled)
                                    {
                                        progressdialog.Close();
                                        return(allresults);
                                    }
                                }
                            }
                        }
                        if (ShowProgress)
                        {
                            progressdialog.Close();
                        }
                        return(allresults);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Oops, the exception {0} happened with {1}", e.ToString(), querystring);
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }