[Quantproject-developers] QuantDownloader/Downloader TickerDownloader.cs,1.3,1.4 WebDownloader.cs,1.
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2004-04-17 14:14:50
|
Update of /cvsroot/quantproject/QuantDownloader/Downloader In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5513/Downloader Modified Files: TickerDownloader.cs WebDownloader.cs Log Message: TickerDownloader now works with new options provided by a new web downloader form Index: WebDownloader.cs =================================================================== RCS file: /cvsroot/quantproject/QuantDownloader/Downloader/WebDownloader.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** WebDownloader.cs 21 Mar 2004 19:34:12 -0000 1.9 --- WebDownloader.cs 17 Apr 2004 14:14:41 -0000 1.10 *************** *** 10,13 **** --- 10,15 ---- using System.Threading; using QuantProject.DataAccess; + using QuantProject.DataAccess.Tables; + using QuantProject.Applications.Downloader.TickerSelectors; namespace QuantProject.Applications.Downloader *************** *** 16,20 **** /// Summary description for Form1. /// </summary> ! public class WebDownloader : System.Windows.Forms.Form { public OleDbConnection OleDbConnection1 = ConnectionProvider.OleDbConnection; --- 18,22 ---- /// Summary description for Form1. /// </summary> ! public class WebDownloader : System.Windows.Forms.Form, ITickerSelector { public OleDbConnection OleDbConnection1 = ConnectionProvider.OleDbConnection; *************** *** 43,46 **** --- 45,49 ---- internal System.Windows.Forms.CheckBox checkBoxIsDicotomicSearchActivated; private System.Windows.Forms.RadioButton radioButtonDownloadBeforeMinAndAfterMax; + private System.Windows.Forms.RadioButton radioButtonDownloadOnlyAfterMax; /// <summary> /// Required designer variable. *************** *** 102,109 **** private void commonInitialization() { ! this.radioButtonAllAvailableUntilNow.Checked = true; ! this.dateTimePickerStartingDate.Value = new DateTime(1980,1,1); //this.dateTimePickerStartingDate.Refresh(); ! this.radioButtonOverWriteNo.Checked = true; } --- 105,113 ---- private void commonInitialization() { ! this.dateTimePickerStartingDate.Value = QuantProject.ADT.ConstantsProvider.InitialDateTimeForDownload; //this.dateTimePickerStartingDate.Refresh(); ! this.radioButtonAllAvailableUntilNow.Checked = true; ! this.radioButtonDownloadOnlyAfterMax.Checked = true; ! this.dataGrid1.ContextMenu = new TickerViewerMenu(this); } *************** *** 134,137 **** --- 138,142 ---- this.checkBoxIsDicotomicSearchActivated = new System.Windows.Forms.CheckBox(); this.groupBoxUpdateDatabaseOptions = new System.Windows.Forms.GroupBox(); + this.radioButtonDownloadOnlyAfterMax = new System.Windows.Forms.RadioButton(); this.radioButtonDownloadBeforeMinAndAfterMax = new System.Windows.Forms.RadioButton(); this.radioButtonOverWriteNo = new System.Windows.Forms.RadioButton(); *************** *** 144,148 **** // button1 // ! this.button1.Location = new System.Drawing.Point(88, 320); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(112, 32); --- 149,153 ---- // button1 // ! this.button1.Location = new System.Drawing.Point(88, 352); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(112, 32); *************** *** 155,161 **** this.dataGrid1.DataMember = ""; this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText; ! this.dataGrid1.Location = new System.Drawing.Point(304, 8); this.dataGrid1.Name = "dataGrid1"; ! this.dataGrid1.Size = new System.Drawing.Size(272, 432); this.dataGrid1.TabIndex = 1; // --- 160,166 ---- this.dataGrid1.DataMember = ""; this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText; ! this.dataGrid1.Location = new System.Drawing.Point(328, 8); this.dataGrid1.Name = "dataGrid1"; ! this.dataGrid1.Size = new System.Drawing.Size(304, 456); this.dataGrid1.TabIndex = 1; // *************** *** 239,243 **** // buttonDownloadQuotesOfSelectedTickers // ! this.buttonDownloadQuotesOfSelectedTickers.Location = new System.Drawing.Point(88, 360); this.buttonDownloadQuotesOfSelectedTickers.Name = "buttonDownloadQuotesOfSelectedTickers"; this.buttonDownloadQuotesOfSelectedTickers.Size = new System.Drawing.Size(112, 32); --- 244,248 ---- // buttonDownloadQuotesOfSelectedTickers // ! this.buttonDownloadQuotesOfSelectedTickers.Location = new System.Drawing.Point(88, 392); this.buttonDownloadQuotesOfSelectedTickers.Name = "buttonDownloadQuotesOfSelectedTickers"; this.buttonDownloadQuotesOfSelectedTickers.Size = new System.Drawing.Size(112, 32); *************** *** 248,252 **** // labelNumberOfTickersToDownload // ! this.labelNumberOfTickersToDownload.Location = new System.Drawing.Point(152, 408); this.labelNumberOfTickersToDownload.Name = "labelNumberOfTickersToDownload"; this.labelNumberOfTickersToDownload.Size = new System.Drawing.Size(48, 24); --- 253,257 ---- // labelNumberOfTickersToDownload // ! this.labelNumberOfTickersToDownload.Location = new System.Drawing.Point(152, 440); this.labelNumberOfTickersToDownload.Name = "labelNumberOfTickersToDownload"; this.labelNumberOfTickersToDownload.Size = new System.Drawing.Size(48, 24); *************** *** 256,260 **** // labelTickersLeft // ! this.labelTickersLeft.Location = new System.Drawing.Point(8, 408); this.labelTickersLeft.Name = "labelTickersLeft"; this.labelTickersLeft.Size = new System.Drawing.Size(136, 24); --- 261,265 ---- // labelTickersLeft // ! this.labelTickersLeft.Location = new System.Drawing.Point(8, 440); this.labelTickersLeft.Name = "labelTickersLeft"; this.labelTickersLeft.Size = new System.Drawing.Size(136, 24); *************** *** 292,296 **** this.radioButtonAllAvailableUntilNowSinceStartingDate.Size = new System.Drawing.Size(272, 24); this.radioButtonAllAvailableUntilNowSinceStartingDate.TabIndex = 12; ! this.radioButtonAllAvailableUntilNowSinceStartingDate.Text = "Change starting date"; // // groupBoxWebDownloaderOptions --- 297,301 ---- this.radioButtonAllAvailableUntilNowSinceStartingDate.Size = new System.Drawing.Size(272, 24); this.radioButtonAllAvailableUntilNowSinceStartingDate.TabIndex = 12; ! this.radioButtonAllAvailableUntilNowSinceStartingDate.Text = "All available quotes until now, changing starting date"; // // groupBoxWebDownloaderOptions *************** *** 301,305 **** this.groupBoxWebDownloaderOptions.Location = new System.Drawing.Point(8, 8); this.groupBoxWebDownloaderOptions.Name = "groupBoxWebDownloaderOptions"; ! this.groupBoxWebDownloaderOptions.Size = new System.Drawing.Size(288, 88); this.groupBoxWebDownloaderOptions.TabIndex = 13; this.groupBoxWebDownloaderOptions.TabStop = false; --- 306,310 ---- this.groupBoxWebDownloaderOptions.Location = new System.Drawing.Point(8, 8); this.groupBoxWebDownloaderOptions.Name = "groupBoxWebDownloaderOptions"; ! this.groupBoxWebDownloaderOptions.Size = new System.Drawing.Size(312, 88); this.groupBoxWebDownloaderOptions.TabIndex = 13; this.groupBoxWebDownloaderOptions.TabStop = false; *************** *** 310,314 **** this.checkBoxIsDicotomicSearchActivated.Checked = true; this.checkBoxIsDicotomicSearchActivated.CheckState = System.Windows.Forms.CheckState.Checked; ! this.checkBoxIsDicotomicSearchActivated.Location = new System.Drawing.Point(16, 288); this.checkBoxIsDicotomicSearchActivated.Name = "checkBoxIsDicotomicSearchActivated"; this.checkBoxIsDicotomicSearchActivated.Size = new System.Drawing.Size(272, 24); --- 315,319 ---- this.checkBoxIsDicotomicSearchActivated.Checked = true; this.checkBoxIsDicotomicSearchActivated.CheckState = System.Windows.Forms.CheckState.Checked; ! this.checkBoxIsDicotomicSearchActivated.Location = new System.Drawing.Point(16, 320); this.checkBoxIsDicotomicSearchActivated.Name = "checkBoxIsDicotomicSearchActivated"; this.checkBoxIsDicotomicSearchActivated.Size = new System.Drawing.Size(272, 24); *************** *** 319,322 **** --- 324,328 ---- // this.groupBoxUpdateDatabaseOptions.Controls.AddRange(new System.Windows.Forms.Control[] { + this.radioButtonDownloadOnlyAfterMax, this.radioButtonDownloadBeforeMinAndAfterMax, this.radioButtonOverWriteNo, *************** *** 324,347 **** this.groupBoxUpdateDatabaseOptions.Location = new System.Drawing.Point(8, 136); this.groupBoxUpdateDatabaseOptions.Name = "groupBoxUpdateDatabaseOptions"; ! this.groupBoxUpdateDatabaseOptions.Size = new System.Drawing.Size(288, 144); this.groupBoxUpdateDatabaseOptions.TabIndex = 14; this.groupBoxUpdateDatabaseOptions.TabStop = false; this.groupBoxUpdateDatabaseOptions.Text = "Update Database options"; // // radioButtonDownloadBeforeMinAndAfterMax // ! this.radioButtonDownloadBeforeMinAndAfterMax.Enabled = false; ! this.radioButtonDownloadBeforeMinAndAfterMax.Location = new System.Drawing.Point(16, 24); this.radioButtonDownloadBeforeMinAndAfterMax.Name = "radioButtonDownloadBeforeMinAndAfterMax"; ! this.radioButtonDownloadBeforeMinAndAfterMax.Size = new System.Drawing.Size(248, 32); this.radioButtonDownloadBeforeMinAndAfterMax.TabIndex = 2; ! this.radioButtonDownloadBeforeMinAndAfterMax.Text = "Download only quotes that come before first quote or after last quote in database" + ! ""; // // radioButtonOverWriteNo // ! this.radioButtonOverWriteNo.Location = new System.Drawing.Point(16, 64); this.radioButtonOverWriteNo.Name = "radioButtonOverWriteNo"; ! this.radioButtonOverWriteNo.Size = new System.Drawing.Size(248, 32); this.radioButtonOverWriteNo.TabIndex = 1; this.radioButtonOverWriteNo.Text = "Download all quotes, adding to database only the missing ones"; --- 330,361 ---- this.groupBoxUpdateDatabaseOptions.Location = new System.Drawing.Point(8, 136); this.groupBoxUpdateDatabaseOptions.Name = "groupBoxUpdateDatabaseOptions"; ! this.groupBoxUpdateDatabaseOptions.Size = new System.Drawing.Size(312, 176); this.groupBoxUpdateDatabaseOptions.TabIndex = 14; this.groupBoxUpdateDatabaseOptions.TabStop = false; this.groupBoxUpdateDatabaseOptions.Text = "Update Database options"; // + // radioButtonDownloadOnlyAfterMax + // + this.radioButtonDownloadOnlyAfterMax.Checked = true; + this.radioButtonDownloadOnlyAfterMax.Location = new System.Drawing.Point(16, 24); + this.radioButtonDownloadOnlyAfterMax.Name = "radioButtonDownloadOnlyAfterMax"; + this.radioButtonDownloadOnlyAfterMax.Size = new System.Drawing.Size(288, 24); + this.radioButtonDownloadOnlyAfterMax.TabIndex = 3; + this.radioButtonDownloadOnlyAfterMax.TabStop = true; + this.radioButtonDownloadOnlyAfterMax.Text = "Download only quotes after last quote (fastest)"; + // // radioButtonDownloadBeforeMinAndAfterMax // ! this.radioButtonDownloadBeforeMinAndAfterMax.Location = new System.Drawing.Point(16, 56); this.radioButtonDownloadBeforeMinAndAfterMax.Name = "radioButtonDownloadBeforeMinAndAfterMax"; ! this.radioButtonDownloadBeforeMinAndAfterMax.Size = new System.Drawing.Size(288, 32); this.radioButtonDownloadBeforeMinAndAfterMax.TabIndex = 2; ! this.radioButtonDownloadBeforeMinAndAfterMax.Text = "Download only quotes before first quote and after last quote"; // // radioButtonOverWriteNo // ! this.radioButtonOverWriteNo.Location = new System.Drawing.Point(16, 96); this.radioButtonOverWriteNo.Name = "radioButtonOverWriteNo"; ! this.radioButtonOverWriteNo.Size = new System.Drawing.Size(288, 32); this.radioButtonOverWriteNo.TabIndex = 1; this.radioButtonOverWriteNo.Text = "Download all quotes, adding to database only the missing ones"; *************** *** 349,355 **** // radioButtonOverWriteYes // ! this.radioButtonOverWriteYes.Location = new System.Drawing.Point(16, 104); this.radioButtonOverWriteYes.Name = "radioButtonOverWriteYes"; ! this.radioButtonOverWriteYes.Size = new System.Drawing.Size(248, 32); this.radioButtonOverWriteYes.TabIndex = 0; this.radioButtonOverWriteYes.Text = "Download all quotes, overwriting the existing ones in database"; --- 363,369 ---- // radioButtonOverWriteYes // ! this.radioButtonOverWriteYes.Location = new System.Drawing.Point(16, 136); this.radioButtonOverWriteYes.Name = "radioButtonOverWriteYes"; ! this.radioButtonOverWriteYes.Size = new System.Drawing.Size(288, 32); this.radioButtonOverWriteYes.TabIndex = 0; this.radioButtonOverWriteYes.Text = "Download all quotes, overwriting the existing ones in database"; *************** *** 358,362 **** // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); ! this.ClientSize = new System.Drawing.Size(584, 446); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.groupBoxUpdateDatabaseOptions, --- 372,376 ---- // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); ! this.ClientSize = new System.Drawing.Size(664, 470); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.groupBoxUpdateDatabaseOptions, *************** *** 498,503 **** #endregion - private void downloadQuotes_withTickerDataSet_create_dsTickerCurrentlyDownloaded( DataTable dt ) { --- 512,547 ---- #endregion + #region ITickerSelector's implementation + public TickerDataTable GetTableOfSelectedTickers() + { + DataTable dataTableOfDataGrid1 = (DataTable)this.dataGrid1.DataSource; + TickerDataTable tableOfSelectedTickers = new TickerDataTable(); + int indexOfRow = 0; + while(indexOfRow != dataTableOfDataGrid1.Rows.Count) + { + if(this.dataGrid1.IsSelected(indexOfRow)) + { + DataRow dataRow = tableOfSelectedTickers.NewRow(); + dataRow[0] = (string)dataTableOfDataGrid1.Rows[indexOfRow][0]; + tableOfSelectedTickers.Rows.Add(dataRow); + } + indexOfRow++; + } + return tableOfSelectedTickers; + } + + public void SelectAllTickers() + { + DataTable dataTableOfDataGrid1 = (DataTable)this.dataGrid1.DataSource; + int indexOfRow = 0; + while(indexOfRow != dataTableOfDataGrid1.Rows.Count) + { + this.dataGrid1.Select(indexOfRow); + indexOfRow++; + } + } + #endregion + private void downloadQuotes_withTickerDataSet_create_dsTickerCurrentlyDownloaded( DataTable dt ) { *************** *** 508,511 **** --- 552,556 ---- new DataColumn( dt.Columns[ "tiTicker" ].ColumnName , dt.Columns[ "tiTicker" ].DataType ) ); this.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ].Columns.Add( "currentState" , System.Type.GetType( "System.String" ) ); + this.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ].Columns.Add( "adjustedClose" , System.Type.GetType( "System.String" ) ); this.dataGrid1.DataSource = this.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ]; } *************** *** 532,535 **** --- 577,581 ---- } Cursor.Current = Cursors.Default; + //newThread.Join(); //qd.downloadTicker(); *************** *** 566,570 **** { Cursor.Current = Cursors.WaitCursor; ! this.OleDbConnection1.Open(); oleDbCommand1.Connection = this.OleDbConnection1; //this.oleDbCommand1.ExecuteNonQuery(); --- 612,617 ---- { Cursor.Current = Cursors.WaitCursor; ! if (this.OleDbConnection1.State != ConnectionState.Open) ! this.OleDbConnection1.Open(); oleDbCommand1.Connection = this.OleDbConnection1; //this.oleDbCommand1.ExecuteNonQuery(); *************** *** 591,594 **** --- 638,642 ---- this.openDbAndSetOleDbCommand(); this.downloadQuotesOfAllTickers(); + this.button1.Enabled = false; } *************** *** 597,600 **** --- 645,649 ---- this.openDbAndSetOleDbCommand(); this.downloadQuotesOfSelectedTickers(); + this.buttonDownloadQuotesOfSelectedTickers.Enabled = false; } *************** *** 610,613 **** --- 659,679 ---- } } + + public bool IsUpdateOptionSelected + { + get + { + return (this.radioButtonDownloadBeforeMinAndAfterMax.Checked || + this.radioButtonDownloadOnlyAfterMax.Checked); + } + } + + public bool IsOnlyAfterLastQuoteSelected + { + get + { + return this.radioButtonDownloadOnlyAfterMax.Checked; + } + } } } Index: TickerDownloader.cs =================================================================== RCS file: /cvsroot/quantproject/QuantDownloader/Downloader/TickerDownloader.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TickerDownloader.cs 21 Mar 2004 19:30:28 -0000 1.3 --- TickerDownloader.cs 17 Apr 2004 14:14:41 -0000 1.4 *************** *** 4,7 **** --- 4,9 ---- using System.Net; using System.Windows.Forms; + using QuantProject.DataAccess.Tables; + using QuantProject.ADT; namespace QuantProject.Applications.Downloader *************** *** 17,20 **** --- 19,23 ---- private string p_quTicker; private int p_numRows; + private DateTime INITIAL_DATE = ConstantsProvider.InitialDateTimeForDownload; private DateTime startDate; private DateTime endDate = DateTime.Today; *************** *** 22,26 **** private int endMonth = DateTime.Now.Month; private int endYear = DateTime.Now.Year; ! private DateTime INITIAL_DATE = new DateTime(1980, 1, 1); public TickerDownloader( WebDownloader myForm, DataRow currentDataTickerRow, string quTicker , int numRows ) { --- 25,30 ---- private int endMonth = DateTime.Now.Month; private int endYear = DateTime.Now.Year; ! private int numberOfQuotesInDatabase; ! public TickerDownloader( WebDownloader myForm, DataRow currentDataTickerRow, string quTicker , int numRows ) { *************** *** 54,58 **** } } ! private void addTickerToFaultyTickers() { --- 58,71 ---- } } ! ! private void updateCurrentStatusAdjustedClose(string stateOfAdjustedCloseValue ) ! { ! lock( p_myForm.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ] ) ! { ! DataRow[] myRows = p_myForm.DsTickerCurrentlyDownloaded.Tables[ "Tickers" ].Select( "tiTicker='" + p_quTicker + "'" ); ! myRows[ 0 ][ "adjustedClose" ] = stateOfAdjustedCloseValue; ! p_myForm.dataGrid1.Refresh(); ! } ! } private void addTickerToFaultyTickers() { *************** *** 88,92 **** + a + "&b=" + b + "&c=" + c +"&d=" + d + "&e=" + e + "&f=" + f + "&s=" + p_quTicker + "&y=0&g=d&ignore=.csv"); Req.Method = "GET"; ! Req.Timeout = 25000; HttpWebResponse hwr = (HttpWebResponse)Req.GetResponse(); Stream strm = hwr.GetResponseStream(); --- 101,105 ---- + a + "&b=" + b + "&c=" + c +"&d=" + d + "&e=" + e + "&f=" + f + "&s=" + p_quTicker + "&y=0&g=d&ignore=.csv"); Req.Method = "GET"; ! Req.Timeout = ConstantsProvider.TimeOutValue; HttpWebResponse hwr = (HttpWebResponse)Req.GetResponse(); Stream strm = hwr.GetResponseStream(); *************** *** 98,104 **** sr.Close(); strm.Close(); ! hwr.Close(); ! updateCurrentStatus( d + "/" + e + "/" + f ); numTrials = 6 ; } --- 111,117 ---- sr.Close(); strm.Close(); ! //hwr.Close(); ! updateCurrentStatus( d + "/" + e + "/" + f ); numTrials = 6 ; } *************** *** 138,141 **** --- 151,155 ---- newRow[ "tiTicker" ] = p_quTicker; newRow[ "currentState" ] = "Searching ..."; + newRow[ "adjustedClose"] = "..."; try { *************** *** 151,174 **** } public void DownloadTicker() { // update grid in webdownloader form addTickerTo_gridDataSet(); ! /* if(tickerIsInDatabase && p_myForm.UpdateFlagYes) { ! // try to import ticker before the first quote ! ! // try to import ticker after the last quote } else ! // tickers'quotes are downloaded for the first time ! {*/ ! if(this.p_myForm.checkBoxIsDicotomicSearchActivated.Checked == true) ! this.startDate = firstAvailableDateOnYahoo(this.INITIAL_DATE, this.endDate); ! setTimeFrameAndImportTickerForEachTimeFrame(200); ! ! //} ! //Monitor.Pulse( p_myForm.dsTickerCurrentlyDownloaded.Tables[ "Tickers" ] ); } public void DownloadTicker(DateTime startingDate) --- 165,267 ---- } + private void resetStartDateIfNecessary() + { + if(this.p_myForm.checkBoxIsDicotomicSearchActivated.Checked == true) + this.startDate = firstAvailableDateOnYahoo(this.INITIAL_DATE, this.endDate); + } + + private void downloadTickerBeforeFirstQuote() + { + this.endDate = Quotes.GetStartDate(this.p_quTicker); + this.resetStartDateIfNecessary(); + this.setTimeFrameAndImportTickerForEachTimeFrame(200); + } + + private bool getResponseForRepeatedChecks(int numberOfRepeatedChecks) + { + bool response = false; + Quotes tickerQuotes = new Quotes(this.p_quTicker); + for(int i = 1; i< this.numberOfQuotesInDatabase; i += this.numberOfQuotesInDatabase/numberOfRepeatedChecks) + { + DateTime dateToCheck = tickerQuotes.GetPrecedingDate(this.startDate, i); + response = + Quotes.IsAdjustedCloseChanged(this.p_quTicker, dateToCheck, + this.adjustedCloseFromSource(dateToCheck)); + } + return response; + } + + private void checkForNewAdjustedValueFromSource() + { + try + { + if(this.getResponseForRepeatedChecks(ConstantsProvider.NumberOfCheckToPerformOnAdjustedValues)) + { + this.updateCurrentStatusAdjustedClose("Changed!"); + } + else + { + this.updateCurrentStatusAdjustedClose("OK"); + } + } + catch(Exception ex) + { + MessageBox.Show(ex.ToString()); + } + } + + + + private void downloadTickerAfterLastQuote() + { + this.startDate = Quotes.GetEndDate(this.p_quTicker); + this.endDate = DateTime.Today; + this.checkForNewAdjustedValueFromSource(); + this.setTimeFrameAndImportTickerForEachTimeFrame(200); + + } + + private float adjustedCloseFromSource(DateTime adjustedCloseDate) + { + string Line; + string[] LineIn = null; + StreamReader streamReader = this.getStreamReaderFromSource(adjustedCloseDate, 0); + Line = streamReader.ReadLine(); + Line = streamReader.ReadLine(); + if ( Line != null && ! Line.StartsWith("<")) + { + LineIn=Line.Split(','); + } + return Single.Parse(LineIn[6]); + } public void DownloadTicker() { // update grid in webdownloader form addTickerTo_gridDataSet(); ! this.numberOfQuotesInDatabase = Quotes.GetNumberOfQuotes(this.p_quTicker); ! if(this.numberOfQuotesInDatabase>0 && p_myForm.IsUpdateOptionSelected) ! // there are some ticker's quotes in the database and ! // the user has chosen to download new quotes (only after last quote ! // or both before first quote and after last quote) { ! if(this.p_myForm.IsOnlyAfterLastQuoteSelected) ! { ! this.downloadTickerAfterLastQuote(); ! } ! else ! { ! this.downloadTickerBeforeFirstQuote(); ! this.downloadTickerAfterLastQuote(); ! } } else ! // ticker's quotes are downloaded for the first time or ! // the user has chosen to download all quotes ! { ! this.resetStartDateIfNecessary(); ! setTimeFrameAndImportTickerForEachTimeFrame(200); ! } //Monitor.Pulse( p_myForm.dsTickerCurrentlyDownloaded.Tables[ "Tickers" ] ); + } public void DownloadTicker(DateTime startingDate) *************** *** 176,180 **** this.INITIAL_DATE = startingDate; this.DownloadTicker(); - } --- 269,272 ---- *************** *** 203,206 **** --- 295,335 ---- } + private StreamReader getStreamReaderFromSource( DateTime initialDateOfTheTimeWindow, + int daysOfTheTimeWindow ) + { + int a = initialDateOfTheTimeWindow.Month - 1; + int b = initialDateOfTheTimeWindow.Day; + int c = initialDateOfTheTimeWindow.Year; + DateTime endDateOfTheTimeWindow = initialDateOfTheTimeWindow.AddDays(daysOfTheTimeWindow); + int d = endDateOfTheTimeWindow.Month - 1; + int e = endDateOfTheTimeWindow.Day; + int f = endDateOfTheTimeWindow.Year; + HttpWebRequest Req; + HttpWebResponse hwr; + Stream strm; + StreamReader sr = null; + int numTrials = 1; + while(numTrials < 5) + { + try + { + Req = (HttpWebRequest)WebRequest.Create("http:" + "//table.finance.yahoo.com/table.csv?a=" + + a + "&b=" + b + "&c=" + c +"&d=" + d + "&e=" + e + "&f=" + f + "&s=" + p_quTicker + "&y=0&g=d&ignore=.csv"); + Req.Method = "GET"; + Req.Timeout = ConstantsProvider.TimeOutValue; + hwr = (HttpWebResponse)Req.GetResponse(); + strm = hwr.GetResponseStream(); + sr = new StreamReader(strm); + numTrials = 6; + + } + catch (Exception exception) + { + string notUsed = exception.ToString(); + numTrials++; + } + } + return sr; + } private bool getResponseForTimeWindow( DateTime initialDateOfTheTimeWindow, *************** *** 227,231 **** + a + "&b=" + b + "&c=" + c +"&d=" + d + "&e=" + e + "&f=" + f + "&s=" + p_quTicker + "&y=0&g=d&ignore=.csv"); Req.Method = "GET"; ! Req.Timeout = 20000; hwr = (HttpWebResponse)Req.GetResponse(); strm = hwr.GetResponseStream(); --- 356,360 ---- + a + "&b=" + b + "&c=" + c +"&d=" + d + "&e=" + e + "&f=" + f + "&s=" + p_quTicker + "&y=0&g=d&ignore=.csv"); Req.Method = "GET"; ! Req.Timeout = ConstantsProvider.TimeOutValue; hwr = (HttpWebResponse)Req.GetResponse(); strm = hwr.GetResponseStream(); *************** *** 234,243 **** sr.Close(); strm.Close(); ! hwr.Close(); numTrials = 6; } catch (Exception exception) { ! MessageBox.Show( exception.ToString() + "\n\n for: " + initialDateOfTheTimeWindow.ToString()); numTrials++; } --- 363,372 ---- sr.Close(); strm.Close(); ! //hwr.Close(); numTrials = 6; } catch (Exception exception) { ! string notUsed = exception.ToString(); numTrials++; } *************** *** 284,288 **** } } - } } --- 413,416 ---- |