private void Initialize(ConnectionSettingsManager connectionSettingsManager, AuthAPIManager authAPIManager, FileLogger fileLogger)
 {
     _connectionSettingsManager = connectionSettingsManager;
     _authAPIManager            = authAPIManager;
     _fileLogger = fileLogger;
     _authAPIManager.ConfigurationUpdatedEvent += OnConfigurationUpdate;
 }
Ejemplo n.º 2
0
        public AttendedExecutionManager(ExecutionManager executionManager, AuthAPIManager authAPIManager)
        {
            _executionManager = executionManager;
            _authAPIManager   = authAPIManager;

            _authAPIManager.ConfigurationUpdatedEvent += OnConfigurationUpdate;
        }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
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;
            }
        }
Ejemplo n.º 5
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.º 6
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;
            }
        }
        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;
            }
        }
Ejemplo n.º 8
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;
            }
        }
Ejemplo n.º 9
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;
            }
        }
Ejemplo n.º 10
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;
            }
        }
Ejemplo n.º 11
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.º 12
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.º 13
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;
            }
        }
Ejemplo n.º 14
0
        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;
            }
        }
Ejemplo n.º 15
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;
            }
        }
Ejemplo n.º 16
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;
            }
        }
Ejemplo n.º 17
0
        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();
        }
Ejemplo n.º 18
0
        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;
        }