| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- using GalaSoft.MvvmLight;
- using Muchinfo.MTPClient.Data;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Infrastructure.Helpers;
- using Muchinfo.MTPClient.Infrastructure.LinkProxy;
- using Muchinfo.MTPClient.NetworkCore;
- using Muchinfo.MTPClient.Resources;
- using Muchinfo.MTPClient.UI.Views;
- using System;
- using System.Collections.ObjectModel;
- namespace Muchinfo.MTPClient.UI.ViewModels
- {
- /// <summary>
- /// 链路状态
- /// </summary>
- public class LinkStateViewModel : ViewModelBase
- {
- private ObservableCollection<LinkState> _links = new ObservableCollection<LinkState>();
- private LinkStateView View = null;
- //private bool TradeIsOk = false; //交易服务状态
- //private bool QuoteIsOk = false; //行情服务状态
- /// <summary>
- /// 链路集合
- /// </summary>
- public ObservableCollection<LinkState> Links
- {
- get
- {
- return _links;
- }
- }
- System.Timers.Timer timer = new System.Timers.Timer(2000);
- public LinkStateViewModel(LinkStateView view)
- {
- View = view;
- //timer.Elapsed += timer_Elapsed;
- //RefrushState();
- //timer.Start();
- MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.TradeServerConnectMsg, TradeConnectChangeState);
- MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.QuoteServerStateChange, QuoteConnectChangeState);
- RefrushState();
- }
- private void TradeConnectChangeState(bool state)
- {
- // TradeIsOk = state;
- RefrushState();
- }
- private void QuoteConnectChangeState(bool state)
- {
- // QuoteIsOk = state;
- RefrushState();
- }
- /// <summary>
- /// 刷新链路状态
- /// </summary>
- public void RefrushState()
- {
- System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- if (null != Links)
- {
- Links.Clear();
- }
- var linkProxy = LinkManager.Instance.TradeTcpLinkProxy;
- if (null != linkProxy)
- {
- var temp = new LinkState();
- temp.Name = Client_Resource.Link_Trade_Service; // "交易服务";
- temp.Ip = linkProxy._host;
- temp.Port = linkProxy._port;
- if (linkProxy.TcpConnectState == TCPConnectState.Connected)
- {
- temp.IsEnable = true;
- }
- else
- {
- temp.IsEnable = false;
- }
- Links.Add(temp);
- }
- //--------------------
- var QuotelinkProxy = LinkManager.Instance.QuoteTcpLinkProxy;
- if (null != QuotelinkProxy)
- {
- var Quotetemp = new LinkState();
- Quotetemp.Name = Client_Resource.Link_Quote_Service;// "行情服务";
- Quotetemp.Ip = QuotelinkProxy._host;
- Quotetemp.Port = QuotelinkProxy._port;
- if (QuotelinkProxy.TcpConnectState == TCPConnectState.Connected)
- {
- Quotetemp.IsEnable = true;
- }
- else
- {
- Quotetemp.IsEnable = false;
- }
- Links.Add(Quotetemp);
- }
- var guestProxy = LinkManager.Instance.GuestQuoteTcpLinkProxy;
- if (null != guestProxy)
- {
- var guesttemp = new LinkState();
- guesttemp.Name = Client_Resource.GuestQuoteSeivece; // "游客服务";
- guesttemp.Ip = guestProxy._host;
- guesttemp.Port = guestProxy._port;
- if (guestProxy.TcpConnectState == TCPConnectState.Connected)
- {
- guesttemp.IsEnable = true;
- }
- else
- {
- guesttemp.IsEnable = false;
- }
- Links.Add(guesttemp);
- }
- }));
- return;
- //if (View != null)
- // View.Dispatcher.BeginInvoke(new Action(() =>
- // {
- // _links.Clear();
- // var links = LinkerManager.LinkerEntities;
- // if (links == null) return;
- // foreach (var item in links)
- // {
- // var temp = new LinkState();
- // temp.LinkerEntity = item;
- // temp.Name = item.LinkName;
- // switch (item.LinkerType)
- // {
- // case ServiceProxyType.BizService:
- // // temp.Name = "业务服务";
- // // temp.Name = item.LinkName;
- // break;
- // //case ServiceProxyType.QuoteService:
- // // // temp.Name = "历史行情服务";
- // // // temp.Name = item.LinkName;
- // // break;
- // case ServiceProxyType.NewsService:
- // // temp.Name = "新闻服务";
- // //temp.Name = item.LinkName;
- // break;
- // case ServiceProxyType.QuoteHisRealTime:
- // // temp.Name = "实时行情服务";
- // // temp.Name = item.LinkName;
- // break;
- // case ServiceProxyType.OtherService:
- // temp.Name = Client_Resource.Link_Other_Service;
- // break;
- // default:
- // break;
- // }
- // try
- // {
- // string addr = item.ServiceProxy.IPAddress;
- // string[] chars = addr.Split(':');
- // temp.Ip = chars[0];
- // temp.Port = int.Parse(chars[1].Replace("/", ""));
- // }
- // catch
- // {
- // temp.Ip = Client_Resource.Link_Unknow;
- // temp.Port = 0;
- // }
- // if (item.ServiceProxy == null || item.ServiceProxy.ClientState == CommunicationState.Closed ||
- // item.ServiceProxy.ClientState == CommunicationState.Closing ||
- // item.ServiceProxy.ClientState == CommunicationState.Faulted)
- // temp.IsEnable = false;
- // else temp.IsEnable = true;
- // _links.Add(temp);
- // }
- // }));
- }
- void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
- {
- timer.Stop();
- RefrushState();
- timer.Start();
- }
- public override void Cleanup()
- {
- base.Cleanup();
- if (timer != null) timer.Stop();
- }
- }
- }
|