public ServerResponse GetAutomations()
        {
            try
            {
                var apiResponse            = AutomationsAPIManager.GetAutomations(_authAPIManager);
                var automationPackageNames = apiResponse.Data.Items.Where(
                    a => !string.IsNullOrEmpty(a.OriginalPackageName) &&
                    a.OriginalPackageName.EndsWith(".nupkg") &&
                    a.AutomationEngine.Equals("OpenBots")
                    ).Select(a => a.OriginalPackageName).ToList();
                return(new ServerResponse(automationPackageNames, apiResponse.StatusCode.ToString()));
            }
            catch (Exception ex)
            {
                var errorCode    = ex.GetType().GetProperty("ErrorCode")?.GetValue(ex, null)?.ToString() ?? string.Empty;
                var errorMessage = ex.GetType().GetProperty("ErrorContent")?.GetValue(ex, null)?.ToString() ?? ex.Message;

                // Log Event (Error)
                _fileLogger.LogEvent("Get Automations", $"Error occurred while getting automations from the Server; " +
                                     $"Error Code = {errorCode}; Error Message = {errorMessage}", LogEventLevel.Error);

                // Form Server Response
                return(new ServerResponse(null, errorCode, errorMessage));
            }
        }
Beispiel #2
0
        public bool ExecuteTask(string projectPackage, ServerConnectionSettings settings, bool isServerAutomation)
        {
            if (!_executionManager.IsEngineBusy)
            {
                bool   isSuccessful;
                string projectDirectoryPath, configFilePath, mainScriptFilePath;
                projectDirectoryPath = configFilePath = mainScriptFilePath = string.Empty;
                try
                {
                    _executionManager.SetEngineStatus(true);
                    if (isServerAutomation)
                    {
                        // projectPackage is "Name" of the Project Package here
                        string filter     = $"originalPackageName eq '{projectPackage}'";
                        var    automation = AutomationsAPIManager.GetAutomations(_authAPIManager, filter).Data?.Items.FirstOrDefault();
                        mainScriptFilePath = AutomationManager.DownloadAndExtractAutomation(_authAPIManager, automation, string.Empty, settings.DNSHost, settings.UserName, out configFilePath);
                    }
                    else
                    {
                        // projectPackage is "Path" of the Project Package here
                        mainScriptFilePath = AutomationManager.GetMainScriptFilePath(projectPackage, out configFilePath);
                    }

                    projectDirectoryPath = Path.GetDirectoryName(mainScriptFilePath);
                    NugetPackageManager.InstallProjectDependencies(configFilePath, settings.DNSHost, settings.UserName);
                    var assembliesList = NugetPackageManager.LoadPackageAssemblies(configFilePath, settings.DNSHost, settings.UserName);

                    RunAttendedAutomation(mainScriptFilePath, settings, assembliesList);

                    isSuccessful = true;
                }
                catch (Exception)
                {
                    isSuccessful = false;
                }
                finally
                {
                    // Delete Project Directory
                    if (Directory.Exists(projectDirectoryPath))
                    {
                        Directory.Delete(projectDirectoryPath, true);
                    }

                    _executionManager.SetEngineStatus(false);
                }

                return(isSuccessful);
            }
            return(false);
        }
Beispiel #3
0
        public bool ExecuteTask(string projectPackage, ServerConnectionSettings settings, bool isServerAutomation)
        {
            if (!_executionManager.IsEngineBusy)
            {
                bool   isSuccessful;
                string projectDirectoryPath, configFilePath, mainScriptFilePath;
                projectDirectoryPath = configFilePath = mainScriptFilePath = string.Empty;
                try
                {
                    _executionManager.SetEngineStatus(true);
                    if (isServerAutomation)
                    {
                        // projectPackage is "Name" of the Project Package here
                        string filter     = $"originalPackageName eq '{projectPackage}'";
                        var    automation = AutomationsAPIManager.GetAutomations(_authAPIManager, filter).Data?.Items.FirstOrDefault();
                        mainScriptFilePath = AutomationManager.DownloadAndExtractAutomation(_authAPIManager, automation, string.Empty, settings.DNSHost, settings.UserName, out projectDirectoryPath, out configFilePath);
                    }
                    else
                    {
                        // projectPackage is "Path" of the Project Package here
                        mainScriptFilePath = AutomationManager.GetMainScriptFilePath(projectPackage, out configFilePath);
                    }

                    projectDirectoryPath = Path.GetDirectoryName(mainScriptFilePath);
                    string projectType    = JObject.Parse(File.ReadAllText(configFilePath))["ProjectType"].ToString();
                    var    automationType = (AutomationType)Enum.Parse(typeof(AutomationType), projectType);
                    switch (automationType)
                    {
                    case AutomationType.OpenBots:
                        NugetPackageManager.InstallProjectDependencies(configFilePath, settings.DNSHost, settings.UserName);
                        var assembliesList = NugetPackageManager.LoadPackageAssemblies(configFilePath, settings.DNSHost, settings.UserName);
                        RunOpenBotsAutomation(mainScriptFilePath, Path.GetFileNameWithoutExtension(projectPackage), settings, assembliesList);
                        break;

                    case AutomationType.Python:
                        RunPythonAutomation(mainScriptFilePath, Path.GetFileNameWithoutExtension(projectPackage), settings);
                        break;

                    case AutomationType.TagUI:
                        RunTagUIAutomation(mainScriptFilePath, Path.GetFileNameWithoutExtension(projectPackage), settings, projectDirectoryPath);
                        break;

                    case AutomationType.CSScript:
                        RunCSharpAutomation(mainScriptFilePath, Path.GetFileNameWithoutExtension(projectPackage), settings);
                        break;

                    default:
                        throw new NotImplementedException($"Specified automation type \"{automationType}\" is not supported in the OpenBots Agent.");
                    }

                    isSuccessful = true;
                }
                catch (Exception)
                {
                    isSuccessful = false;
                }
                finally
                {
                    // Delete Project Directory
                    if (Directory.Exists(projectDirectoryPath))
                    {
                        Directory.Delete(projectDirectoryPath, true);
                    }

                    _executionManager.SetEngineStatus(false);
                }

                return(isSuccessful);
            }
            return(false);
        }