WcfClient.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using System.Collections.Generic;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.Util;
  5. using Aitex.Core.Utilities;
  6. using Aitex.Core.WCF;
  7. using Aitex.Triton160.Common;
  8. using Aitex.Triton160.UI.WCF;
  9. namespace Aitex.Triton160.UI.Wcf
  10. {
  11. class WcfClient : Singleton<WcfClient>
  12. {
  13. public bool IsConnectedWithRT { get { return _retryConnectRT.Result; } }
  14. public InvokeServiceClient Invoker { get { return _invoke; } }
  15. public RecipeServiceClient Recipe { get { return _recipe; } }
  16. public QueryDataServiceClient Query {
  17. get { return _query; }
  18. }
  19. public AccountServiceClient Account
  20. {
  21. get
  22. {
  23. return _account;
  24. }
  25. }
  26. private InvokeServiceClient _invoke;
  27. private EventServiceClient _event;
  28. private RecipeServiceClient _recipe;
  29. private QueryDataServiceClient _query;
  30. private AccountServiceClient _account;
  31. Guid _guid;
  32. PeriodicJob _runJob;
  33. Retry _retryConnectRT = new Retry();
  34. private RD_TRIG trigger = new RD_TRIG();
  35. Dictionary<string, object> _values = new Dictionary<string, object>();
  36. public WcfClient()
  37. {
  38. }
  39. public void Initialize()
  40. {
  41. _invoke = new InvokeServiceClient();
  42. _recipe = new RecipeServiceClient();
  43. _query = new QueryDataServiceClient();
  44. _account = new AccountServiceClient();
  45. _event = new EventServiceClient(new EventServiceCallback());
  46. _event.OnEvent += new Action<EventItem>(EventService_OnEvent);
  47. _guid = Guid.NewGuid();
  48. _runJob = new PeriodicJob(1000, this.Run, "", true);
  49. Register();
  50. }
  51. void EventService_OnEvent(EventItem obj)
  52. {
  53. Triton160UiSystem.Instance.EV.Event(obj);
  54. }
  55. public void Terminate()
  56. {
  57. _event.UnRegister(_guid);
  58. _runJob.Stop();
  59. }
  60. public void Register()
  61. {
  62. _retryConnectRT.Result = _event.Register(_guid);
  63. if (_retryConnectRT.IsErrored)
  64. Triton160UiSystem.Instance.EV.Event(Aitex.Triton160.UI.Properties.Resources.WcfClient_Register_connecting_rt);
  65. if (_retryConnectRT.IsSucceeded)
  66. Triton160UiSystem.Instance.EV.Event(Aitex.Triton160.UI.Properties.Resources.WcfClient_Register_Connected_with_rt);
  67. }
  68. public bool Run()
  69. {
  70. Register();
  71. return true;
  72. }
  73. public void InvokeService_DoOperation(TritonOperation operationName, params object[] args)
  74. {
  75. InvokeService_DoOperation(operationName.ToString(), args);
  76. }
  77. //----------------------------------------------------------------------------------------------------------------------------------------------
  78. //
  79. //
  80. public void InvokeService_DoOperation(string operationName, params object[] args)
  81. {
  82. if (!_retryConnectRT.Result)
  83. {
  84. string parameter = "";
  85. if (args.Length == 0)
  86. parameter = "()";
  87. else
  88. {
  89. parameter += "(";
  90. foreach (object o in args)
  91. parameter += (o.ToString()+",");
  92. parameter += ")";
  93. }
  94. Triton160UiSystem.Instance.EV.Event(String.Format("未连接控制系统,无法操作{0}{1}", operationName, parameter));
  95. return;
  96. }
  97. _invoke.DoOperation(operationName, args);
  98. }
  99. }
  100. }