namespace IndexFormula.Finance.DataProvider
{
using System;
using System.Collections;
using System.Globalization;
using System.IO;
public class YahooCSVDataManager : CacheDataManagerBase
{
private string Ext;
private string Root;
public YahooCSVDataManager()
{
base.CacheTimeSpan = TimeSpan.FromHours(12.0);
}
///
/// 存储CSV文件路径和扩展名
///
///
///
public YahooCSVDataManager(string Root, string Ext)
{
if (!Root.EndsWith(@"\"))
{
Root = Root + @"\";
}
this.Root = Root;
if (!Ext.StartsWith("."))
{
Ext = "." + Ext;
}
this.Ext = Ext;
}
public override IDataProvider GetData(string Code, int Count)
{
string path = this.Root + Code + this.Ext;
if (File.Exists(path))
{
using (StreamReader reader = new StreamReader(path))
{
CommonDataProvider provider = this.LoadYahooCSV(reader);
provider.SetStringData("Code", Code);
return provider;
}
}
return CommonDataProvider.Empty;
}
public CommonDataProvider LoadYahooCSV(Stream stream)
{
using (StreamReader reader = new StreamReader(stream))
{
return this.LoadYahooCSV(reader);
}
}
public CommonDataProvider LoadYahooCSV(StreamReader sr)
{
string[] strArray = sr.ReadToEnd().Trim().Split(new char[] { '\n' });
ArrayList list = new ArrayList();
for (int i = 1; i < strArray.Length; i++)
{
strArray[i] = strArray[i].Trim();
if (!strArray[i].StartsWith("