MemoryDataManager.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. namespace Easychart.Finance.DataProvider
  2. {
  3. using System;
  4. using System.Collections;
  5. public class MemoryDataManager : DataManagerBase
  6. {
  7. private static Hashtable htHistorical = new Hashtable();
  8. private static Hashtable htStreaming = new Hashtable();
  9. private DataManagerBase InnerDataManager;
  10. public MemoryDataManager(DataManagerBase InnerDataManager)
  11. {
  12. this.InnerDataManager = InnerDataManager;
  13. }
  14. public void AddNewPacket(DataPacket dp)
  15. {
  16. string symbol = dp.Symbol;
  17. if (symbol.EndsWith("=X"))
  18. {
  19. symbol = symbol.Substring(0, symbol.Length - 2);
  20. }
  21. CommonDataProvider empty = htStreaming[symbol] as CommonDataProvider;
  22. if (empty == null)
  23. {
  24. empty = CommonDataProvider.Empty;
  25. htStreaming[symbol] = empty;
  26. }
  27. empty.Merge(dp);
  28. }
  29. public override IDataProvider GetData(string Code, int Count)
  30. {
  31. CommonDataProvider empty = (CommonDataProvider) htHistorical[Code];
  32. if (empty == null)
  33. {
  34. if (this.InnerDataManager != null)
  35. {
  36. this.InnerDataManager.StartTime = base.StartTime;
  37. this.InnerDataManager.EndTime = base.EndTime;
  38. empty = this.InnerDataManager[Code, Count] as CommonDataProvider;
  39. empty.DataManager = this;
  40. }
  41. else
  42. {
  43. empty = CommonDataProvider.Empty;
  44. }
  45. htHistorical[Code] = empty;
  46. }
  47. CommonDataProvider cdp = (CommonDataProvider) htStreaming[Code];
  48. if (cdp != null)
  49. {
  50. empty.Merge(cdp);
  51. cdp.ClearData();
  52. }
  53. empty.SetStringData("Code", Code);
  54. return empty;
  55. }
  56. public void RemoveSymbol(string Symbol)
  57. {
  58. htHistorical.Remove(Symbol);
  59. htStreaming.Remove(Symbol);
  60. }
  61. }
  62. }