private async Task UpdateAgent(ServerAgent agent, MessageClient messageClient, CancellationToken token) { var message = new AgentUpdateRequest { Filename = UpdateFilename, }; try { await messageClient.Send(message) .GetResponseAsync(token); await messageClient.DisconnectAsync(); } finally { messageClient?.Dispose(); } await Task.Delay(3000, token); // TODO: Verify update was successful by polling for server and checking version messageClient = null; try { messageClient = await Reconnect(agent, TimeSpan.FromMinutes(2)); } finally { messageClient?.Dispose(); } }
/// <summary> /// 修改代理 /// </summary> public async Task UpdateAsync(AgentUpdateRequest request) { var entity = await AgentRepository.FindAsync(request.Id); request.MapTo(entity); await AgentRepository.UpdateAsync(entity); await UnitOfWork.CommitAsync(); }
public virtual async Task <IActionResult> UpdateAsync([FromBody] AgentUpdateRequest request) { if (request == null) { return(Fail(WebResource.UpdateRequestIsEmpty)); } await AgentService.UpdateAgentAsync(request); AgentDto byIdAsync = await AgentService.GetByIdAsync(request.Id); return(Success(byIdAsync, null)); }
private async Task UpdateAgent(ServerAgent agent, MessageClient messageClient, CancellationToken token) { var message = new AgentUpdateRequest { Filename = UpdateFilename, }; try { await messageClient.Send(message) .GetResponseAsync(token); try { messageClient.Disconnect(); } catch {} } finally { messageClient?.Dispose(); messageClient = null; } Output.WriteBlock(block => block .Write("Agent update started on ", ConsoleColor.DarkCyan) .Write(agent.Name, ConsoleColor.Cyan) .WriteLine("...", ConsoleColor.DarkCyan)); await Task.Delay(6_000, token); var reconnectTimeout = TimeSpan.FromMinutes(2); try { messageClient = await Reconnect(agent, reconnectTimeout, token); } catch (OperationCanceledException) { throw new ApplicationException($"A timeout occurred after {reconnectTimeout} while waiting for the update to complete."); } finally { if (messageClient != null) { messageClient.Disconnect(); messageClient.Dispose(); } } }
public async Task <IActionResult> UpdateAsync(string id, [FromBody] AgentUpdateRequest request) { if (request == null) { return(Fail(WebResource.UpdateRequestIsEmpty)); } if (id.IsEmpty() && request.Id.IsEmpty()) { return(Fail(WebResource.IdIsEmpty)); } if (request.Id.IsEmpty()) { request.Id = id.ToGuid(); } await AgentService.UpdateAsync(request); AgentDto byIdAsync = await AgentService.GetByIdAsync(request.Id); return(Success(byIdAsync)); }
public async Task Update(ServerAgentDefinition agent, CancellationToken token) { //Output // .Append("Checking Agent ", ConsoleColor.DarkCyan) // .Append(agent.Name, ConsoleColor.Cyan) // .AppendLine(" for updates...", ConsoleColor.DarkCyan); //MessageClient client = null; try { //client = new MessageClient(PhotonServer.Instance.MessageRegistry) { // //Context = sessionBase, //}; //MessageClient.ThreadException += MessageClient_OnThreadException; //await client.ConnectAsync(agent.TcpHost, agent.TcpPort, token); //var versionRequest = new AgentGetVersionRequest(); //var versionResponse = await client.Send(versionRequest) // .GetResponseAsync<AgentGetVersionResponse>(token); //if (!HasUpdates(versionResponse.Version, UpdateVersion)) { // Output // .Append("Agent ", ConsoleColor.DarkBlue) // .Append(agent.Name, ConsoleColor.Blue) // .AppendLine(" is up-to-date. Version: ", ConsoleColor.DarkBlue) // .AppendLine(versionResponse.Version, ConsoleColor.Blue); // return; //} //Output // .Append("Updating Agent ", ConsoleColor.DarkCyan) // .Append(agent.Name, ConsoleColor.Cyan) // .AppendLine("...", ConsoleColor.DarkCyan); var message = new AgentUpdateRequest { Filename = MsiFilename, }; await MessageClient.Send(message) .GetResponseAsync(token); await MessageClient.DisconnectAsync(); } finally { MessageClient?.Dispose(); } await Task.Delay(3000, token); // TODO: Verify update was successful by polling for server and checking version client = null; try { client = await Reconnect(agent, TimeSpan.FromSeconds(60)); await client.DisconnectAsync(); } finally { client?.Dispose(); } Output .Append("Agent ", ConsoleColor.DarkGreen) .Append(agent.Name, ConsoleColor.Green) .AppendLine(" updated successfully.", ConsoleColor.DarkGreen); }