public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems) { AmazonDataSyncConfig config = new AmazonDataSyncConfig(); config.RegionEndpoint = region; ConfigureClient(config); AmazonDataSyncClient client = new AmazonDataSyncClient(creds, config); ListAgentsResponse resp = new ListAgentsResponse(); do { ListAgentsRequest req = new ListAgentsRequest { NextToken = resp.NextToken , MaxResults = maxItems }; resp = client.ListAgents(req); CheckError(resp.HttpStatusCode, "200"); foreach (var obj in resp.Agents) { AddObject(obj); } }while (!string.IsNullOrEmpty(resp.NextToken)); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { ListAgentsResponse response = new ListAgentsResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("Agents", targetDepth)) { var unmarshaller = new ListUnmarshaller <AgentListEntry, AgentListEntryUnmarshaller>(AgentListEntryUnmarshaller.Instance); response.Agents = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("NextToken", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.NextToken = unmarshaller.Unmarshall(context); continue; } } return(response); }
private void ProcessReceivedMessageRequest(HostCustomEventArgs args) { //server recieves requests only from Console! var message = (RequestMessage)args.Result; if (_console == null) { _console = args.Token; } if (message.Request is ListAgentsRequest) { // send all agents list to console (icluding static agent info: name, ip, OS, etc...) var agentsResponse = new ListAgentsResponse() { Agents = new List <Agent>() }; for (var i = 0; i < _agents.Count; i++) { agentsResponse.Agents.Add(_agents[i].Agent); } var responseMessage = new ResponseMessage() { UniqueID = message.UniqueID, Response = agentsResponse }; _server.Send(responseMessage, args.Token); } else if (message.Request is WakeOnLanRequest) { Agent targetAgent = _agents[message.AgentId].Agent; string targetIp = targetAgent.Data.IpConfig.IpAddress; string targetMask = targetAgent.Data.IpConfig.NetMask; Logger.WriteStr("Recieved command to wake up agent " + targetAgent.Name); bool notFound = true; //look for client on the same subnet with target, which has Online status for (var i = 0; i < _agents.Count; i++) { //exclude itself if (message.AgentId != i) { var agentToken = _agents[i]; if (NetworkHelper.IsOnSameNetwork(agentToken.Agent.Data.IpConfig.IpAddress, agentToken.Agent.Data.IpConfig.NetMask, targetIp, targetMask) && agentToken.Agent.Status == (int)EAgentStatus.Online) { // send original message with MAC address to the found agent _server.Send(message, agentToken); notFound = false; // exit loop break; } } } if (notFound) // there is no agent in the same subnet with target agent { Logger.WriteStr("Cannot wake up " + targetAgent.Name + " because there is no agent in the same subnet."); // send unsuccessfull message back to console var response = new WakeOnLanResponse(false, ((WakeOnLanRequest)message.Request).RunId); var responseMessage = new ResponseMessage() { Response = response, AgentId = message.AgentId }; _server.Send(responseMessage, _console); } } else if (message.Request is BulkStaticRequest) { //retrieve from local "database": it will speed up response. //(this data is not changes at least untill agent reconnects) var agentToken = _agents[message.AgentId]; if (agentToken.Agent.Data.IpConfig != null && agentToken.Agent.Data.OS != null) { var response = new BulkStaticResponse() { IpConf = agentToken.Agent.Data.IpConfig, OsInfo = agentToken.Agent.Data.OS }; var responseMessage = new ResponseMessage() { Response = response, AgentId = message.AgentId }; _server.Send(responseMessage, args.Token); } else { // nas no reqired info, so send request to client _server.Send(message, agentToken); } } else { //match agent by agentId and redirect received Message Request to it, if it still is connected var agentToken = _agents[message.AgentId]; if (agentToken.Socket != null) { // redirect to agent _server.Send(message, agentToken); } else { // Agent is not connected so send update to console if (_console != null) { var update = new AgentStatusUpdate { status = (int)EAgentStatus.Offline }; var updateMessage = new ResponseMessage() { Response = update, AgentId = message.AgentId }; _server.Send(updateMessage, _console); } } } }