LinkManager.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using Muchinfo.TASClient.Adapter.Factory;
  2. using Muchinfo.TASClient.Service.LinkProxy.Enum;
  3. using Muchinfo.TASClient.Service.LinkProxy.TCP;
  4. namespace Muchinfo.TASClient.Service.LinkProxy
  5. {
  6. public class LinkManagerParameters
  7. {
  8. public string TradeHost { get; set; }
  9. public int TradePort { get; set; }
  10. public string QuotationHost { get; set; }
  11. public int QuotationPort { get; set; }
  12. public LinkType TradeLinkeType { get; set; }
  13. public DatagramType TradeDatagramType { get; set; }
  14. }
  15. public class LinkManager
  16. {
  17. #region Public Fields
  18. /// <summary>
  19. /// 链路参数
  20. /// </summary>
  21. public LinkManagerParameters Parameters { get; set; }
  22. /// <summary>
  23. /// 业务对象数据转换器
  24. /// </summary>
  25. /// <value>The biz adapter factory.</value>
  26. public AdapterFactory TradeAdapterFactory { get; private set; }
  27. /// <summary>
  28. /// Gets or sets the trade TCP link proxy.
  29. /// </summary>
  30. /// <value>The trade TCP link proxy.</value>
  31. public TradeTcpLinkProxy TradeTcpLinkProxy { get; set; }
  32. /// <summary>
  33. /// Gets or sets the quotation TCP link proxy.
  34. /// </summary>
  35. /// <value>The quotation TCP link proxy.</value>
  36. public QuotationTcpLinkProxy QuotationTcpLinkProxy { get; set; }
  37. #endregion
  38. #region Singalton
  39. private static LinkManager _instance;
  40. private static object _lock = new object();
  41. public static LinkManager Instance
  42. {
  43. get
  44. {
  45. if (null == _instance)
  46. {
  47. lock (_lock)
  48. {
  49. if (null == _instance)
  50. {
  51. _instance = new LinkManager();
  52. }
  53. }
  54. }
  55. return _instance;
  56. }
  57. }
  58. private LinkManager() { }
  59. #endregion
  60. /// <summary>
  61. /// 链路初始化
  62. /// </summary>
  63. /// <param name="parameters">The parameters.</param>
  64. public void Initialize(LinkManagerParameters parameters)
  65. {
  66. Parameters = parameters;
  67. if (null == Parameters) return;
  68. switch (Parameters.TradeDatagramType)
  69. {
  70. case DatagramType.Protobuf:
  71. TradeAdapterFactory = new ProtobufFactory();
  72. break;
  73. case DatagramType.Json:
  74. TradeAdapterFactory = new JsonFactory();
  75. break;
  76. }
  77. #if DEBUG
  78. #else
  79. switch (Parameters.TradeLinkeType)
  80. {
  81. case LinkType.TCP:
  82. TradeTcpLinkProxy = new TradeTcpLinkProxy(Parameters.TradeHost, Parameters.TradePort);
  83. break;
  84. default:
  85. //todo
  86. break;
  87. }
  88. #endif
  89. //QuotationTcpLinkProxy = new QuotationTcpLinkProxy(Parameters.QuotationHost, Parameters.QuotationPort);
  90. }
  91. }
  92. }