public void Dispose() { if (clientLife != null) { if (clientLife.IsAlive) { clientLife.Abort(); } } executeServiceClient = null; instanceContext = null; }
/// <summary> /// 保持连接的心跳及重新连接的线程任务 /// </summary> private void ClientAliveTask(object yourExecuteClient) { ExecuteServiceClient executeClient = (ExecuteServiceClient)yourExecuteClient; int counectTime = reCounectTime; ReConnect: executeClient = RestartClient(); try { SetClientState(RemoteClientState.Connecting); GetAllRunnerInforEx(); SetClientState(RemoteClientState.Connected); } catch (Exception ex) { ErrorLog.PutInLog(ex); if (counectTime > 0 && isLive) { counectTime--; SetClientState(RemoteClientState.Break); Thread.Sleep(2000); goto ReConnect; } else { StopClient(); } } while (isLive) { try { executeClient.ExecuteServiceBeat(); } catch (Exception ex) { SetClientState(RemoteClientState.Break); Thread.Sleep(2000); ErrorLog.PutInLog(ex); counectTime = reCounectTime; goto ReConnect; } Thread.Sleep(10000); } SetClientState(RemoteClientState.Lost); }
//private IControlRepository _controlRepository; public void Initialize(string username, string[] servers, List <string> lstHubProxies, ILoggerFactory loggerFactory = null, string authToken = null) { _loggerFactory = loggerFactory ?? new DebugLoggerFactory(); _log = _loggerFactory.Create(typeof(ReactiveDeliveryClient)); HubListeners = new HubListeners(); _connectionProvider = new ConnectionProvider(username, servers, _loggerFactory, lstHubProxies, HubListeners.InitializeListeners); var executeServiceClient = new ExecuteServiceClient(_connectionProvider); if (authToken != null) { //var controlServiceClient = new ControlServiceClient(new AuthTokenProvider(authToken), _connectionProvider, _loggerFactory); //_controlRepository = new ControlRepository(controlServiceClient); } _concurrencyService = new ConcurrencyService(); _executionProxy = new ExecutionProxy(executeServiceClient, _concurrencyService); }
/// <summary> /// 创建一个【ExecuteServiceClient】实例 /// </summary> /// <returns>【ExecuteServiceClient】实例</returns> private ExecuteServiceClient RestartClient() { if (instanceContext == null) { //InstanceContext ExecuteServiceCallback executeServiceCallback = new ExecuteServiceCallback(); executeServiceCallback.OnRunnerStateChange += executeServiceCallback_OnRunnerStateChange; instanceContext = new InstanceContext(executeServiceCallback); //Binding System.ServiceModel.Channels.Binding binding = new WSDualHttpBinding(); ((System.ServiceModel.WSDualHttpBinding)(binding)).Security.Mode = WSDualHttpSecurityMode.None; ((System.ServiceModel.WSDualHttpBinding)(binding)).Security.Message.ClientCredentialType = MessageCredentialType.UserName; binding.SendTimeout = new TimeSpan(0, 0, 10); binding.OpenTimeout = new TimeSpan(0, 0, 10); binding.ReceiveTimeout = new TimeSpan(0, 0, 10); System.ServiceModel.Channels.Binding tcpBinding = new NetTcpBinding(); ((System.ServiceModel.NetTcpBinding)(tcpBinding)).Security.Mode = SecurityMode.None; ((System.ServiceModel.NetTcpBinding)(tcpBinding)).Security.Message.ClientCredentialType = MessageCredentialType.UserName; tcpBinding.SendTimeout = new TimeSpan(0, 0, 10); tcpBinding.OpenTimeout = new TimeSpan(0, 0, 10); tcpBinding.ReceiveTimeout = new TimeSpan(0, 0, 10); executeServiceClient = new ExecuteServiceClient(instanceContext, binding, myEp); //executeServiceClient = new ExecuteServiceClient(instanceContext, new WSDualHttpBinding(), myEp); instanceContext.Closed += instanceContext_Closed; instanceContext.Opened += instanceContext_Opened; return(executeServiceClient); } else { instanceContext.Closed -= instanceContext_Closed; instanceContext.Opened -= instanceContext_Opened; instanceContext = null; return(RestartClient()); } }
private void PrepareEnviroment(ExecuteServiceClient esService, PackageOnNode pack, string resorceHomeFolder, string farmId) { esService.CopyOnStartPaths(pack.CopyOnStartup, farmId, resorceHomeFolder); }