| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- 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
- {
- /// <summary>
- /// 用户登录
- /// </summary>
- public class CommunicationSetViewModel : ViewModelBase
- {
- #region 绑定属性
- private ObservableCollection<TradeServer> _serverCollection = new ObservableCollection<TradeServer>();
- /// <summary>
- /// 获取可用的服务器
- /// </summary>
- public ObservableCollection<TradeServer> ServerCollection
- {
- get
- {
- return _serverCollection;
- }
- set
- {
- Set(() => ServerCollection, ref _serverCollection, value);
- }
- }
- private ObservableCollection<TradeServer> _realQuoteServers;
- /// <summary>
- /// 实时行情
- /// </summary>
- public ObservableCollection<TradeServer> RealQuoteServers
- {
- get
- {
- return _realQuoteServers;
- }
- set
- {
- Set(() => RealQuoteServers, ref _realQuoteServers, value);
- }
- }
- /// <summary>
- /// 交易所id
- /// </summary>
- public string ExchangId { get; set; }
- /// <summary>
- /// 选择的服务类型
- /// </summary>
- public Services SelectServices { get; set; }
- #endregion
- #region 构造函数
- /// <summary>
- /// 构造方法
- /// </summary>
- /// <param name="exchangeid">交易所id</param>
- public CommunicationSetViewModel(string exchangeid, Services selectServices)
- {
- ExchangId = exchangeid;
- SelectServices = selectServices;
- //ServerCollection = CreateServerAddress(ServiceProxyType.BizService, exchangeid);
- //RealQuoteServers = CreateServerAddress(ServiceProxyType.QuoteHisRealTime, exchangeid);
- }
- #endregion
- #region 绑定命令
- /// <summary>
- /// 测速
- /// </summary>
- public RelayCommand<TradeServer> TestSpeedCommand
- {
- get
- {
- return new RelayCommand<TradeServer>(
- (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);
- //});
- });
- }
- }
- /// <summary>
- /// 确定
- /// </summary>
- public RelayCommand<CommunicationSetView> OKCommand
- {
- get
- {
- return new RelayCommand<CommunicationSetView>(
- (v) =>
- {
- //SelectServerAddress(ServiceProxyType.BizService, ServerCollection);
- //SelectServerAddress(ServiceProxyType.QuoteHisRealTime, RealQuoteServers);
- v.DialogResult = true;
- });
- }
- }
- /// <summary>
- /// 取消
- /// </summary>
- public RelayCommand<CommunicationSetView> CancelCommand
- {
- get
- {
- return new RelayCommand<CommunicationSetView>(
- (v) =>
- {
- v.DialogResult = false;
- });
- }
- }
- ///// <summary>
- ///// 创建链路
- ///// </summary>
- ///// <param name="service">服务类型</param>
- ///// <param name="exchangeid">交易所ID</param>
- ///// <returns></returns>
- //public ObservableCollection<TradeServer> CreateServerAddress(ServiceProxyType service, string exchangeid)
- //{
- // var tradeServerList = new ObservableCollection<TradeServer>();
- // 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<TradeServer> 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
- }
- }
|