using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Model.Account; using Muchinfo.MTPClient.UI.Views; using System.Collections.ObjectModel; namespace Muchinfo.MTPClient.UI.ViewModels { /// /// 用户登录 /// public class CommunicationSetViewModel : ViewModelBase { #region 绑定属性 private ObservableCollection _serverCollection = new ObservableCollection(); /// /// 获取可用的服务器 /// public ObservableCollection ServerCollection { get { return _serverCollection; } set { Set(() => ServerCollection, ref _serverCollection, value); } } private ObservableCollection _realQuoteServers; /// /// 实时行情 /// public ObservableCollection RealQuoteServers { get { return _realQuoteServers; } set { Set(() => RealQuoteServers, ref _realQuoteServers, value); } } /// /// 交易所id /// public string ExchangId { get; set; } /// /// 选择的服务类型 /// public Services SelectServices { get; set; } #endregion #region 构造函数 /// /// 构造方法 /// /// 交易所id public CommunicationSetViewModel(string exchangeid, Services selectServices) { ExchangId = exchangeid; SelectServices = selectServices; //ServerCollection = CreateServerAddress(ServiceProxyType.BizService, exchangeid); //RealQuoteServers = CreateServerAddress(ServiceProxyType.QuoteHisRealTime, exchangeid); } #endregion #region 绑定命令 /// /// 测速 /// public RelayCommand TestSpeedCommand { get { return new RelayCommand( (Server) => { //todo: //Task.Factory.TryStartNew(() => //{ // if (Server.RequestTimeText.IndexOf("..") > -1) return; // Server.RequestTimeText = Muchinfo_Resource.UI2014_TestingSpeed; // Server.RequestTime = LinkerManager.TestSpeed(Server.ServerIP, Server.ServerPort); //}); }); } } /// /// 确定 /// public RelayCommand OKCommand { get { return new RelayCommand( (v) => { //SelectServerAddress(ServiceProxyType.BizService, ServerCollection); //SelectServerAddress(ServiceProxyType.QuoteHisRealTime, RealQuoteServers); v.DialogResult = true; }); } } /// /// 取消 /// public RelayCommand CancelCommand { get { return new RelayCommand( (v) => { v.DialogResult = false; }); } } ///// ///// 创建链路 ///// ///// 服务类型 ///// 交易所ID ///// //public ObservableCollection CreateServerAddress(ServiceProxyType service, string exchangeid) //{ // var tradeServerList = new ObservableCollection(); // if (UserManager.LoginAccount.ServerAddressConfigs.ContainsKey(service)) // { // //初始化业务服务地址,以供选择 // var bizlist = UserManager.LoginAccount.ServerAddressConfigs[service]; // foreach (var item in bizlist) // { // if (item.ServerAddresses != null) // { // var address = item.ServerAddresses.FirstOrDefault(z => z.IsSelected && z.Services == SelectServices); // var addressList = item.ServerAddresses.Where((addr) => addr.Services == SelectServices); // foreach (var item2 in addressList) // { // if (address == null) // { // if (item2.ConnectTime != TimeSpan.MaxValue) //选择第一个可用的 // { // item2.IsSelected = true; // address = item2; // } // } // try // { // var ts = new TradeServer(); // ts.ServerName = item2.Name; // ts.ServerIP = item2.Address.Split(':')[0]; // ts.ServerPort = int.Parse(item2.Address.Split(':')[1]); // ts.RequestTime = item2.ConnectTime; // ts.Rate = item2.OnlinePecentage.ToString("f0") + "%"; // ts.IsChecked = item2.IsSelected; // tradeServerList.Add(ts); // } // catch // { // } // } // } // break; // } // } // return tradeServerList; //} //public void SelectServerAddress(ServiceProxyType serverType, ObservableCollection ServerList) //{ // if (UserManager.LoginAccount.ServerAddressConfigs.ContainsKey(serverType)) // { // //初始化业务服务地址,以供选择 // var bizlist = // UserManager.LoginAccount.ServerAddressConfigs[serverType]; // foreach (var item in bizlist) // { // if (item.ServerAddresses != null) // { // foreach (var item2 in item.ServerAddresses) // { // try // { // var temp = // ServerList.FirstOrDefault( // (s) => // (s.ServerIP + ":" + s.ServerPort).Equals(item2.Address) && // s.ServerName.Equals(item2.Name)); // if (temp == null) continue; // item2.IsSelected = temp.IsChecked; // } // catch // { // } // } // } // break; // } // } //} #endregion } }