| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using Muchinfo.TASClient.Adapter.Factory;
- using Muchinfo.TASClient.Service.LinkProxy.Enum;
- using Muchinfo.TASClient.Service.LinkProxy.TCP;
- namespace Muchinfo.TASClient.Service.LinkProxy
- {
- public class LinkManagerParameters
- {
- public string TradeHost { get; set; }
- public int TradePort { get; set; }
- public string QuotationHost { get; set; }
- public int QuotationPort { get; set; }
- public LinkType TradeLinkeType { get; set; }
- public DatagramType TradeDatagramType { get; set; }
- }
- public class LinkManager
- {
- #region Public Fields
- /// <summary>
- /// 链路参数
- /// </summary>
- public LinkManagerParameters Parameters { get; set; }
- /// <summary>
- /// 业务对象数据转换器
- /// </summary>
- /// <value>The biz adapter factory.</value>
- public AdapterFactory TradeAdapterFactory { get; private set; }
- /// <summary>
- /// Gets or sets the trade TCP link proxy.
- /// </summary>
- /// <value>The trade TCP link proxy.</value>
- public TradeTcpLinkProxy TradeTcpLinkProxy { get; set; }
- /// <summary>
- /// Gets or sets the quotation TCP link proxy.
- /// </summary>
- /// <value>The quotation TCP link proxy.</value>
- public QuotationTcpLinkProxy QuotationTcpLinkProxy { get; set; }
- #endregion
- #region Singalton
- private static LinkManager _instance;
- private static object _lock = new object();
- public static LinkManager Instance
- {
- get
- {
- if (null == _instance)
- {
- lock (_lock)
- {
- if (null == _instance)
- {
- _instance = new LinkManager();
- }
- }
- }
- return _instance;
- }
- }
- private LinkManager() { }
- #endregion
- /// <summary>
- /// 链路初始化
- /// </summary>
- /// <param name="parameters">The parameters.</param>
- public void Initialize(LinkManagerParameters parameters)
- {
- Parameters = parameters;
- if (null == Parameters) return;
- switch (Parameters.TradeDatagramType)
- {
- case DatagramType.Protobuf:
- TradeAdapterFactory = new ProtobufFactory();
- break;
- case DatagramType.Json:
- TradeAdapterFactory = new JsonFactory();
- break;
- }
- #if DEBUG
- #else
- switch (Parameters.TradeLinkeType)
- {
- case LinkType.TCP:
- TradeTcpLinkProxy = new TradeTcpLinkProxy(Parameters.TradeHost, Parameters.TradePort);
- break;
- default:
- //todo
- break;
- }
- #endif
- //QuotationTcpLinkProxy = new QuotationTcpLinkProxy(Parameters.QuotationHost, Parameters.QuotationPort);
- }
- }
- }
|