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 /// /// 链路参数 /// public LinkManagerParameters Parameters { get; set; } /// /// 业务对象数据转换器 /// /// The biz adapter factory. public AdapterFactory TradeAdapterFactory { get; private set; } /// /// Gets or sets the trade TCP link proxy. /// /// The trade TCP link proxy. public TradeTcpLinkProxy TradeTcpLinkProxy { get; set; } /// /// Gets or sets the quotation TCP link proxy. /// /// The quotation TCP link proxy. 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 /// /// 链路初始化 /// /// The parameters. 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); } } }