Example #1
0
        private static void ExecuteShellCommand(YabeAction action)
        {
            Console.WriteLine("----------");
            Console.WriteLine(DateTime.Now.ToString() + " Executing: " + action.shellcommand);

            ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd.exe", "/c " + action.shellcommand);
            procStartInfo.RedirectStandardOutput = true;
            procStartInfo.UseShellExecute = false;
            procStartInfo.CreateNoWindow = true;

            Process proc = new Process();
            proc.StartInfo = procStartInfo;
            proc.Start();
            string result = proc.StandardOutput.ReadToEnd();
            string exitCode = proc.ExitCode.ToString();

            Console.WriteLine("Result = " + result);
            Console.WriteLine("Exit Code = " + exitCode);

            if (!action.successExitCodes.Contains(exitCode))
            {
                ActionFailedException ex = new ActionFailedException();
                ex.errorMessage = "Action " + action.id + " failed during execution.";
                ex.actionId = action.id;
                throw ex;
            }
        }
Example #2
0
        private static void SetupActions(XmlReader reader)
        {
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element && reader.Name == "action")
                {
                    YabeAction action = new YabeAction();
                    action.successExitCodes = new List<string>();
                    action.successRegexPatterns = new List<string>();

                    int actionId = Convert.ToInt32(reader.GetAttribute("id"));

                    YabeActionType actionType = YabeActionType.ShellCommand;
                    switch (reader.GetAttribute("type"))
                    {
                        case "shellcommand": actionType = YabeActionType.ShellCommand; break;
                    }

                    action.id = actionId;
                    action.type = actionType;

                    // Extract Shellcommand data
                    if (actionType == YabeActionType.ShellCommand)
                    {
                        XmlReader reader2 = reader.ReadSubtree();
                        while (reader2.Read())
                        {
                            if (reader2.NodeType == XmlNodeType.Element && reader2.Name == "shellcommand")
                            {
                                action.shellcommand = reader2.ReadElementContentAsString();
                            }
                            if (reader2.NodeType == XmlNodeType.Element && reader2.Name == "exitcodesuccess")
                            {
                                action.successExitCodes.Add(reader2.ReadElementContentAsString());
                            }
                            if (reader2.NodeType == XmlNodeType.Element && reader2.Name == "regexsuccess")
                            {
                                action.successRegexPatterns.Add(reader2.ReadElementContentAsString());
                            }
                        }

                        // Add ShellCommand action to action list
                        yabeConfig.actions.Add(action);
                    }
                }
            }
        }