using System; using System.Collections.Generic; using Aitex.Core.RT.Event; using Aitex.Core.Util; using Aitex.Core.Utilities; using Aitex.Core.WCF; using Aitex.Triton160.Common; using Aitex.Triton160.UI.WCF; namespace Aitex.Triton160.UI.Wcf { class WcfClient : Singleton { public bool IsConnectedWithRT { get { return _retryConnectRT.Result; } } public InvokeServiceClient Invoker { get { return _invoke; } } public RecipeServiceClient Recipe { get { return _recipe; } } public QueryDataServiceClient Query { get { return _query; } } public AccountServiceClient Account { get { return _account; } } private InvokeServiceClient _invoke; private EventServiceClient _event; private RecipeServiceClient _recipe; private QueryDataServiceClient _query; private AccountServiceClient _account; Guid _guid; PeriodicJob _runJob; Retry _retryConnectRT = new Retry(); private RD_TRIG trigger = new RD_TRIG(); Dictionary _values = new Dictionary(); public WcfClient() { } public void Initialize() { _invoke = new InvokeServiceClient(); _recipe = new RecipeServiceClient(); _query = new QueryDataServiceClient(); _account = new AccountServiceClient(); _event = new EventServiceClient(new EventServiceCallback()); _event.OnEvent += new Action(EventService_OnEvent); _guid = Guid.NewGuid(); _runJob = new PeriodicJob(1000, this.Run, "", true); Register(); } void EventService_OnEvent(EventItem obj) { Triton160UiSystem.Instance.EV.Event(obj); } public void Terminate() { _event.UnRegister(_guid); _runJob.Stop(); } public void Register() { _retryConnectRT.Result = _event.Register(_guid); if (_retryConnectRT.IsErrored) Triton160UiSystem.Instance.EV.Event(Aitex.Triton160.UI.Properties.Resources.WcfClient_Register_connecting_rt); if (_retryConnectRT.IsSucceeded) Triton160UiSystem.Instance.EV.Event(Aitex.Triton160.UI.Properties.Resources.WcfClient_Register_Connected_with_rt); } public bool Run() { Register(); return true; } public void InvokeService_DoOperation(TritonOperation operationName, params object[] args) { InvokeService_DoOperation(operationName.ToString(), args); } //---------------------------------------------------------------------------------------------------------------------------------------------- // // public void InvokeService_DoOperation(string operationName, params object[] args) { if (!_retryConnectRT.Result) { string parameter = ""; if (args.Length == 0) parameter = "()"; else { parameter += "("; foreach (object o in args) parameter += (o.ToString()+","); parameter += ")"; } Triton160UiSystem.Instance.EV.Event(String.Format("未连接控制系统,无法操作{0}{1}", operationName, parameter)); return; } _invoke.DoOperation(operationName, args); } } }