DataService.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using MuchInfo.Chart.Data.EnumTypes;
  2. using MuchInfo.Chart.Data.Interfaces;
  3. using MuchInfo.Chart.DataAccess;
  4. using MuchInfo.Chart.WPF.Primitives;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Windows;
  9. using System.Windows.Input;
  10. namespace MuchInfo.Chart.App.Services
  11. {
  12. /// <summary>
  13. /// Class DataService
  14. /// </summary>
  15. public class DataService : IDataService
  16. {
  17. #region Methods
  18. #region Public Methods
  19. public List<ModifierKeys> GetModifierKeys()
  20. {
  21. var list = GetEnumList<ModifierKeys>();
  22. list.Remove(ModifierKeys.Windows);
  23. return list;
  24. }
  25. public List<CycleType> GetCycleTypes()
  26. {
  27. var list = GetEnumList<CycleType>();
  28. list.Remove(CycleType.None);
  29. list.Remove(CycleType.Custom);
  30. return list;
  31. }
  32. /// <summary>
  33. /// Gets the data set.
  34. /// </summary>
  35. /// <param name="symbol">The symbol.</param>
  36. /// <param name="type">The type.</param>
  37. /// <param name="count">The count.</param>
  38. /// <returns>ChartDataSet.</returns>
  39. public ChartDataSet GetDataSet(string symbol, CycleType type, int count)
  40. {
  41. try
  42. {
  43. if (string.IsNullOrWhiteSpace(symbol)) return null;
  44. var dataAccess = new FileDataAccess();
  45. var dataPoints = dataAccess.GetDataPoints(symbol, type, DateTime.MinValue, DateTime.Now, count);
  46. if (dataPoints == null) return null;
  47. var result = dataPoints.Cast<ILineDataPoint>().ToList();
  48. var dataSet = new ChartDataSet(result);
  49. return dataSet;
  50. }
  51. catch
  52. {
  53. return null;
  54. }
  55. }
  56. public List<DrawingToolPositionType> GetDrawingToolPositions()
  57. {
  58. return GetEnumList<DrawingToolPositionType>();
  59. }
  60. public List<DrawingToolType> GetDrawingToolTypes()
  61. {
  62. return GetEnumList<DrawingToolType>();
  63. }
  64. public List<string> GetIndicatorTypes()
  65. {
  66. return new List<string>()
  67. {
  68. "MACD",
  69. "FASTSO",
  70. "RSI"
  71. };
  72. }
  73. public Dictionary<ChartLanguageType, string> GetLanguages()
  74. {
  75. return new Dictionary<ChartLanguageType, string>
  76. {
  77. {ChartLanguageType.SimplifiedChinese, "简体中文"},
  78. {ChartLanguageType.TraditionalChinese, "繁体中文"},
  79. {ChartLanguageType.English, "英文"}
  80. };
  81. }
  82. public List<LinePlotType> GetLinePlotTypes()
  83. {
  84. return GetEnumList<LinePlotType>();
  85. }
  86. public List<Visibility> GetVisibilities()
  87. {
  88. return new List<Visibility>
  89. {
  90. Visibility.Visible,
  91. Visibility.Collapsed
  92. };
  93. }
  94. #endregion Public Methods
  95. #region Private Methods
  96. private List<T> GetEnumList<T>()
  97. {
  98. var values = Enum.GetValues(typeof(T));
  99. return values.Cast<T>().ToList();
  100. }
  101. #endregion Private Methods
  102. #endregion Methods
  103. }
  104. }