PageRenderTime 64ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/Main/src/Xbap/DynamicDataDisplay.Xbap.Samples/Demos/v02/CurrencyExchange/CurrencyExchangeSample.xaml.cs

#
C# | 87 lines | 68 code | 11 blank | 8 comment | 1 complexity | aa817a4c0d002d5eb7677da4cb8ed548 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using Microsoft.Research.DynamicDataDisplay.DataSources;
  15. using System.IO;
  16. using System.Globalization;
  17. using System.Reflection;
  18. namespace Microsoft.Research.DynamicDataDisplay.Samples.Demos.v02.CurrencyExchange
  19. {
  20. /// <summary>
  21. /// Interaction logic for CurrencyExchangeSample.xaml
  22. /// </summary>
  23. public partial class CurrencyExchangeSample : Page
  24. {
  25. public CurrencyExchangeSample()
  26. {
  27. InitializeComponent();
  28. Loaded += new RoutedEventHandler(Window1_Loaded);
  29. }
  30. List<CurrencyInfo> usd;
  31. List<CurrencyInfo> eur;
  32. List<CurrencyInfo> gbp;
  33. List<CurrencyInfo> jpy;
  34. private void Window1_Loaded(object sender, RoutedEventArgs e)
  35. {
  36. usd = LoadCurrencyRates("usd.txt");
  37. eur = LoadCurrencyRates("eur.txt");
  38. gbp = LoadCurrencyRates("gbp.txt");
  39. jpy = LoadCurrencyRates("jpy.txt");
  40. Color[] colors = ColorHelper.CreateRandomColors(4);
  41. // todo
  42. //plotter.AddLineGraph(CreateCurrencyDataSource(usd), colors[0], 1, "RUB / USD");
  43. //plotter.AddLineGraph(CreateCurrencyDataSource(eur), colors[1], 1, "RUB / EURO");
  44. //plotter.AddLineGraph(CreateCurrencyDataSource(gbp), colors[2], 1, "RUB / GBP");
  45. //plotter.AddLineGraph(CreateCurrencyDataSource(jpy), colors[3], 1, "RUB / JPY");
  46. }
  47. private EnumerableDataSource<CurrencyInfo> CreateCurrencyDataSource(List<CurrencyInfo> rates)
  48. {
  49. EnumerableDataSource<CurrencyInfo> ds = new EnumerableDataSource<CurrencyInfo>(rates);
  50. ds.SetXMapping(ci => dateAxis.ConvertToDouble(ci.Date));
  51. ds.SetYMapping(ci => ci.Rate);
  52. return ds;
  53. }
  54. private static List<CurrencyInfo> LoadCurrencyRates(string fileName)
  55. {
  56. var assembly = Assembly.GetExecutingAssembly();
  57. using (Stream resourceStream = assembly.GetManifestResourceStream("Microsoft.Research.DynamicDataDisplay.Xbap.Samples.Demos.v02.CurrencyExchange." + fileName))
  58. {
  59. using (StreamReader reader = new StreamReader(resourceStream))
  60. {
  61. var strings = reader.ReadToEnd().Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
  62. var res = new List<CurrencyInfo>(strings.Length - 1);
  63. for (int i = 1; i < strings.Length; i++)
  64. {
  65. string line = strings[i];
  66. string[] subLines = line.Split('\t');
  67. DateTime date = DateTime.Parse(subLines[1]);
  68. double rate = Double.Parse(subLines[5], CultureInfo.InvariantCulture);
  69. res.Add(new CurrencyInfo { Date = date, Rate = rate });
  70. }
  71. return res;
  72. }
  73. }
  74. }
  75. }
  76. }