[Quantproject-developers] QuantDownloader/Downloader TickerDownloader.cs,1.10,1.11
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2004-07-25 12:12:28
|
Update of /cvsroot/quantproject/QuantDownloader/Downloader In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5354/Downloader Modified Files: TickerDownloader.cs Log Message: Cleaned code in TickerDownloader class. Index: TickerDownloader.cs =================================================================== RCS file: /cvsroot/quantproject/QuantDownloader/Downloader/TickerDownloader.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TickerDownloader.cs 4 Jul 2004 17:53:36 -0000 1.10 --- TickerDownloader.cs 25 Jul 2004 12:12:15 -0000 1.11 *************** *** 29,32 **** --- 29,34 ---- private DataTable downloadedValuesFromSource = new DataTable("quotes"); private OleDbSingleTableAdapter adapter; + private Stream stream; + private StreamReader streamReader; public TickerDownloader( WebDownloader myForm, DataRow currentDataTickerRow, string quTicker , int numRows ) *************** *** 179,186 **** /// Adds rows to the table (member of the object) containing the downloaded values /// </summary> ! private void addValuesToTable( StreamReader streamReader ) { string Line; string[] LineIn; Line = streamReader.ReadLine(); Line = streamReader.ReadLine(); --- 181,190 ---- /// Adds rows to the table (member of the object) containing the downloaded values /// </summary> ! private void addCurrentStreamToTable() { string Line; string[] LineIn; + if(this.streamReader==null) + return; Line = streamReader.ReadLine(); Line = streamReader.ReadLine(); *************** *** 210,255 **** private void importTickerForCurrentTimeFrame( DateTime currBeginDate , DateTime currEndDate ) { - int a = currBeginDate.Month - 1; - int b = currBeginDate.Day; - int c = currBeginDate.Year; - int d = currEndDate.Month - 1; - int e = currEndDate.Day; - int f = currEndDate.Year; - int numTrials = 1; - - while (numTrials < 5) - { - this.p_myForm.Refresh(); try { ! HttpWebRequest Req = (HttpWebRequest)WebRequest.Create("http:" + "//ichart.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; ! HttpWebResponse hwr = (HttpWebResponse)Req.GetResponse(); ! Stream strm = hwr.GetResponseStream(); ! StreamReader sr = new StreamReader(strm); ! ! //DataBaseImporter dataBaseImporter = ! //new DataBaseImporter( this.oleDbConnection1 , sr, this.p_myForm.radioButtonOverWriteYes.Checked ); ! //dataBaseImporter.ImportTicker( p_quTicker ); ! this.addValuesToTable(sr); ! ! sr.Close(); ! strm.Close(); ! //hwr.Close(); ! ! updateCurrentStatus( d + "/" + e + "/" + f ); ! numTrials = 6 ; } catch (Exception exception) { MessageBox.Show( exception.ToString() ); ! updateCurrentStatus( "Trial: " + numTrials ); numTrials++; if (numTrials > 5) ! addTickerToFaultyTickers(); } - } } --- 214,235 ---- private void importTickerForCurrentTimeFrame( DateTime currBeginDate , DateTime currEndDate ) { try { ! this.p_myForm.Refresh(); ! this.setStreamsFromYahoo(currBeginDate, currEndDate); ! this.addCurrentStreamToTable(); ! this.updateCurrentStatus(currEndDate.ToShortDateString()); ! if(this.streamReader!=null) ! this.streamReader.Close(); ! //this.updateCurrentStatus( d + "/" + e + "/" + f ); } catch (Exception exception) { MessageBox.Show( exception.ToString() ); ! /*updateCurrentStatus( "Trial: " + numTrials ); numTrials++; if (numTrials > 5) ! addTickerToFaultyTickers();*/ } } *************** *** 361,367 **** //download is executed { - this.updateCurrentStatusAdjustedClose("OK"); this.downloadedValuesFromSource = this.getTableOfDownloadedValues(); this.commitDownloadedValuesToDatabase(); } } --- 341,347 ---- //download is executed { this.downloadedValuesFromSource = this.getTableOfDownloadedValues(); this.commitDownloadedValuesToDatabase(); + this.updateCurrentStatusAdjustedClose("OK"); } } *************** *** 392,398 **** string Line; string[] LineIn = null; ! StreamReader streamReader = this.getStreamReaderFromSource(adjustedCloseDate, 0); ! Line = streamReader.ReadLine(); ! Line = streamReader.ReadLine(); if ( Line != null && ! Line.StartsWith("<")) { --- 372,378 ---- string Line; string[] LineIn = null; ! this.setStreamsFromYahoo(adjustedCloseDate, 0); ! Line = this.streamReader.ReadLine(); ! Line = this.streamReader.ReadLine(); if ( Line != null && ! Line.StartsWith("<")) { *************** *** 500,503 **** --- 480,485 ---- { string Line; + if(streamReader == null) + return false; Line = streamReader.ReadLine(); // column headers are read *************** *** 514,533 **** } numDays++; - } return isOneDateAvailableInNextDaysToBeTested; - } ! 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; --- 496,519 ---- } numDays++; } return isOneDateAvailableInNextDaysToBeTested; } ! private void setStreamsFromYahoo( DateTime initialDateOfTheTimeWindow,int daysOfTheTimeWindow) ! { DateTime endDateOfTheTimeWindow = initialDateOfTheTimeWindow.AddDays(daysOfTheTimeWindow); ! this.setStreamsFromYahoo(initialDateOfTheTimeWindow, endDateOfTheTimeWindow); ! } ! ! /* ! private StreamReader getStreamReaderFromYahoo(DateTime startDate, DateTime endDate) ! { ! int a = startDate.Month - 1; ! int b = startDate.Day; ! int c = startDate.Year; ! int d = endDate.Month - 1; ! int e = endDate.Day; ! int f = endDate.Year; HttpWebRequest Req; HttpWebResponse hwr; *************** *** 539,548 **** 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"); ! string url = "http:" + "//ichart.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 = (HttpWebRequest)WebRequest.Create( url ); ! Req.Method = "GET"; Req.Timeout = ConstantsProvider.TimeOutValue; hwr = (HttpWebResponse)Req.GetResponse(); --- 525,534 ---- 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"); ! string url = "http:" + "//ichart.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 = (HttpWebRequest)WebRequest.Create( url ); ! Req.Method = "GET"; Req.Timeout = ConstantsProvider.TimeOutValue; hwr = (HttpWebResponse)Req.GetResponse(); *************** *** 560,579 **** return sr; } ! ! private bool getResponseForTimeWindow( 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; ! bool response = false; int numTrials = 1; while(numTrials < 5) --- 546,565 ---- return sr; } ! */ ! private void setStreamsFromYahoo(DateTime startDate, DateTime endDate) { ! int a = startDate.Month - 1; ! int b = startDate.Day; ! int c = startDate.Year; ! int d = endDate.Month - 1; ! int e = endDate.Day; ! int f = endDate.Year; HttpWebRequest Req; HttpWebResponse hwr; ! string url; ! //url = "http:" + "//ichart.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"; ! url = "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"; int numTrials = 1; while(numTrials < 5) *************** *** 581,605 **** try { ! Req = (HttpWebRequest)WebRequest.Create("http:" + "//ichart.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); ! response = this.isAtLeastOneDateAvailable(sr, daysOfTheTimeWindow ); ! sr.Close(); ! strm.Close(); ! //hwr.Close(); numTrials = 6; } catch (Exception exception) { string notUsed = exception.ToString(); numTrials++; } } return response; } private DateTime getMiddleDate(DateTime startingDate, DateTime endingDate) --- 567,601 ---- try { ! Req = (HttpWebRequest)WebRequest.Create( url ); Req.Method = "GET"; Req.Timeout = ConstantsProvider.TimeOutValue; hwr = (HttpWebResponse)Req.GetResponse(); ! this.stream = hwr.GetResponseStream(); ! this.streamReader = new StreamReader(this.stream); numTrials = 6; } + catch (Exception exception) { string notUsed = exception.ToString(); numTrials++; + //if(numTrials==6) + //throw new Exception("It has not been possible to set streams from Yahoo: \n\n" + + // "Check the connection to the internet or the following url: \n\n" + + // url,exception); } } + } + + + private bool getResponseForTimeWindow( DateTime initialDateOfTheTimeWindow, + int daysOfTheTimeWindow ) + { + this.setStreamsFromYahoo(initialDateOfTheTimeWindow, daysOfTheTimeWindow); + bool response = false; + response = this.isAtLeastOneDateAvailable(this.streamReader,daysOfTheTimeWindow ); return response; } + private DateTime getMiddleDate(DateTime startingDate, DateTime endingDate) *************** *** 615,619 **** DateTime endingDate) { - if(startingDate == this.INITIAL_DATE) // at the first call, when the actual parameters are INITIAL_DATE and now --- 611,614 ---- |