private static AgentsApi GetApiInstance(string token, string serverUrl) { var apiInstance = new AgentsApi(serverUrl); apiInstance.Configuration.AccessToken = token; return(apiInstance); }
public static bool FindAgent(AuthAPIManager apiManager, string filter) { AgentsApi agentsApi = new AgentsApi(apiManager.Configuration); try { return((agentsApi.ApiV1AgentsGetWithHttpInfo(filter).Data.Items.Count == 0) ? false : true); } catch (Exception ex) { // In case of Unauthorized request if (ex.GetType().GetProperty("ErrorCode").GetValue(ex, null).ToString() == "401") { // Refresh Token and Call API agentsApi.Configuration.AccessToken = apiManager.GetToken(); return((agentsApi.ApiV1AgentsGetWithHttpInfo(filter).Data.Items.Count == 0) ? false : true); } throw ex; } }
public static ApiResponse <IActionResult> DisconnectAgent(AuthAPIManager apiManager, ServerConnectionSettings serverSettings) { AgentsApi agentsApi = new AgentsApi(apiManager.Configuration); try { return(agentsApi.ApiV1AgentsDisconnectPatchWithHttpInfo(serverSettings.AgentId, serverSettings.MachineName, serverSettings.MACAddress)); } catch (Exception ex) { // In case of Unauthorized request if (ex.GetType().GetProperty("ErrorCode").GetValue(ex, null).ToString() == "401") { // Refresh Token and Call API agentsApi.Configuration.AccessToken = apiManager.GetToken(); return(agentsApi.ApiV1AgentsDisconnectPatchWithHttpInfo(serverSettings.AgentId, serverSettings.MachineName, serverSettings.MACAddress)); } throw ex; } }
public static AgentViewModel GetAgent(AuthAPIManager apiManager, string agentId) { AgentsApi agentsApi = new AgentsApi(apiManager.Configuration); try { return(agentsApi.GetAgentModel(agentId)); } catch (Exception ex) { // In case of Unauthorized request if (ex.GetType().GetProperty("ErrorCode").GetValue(ex, null).ToString() == "401") { // Refresh Token and Call API agentsApi.Configuration.AccessToken = apiManager.GetToken(); return(agentsApi.GetAgentModel(agentId)); } throw ex; } }
public static int SendAgentHeartBeat(AuthAPIManager apiManager, string agentId, AgentHeartbeat body) { AgentsApi agentsApi = new AgentsApi(apiManager.Configuration); try { return(agentsApi.ApiV1AgentsAgentIdAddHeartbeatPostWithHttpInfo(agentId, body).StatusCode); } catch (Exception ex) { // In case of Unauthorized request if (ex.GetType().GetProperty("ErrorCode").GetValue(ex, null).ToString() == "401") { // Refresh Token and Call API agentsApi.Configuration.AccessToken = apiManager.GetToken(); return(agentsApi.ApiV1AgentsAgentIdAddHeartbeatPostWithHttpInfo(agentId, body).StatusCode); } throw ex; } }
public static string CreateAgent(AuthAPIManager apiManager, ServerConnectionSettings serverSettings) { AgentsApi agentsApi = new AgentsApi(apiManager.Configuration); var agentModel = new CreateAgentViewModel(null, serverSettings.AgentName, serverSettings.DNSHost, serverSettings.MACAddress, serverSettings.IPAddress, true, null, null, null, null, true, false, null, serverSettings.AgentUsername, serverSettings.AgentPassword); try { return(agentsApi.ApiV1AgentsPostWithHttpInfo(agentModel).Data.Id.ToString()); } catch (Exception ex) { // In case of Unauthorized request if (ex.GetType().GetProperty("ErrorCode").GetValue(ex, null).ToString() == "401") { // Refresh Token and Call API agentsApi.Configuration.AccessToken = apiManager.GetToken(); return(agentsApi.ApiV1AgentsPostWithHttpInfo(agentModel).Data.Id.ToString()); } throw ex; } }