📄 cdownloadyahoodata.cs
字号:
using System;
using System.Net;
using System.IO;
using Microsoft.VisualBasic;
namespace SmartWKN
{
/// <summary>
/// Download Yahoo Data
/// </summary>
public class cDownloadYahooData
{
public cDownloadYahooData()
{
//
// TODO: Konstruktorlogik hier hinzuf黦en
//
}
public struct YahooData
{
public string WKN;
public string LastPrice;
public string Date;
public string Time;
public string Change;
public string Open;
public string High;
public string Low;
}
private bool bolSucess = false;
public bool Sucess
{
get { return bolSucess; }
}
public YahooData GetYahooData(string URL, string GraphURL, string SaveTO, string SaveTOImage)
{
YahooData retValue;
HttpWebRequest req = null;
HttpWebResponse resp = null;
FileStream str = null;
Stream respStream = null;
BinaryReader binReader = null;
BinaryWriter binWriter = null;
int bytesRead = 0;
byte[] buffer = new byte[1024];
StreamReader reader = null;
retValue = new YahooData();
// Detect Internet Connection
if (cDetectInternet.DetectInternet() == false)
{
bolSucess = false;
return retValue;
}
// Download Data
try
{
req = (HttpWebRequest)HttpWebRequest.Create(URL);
resp = (HttpWebResponse)req.GetResponse();
if(resp.StatusCode == HttpStatusCode.OK)
{
str = new FileStream(SaveTO, FileMode.Create);
respStream = resp.GetResponseStream();
binReader = new BinaryReader(respStream, System.Text.Encoding.Default);
binWriter = new BinaryWriter(str);
do
{
bytesRead = binReader.Read(buffer, 0, buffer.Length);
binWriter.Write(buffer, 0, buffer.Length);
}
while(bytesRead > 0);
binReader.Close();
binWriter.Close();
str.Close();
req = null;
resp.Close();
resp = null;
}
}
catch(Exception exc)
{
System.Diagnostics.Debug.WriteLine(exc.Message);
bolSucess = false;
return retValue;
}
//Parse Data
if(File.Exists(SaveTO) == false)
{
bolSucess = false;
return retValue;
}
try
{
reader = new StreamReader(SaveTO, System.Text.Encoding.Default);
string strTemp = reader.ReadLine();
reader.Close();
string[] strData = strTemp.Split(Strings.Chr(44));
retValue.WKN = strData[0].Replace(Strings.Chr(34).ToString(), string.Empty);
retValue.LastPrice = strData[1];
retValue.Date = strData[2].Replace(Strings.Chr(34).ToString(), String.Empty);
retValue.Time = strData[3].Replace(Strings.Chr(34).ToString(), String.Empty);
retValue.Change = strData[4];
retValue.Open = strData[5];
retValue.High = strData[6];
retValue.Low = strData[7];
}
catch
{
bolSucess = false;
return retValue;
}
DownloadGraph(GraphURL, SaveTOImage);
bolSucess = true;
return retValue;
}
private void DownloadGraph(string URL, string SaveTO)
{
HttpWebRequest req = null;
HttpWebResponse resp = null;
FileStream str = null;
Stream respStream = null;
BinaryReader binReader = null;
BinaryWriter binWriter = null;
int bytesRead = 0;
byte[] buffer = new byte[1024];
try
{
if(File.Exists(SaveTO) == true)
{
File.Delete(SaveTO);
}
}
catch
{
}
try
{
req = (HttpWebRequest)HttpWebRequest.Create(URL);
resp = (HttpWebResponse)req.GetResponse();
if(resp.StatusCode == HttpStatusCode.OK)
{
str = new FileStream(SaveTO, FileMode.Create);
respStream = resp.GetResponseStream();
binReader = new BinaryReader(respStream, System.Text.Encoding.Default);
binWriter = new BinaryWriter(str);
do
{
bytesRead = binReader.Read(buffer, 0, buffer.Length);
binWriter.Write(buffer, 0, buffer.Length);
}
while(bytesRead > 0);
binReader.Close();
binWriter.Close();
str.Close();
}
}
catch(Exception exc)
{
System.Diagnostics.Debug.WriteLine(exc.Message);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -