123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- 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<WcfClient>
- {
- 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<string, object> _values = new Dictionary<string, object>();
- 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<EventItem>(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);
- }
- }
- }
|