Beispiel #1
0
        private void uiBtnRunScript_Click(object sender, EventArgs e)
        {
            if (lstScriptActions.Items.Count == 0)
            {
                // MessageBox.Show("You must first build the script by adding commands!", "Please Build Script");
                Notify("You must first build the script by adding commands!");
                return;
            }


            if (ScriptFilePath == null)
            {
                //MessageBox.Show("You must first save your script before you can run it!", "Please Save Script");
                Notify("You must first save your script before you can run it!");
                return;
            }

            Notify("Running Script..");


            UI.Forms.frmScriptEngine newEngine = new UI.Forms.frmScriptEngine(ScriptFilePath, this);

            //this.executionManager = new ScriptExectionManager();
            //executionManager.CurrentlyExecuting = true;
            //executionManager.ScriptName = new System.IO.FileInfo(ScriptFilePath).Name;

            newEngine.callBackForm = this;
            newEngine.Show();
        }
Beispiel #2
0
        public override void RunCommand(object sender)
        {
            var startFile = v_taskPath.ConvertToUserVariable(sender);

            //create variable list
            var variableList = new List <Script.ScriptVariable>();

            foreach (DataRow rw in v_VariableAssignments.Rows)
            {
                var variableName  = (string)rw.ItemArray[0];
                var variableValue = ((string)rw.ItemArray[1]).ConvertToUserVariable(sender);
                variableList.Add(new Script.ScriptVariable
                {
                    VariableName  = variableName,
                    VariableValue = variableValue
                });
            }

            UI.Forms.frmScriptEngine newEngine = new UI.Forms.frmScriptEngine(startFile, null, variableList, true);
            Core.Automation.Engine.AutomationEngineInstance currentScriptEngine = (Core.Automation.Engine.AutomationEngineInstance)sender;
            currentScriptEngine.tasktEngineUI.Invoke((Action) delegate() { currentScriptEngine.tasktEngineUI.TopMost = false; });
            Application.Run(newEngine);
            //currentScriptEngine.tasktEngineUI.TopMost = false;
            currentScriptEngine.tasktEngineUI.Invoke((Action) delegate() { currentScriptEngine.tasktEngineUI.TopMost = true; });
        }
Beispiel #3
0
        /// <summary>
        /// Checks in the client with the server
        /// </summary>
        /// <returns>Whether or not the call was successful</returns>
        public static bool CheckIn()
        {
            try
            {
                if (!(appSettings.ServerSettings.ServerConnectionEnabled) || associatedBuilder == null)
                {
                    return(false);
                }

                httpLogger.Information("Client is attempting to check in with the server");


                var workerID = appSettings.ServerSettings.HTTPGuid;

                if (workerID != Guid.Empty)
                {
                    httpLogger.Information("Requesting to check in with the server");
                    var client  = new WebClient();
                    var content = client.DownloadString("https://localhost:44377/api/Workers/CheckIn?workerID=" + workerID + "&engineBusy=" + Core.Client.EngineBusy);
                    httpLogger.Information("Received /api/Workers/CheckIn response: " + content);
                    var deserialized = Newtonsoft.Json.JsonConvert.DeserializeObject <CheckInResponse>(content);

                    if (deserialized.ScheduledTask != null)
                    {
                        associatedBuilder.Invoke(new MethodInvoker(delegate()
                        {
                            if (deserialized.ScheduledTask.ExecutionType == "Local")
                            {
                                UI.Forms.frmScriptEngine newEngine = new UI.Forms.frmScriptEngine(deserialized.PublishedScript.ScriptData, null);
                                newEngine.remoteTask      = deserialized.ScheduledTask;
                                newEngine.serverExecution = true;
                                newEngine.Show();
                            }
                            else
                            {
                                UI.Forms.frmScriptEngine newEngine = new UI.Forms.frmScriptEngine();
                                newEngine.xmlData         = deserialized.PublishedScript.ScriptData;
                                newEngine.remoteTask      = deserialized.ScheduledTask;
                                newEngine.serverExecution = true;
                                newEngine.Show();
                            }
                        }));
                    }


                    return(true);
                }
                else
                {
                    httpLogger.Information("Client unable to check in because the client does not have a GUID");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                httpLogger.Information("Error Checking In: " + ex.ToString());
                return(false);
            }
        }
Beispiel #4
0
        private void uiBtnRun_Click(object sender, EventArgs e)
        {
            //build script path and execute
            var scriptFilePath = System.IO.Path.Combine(appSettings.ClientSettings.AttendedTasksFolder, cboSelectedScript.Text);

            UI.Forms.frmScriptEngine newEngine = new UI.Forms.frmScriptEngine(scriptFilePath, null);
            newEngine.Show();
        }
 private static void RunXMLScript(string scriptData)
 {
     associatedBuilder.Invoke(new MethodInvoker(delegate()
     {
         UI.Forms.frmScriptEngine newEngine = new UI.Forms.frmScriptEngine();
         newEngine.xmlData      = scriptData;
         newEngine.callBackForm = null;
         newEngine.Show();
     }));
 }
        public void ExecuteScriptAsync(UI.Forms.frmScriptEngine scriptEngine, string filePath)
        {
            engineLogger.Information("Client requesting to execute script using frmEngine");

            tasktEngineUI = scriptEngine;
            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                ExecuteScript(filePath, true);
            }).Start();
        }
        private void uiBtnRunScript_Click(object sender, EventArgs e)
        {
            if (ScriptFilePath == null)
            {
                return;
            }

            Notify("Running Script..");
            UI.Forms.frmScriptEngine newEngine = new UI.Forms.frmScriptEngine(ScriptFilePath, this);
            newEngine.callBackForm = this;
            newEngine.Show();
        }
Beispiel #8
0
        private void uiBtnRunScript_Click(object sender, EventArgs e)
        {
            if (ScriptFilePath == null)
            {
                MessageBox.Show("You must first save your script before you can run it!", "Please Save Script");
                return;
            }

            Notify("Running Script..");
            UI.Forms.frmScriptEngine newEngine = new UI.Forms.frmScriptEngine(ScriptFilePath, this);
            newEngine.callBackForm = this;
            newEngine.Show();
        }
Beispiel #9
0
 private void RunXMLScript()
 {
     if (InvokeRequired)
     {
         Invoke(new MethodInvoker(RunXMLScript));
     }
     else
     {
         frmScriptEngine newEngine = new UI.Forms.frmScriptEngine("", this);
         newEngine.xmlInfo      = streamedXMLData;
         newEngine.callBackForm = this;
         newEngine.Show();
     }
 }
        public void ExecuteScriptAsync(UI.Forms.frmScriptEngine scriptEngine, string filePath, List <Core.Script.ScriptVariable> variables = null)
        {
            engineLogger.Information("Client requesting to execute script using frmEngine");

            tasktEngineUI = scriptEngine;

            if (variables != null)
            {
                VariableList = variables;
            }

            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                ExecuteScript(filePath, true);
            }).Start();
        }
Beispiel #11
0
        public override void RunCommand(object sender)
        {
            Core.Automation.Engine.AutomationEngineInstance currentScriptEngine = (Core.Automation.Engine.AutomationEngineInstance)sender;
            var startFile = v_taskPath.ConvertToUserVariable(sender);

            //create variable list
            var variableList       = new List <Script.ScriptVariable>();
            var variableReturnList = new List <Script.ScriptVariable>();

            foreach (DataRow rw in v_VariableAssignments.Rows)
            {
                var    variableName = (string)rw.ItemArray[0];
                object variableValue;
                try
                {
                    variableValue = LookupVariable(currentScriptEngine, (string)rw.ItemArray[1]).VariableValue;
                }
                catch (Exception ex)
                {
                    variableValue = ((string)rw.ItemArray[1]).ConvertToUserVariable(sender);
                }
                var variableReturn = (string)rw.ItemArray[2];
                variableList.Add(new Script.ScriptVariable
                {
                    VariableName  = variableName,
                    VariableValue = variableValue
                });
                if (variableReturn == "Yes")
                {
                    variableReturnList.Add(new Script.ScriptVariable
                    {
                        VariableName  = variableName,
                        VariableValue = variableValue
                    });
                }
            }

            UI.Forms.frmScriptEngine newEngine = new UI.Forms.frmScriptEngine(startFile, null, variableList, true);

            //Core.Automation.Engine.AutomationEngineInstance currentScriptEngine = (Core.Automation.Engine.AutomationEngineInstance) sender;
            currentScriptEngine.tasktEngineUI.Invoke((Action) delegate() { currentScriptEngine.tasktEngineUI.TopMost = false; });
            Application.Run(newEngine);

            //get new variable list from the new task engine after it finishes running
            var newVariableList = newEngine.engineInstance.VariableList;

            foreach (var variable in variableReturnList)
            {
                //check if the variables we wish to return are in the new variable list
                if (newVariableList.Exists(x => x.VariableName == variable.VariableName))
                {
                    //if yes, get that variable from the new list
                    Script.ScriptVariable newTemp = newVariableList.Where(x => x.VariableName == variable.VariableName).FirstOrDefault();
                    //check if that variable previously existed in the current engine
                    if (currentScriptEngine.VariableList.Exists(x => x.VariableName == newTemp.VariableName))
                    {
                        //if yes, overwrite it
                        Script.ScriptVariable currentTemp = currentScriptEngine.VariableList.Where(x => x.VariableName == newTemp.VariableName).FirstOrDefault();
                        currentScriptEngine.VariableList.Remove(currentTemp);
                    }
                    //Add to current engine variable list
                    currentScriptEngine.VariableList.Add(newTemp);
                }
            }

            //currentScriptEngine.tasktEngineUI.TopMost = false;
            currentScriptEngine.tasktEngineUI.Invoke((Action) delegate() { currentScriptEngine.tasktEngineUI.TopMost = true; });
        }
Beispiel #12
0
        private static void ProcessRequest(string data, string[] messageContent, NetworkStream stream)
        {
            if ((data.StartsWith("POST /ExecuteScript")) || (data.StartsWith("POST /AwaitScript")))
            {
                automationLogger.Information($"Client Requests Script Execution");

                //locate the body content
                string dataParameter  = "";
                bool   isFileLocation = false;

                //find the script parameter
                foreach (var item in messageContent)
                {
                    if (item.StartsWith("ScriptData: "))
                    {
                        dataParameter  = item.Replace("ScriptData: ", "");
                        isFileLocation = false;

                        break;
                    }

                    else if (item.StartsWith("ScriptLocation: "))
                    {
                        dataParameter  = item.Replace("ScriptLocation: ", "");
                        isFileLocation = true;
                        break;
                    }
                }

                //check to see if nothing was provided
                if (string.IsNullOrEmpty(dataParameter))
                {
                    automationLogger.Information($"Client Script Data Not Found");
                    return;
                }


                if (dataParameter.TryParseBase64(out var base64SourceString))
                {
                    automationLogger.Information($"Client Passed Base64 String: {base64SourceString}");
                    dataParameter = base64SourceString;
                }
                else
                {
                    automationLogger.Information($"Client Did Not Pass Base64 String");
                }


                //check if data parameter references file location
                if (isFileLocation)
                {
                    if (File.Exists(dataParameter))
                    {
                        //file was found at path provided
                        dataParameter = File.ReadAllText(dataParameter);
                    }
                    else if (File.Exists(Path.Combine(IO.Folders.GetFolder(IO.Folders.FolderType.ScriptsFolder), dataParameter)))
                    {
                        //file was found at fallback to scripts folder
                        dataParameter = Path.Combine(IO.Folders.GetFolder(IO.Folders.FolderType.ScriptsFolder), dataParameter);
                        dataParameter = File.ReadAllText(dataParameter);
                    }
                    else
                    {
                        //file not found
                        automationLogger.Information($"Client Script Location Not Found: {dataParameter}");
                        SendResponse(ResponseCode.InternalServerError, $"Client Script Location Not Found: {dataParameter}", stream);
                        return;
                    }
                }

                //log execution
                automationLogger.Information($"Executing Script: {dataParameter}");


                //invoke builder and pass it script data to execute
                associatedBuilder.Invoke(new MethodInvoker(delegate()
                {
                    UI.Forms.frmScriptEngine newEngine = new UI.Forms.frmScriptEngine();
                    newEngine.xmlData      = dataParameter;
                    newEngine.callBackForm = null;
                    //instance = newEngine.engineInstance;
                    newEngine.Show();
                }));


                if (data.StartsWith("POST /AwaitScript"))
                {
                    //reset result value
                    TasktResult = "";

                    //add reference to script finished event
                    automationInstance.ScriptFinishedEvent += AutomationInstance_ScriptFinishedEvent;

                    //wait for script to finish before returning
                    do
                    {
                        Thread.Sleep(1000);
                    } while (TasktResult == string.Empty);

                    //send response back to client
                    SendResponse(ResponseCode.OK, automationInstance.TasktResult, stream);
                }
                else
                {
                    //return success immediately
                    SendResponse(ResponseCode.OK, "Script Launched Successfully", stream);
                }
            }
            else if (data.StartsWith("POST /ExecuteCommand"))
            {
                automationLogger.Information($"Client Requests Command Execution");

                //locate the body content
                string dataParameter = "";

                //find the script parameter
                foreach (var item in messageContent)
                {
                    if (item.StartsWith("CommandData: "))
                    {
                        dataParameter = item.Replace("CommandData: ", "");
                        break;
                    }
                }

                //check to see if nothing was provided
                if (string.IsNullOrEmpty(dataParameter))
                {
                    automationLogger.Information($"Client Command Data Not Found");
                    return;
                }


                if (dataParameter.TryParseBase64(out var base64SourceString))
                {
                    automationLogger.Information($"Client Passed Base64 String: {base64SourceString}");
                    dataParameter = base64SourceString;
                }
                else
                {
                    automationLogger.Information($"Client Did Not Pass Base64 String");
                }

                try
                {
                    //deserialize command
                    var command = Newtonsoft.Json.JsonConvert.DeserializeObject(dataParameter, new Newtonsoft.Json.JsonSerializerSettings()
                    {
                        TypeNameHandling = Newtonsoft.Json.TypeNameHandling.All
                    });

                    //log execution
                    automationLogger.Information($"Executing Command: {dataParameter}");

                    //define script action
                    var scriptAction = new Script.ScriptAction()
                    {
                        ScriptCommand = (Core.Automation.Commands.ScriptCommand)command
                    };

                    //execute command
                    ExecuteCommandEngine.ExecuteCommand(scriptAction);

                    //send back response
                    SendResponse(ResponseCode.OK, "Command Executed Successfully", stream);
                }
                catch (Exception ex)
                {
                    SendResponse(ResponseCode.InternalServerError, $"An error occured: {ex.ToString()}", stream);
                }
            }

            else if (data.StartsWith("POST /EngineStatus"))
            {
                automationLogger.Information($"Returning Engine Status: {Client.ClientStatus}");
                SendResponse(ResponseCode.OK, Core.Client.ClientStatus, stream);
            }
            else if (data.StartsWith("POST /RestartTaskt"))
            {
                automationLogger.Information($"Restarting taskt");
                SendResponse(ResponseCode.OK, "taskt is being Restarted", stream);
                Application.Restart();
            }
            else
            {
                automationLogger.Information($"Invalid Client Request");
                SendResponse(ResponseCode.InternalServerError, "Invalid Client Request", stream);
            }
        }