Ejemplo n.º 1
0
        private static AgentsApi GetApiInstance(string token, string serverUrl)
        {
            var apiInstance = new AgentsApi(serverUrl);

            apiInstance.Configuration.AccessToken = token;

            return(apiInstance);
        }
Ejemplo n.º 2
0
        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;
            }
        }
Ejemplo n.º 3
0
        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;
            }
        }
Ejemplo n.º 4
0
        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;
            }
        }
Ejemplo n.º 5
0
        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;
            }
        }
Ejemplo n.º 6
0
        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;
            }
        }