Пример #1
0
        /// <summary>
        /// Handles Script Finished Event raised by Automation Engine
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Engine_ScriptFinishedEvent(object sender, ScriptFinishedEventArgs e)
        {
            switch (e.Result)
            {
            case ScriptFinishedEventArgs.ScriptFinishedResult.Successful:
                AddStatus("Script Completed Successfully");
                UpdateUI("debug info (success)");

                break;

            case ScriptFinishedEventArgs.ScriptFinishedResult.Error:
                AddStatus("Error: " + e.Error);
                AddStatus("Script Completed With Errors!");
                UpdateUI("debug info (error)");

                if (!advancedDebug)
                {
                    pbBotIcon.Image = Properties.Resources.robot_error;
                }

                break;

            case ScriptFinishedEventArgs.ScriptFinishedResult.Cancelled:
                AddStatus("Script Cancelled By User");
                UpdateUI("debug info (cancelled)");
                break;

            default:
                break;
            }



            AddStatus("Total Execution Time: " + e.ExecutionTime.ToString());
        }
Пример #2
0
        /// <summary>
        /// Handles Script Finished Event raised by Automation Engine
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Engine_ScriptFinishedEvent(object sender, ScriptFinishedEventArgs e)
        {
            switch (e.Result)
            {
            case ScriptFinishedEventArgs.ScriptFinishedResult.Successful:
                AddStatus("Script Completed Successfully");
                UpdateUI("debug info (success)");
                break;

            case ScriptFinishedEventArgs.ScriptFinishedResult.Error:
                AddStatus("Error: " + e.Error);
                AddStatus("Script Completed With Errors!");
                UpdateUI("debug info (error)");
                break;

            case ScriptFinishedEventArgs.ScriptFinishedResult.Cancelled:
                AddStatus("Script Cancelled By User");
                UpdateUI("debug info (cancelled)");
                break;

            default:
                break;
            }


            Result = engineInstance.TasktResult;


            AddStatus("Total Execution Time: " + e.ExecutionTime.ToString());

            if (CloseWhenDone)
            {
                engineInstance.tasktEngineUI.Invoke((Action) delegate() { this.Close(); });
            }
        }
Пример #3
0
        /// <summary>
        /// Handles Script Finished Event raised by Automation Engine
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Engine_ScriptFinishedEvent(object sender, ScriptFinishedEventArgs e)
        {
            if (EngineContext.IsChildEngine)
            {
                CloseWhenDone = true;
            }

            switch (e.Result)
            {
            case ScriptFinishedResult.Successful:
                AddStatus("Script Completed Successfully");
                UpdateUI("debug info (success)");
                break;

            case ScriptFinishedResult.Error:
                AddStatus($"Error: {e.Error}", Color.Red);
                AddStatus("Script Completed With Errors!");
                UpdateUI("debug info (error)");

                if (_isParentScheduledTask)
                {
                    CloseWhenDone = false;
                }
                break;

            case ScriptFinishedResult.Cancelled:
                AddStatus("Script Cancelled By User");
                UpdateUI("debug info (cancelled)");

                if (_isParentScheduledTask)
                {
                    CloseWhenDone = false;
                }
                break;

            default:
                break;
            }

            AddStatus("Total Execution Time: " + e.ExecutionTime.ToString());

            try
            {
                UpdateLineNumber(0);
            }
            catch (Exception)
            {
                /*Attemting to reset the debug line to 0 will occasionally produce an exception
                 * if the engine is improperly closed or interrupted during execution.*/
            }

            if (CloseWhenDone)
            {
                ((frmScriptEngine)EngineInstance.EngineContext.ScriptEngine).Invoke((Action) delegate() { Close(); });
            }
        }
Пример #4
0
 private static void AutomationInstance_ScriptFinishedEvent(object sender, ScriptFinishedEventArgs e)
 {
     //set result once script completes
     TasktResult = AutomationInstance.TaskResult;
 }
        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);
        }
Пример #6
0
        public virtual void ScriptFinished(ScriptFinishedResult result, string error = null)
        {
            if (ChildScriptFailed && !ChildScriptErrorCaught)
            {
                error  = "Terminate with failure";
                result = ScriptFinishedResult.Error;
                Log.Fatal("Result Code: " + result.ToString());
            }
            else
            {
                Log.Information("Result Code: " + result.ToString());
            }

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

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

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

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

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

            else
            {
                if (ErrorsOccured.Count > 0)
                {
                    error = ErrorsOccured.OrderByDescending(x => x.LineNumber).FirstOrDefault().StackTrace;
                }

                Log.Error("Error: " + error);
                EngineContext.TaskResult = error;
            }

            if ((EngineContext.ScriptEngine != null && !EngineContext.IsChildEngine) ||
                (EngineContext.IsServerExecution && !EngineContext.IsServerChildExecution))
            {
                Log.CloseAndFlush();
            }

            EngineContext.CurrentEngineStatus = EngineStatus.Finished;
            ScriptFinishedEventArgs args = new ScriptFinishedEventArgs
            {
                LoggedOn      = DateTime.Now,
                Result        = result,
                Error         = error,
                ExecutionTime = _stopWatch.Elapsed,
                FileName      = EngineContext.FilePath
            };

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

            //write execution metrics
            if (EngineContext.EngineSettings.TrackExecutionMetrics && (EngineContext.FilePath != null))
            {
                string summaryLoggerFilePath = Path.Combine(Folders.GetFolder(FolderType.LogFolder), "OpenBots Execution Summary Logs.txt");
                Logger summaryLogger         = new LoggingMethods().CreateJsonFileLogger(summaryLoggerFilePath, RollingInterval.Infinite);
                summaryLogger.Information(serializedArguments);

                if (!EngineContext.IsChildEngine)
                {
                    summaryLogger.Dispose();
                }
            }

            ScriptFinishedEvent?.Invoke(this, args);
        }