CommunicationSetViewModel.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. using GalaSoft.MvvmLight;
  2. using GalaSoft.MvvmLight.Command;
  3. using Muchinfo.MTPClient.Data.Enums;
  4. using Muchinfo.MTPClient.Data.Model.Account;
  5. using Muchinfo.MTPClient.UI.Views;
  6. using System.Collections.ObjectModel;
  7. namespace Muchinfo.MTPClient.UI.ViewModels
  8. {
  9. /// <summary>
  10. /// 用户登录
  11. /// </summary>
  12. public class CommunicationSetViewModel : ViewModelBase
  13. {
  14. #region 绑定属性
  15. private ObservableCollection<TradeServer> _serverCollection = new ObservableCollection<TradeServer>();
  16. /// <summary>
  17. /// 获取可用的服务器
  18. /// </summary>
  19. public ObservableCollection<TradeServer> ServerCollection
  20. {
  21. get
  22. {
  23. return _serverCollection;
  24. }
  25. set
  26. {
  27. Set(() => ServerCollection, ref _serverCollection, value);
  28. }
  29. }
  30. private ObservableCollection<TradeServer> _realQuoteServers;
  31. /// <summary>
  32. /// 实时行情
  33. /// </summary>
  34. public ObservableCollection<TradeServer> RealQuoteServers
  35. {
  36. get
  37. {
  38. return _realQuoteServers;
  39. }
  40. set
  41. {
  42. Set(() => RealQuoteServers, ref _realQuoteServers, value);
  43. }
  44. }
  45. /// <summary>
  46. /// 交易所id
  47. /// </summary>
  48. public string ExchangId { get; set; }
  49. /// <summary>
  50. /// 选择的服务类型
  51. /// </summary>
  52. public Services SelectServices { get; set; }
  53. #endregion
  54. #region 构造函数
  55. /// <summary>
  56. /// 构造方法
  57. /// </summary>
  58. /// <param name="exchangeid">交易所id</param>
  59. public CommunicationSetViewModel(string exchangeid, Services selectServices)
  60. {
  61. ExchangId = exchangeid;
  62. SelectServices = selectServices;
  63. //ServerCollection = CreateServerAddress(ServiceProxyType.BizService, exchangeid);
  64. //RealQuoteServers = CreateServerAddress(ServiceProxyType.QuoteHisRealTime, exchangeid);
  65. }
  66. #endregion
  67. #region 绑定命令
  68. /// <summary>
  69. /// 测速
  70. /// </summary>
  71. public RelayCommand<TradeServer> TestSpeedCommand
  72. {
  73. get
  74. {
  75. return new RelayCommand<TradeServer>(
  76. (Server) =>
  77. {
  78. //todo:
  79. //Task.Factory.TryStartNew(() =>
  80. //{
  81. // if (Server.RequestTimeText.IndexOf("..") > -1) return;
  82. // Server.RequestTimeText = Muchinfo_Resource.UI2014_TestingSpeed;
  83. // Server.RequestTime = LinkerManager.TestSpeed(Server.ServerIP, Server.ServerPort);
  84. //});
  85. });
  86. }
  87. }
  88. /// <summary>
  89. /// 确定
  90. /// </summary>
  91. public RelayCommand<CommunicationSetView> OKCommand
  92. {
  93. get
  94. {
  95. return new RelayCommand<CommunicationSetView>(
  96. (v) =>
  97. {
  98. //SelectServerAddress(ServiceProxyType.BizService, ServerCollection);
  99. //SelectServerAddress(ServiceProxyType.QuoteHisRealTime, RealQuoteServers);
  100. v.DialogResult = true;
  101. });
  102. }
  103. }
  104. /// <summary>
  105. /// 取消
  106. /// </summary>
  107. public RelayCommand<CommunicationSetView> CancelCommand
  108. {
  109. get
  110. {
  111. return new RelayCommand<CommunicationSetView>(
  112. (v) =>
  113. {
  114. v.DialogResult = false;
  115. });
  116. }
  117. }
  118. ///// <summary>
  119. ///// 创建链路
  120. ///// </summary>
  121. ///// <param name="service">服务类型</param>
  122. ///// <param name="exchangeid">交易所ID</param>
  123. ///// <returns></returns>
  124. //public ObservableCollection<TradeServer> CreateServerAddress(ServiceProxyType service, string exchangeid)
  125. //{
  126. // var tradeServerList = new ObservableCollection<TradeServer>();
  127. // if (UserManager.LoginAccount.ServerAddressConfigs.ContainsKey(service))
  128. // {
  129. // //初始化业务服务地址,以供选择
  130. // var bizlist = UserManager.LoginAccount.ServerAddressConfigs[service];
  131. // foreach (var item in bizlist)
  132. // {
  133. // if (item.ServerAddresses != null)
  134. // {
  135. // var address = item.ServerAddresses.FirstOrDefault(z => z.IsSelected && z.Services == SelectServices);
  136. // var addressList = item.ServerAddresses.Where((addr) => addr.Services == SelectServices);
  137. // foreach (var item2 in addressList)
  138. // {
  139. // if (address == null)
  140. // {
  141. // if (item2.ConnectTime != TimeSpan.MaxValue) //选择第一个可用的
  142. // {
  143. // item2.IsSelected = true;
  144. // address = item2;
  145. // }
  146. // }
  147. // try
  148. // {
  149. // var ts = new TradeServer();
  150. // ts.ServerName = item2.Name;
  151. // ts.ServerIP = item2.Address.Split(':')[0];
  152. // ts.ServerPort = int.Parse(item2.Address.Split(':')[1]);
  153. // ts.RequestTime = item2.ConnectTime;
  154. // ts.Rate = item2.OnlinePecentage.ToString("f0") + "%";
  155. // ts.IsChecked = item2.IsSelected;
  156. // tradeServerList.Add(ts);
  157. // }
  158. // catch
  159. // {
  160. // }
  161. // }
  162. // }
  163. // break;
  164. // }
  165. // }
  166. // return tradeServerList;
  167. //}
  168. //public void SelectServerAddress(ServiceProxyType serverType, ObservableCollection<TradeServer> ServerList)
  169. //{
  170. // if (UserManager.LoginAccount.ServerAddressConfigs.ContainsKey(serverType))
  171. // {
  172. // //初始化业务服务地址,以供选择
  173. // var bizlist =
  174. // UserManager.LoginAccount.ServerAddressConfigs[serverType];
  175. // foreach (var item in bizlist)
  176. // {
  177. // if (item.ServerAddresses != null)
  178. // {
  179. // foreach (var item2 in item.ServerAddresses)
  180. // {
  181. // try
  182. // {
  183. // var temp =
  184. // ServerList.FirstOrDefault(
  185. // (s) =>
  186. // (s.ServerIP + ":" + s.ServerPort).Equals(item2.Address) &&
  187. // s.ServerName.Equals(item2.Name));
  188. // if (temp == null) continue;
  189. // item2.IsSelected = temp.IsChecked;
  190. // }
  191. // catch
  192. // {
  193. // }
  194. // }
  195. // }
  196. // break;
  197. // }
  198. // }
  199. //}
  200. #endregion
  201. }
  202. }