public override async Task RunCommand(object sender)
        {
            var engine = (IAutomationEngineInstance)sender;

            var vHumanTaskId = (Guid)await v_TaskId.EvaluateCode(engine);

            var vDocId = (Guid)await v_DocumentId.EvaluateCode(engine);

            string vUsername;
            string vPassword;

            var environmentSettings = new EnvironmentSettings();

            environmentSettings.Load();
            AuthMethods authMethods = new AuthMethods();

            authMethods.Initialize(environmentSettings.ServerType, environmentSettings.OrganizationName, environmentSettings.ServerUrl, environmentSettings.Username, environmentSettings.Password);

            if (environmentSettings.ServerType == "Local")
            {
                throw new Exception("Documents commands cannot be used with local Server");
            }
            else
            {
                vUsername = environmentSettings.Username;
                vPassword = environmentSettings.Password;
            }

            var userInfo = authMethods.GetDocumentsAuthToken(vUsername, vPassword);

            DocumentMethods.MarkDocumentAsVerified(userInfo, vHumanTaskId, vDocId);
        }
        public override async Task RunCommand(object sender)
        {
            var engine = (IAutomationEngineInstance)sender;

            string vUsername;
            string vPassword;

            var environmentSettings = new EnvironmentSettings();

            environmentSettings.Load();
            AuthMethods authMethods = new AuthMethods();

            authMethods.Initialize(environmentSettings.ServerType, environmentSettings.OrganizationName, environmentSettings.ServerUrl, environmentSettings.Username, environmentSettings.Password);

            if (environmentSettings.ServerType == "Local")
            {
                throw new Exception("Documents commands cannot be used with local Server");
            }
            else
            {
                vUsername = environmentSettings.Username;
                vPassword = environmentSettings.Password;
            }

            Guid vHumanTaskId = (Guid)await v_TaskId.EvaluateCode(engine);

            bool vSavePageText = (bool)await v_SavePageText.EvaluateCode(engine);

            bool vSavePageImages = (bool)await v_SavePageImages.EvaluateCode(engine);

            string vOutputFolder = (string)await v_OutputFolder.EvaluateCode(engine);

            bool vAwaitCompletion = (bool)await v_AwaitCompletion.EvaluateCode(engine);

            int vTimeout = (int)await v_Timeout.EvaluateCode(engine);

            var vData = await v_OutputUserVariableName5.EvaluateCode(engine);

            DataTable dataDt = vData == null ? null : (DataTable)vData;

            var            userInfo = authMethods.GetDocumentsAuthToken(vUsername, vPassword);
            DocumentResult docInfo  = DocumentMethods.SaveDocumentResults(userInfo, vHumanTaskId, vAwaitCompletion, vSavePageImages, vSavePageText, vTimeout,
                                                                          vOutputFolder, dataDt);
            string    docInfoAsJSON      = docInfo.OutputAsJSON;
            DataTable docInfoAsDataTable = docInfo.DataAsTable;

            dataDt = docInfo.OutputAsTable;

            docInfo.Status.SetVariableValue(engine, v_OutputUserVariableName);
            docInfo.IsCompleted.SetVariableValue(engine, v_OutputUserVariableName1);
            docInfo.HasFailedOrError.SetVariableValue(engine, v_OutputUserVariableName2);
            docInfoAsJSON.SetVariableValue(engine, v_OutputUserVariableName3);
            docInfoAsDataTable.SetVariableValue(engine, v_OutputUserVariableName4);
            dataDt.SetVariableValue(engine, v_OutputUserVariableName5);
        }
Example #3
0
        public override async Task RunCommand(object sender)
        {
            var engine = (IAutomationEngineInstance)sender;

            string vUsername;
            string vPassword;

            var environmentSettings = new EnvironmentSettings();

            environmentSettings.Load();
            AuthMethods authMethods = new AuthMethods();

            authMethods.Initialize(environmentSettings.ServerType, environmentSettings.OrganizationName, environmentSettings.ServerUrl, environmentSettings.Username, environmentSettings.Password);

            if (environmentSettings.ServerType == "Local")
            {
                throw new Exception("Documents commands cannot be used with local Server");
            }
            else
            {
                vUsername = environmentSettings.Username;
                vPassword = environmentSettings.Password;
            }

            string vFileToProcess = (string)await v_FilePath.EvaluateCode(engine);

            string vTaskQueueName = (string)await v_QueueName.EvaluateCode(engine);

            string vName = (string)await v_Name.EvaluateCode(engine);

            string vDescription = (string)await v_Description.EvaluateCode(engine);

            string vCaseNumber = (string)await v_CaseNumber.EvaluateCode(engine);

            string vCaseType = (string)await v_CaseType.EvaluateCode(engine);

            string vAssignedTo = (string)await v_AssignedTo.EvaluateCode(engine);

            dynamic vDueOn = v_DueDate.EvaluateCode(engine);

            if (!string.IsNullOrEmpty(v_DueDate))
            {
                vDueOn = (DateTime)await v_DueDate.EvaluateCode(engine);
            }

            UserInfo userInfo = authMethods.GetDocumentsAuthToken(vUsername, vPassword);
            var      docInfo  = DocumentMethods.SubmitDocument(userInfo, vFileToProcess, vTaskQueueName, vName, vDescription, vCaseType, vCaseNumber,
                                                               vAssignedTo, vDueOn);

            Guid   taskId = Guid.Parse(docInfo["TaskID"]);
            string status = docInfo["Status"];

            taskId.SetVariableValue(engine, v_OutputUserVariableName);
            status.SetVariableValue(engine, v_OutputUserVariableName2);
        }
Example #4
0
        private string GetPublicIP(EnvironmentSettings environmentSettings)
        {
            try
            {
                AuthMethods authMethods = new AuthMethods();
                authMethods.Initialize(environmentSettings.ServerType, environmentSettings.OrganizationName, environmentSettings.ServerUrl, environmentSettings.Username, environmentSettings.Password);

                return(authMethods.Ping());
            }
            catch (Exception)
            {
                return("Server is not responding");
            }
        }
Example #5
0
        public override async Task RunCommand(object sender)
        {
            var engine  = (IAutomationEngineInstance)sender;
            var vTaskId = (Guid)await v_TaskId.EvaluateCode(engine);

            var vAwaitCompletion = (bool)await v_AwaitCompletion.EvaluateCode(engine);

            string vUsername;
            string vPassword;

            var environmentSettings = new EnvironmentSettings();

            environmentSettings.Load();
            AuthMethods authMethods = new AuthMethods();

            authMethods.Initialize(environmentSettings.ServerType, environmentSettings.OrganizationName, environmentSettings.ServerUrl, environmentSettings.Username, environmentSettings.Password);

            if (environmentSettings.ServerType == "Local")
            {
                throw new Exception("Documents commands cannot be used with local Server");
            }
            else
            {
                vUsername = environmentSettings.Username;
                vPassword = environmentSettings.Password;
            }

            var            userInfo  = authMethods.GetDocumentsAuthToken(vUsername, vPassword);
            DocumentStatus docStatus = DocumentMethods.GetDocumentStatus(userInfo, vTaskId);

            if (vAwaitCompletion)
            {
                int vTimeout = (int)await v_Timeout.EvaluateCode(engine);

                docStatus = DocumentMethods.AwaitProcessing(userInfo, vTaskId, vTimeout);
            }

            docStatus.Status.SetVariableValue(engine, v_OutputUserVariableName);
            docStatus.IsDocumentCompleted.SetVariableValue(engine, v_OutputUserVariableName1);
            docStatus.HasError.SetVariableValue(engine, v_OutputUserVariableName2);
            docStatus.IsCurrentlyProcessing.SetVariableValue(engine, v_OutputUserVariableName3);
            docStatus.IsSuccessful.SetVariableValue(engine, v_OutputUserVariableName4);
        }
Example #6
0
        public static UserInfo RefreshToken(IAutomationEngineInstance engine)
        {
            var sessionVariablesDict = engine.EngineContext.SessionVariables;

            UserInfo userInfo = (UserInfo)sessionVariablesDict["UserInfo"];

            sessionVariablesDict.Remove("UserInfo");

            //use refresh token and get new auth/refresh tokens
            var environmentSettings = new EnvironmentSettings();

            environmentSettings.Load();
            AuthMethods authMethods = new AuthMethods();

            authMethods.Initialize(environmentSettings.ServerType, environmentSettings.OrganizationName, environmentSettings.ServerUrl, environmentSettings.Username, environmentSettings.Password, environmentSettings.AgentId);

            authMethods.RefreshToken(userInfo);

            return(userInfo);
        }
Example #7
0
        public static UserInfo GetUserInfo(IAutomationEngineInstance engine)
        {
            var environmentSettings = new EnvironmentSettings();

            environmentSettings.Load();
            AuthMethods authMethods = new AuthMethods();

            authMethods.Initialize(environmentSettings.ServerType, environmentSettings.OrganizationName, environmentSettings.ServerUrl, environmentSettings.Username, environmentSettings.Password, environmentSettings.AgentId);

            var    sessionVariablesDict = engine.EngineContext.SessionVariables;
            object sessionUserInfo;

            bool keyExists = sessionVariablesDict.TryGetValue("UserInfo", out sessionUserInfo);

            if (!keyExists)
            {
                sessionUserInfo = authMethods.GetUserInfo();
                SetAuthSessionVariables(engine, (UserInfo)sessionUserInfo);
            }

            return((UserInfo)sessionUserInfo);
        }
        private bool PublishProject()
        {
            try
            {
                string[] scriptFiles = SystemFile.Directory.GetFiles(_projectPath, "*.*", SystemFile.SearchOption.AllDirectories);
                List <ManifestContentFiles> manifestFiles = new List <ManifestContentFiles>();
                foreach (string file in scriptFiles)
                {
                    ManifestContentFiles manifestFile = new ManifestContentFiles
                    {
                        Include = file.Replace(_projectPath, "")
                    };
                    manifestFiles.Add(manifestFile);
                }

                ManifestMetadata metadata = new ManifestMetadata()
                {
                    Id          = _projectName.Replace(" ", "_"),
                    Title       = _projectName,
                    Authors     = txtAuthorName.Text.Trim(),
                    Version     = txtVersion.Text.Trim(),
                    Description = txtDescription.Text.Trim(),
                    RequireLicenseAcceptance = false,
                    IconUrl        = "https://openbots.ai/wp-content/uploads/2020/11/Studio-Icon-256px.png",
                    DependencySets = new List <ManifestDependencySet>()
                    {
                        new ManifestDependencySet()
                        {
                            Dependencies = new List <ManifestDependency>()
                            {
                                new ManifestDependency()
                                {
                                    Id      = "OpenBots.Studio",
                                    Version = new Version(Application.ProductVersion).ToString()
                                },
                            }
                        }
                    },
                    ContentFiles = manifestFiles,
                };

                foreach (var dependency in _projectDependencies)
                {
                    var dep = new ManifestDependency
                    {
                        Id      = dependency.Key,
                        Version = dependency.Value
                    };
                    metadata.DependencySets[0].Dependencies.Add(dep);
                }

                PackageBuilder builder = new PackageBuilder();
                builder.PopulateFiles(_projectPath, new[] { new ManifestFile()
                                                            {
                                                                Source = "**"
                                                            } });
                builder.Populate(metadata);

                if (!SystemFile.Directory.Exists(txtLocation.Text))
                {
                    SystemFile.Directory.CreateDirectory(txtLocation.Text);
                }

                string nugetFilePath = SystemFile.Path.Combine(txtLocation.Text.Trim(), $"{_projectName}_{txtVersion.Text.Trim()}.nupkg");
                using (SystemFile.FileStream stream = File.Open(nugetFilePath, SystemFile.FileMode.OpenOrCreate))
                    builder.Save(stream);

                NotificationMessage = $"'{_projectName}' published successfully";

                if (cbxLocation.Text == "Local Only")
                {
                    return(true);
                }

                try {
                    lblError.Text = $"Publishing {_projectName} to the server...";

                    var environmentSettings = new EnvironmentSettings();
                    environmentSettings.Load();
                    AuthMethods authMethods = new AuthMethods();
                    authMethods.Initialize(environmentSettings.ServerType, environmentSettings.OrganizationName, environmentSettings.ServerUrl, environmentSettings.Username, environmentSettings.Password);

                    var automation = AutomationMethods.UploadAutomation(_projectName, nugetFilePath, _automationEngine, authMethods);

                    if (_projectArguments.Count > 0)
                    {
                        IEnumerable <AutomationParameter> automationParameters = _projectArguments.Select(arg => new AutomationParameter()
                        {
                            Name         = arg.ArgumentName,
                            DataType     = GetServerType(arg.ArgumentType),
                            Value        = arg.ArgumentValue?.ToString(),
                            AutomationId = automation.Id
                        });

                        AutomationMethods.UpdateParameters(automation.Id, automationParameters, authMethods);
                    }
                }
                catch (Exception ex)
                {
                    if (ex.Message != "Agent is not connected" && !string.IsNullOrEmpty(ex.InnerException.Message))
                    {
                        NotificationMessage = $"'{_projectName}' was published locally. To publish to an OpenBots Server please install and connect the OpenBots Agent." +
                                              $" Error: {ex.InnerException.Message}";
                    }
                    else
                    {
                        NotificationMessage = $"'{_projectName}' was published locally. To publish to an OpenBots Server please install and connect the OpenBots Agent." +
                                              $" Error: {ex.Message}";
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
                return(false);
            }
        }