Esempio n. 1
0
        public ServerResponse Connect(ServerConnectionSettings connectionSettings)
        {
            // Initialize File Logger for Debug Purpose
            _fileLogger.Initialize(new EnvironmentSettings().GetEnvironmentVariablePath(connectionSettings.DNSHost, connectionSettings.UserName));

            // Log Event
            _fileLogger.LogEvent("Connect", "Attempt to connect to the Server");

            _connectionSettingsManager.ConnectionSettings = connectionSettings;

            // Initialize AuthAPIManager
            _authAPIManager.Initialize(_connectionSettingsManager.ConnectionSettings);
            try
            {
                // Authenticate Agent
                _authAPIManager.GetToken();

                // API Call to Connect
                var connectAPIResponse = AgentsAPIManager.ConnectAgent(_authAPIManager,
                                                                       _connectionSettingsManager.ConnectionSettings = _authAPIManager.ConnectionSettings);

                // Update Server Settings
                _connectionSettingsManager.ConnectionSettings.ServerConnectionEnabled = true;
                _connectionSettingsManager.ConnectionSettings.AgentId   = connectAPIResponse.Data.AgentId.ToString();
                _connectionSettingsManager.ConnectionSettings.AgentName = connectAPIResponse.Data.AgentName.ToString();

                // Start Server Communication
                StartServerCommunication();

                // Send Response to Agent
                return(new ServerResponse(_connectionSettingsManager.ConnectionSettings, connectAPIResponse.StatusCode.ToString()));
            }
            catch (Exception ex)
            {
                // Update Server Settings
                _connectionSettingsManager.ConnectionSettings.ServerConnectionEnabled = false;
                _connectionSettingsManager.ConnectionSettings.AgentId   = string.Empty;
                _connectionSettingsManager.ConnectionSettings.AgentName = string.Empty;

                string errorMessage;
                var    errorCode = ex.GetType().GetProperty("ErrorCode")?.GetValue(ex, null)?.ToString() ?? string.Empty;

                errorMessage = ex.GetType().GetProperty("ErrorContent")?.GetValue(ex, null)?.ToString() ?? ex.Message;

                // Log Event (Error)
                _fileLogger.LogEvent("Connect", $"Error occurred while connecting to the Server; " +
                                     $"Error Code = {errorCode}; Error Message = {errorMessage}", LogEventLevel.Error);

                // Send Response to Agent
                return(new ServerResponse(null, errorCode, errorMessage));
            }
        }
Esempio n. 2
0
        public static Credential GetCredentials(AuthAPIManager apiManager, string credentialId)
        {
            CredentialsApi credentialsApi = new CredentialsApi(apiManager.Configuration);

            try
            {
                return(credentialsApi.GetCredential(credentialId));
            }
            catch (Exception ex)
            {
                // In case of Unauthorized request
                if (ex.GetType().GetProperty("ErrorCode").GetValue(ex, null).ToString() == "401")
                {
                    // Refresh Token and Call API
                    credentialsApi.Configuration.AccessToken = apiManager.GetToken();
                    return(credentialsApi.GetCredential(credentialId));
                }
                throw ex;
            }
        }
        public static Process GetProcess(AuthAPIManager apiManager, string processID)
        {
            ProcessesApi processesApi = new ProcessesApi(apiManager.Configuration);

            try
            {
                return(processesApi.GetProcessWithHttpInfo(processID).Data);
            }
            catch (Exception ex)
            {
                // In case of Unauthorized request
                if (ex.GetType().GetProperty("ErrorCode").GetValue(ex, null).ToString() == "401")
                {
                    // Refresh Token and Call API
                    processesApi.Configuration.AccessToken = apiManager.GetToken();
                    return(processesApi.GetProcessWithHttpInfo(processID).Data);
                }
                throw ex;
            }
        }
Esempio 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;
            }
        }
Esempio n. 5
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;
            }
        }
Esempio n. 6
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;
            }
        }
        public static AutomationExecutionLog CreateExecutionLog(AuthAPIManager apiManager, AutomationExecutionLog body)
        {
            AutomationExecutionLogsApi executionLogsApi = new AutomationExecutionLogsApi(apiManager.Configuration);

            try
            {
                return(executionLogsApi.ApiV1AutomationExecutionLogsStartAutomationPost(body));
            }
            catch (Exception ex)
            {
                // In case of Unauthorized request
                if (ex.GetType().GetProperty("ErrorCode").GetValue(ex, null).ToString() == "401")
                {
                    // Refresh Token and Call API
                    executionLogsApi.Configuration.AccessToken = apiManager.GetToken();
                    return(executionLogsApi.ApiV1AutomationExecutionLogsStartAutomationPost(body));
                }
                throw ex;
            }
        }
Esempio n. 8
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;
            }
        }
Esempio n. 9
0
        public static ApiResponse <AutomationPaginatedList> GetAutomations(AuthAPIManager apiManager, string filter = null)
        {
            AutomationsApi automationsApi = new AutomationsApi(apiManager.Configuration);

            try
            {
                return(automationsApi.ApiV1AutomationsGetWithHttpInfo(filter));
            }
            catch (Exception ex)
            {
                // In case of Unauthorized request
                if (ex.GetType().GetProperty("ErrorCode").GetValue(ex, null).ToString() == "401")
                {
                    // Refresh Token and Call API
                    automationsApi.Configuration.AccessToken = apiManager.GetToken();
                    return(automationsApi.ApiV1AutomationsGetWithHttpInfo(filter));
                }
                throw ex;
            }
        }
Esempio n. 10
0
        public static ApiResponse <IO.MemoryStream> ExportAutomation(AuthAPIManager apiManager, string automationID)
        {
            AutomationsApi automationsApi = new AutomationsApi(apiManager.Configuration);

            try
            {
                return(automationsApi.ExportAutomationWithHttpInfo(automationID));
            }
            catch (Exception ex)
            {
                // In case of Unauthorized request
                if (ex.GetType().GetProperty("ErrorCode").GetValue(ex, null).ToString() == "401")
                {
                    // Refresh Token and Call API
                    automationsApi.Configuration.AccessToken = apiManager.GetToken();
                    return(automationsApi.ExportAutomationWithHttpInfo(automationID));
                }
                throw ex;
            }
        }
Esempio n. 11
0
        public static JobViewModel GetJobViewModel(AuthAPIManager apiManager, string jobId)
        {
            JobsApi jobsApi = new JobsApi(apiManager.Configuration);

            try
            {
                return(jobsApi.ApiV1JobsViewIdGet(jobId));
            }
            catch (Exception ex)
            {
                // In case of Unauthorized request
                if (ex.GetType().GetProperty("ErrorCode").GetValue(ex, null).ToString() == "401")
                {
                    // Refresh Token and Call API
                    jobsApi.Configuration.AccessToken = apiManager.GetToken();
                    return(jobsApi.ApiV1JobsViewIdGet(jobId));
                }
                throw ex;
            }
        }
Esempio n. 12
0
        public static int UpdateJobPatch(AuthAPIManager apiManager, string id, List <Operation> body)
        {
            JobsApi jobsApi = new JobsApi(apiManager.Configuration);

            try
            {
                return(jobsApi.ApiV1JobsIdPatchWithHttpInfo(id, 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
                    jobsApi.Configuration.AccessToken = apiManager.GetToken();
                    return(jobsApi.ApiV1JobsIdPatchWithHttpInfo(id, body).StatusCode);
                }
                throw ex;
            }
        }
Esempio n. 13
0
        public static ApiResponse <Job> UpdateJobStatus(AuthAPIManager apiManager, string agentId, string jobId, JobStatusType status, JobErrorViewModel errorModel = null)
        {
            JobsApi jobsApi = new JobsApi(apiManager.Configuration);

            try
            {
                return(jobsApi.ApiV1JobsIdStatusStatusPutWithHttpInfo(agentId, jobId, status, errorModel));
            }
            catch (Exception ex)
            {
                // In case of Unauthorized request
                if (ex.GetType().GetProperty("ErrorCode").GetValue(ex, null).ToString() == "401")
                {
                    // Refresh Token and Call API
                    jobsApi.Configuration.AccessToken = apiManager.GetToken();
                    return(jobsApi.ApiV1JobsIdStatusStatusPutWithHttpInfo(agentId, jobId, status, errorModel));
                }
                throw ex;
            }
        }
Esempio n. 14
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;
            }
        }