using Muchinfo.Quote; using Muchinfo.Quote.HistoryClient; using Muchinfo.Quote.SqliteDal; using System; using System.Collections.Generic; using System.Linq; namespace MuchInfo.Chart.App.Quote { public class QuoteComponentProxy { #region Fields private HistoryClient _historyClient; private string _uri; #endregion Fields #region Constructors /// /// Initializes a new instance of the class. /// public QuoteComponentProxy(bool quoteCycleBySettlementPlan, string uri) { try { _uri = uri.StartsWith(@"net.tcp://") ? uri : @"net.tcp://" + uri; _historyClient = new HistoryClient(quoteCycleBySettlementPlan); _historyClient.AddServerAddr(new string[] { _uri }); _historyClient.ResponseHistoryCycle -= HistoryClient_ResponseHistoryCycle; _historyClient.ResponseHistoryCycle += HistoryClient_ResponseHistoryCycle; } catch (Exception e) { //FileLog.Default.Write("初始化行情组件出错, 方法: QuoteComponentProxy.QuoteComponentProxy" + Environment.NewLine + e.Message); } } #endregion Constructors #region Events public event EventHandler ResponseHistoryCycle; #endregion Events #region Methods #region Public Methods /// /// 获取盘面信息 /// /// The symbol list. /// DayQuote[][]. public DayQuote[] GetDayQuote(IEnumerable symbolList) { var symbolArray = symbolList == null ? null : symbolList.ToArray(); if (_historyClient == null || symbolArray == null || !symbolArray.Any()) return null; try { return _historyClient.GetDayQuote(symbolArray); } catch (Exception e) { throw e; //FileLog.Default.Write("获取盘面信息出错, 方法: QuoteComponentProxy.GetDayQuote" + Environment.NewLine + e.Message); } } /// /// Gets the goods property. /// /// The exchangecode. /// The sort. /// GoodsProperty[][]. public GoodsProperty[] GetGoodsProperty(int exchangeCode, int sort) { if (_historyClient == null) return null; try { return _historyClient.GetGoodsProperty(exchangeCode, sort); } catch (Exception e) { throw e; //FileLog.Default.Write("获取商品信息出错, 方法: QuoteComponentProxy.GetGoodsProperty" + Environment.NewLine + e.Message); //return null; } } /// /// 获取历史周期行情 /// /// The symbol. /// The cycle. /// The dt start time. /// The dt end time. /// The top N. /// The ret. /// HistoryCycle[][]. public HistoryCycle[] GetHistoryCycle(string symbol, Cycle cycle, DateTime dtStartTime, DateTime dtEndTime, short topN, out RetMessageCode ret) { ret = RetMessageCode.WCFError; if (_historyClient == null) return null; try { return _historyClient.GetHistoryCycle(symbol, cycle, dtStartTime, dtEndTime, topN, out ret); } catch (Exception e) { throw e; //FileLog.Default.Write("获取历史行情出错, 方法: QuoteComponentProxy.GetHistoryCycle" + Environment.NewLine + e.Message); //return null; } } /// /// 获取历史周期行情 /// /// The exchange code. /// The goods code. /// The time span. /// The dt start time. /// The dt end time. /// The top N. /// The ret. /// HistoryCycle[][]. public HistoryCycle[] GetHistoryCycle(int exchangeCode, string goodsCode, TimeSpan timeSpan, DateTime dtStartTime, DateTime dtEndTime, short topN, out RetMessageCode ret) { ret = RetMessageCode.WCFError; if (_historyClient == null) return null; try { return _historyClient.GetHistoryCycle(exchangeCode, goodsCode, timeSpan, dtStartTime, dtEndTime, topN, out ret); } catch (Exception e) { throw e; //FileLog.Default.Write("获取历史行情出错, 方法: QuoteComponentProxy.GetHistoryCycle" + Environment.NewLine + e.Message); //return null; } } /// /// Gets the history tik. /// /// The symbol. /// The dt start time. /// The dt end time. /// The top N. /// HistoryTik[][]. public HistoryTik[] GetHistoryTik(string symbol, DateTime dtStartTime, DateTime dtEndTime, short topN) { if (_historyClient == null) return null; try { return _historyClient.GetHistoryTik(symbol, dtStartTime, dtEndTime, topN); } catch (Exception e) { throw e; //FileLog.Default.Write("获取历史Tik行情出错, 方法: QuoteComponentProxy.GetHistoryTik" + Environment.NewLine + e.Message); //return null; } } /// /// Gets the last settlement plans. /// /// SettlementPlan[][]. public SettlementPlan[] GetLastSettlementPlans() { if (_historyClient == null) return null; try { return _historyClient.GetLastSettlementPlans(); } catch (Exception e) { throw e; //FileLog.Default.Write("获取结算计划出错, 方法: QuoteComponentProxy.GetLastSettlementPlans" + Environment.NewLine + e.Message); //return null; } } /// /// Gets the settlement plans. /// /// The exchange code. /// The sort. /// The dt start time. /// The dt end time. /// The top N. /// SettlementPlan[][]. public SettlementPlan[] GetSettlementPlans(string exchangeCode, int sort, DateTime dtStartTime, DateTime dtEndTime, short topN) { if (_historyClient == null) return null; try { return _historyClient.GetSettlementPlans(exchangeCode, sort, dtStartTime, dtEndTime, topN); } catch (Exception e) { throw e; //FileLog.Default.Write("获取结算计划出错, 方法: QuoteComponentProxy.GetSettlementPlans" + Environment.NewLine + e.Message); //return null; } } #endregion Public Methods #region Private Methods /// /// Handles the ResponseHistoryCycle event of the HistoryClient control. /// /// The source of the event. /// The instance containing the event data. private void HistoryClient_ResponseHistoryCycle(object sender, HistoryCycleResponseEventArgs e) { if (ResponseHistoryCycle != null) { ResponseHistoryCycle(sender, e); } } #endregion Private Methods #endregion Methods #region IServiceProxy /// /// 执行与释放或重置非托管资源相关的应用程序定义的任务。 /// public void Dispose() { if (_historyClient == null) return; this._historyClient.Dispose(); } /// /// 终结点地址 /// public string EndpointAddress { get { if (_historyClient == null) return string.Empty; return _uri; } } #endregion } }