Beispiel #1
0
        public override void RunCommand(object sender)
        {
            var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;

            var keyName    = v_KeyName.ConvertToUserVariable(sender);
            var dataOption = v_DataOption.ConvertToUserVariable(sender);

            BotStoreRequest.RequestType requestType;
            if (dataOption == "Retrieve Entire Record")
            {
                requestType = BotStoreRequest.RequestType.BotStoreModel;
            }
            else
            {
                requestType = BotStoreRequest.RequestType.BotStoreValue;
            }


            try
            {
                var result = HttpServerClient.GetData(keyName, requestType);

                if (requestType == BotStoreRequest.RequestType.BotStoreValue)
                {
                    result = JsonConvert.DeserializeObject <string>(result);
                }


                result.StoreInUserVariable(sender, v_applyToVariableName);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 private void btnTaskPublish_Click(object sender, EventArgs e)
 {
     if (File.Exists(scriptBuilderForm.ScriptFilePath))
     {
         HttpServerClient.PublishScript(scriptBuilderForm.ScriptFilePath, PublishType.ServerReference);
     }
     else
     {
         MessageBox.Show("Please open the task in order to publish it.");
     }
 }
        private void OpenSettingsManager()
        {
            //show settings dialog
            frmSettings newSettings = new frmSettings(this);

            newSettings.ShowDialog();

            //reload app settings
            _appSettings = new ApplicationSettings();
            _appSettings = _appSettings.GetOrCreateApplicationSettings();

            //reinit
            HttpServerClient.InitializeScriptEngine(new frmScriptEngine());
            HttpServerClient.Initialize();
        }
Beispiel #4
0
        public override void RunCommand(object sender)
        {
            var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;

            var keyName  = v_KeyName.ConvertToUserVariable(sender);
            var keyValue = v_InputValue.ConvertToUserVariable(sender);

            try
            {
                var result = HttpServerClient.UploadData(keyName, keyValue);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void btnGetGUID_Click(object sender, EventArgs e)
        {
            var successfulConnection = HttpServerClient.TestConnection(txtHttpsAddress.Text);

            if (successfulConnection)
            {
                var pulledNewGUID = HttpServerClient.GetGuid();

                if (pulledNewGUID)
                {
                    newAppSettings       = new ApplicationSettings();
                    newAppSettings       = newAppSettings.GetOrCreateApplicationSettings();
                    txtHttpsAddress.Text = newAppSettings.ServerSettings.HTTPGuid.ToString();
                    MessageBox.Show("Connected Successfully! GUID will be reloaded automatically the next time settings is loaded!");
                }
                MessageBox.Show("Connected Successfully!");
            }
            else
            {
                MessageBox.Show("Unable To Connect!");
            }
        }
        public virtual void ScriptFinished(ScriptFinishedEventArgs.ScriptFinishedResult result, string error = null)
        {
            engineLogger.Information("Result Code: " + result.ToString());

            //add result variable if missing
            var resultVar = VariableList.Where(f => f.VariableName == "taskt.Result").FirstOrDefault();

            //handle if variable is missing
            if (resultVar == null)
            {
                resultVar = new Script.ScriptVariable()
                {
                    VariableName = "taskt.Result", VariableValue = ""
                };
            }

            //check value
            var resultValue = resultVar.VariableValue.ToString();


            if (error == null)
            {
                engineLogger.Information("Error: None");

                if (taskModel != null && serverSettings.ServerConnectionEnabled)
                {
                    HttpServerClient.UpdateTask(taskModel.TaskID, "Completed", "Script Completed Successfully");
                }

                if (string.IsNullOrEmpty(resultValue))
                {
                    TasktResult = "Successfully Completed Script";
                }
                else
                {
                    TasktResult = resultValue;
                }
            }

            else
            {
                engineLogger.Information("Error: " + error);

                if (taskModel != null)
                {
                    HttpServerClient.UpdateTask(taskModel.TaskID, "Error", error);
                }

                TasktResult = error;
            }

            engineLogger.Dispose();


            CurrentStatus = EngineStatus.Finished;
            ScriptFinishedEventArgs args = new ScriptFinishedEventArgs();

            args.LoggedOn      = DateTime.Now;
            args.Result        = result;
            args.Error         = error;
            args.ExecutionTime = sw.Elapsed;
            args.FileName      = FileName;

            Core.Server.SocketClient.SendExecutionLog("Result Code: " + result.ToString());
            Core.Server.SocketClient.SendExecutionLog("Total Execution Time: " + sw.Elapsed);


            //convert to json
            var serializedArguments = Newtonsoft.Json.JsonConvert.SerializeObject(args);

            //write execution metrics
            if ((engineSettings.TrackExecutionMetrics) && (FileName != null))
            {
                var summaryLogger = new Logging().CreateJsonLogger("Execution Summary", Serilog.RollingInterval.Infinite);
                summaryLogger.Information(serializedArguments);
                summaryLogger.Dispose();
            }


            Core.Client.EngineBusy = false;


            if (serverSettings.ServerConnectionEnabled)
            {
                HttpServerClient.CheckIn();
            }


            ScriptFinishedEvent?.Invoke(this, args);
        }
        public void ExecuteScript(string data, bool dataIsFile)
        {
            Core.Client.EngineBusy = true;


            try
            {
                CurrentStatus = EngineStatus.Running;

                //create stopwatch for metrics tracking
                sw = new System.Diagnostics.Stopwatch();
                sw.Start();

                //log starting
                ReportProgress("Bot Engine Started: " + DateTime.Now.ToString());

                //get automation script
                Core.Script.Script automationScript;
                if (dataIsFile)
                {
                    ReportProgress("Deserializing File");
                    engineLogger.Information("Script Path: " + data);
                    FileName         = data;
                    automationScript = Core.Script.Script.DeserializeFile(data);
                }
                else
                {
                    ReportProgress("Deserializing XML");
                    automationScript = Core.Script.Script.DeserializeXML(data);
                }

                if (serverSettings.ServerConnectionEnabled && taskModel == null)
                {
                    taskModel = HttpServerClient.AddTask(data);
                }
                else if (serverSettings.ServerConnectionEnabled && taskModel != null)
                {
                    taskModel = HttpServerClient.UpdateTask(taskModel.TaskID, "Running", "Running Server Assignment");
                }

                //track variables and app instances
                ReportProgress("Creating Variable List");


                //set variables if they were passed in
                if (VariableList != null)
                {
                    foreach (var var in VariableList)
                    {
                        var variableFound = automationScript.Variables.Where(f => f.VariableName == var.VariableName).FirstOrDefault();

                        if (variableFound != null)
                        {
                            variableFound.VariableValue = var.VariableValue;
                        }
                    }
                }


                VariableList = automationScript.Variables;


                ReportProgress("Creating App Instance Tracking List");
                //create app instances and merge in global instances
                this.AppInstances = new Dictionary <string, object>();
                var GlobalInstances = GlobalAppInstances.GetInstances();
                foreach (var instance in GlobalInstances)
                {
                    this.AppInstances.Add(instance.Key, instance.Value);
                }


                //execute commands
                foreach (var executionCommand in automationScript.Commands)
                {
                    if (IsCancellationPending)
                    {
                        ReportProgress("Cancelling Script");
                        ScriptFinished(ScriptFinishedEventArgs.ScriptFinishedResult.Cancelled);
                        return;
                    }

                    ExecuteCommand(executionCommand);
                }

                if (IsCancellationPending)
                {
                    //mark cancelled - handles when cancelling and user defines 1 parent command or else it will show successful
                    ScriptFinished(ScriptFinishedEventArgs.ScriptFinishedResult.Cancelled);
                }
                else
                {
                    //mark finished
                    ScriptFinished(ScriptFinishedEventArgs.ScriptFinishedResult.Successful);
                }
            }
            catch (Exception ex)
            {
                ScriptFinished(ScriptFinishedEventArgs.ScriptFinishedResult.Error, ex.ToString());
            }
        }
        public virtual void ScriptFinished(ScriptFinishedResult result, string error = null)
        {
            if (ChildScriptFailed && !ChildScriptErrorCaught)
            {
                error  = "Terminate with failure";
                result = ScriptFinishedResult.Error;
                EngineLogger.Fatal("Result Code: " + result.ToString());
            }
            else
            {
                EngineLogger.Information("Result Code: " + result.ToString());
            }

            //add result variable if missing
            var resultVar = VariableList.Where(f => f.VariableName == "taskt.Result").FirstOrDefault();

            //handle if variable is missing
            if (resultVar == null)
            {
                resultVar = new ScriptVariable()
                {
                    VariableName = "taskt.Result", VariableValue = ""
                };
            }

            //check value
            var resultValue = resultVar.VariableValue.ToString();

            if (error == null)
            {
                EngineLogger.Information("Error: None");

                if (TaskModel != null && _serverSettings.ServerConnectionEnabled)
                {
                    HttpServerClient.UpdateTask(TaskModel.TaskID, "Completed", "Script Completed Successfully");
                }

                if (string.IsNullOrEmpty(resultValue))
                {
                    TasktResult = "Successfully Completed Script";
                }
                else
                {
                    TasktResult = resultValue;
                }
            }

            else
            {
                error = ErrorsOccured.OrderByDescending(x => x.LineNumber).FirstOrDefault().StackTrace;
                EngineLogger.Error("Error: " + error);

                if (TaskModel != null)
                {
                    HttpServerClient.UpdateTask(TaskModel.TaskID, "Error", error);
                }

                TasktResult = error;
            }

            if (!TasktEngineUI.IsChildEngine)
            {
                EngineLogger.Dispose();
            }

            _currentStatus = EngineStatus.Finished;
            ScriptFinishedEventArgs args = new ScriptFinishedEventArgs();

            args.LoggedOn      = DateTime.Now;
            args.Result        = result;
            args.Error         = error;
            args.ExecutionTime = _stopWatch.Elapsed;
            args.FileName      = FileName;

            SocketClient.SendExecutionLog("Result Code: " + result.ToString());
            SocketClient.SendExecutionLog("Total Execution Time: " + _stopWatch.Elapsed);

            //convert to json
            var serializedArguments = JsonConvert.SerializeObject(args);

            //write execution metrics
            if (EngineSettings.TrackExecutionMetrics && (FileName != null))
            {
                string summaryLoggerFilePath = Path.Combine(Folders.GetFolder(FolderType.LogFolder), "taskt Execution Summary Logs.txt");
                Logger summaryLogger         = new Logging().CreateJsonFileLogger(summaryLoggerFilePath, Serilog.RollingInterval.Infinite);
                summaryLogger.Information(serializedArguments);
                if (!TasktEngineUI.IsChildEngine)
                {
                    summaryLogger.Dispose();
                }
            }

            Client.EngineBusy = false;

            if (_serverSettings.ServerConnectionEnabled)
            {
                HttpServerClient.CheckIn();
            }

            ScriptFinishedEvent?.Invoke(this, args);
        }
        private void frmScriptBuilder_Load(object sender, EventArgs e)
        {
            //load all commands
            _automationCommands = CommandControls.GenerateCommandsandControls();

            //set controls double buffered
            foreach (Control control in Controls)
            {
                typeof(Control).InvokeMember("DoubleBuffered",
                                             BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                             null, control, new object[] { true });
            }

            //get app settings
            _appSettings = new ApplicationSettings();
            _appSettings = _appSettings.GetOrCreateApplicationSettings();

            if (_appSettings.ServerSettings.ServerConnectionEnabled && _appSettings.ServerSettings.HTTPGuid == Guid.Empty)
            {
                HttpServerClient.GetGuid();
            }
            else if (_appSettings.ServerSettings.ServerConnectionEnabled && _appSettings.ServerSettings.HTTPGuid != Guid.Empty)
            {
                HttpServerClient.InitializeScriptEngine(new frmScriptEngine());
                HttpServerClient.CheckIn();
            }

            HttpServerClient.InitializeScriptEngine(new frmScriptEngine());
            HttpServerClient.AssociatedBuilder = this;

            string clientLoggerFilePath   = Path.Combine(Folders.GetFolder(FolderType.LogFolder), "taskt Automation Client Logs.txt");
            Logger automationClientLogger = new Logging().CreateFileLogger(clientLoggerFilePath, Serilog.RollingInterval.Day);

            LocalTCPClient.InitializeAutomationEngine(new AutomationEngineInstance(automationClientLogger));
            LocalTCPClient.Initialize(this, new AutomationEngineInstance(automationClientLogger));
            //Core.Sockets.SocketClient.Initialize();
            //Core.Sockets.SocketClient.associatedBuilder = this;

            //handle action bar preference
            //hide action panel

            if (_editMode)
            {
                tlpControls.RowStyles[1].SizeType = SizeType.Absolute;
                tlpControls.RowStyles[1].Height   = 0;

                tlpControls.RowStyles[2].SizeType = SizeType.Absolute;
                tlpControls.RowStyles[2].Height   = 81;
            }
            else if (_appSettings.ClientSettings.UseSlimActionBar)
            {
                tlpControls.RowStyles[2].SizeType = SizeType.Absolute;
                tlpControls.RowStyles[2].Height   = 0;
            }
            else
            {
                tlpControls.RowStyles[1].SizeType = SizeType.Absolute;
                tlpControls.RowStyles[1].Height   = 0;
            }

            //get scripts folder
            var rpaScriptsFolder = Folders.GetFolder(FolderType.ScriptsFolder);

            if (!Directory.Exists(rpaScriptsFolder))
            {
                frmDialog userDialog = new frmDialog("Would you like to create a folder to save your scripts in now? " +
                                                     "A script folder is required to save scripts generated with this application. " +
                                                     "The new script folder path would be '" + rpaScriptsFolder + "'.", "Unable to locate Script Folder!",
                                                     DialogType.YesNo, 0);

                if (userDialog.ShowDialog() == DialogResult.OK)
                {
                    Directory.CreateDirectory(rpaScriptsFolder);
                }
            }

            //get latest files for recent files list on load
            GenerateRecentFiles();

            //no height for status bar
            HideNotificationRow();

            //instantiate for script variables
            if (!_editMode)
            {
                _scriptVariables = new List <ScriptVariable>();
                _scriptElements  = new List <ScriptElement>();
            }
            //pnlHeader.BackColor = Color.FromArgb(255, 214, 88);

            //instantiate and populate display icons for commands
            _uiImages = UIImage.UIImageList();

            //set image list
            _selectedTabScriptActions.SmallImageList = _uiImages;

            //set listview column size
            frmScriptBuilder_SizeChanged(null, null);

            var groupedCommands = _automationCommands.GroupBy(f => f.DisplayGroup);

            foreach (var cmd in groupedCommands)
            {
                TreeNode newGroup = new TreeNode(cmd.Key);

                foreach (var subcmd in cmd)
                {
                    TreeNode subNode = new TreeNode(subcmd.ShortName);

                    if (!subcmd.Command.CustomRendering)
                    {
                        subNode.ForeColor = Color.Red;
                    }
                    newGroup.Nodes.Add(subNode);
                }

                tvCommands.Nodes.Add(newGroup);
            }

            tvCommands.Sort();
            //tvCommands.ImageList = uiImages;

            _tvCommandsCopy = new TreeView();
            CopyTreeView(tvCommands, _tvCommandsCopy);
            txtCommandSearch.Text = _txtCommandWatermark;

            //start attended mode if selected
            if (_appSettings.ClientSettings.StartupMode == "Attended Task Mode")
            {
                WindowState = FormWindowState.Minimized;
                var frmAttended = new frmAttendedMode();
                frmAttended.Show();
            }
        }
Beispiel #10
0
        public virtual void ScriptFinished(ScriptFinishedEventArgs.ScriptFinishedResult result, string error = null)
        {
            engineLogger.Information("Result Code: " + result.ToString());



            if (error == null)
            {
                engineLogger.Information("Error: None");

                if (taskModel != null && serverSettings.ServerConnectionEnabled)
                {
                    HttpServerClient.UpdateTask(taskModel.TaskID, "Completed", "Script Completed Successfully");
                }
            }

            else
            {
                engineLogger.Information("Error: " + error);

                if (taskModel != null)
                {
                    HttpServerClient.UpdateTask(taskModel.TaskID, "Error", error);
                }
            }

            engineLogger.Dispose();


            CurrentStatus = EngineStatus.Finished;
            ScriptFinishedEventArgs args = new ScriptFinishedEventArgs();

            args.LoggedOn      = DateTime.Now;
            args.Result        = result;
            args.Error         = error;
            args.ExecutionTime = sw.Elapsed;
            args.FileName      = FileName;

            Core.Server.SocketClient.SendExecutionLog("Result Code: " + result.ToString());
            Core.Server.SocketClient.SendExecutionLog("Total Execution Time: " + sw.Elapsed);


            //convert to json
            var serializedArguments = Newtonsoft.Json.JsonConvert.SerializeObject(args);

            //write execution metrics
            if ((engineSettings.TrackExecutionMetrics) && (FileName != null))
            {
                var summaryLogger = new Logging().CreateJsonLogger("Execution Summary", Serilog.RollingInterval.Infinite);
                summaryLogger.Information(serializedArguments);
                summaryLogger.Dispose();
            }


            Core.Client.EngineBusy = false;


            if (serverSettings.ServerConnectionEnabled)
            {
                HttpServerClient.CheckIn();
            }


            ScriptFinishedEvent?.Invoke(this, args);
        }
 private void btnGetBotGUID_Click(object sender, EventArgs e)
 {
     var newGUID = HttpServerClient.GetGuid();
 }