using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows;
using System.Windows.Resources;
namespace XAMLFinance.ViewModel
{
public class XmlFileDataSource : IXmlDataSource
{
public event EventHandler<DataReadyEventArgs> DataReady;
protected void OnDataReady(DataReadyEventArgs args)
{
if (DataReady != null)
{
DataReady(this, args);
}
}
public void FetchFTSE100()
{
LoadData("FTSE100.xml", DataType.FTSE100);
}
public void FetchInstrumentDetails(string isin)
{
LoadData("InstrumentDetails_" + isin + ".xml", DataType.InstrumentDetails);
}
public void FetchInstrumentPriceHistory(string isin)
{
LoadData("PriceHistory_" + isin + ".xml", DataType.PriceHistory);
}
public void FetchHeatmap()
{
LoadData("Heatmap.xml", DataType.Heatmap);
}
private void LoadData(string filename, DataType dataType)
{
string path = "/XAMLFinanceSilverlight;component/Data/" + filename;
Uri uri = new Uri(path, UriKind.Relative);
StreamResourceInfo sri = Application.GetResourceStream(uri);
StreamReader reader = new StreamReader(sri.Stream);
string xml = reader.ReadToEnd();
OnDataReady(new DataReadyEventArgs(xml, dataType));
}
}
}