private void Initialize(ConnectionSettingsManager connectionSettingsManager, AuthAPIManager authAPIManager, FileLogger fileLogger) { _connectionSettingsManager = connectionSettingsManager; _authAPIManager = authAPIManager; _fileLogger = fileLogger; _authAPIManager.ConfigurationUpdatedEvent += OnConfigurationUpdate; }
public AttendedExecutionManager(ExecutionManager executionManager, AuthAPIManager authAPIManager) { _executionManager = executionManager; _authAPIManager = authAPIManager; _authAPIManager.ConfigurationUpdatedEvent += OnConfigurationUpdate; }
public Agent() { _connectionSettingsManager = new ConnectionSettingsManager(); _authAPIManager = new AuthAPIManager(); _jobsPolling = new JobsPolling(); _attendedExecutionManager = new AttendedExecutionManager(_jobsPolling.ExecutionManager, _authAPIManager); _fileLogger = new FileLogger(); _connectionSettingsManager.ConnectionSettingsUpdatedEvent += OnConnectionSettingsUpdate; _authAPIManager.ConfigurationUpdatedEvent += OnConfigurationUpdate; _jobsPolling.ServerConnectionLostEvent += OnServerConnectionLost; }
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; } }
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 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; } }
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; } }
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; } }
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; } }
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 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; } }
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; } }
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; } }
public void StartJobsPolling(ConnectionSettingsManager connectionSettingsManager, AuthAPIManager authAPIManager, FileLogger fileLogger) { Initialize(connectionSettingsManager, authAPIManager, fileLogger); // Start Timed Polling StartJobsFetchTimer(); // Start Long Polling StartHubManager(); // Start Execution Manager to Run Job(s) StartExecutionManager(); }
public static string DownloadAndExtractAutomation(AuthAPIManager authAPIManager, Automation automation, string jobId, string domainName, string userName, out string executionDirectoryPath, out string configFilePath) { configFilePath = ""; executionDirectoryPath = ""; // Check if (Root) Automations Directory Exists (under User's AppData Folder), If Not create it var automationsDirectory = Path.Combine(new EnvironmentSettings().GetEnvironmentVariablePath(domainName, userName), "Automations", automation.AutomationEngine); if (!Directory.Exists(automationsDirectory)) { Directory.CreateDirectory(automationsDirectory); } // Automation Directory var processDirectoryPath = Path.Combine(automationsDirectory, automation.Id.ToString()); // Create Automation Directory named as Automation Id If it doesn't exist if (!Directory.Exists(processDirectoryPath)) { Directory.CreateDirectory(processDirectoryPath); } // Automation Nuget Package Path var processNugetFilePath = Path.Combine(processDirectoryPath, automation.Name.ToString() + ".nupkg"); // Execution Directory Path executionDirectoryPath = Path.Combine(processDirectoryPath, string.IsNullOrEmpty(jobId) ? new Guid().ToString() : jobId); if (!Directory.Exists(executionDirectoryPath)) { Directory.CreateDirectory(executionDirectoryPath); } var processZipFilePath = Path.Combine(executionDirectoryPath, automation.Name.ToString() + ".zip"); // Check if Automation (.nupkg) file exists if Not Download it if (!File.Exists(processNugetFilePath)) { // Download Automation by Id var apiResponse = AutomationsAPIManager.ExportAutomation(authAPIManager, automation.Id.ToString()); // Write Downloaded(.nupkg) file in the Automation Directory File.WriteAllBytes(processNugetFilePath, apiResponse.Data.ToArray()); } // Create .zip file if it doesn't exist if (!File.Exists(processZipFilePath)) { File.Copy(processNugetFilePath, processZipFilePath); } var extractToDirectoryPath = Path.ChangeExtension(processZipFilePath, null); // Extract Files/Folders from (.zip) file DecompressFile(processZipFilePath, extractToDirectoryPath); // Delete .zip File File.Delete(processZipFilePath); configFilePath = Directory.GetFiles(extractToDirectoryPath, "project.obconfig", SearchOption.AllDirectories).First(); string mainFileName = JObject.Parse(File.ReadAllText(configFilePath))["Main"].ToString(); // Return "Main" Script File Path of the Automation return(Directory.GetFiles(extractToDirectoryPath, mainFileName, SearchOption.AllDirectories).First()); }
public void StartHeartBeatTimer(ConnectionSettingsManager connectionSettingsManager, AuthAPIManager authAPIManager, FileLogger fileLogger) { Initialize(connectionSettingsManager, authAPIManager, fileLogger); if (_connectionSettingsManager.ConnectionSettings.ServerConnectionEnabled) { //handle for reinitialization if (_heartbeatTimer != null) { _heartbeatTimer.Elapsed -= Heartbeat_Elapsed; } //setup heartbeat to the server _heartbeatTimer = new Timer(); _heartbeatTimer.Interval = (connectionSettingsManager.ConnectionSettings.HeartbeatInterval * 1000); _heartbeatTimer.Elapsed += Heartbeat_Elapsed; _heartbeatTimer.Enabled = true; Initialize(_connectionSettingsManager.ConnectionSettings.AgentId); } }
public void StartNewJobsCheckTimer(ConnectionSettingsManager connectionSettingsManager, AuthAPIManager authAPIManager, FileLogger fileLogger) { Initialize(connectionSettingsManager, authAPIManager, fileLogger); //handle for reinitialization if (_newJobsCheckTimer != null) { _newJobsCheckTimer.Elapsed -= NewJobsCheckTimer_Elapsed; } _newJobsCheckTimer = new Timer(); _newJobsCheckTimer.Interval = 3000; _newJobsCheckTimer.Elapsed += NewJobsCheckTimer_Elapsed; _newJobsCheckTimer.Enabled = true; }