public void launchAccount(int account)
        {
            int ExitCode;
            ProcessStartInfo ProcessInfo;
            Process          Process;

            String baseDir = AppDomain.CurrentDomain.BaseDirectory;
            //string path = baseDir + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar + ".." + "Scripts" + Path.DirectorySeparatorChar + "runDeineMudda.bat"

            String path = baseDir + "run_account.bat account" + account;

            ProcessInfo = new ProcessStartInfo("cmd.exe", path);
            ProcessInfo.CreateNoWindow  = false;
            ProcessInfo.UseShellExecute = false;
            // *** Redirect the output ***
            ProcessInfo.RedirectStandardError  = true;
            ProcessInfo.RedirectStandardOutput = true;

            Process = Process.Start(ProcessInfo);
            Process.WaitForExit();

            ExitCode = Process.ExitCode;
            Process.Close();

            MessageBox.Show("ExitCode: " + ExitCode.ToString(), "ExecuteCommand");
        }
Beispiel #2
0
    public void ExecuteCommand(string command, bool thread = false, bool resetRunningCheckpointThreadOnEnd = false)
    {
        if (thread)
        {
            new ThreadedJobCheckpoint(command, resetRunningCheckpointThreadOnEnd).Start();
        }
        else
        {
            int ExitCode;
            ProcessStartInfo ProcessInfo;
            Process          Process;

            ProcessInfo = new ProcessStartInfo("cmd.exe", "/c " + command);

            ProcessInfo.CreateNoWindow = false;//Change that

            ProcessInfo.UseShellExecute = false;

            Process = Process.Start(ProcessInfo);

            Process.WaitForExit();

            ExitCode = Process.ExitCode;
            Process.Close();

            UnityEngine.Debug.Log("ExitCode: " + ExitCode.ToString());

            if (resetRunningCheckpointThreadOnEnd)
            {
                NotifyCheckpointModelCreated();
            }
        }
    }
Beispiel #3
0
        /// <summary>
        /// Prints usage instructions to the Console, and returns the int value for the ExitCode passed in
        /// </summary>
        private static int PrintUsage(ExitCode exitCode)
        {
            ConsoleColor originalColor = Console.ForegroundColor;

            Console.WriteLine("");
            Console.WriteLine("  WTV (When The Version) Automatic date-based version numbering for .Net projects");
            Console.WriteLine("  Andrew Freemantle - www.fatlemon.co.uk/wtv");
            Console.WriteLine("");

            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("    Error: " + exitCode.ToString().Replace("_", " "));

            Console.ForegroundColor = originalColor;
            Console.WriteLine("");
            Console.WriteLine("  Usage: WTV  \"file-in\"  \"file-out\"  [\"path to SubWCrev.exe\"  \"SVN working-copy-path\"]");
            Console.WriteLine("   \"file-in\"  can contain the following placeholders:");
            Console.WriteLine("     {DD}    - Day");
            Console.WriteLine("     {MM}    - Month");
            Console.WriteLine("     {YYYY}  - Year");
            Console.WriteLine("     {SVN}   - SubVersion revision (must specify the path to SubWCrev.exe and working copy path)");
            Console.WriteLine("");
            Console.WriteLine("  Example Pre-Build command: (remove the line breaks)");
            Console.WriteLine("    \"C:\\Path\\To\\WTV.exe\"");
            Console.WriteLine("      \"$(ProjectDir)Properties\\AssemblyInfo.Template.cs\"");
            Console.WriteLine("      \"$(ProjectDir)Properties\\AssemblyInfo.cs\"");
            Console.WriteLine("      \"C:\\Program Files\\TortoiseSVN\\bin\\SubWCRev.exe\"");
            Console.WriteLine("      \"$(SolutionDir).\"");

            return((int)exitCode);
        }
    protected virtual void ThreadFunction()
    {
        int ExitCode;
        ProcessStartInfo ProcessInfo;
        Process          Process;

        ProcessInfo = new ProcessStartInfo("cmd.exe", "/c " + command);

        ProcessInfo.CreateNoWindow = false;//Change that

        ProcessInfo.UseShellExecute = false;

        Process = Process.Start(ProcessInfo);


        Process.WaitForExit();


        ExitCode = Process.ExitCode;
        Process.Close();

        UnityEngine.Debug.Log("ExitCode: " + ExitCode.ToString());

        if (resetRunningCheckpointThreadOnEnd)
        {
            LoadExternal.NotifyCheckpointModelCreated();
        }
    }
Beispiel #5
0
        public virtual string GetDebugInfo(IDictionary <string, string> extraDefs = null)
        {
            var sb = new StringBuilder();

            sb.AppendLine();
            sb.AppendLine("Debugging Information:");
            sb.AppendLine("----------------------");

            var infoFormatter = new DefinitionListFormatter();

            // NOTE: do not log the executed command as it might contain secrets
            //infoFormatter.AddDefinition("Executed command", ExecutedCommand);
            if (HasExited)
            {
                infoFormatter.AddDefinition("Exit code", ExitCode.ToString());
            }
            infoFormatter.AddDefinition("StdOut", StdOut);
            infoFormatter.AddDefinition("StdErr", StdErr);
            infoFormatter.AddDefinition("Exception.Message:", Exception?.Message);
            infoFormatter.AddDefinitions(extraDefs);

            sb.AppendLine(infoFormatter.ToString());

            return(sb.ToString());
        }
        /// <summary>
        /// Runs program and returns output to properties
        /// </summary>
        public async System.Threading.Tasks.Task Run()
        {
            try
            {
                if (_copyfrom != null & _copyto != null)
                {
                    await Copy();
                }

                StartInfo.FileName  = (_path + _filename);
                StartInfo.Arguments = _arguments;
                Log(log.Debug, "Filename:{0}", StartInfo.FileName);
                Log(log.Debug, "Arguments:{0}", StartInfo.Arguments);
                var pProcess = System.Diagnostics.Process.Start(StartInfo);
                StandardOutput = await pProcess.StandardOutput.ReadToEndAsync();

                StandardError = await pProcess.StandardError.ReadToEndAsync();

                //pProcess.WaitForExit();

                ExitCode = pProcess.ExitCode;
                Log(log.Debug, "ExitCode: " + ExitCode.ToString());

                ManageOutput();
                Log(log.Debug, "StandardOutput: " + StandardOutput.Replace("\r", " ").Replace("\n", " "));
                Log(log.Debug, "StandardError: " + StandardError.Replace("\r", " ").Replace("\n", " "));

                RaiseExecuted();
            }
            catch (Exception e)
            {
                Log(log.Error, e.ToString());
            }
        }
Beispiel #7
0
        private static string GetExitCodeDescription(ExitCode result)
        {
            string exitCodeDescription = "Unknown error code";
            var    exitCodeType        = result.GetType();
            var    memberInfo          = exitCodeType.GetMember(result.ToString());
            var    attributes          = memberInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);

            exitCodeDescription = ((DescriptionAttribute)attributes[0]).Description;
            return(exitCodeDescription);
        }
Beispiel #8
0
 private void Exit(ExitCode exitCode)
 {
     App.Logger.Log("Trace", "LauncherController::Exit");
     _downloader.Stop();
     _config.Save();
     if (exitCode != ExitCode.CLOSE_BUTTON)
     {
         App.Logger.Log("ExitCode: " + exitCode.ToString(), "LauncherController::Exit");
     }
     Environment.Exit((int)exitCode);
 }
Beispiel #9
0
            public override string ToString()
            {
                return
                    (@"Begin: " + Begin.ToString("o") + @"
End: " + End.ToString("o") + @"
ExitCode: " + ExitCode.ToString() + @"
Output
====
" + Output + @"
====
Error
====
" + Error + @"====");
            }
Beispiel #10
0
        public static void Exit(ExitCode exitCode)
        {
#if TESTBUILD
            if (IsTesting && exitCode != ExitCode.Succes)
            {
                ErrorText     = exitCode.ToString();
                ErrorHappened = true;
            }
            else
            {
#endif
            Environment.Exit((int)exitCode);
#if TESTBUILD
        }
#endif
        }
    public void ExecuteCommand(string command, bool thread = false)
    {
        int ExitCode;
        ProcessStartInfo ProcessInfo;
        Process          Process;

        ProcessInfo = new ProcessStartInfo("cmd.exe", "/c " + command);

        ProcessInfo.CreateNoWindow = true;//Change that

        ProcessInfo.UseShellExecute = false;

        Process = Process.Start(ProcessInfo);

        Process.WaitForExit();

        ExitCode = Process.ExitCode;
        Process.Close();

        UnityEngine.Debug.Log("ExitCode: " + ExitCode.ToString());
    }
Beispiel #12
0
    static void Main(string[] args)
    {
        int ExitCode;

        try
        {
            var returnedMsgPath = string.Empty;
            if (LocateMsgExe(out returnedMsgPath))
            {
                var startInfo = new ProcessStartInfo()
                {
                    FileName               = returnedMsgPath,
                    Arguments              = @"* /v Hello",
                    UseShellExecute        = false,
                    CreateNoWindow         = true,
                    RedirectStandardError  = true,
                    RedirectStandardOutput = true
                };
                var p = Process.Start(startInfo);
                p.WaitForExit();
                // *** Read the streams ***
                string output = p.StandardOutput.ReadToEnd();
                string error  = p.StandardError.ReadToEnd();
                ExitCode = p.ExitCode;
                MessageBox.Show("output >>" + (String.IsNullOrEmpty(output) ? "(none)" : output));
                MessageBox.Show("error>>" + (String.IsNullOrEmpty(error) ? "(none)" : error));
                MessageBox.Show("ExitCode: " + ExitCode.ToString(), "ExecuteCommand");
                p.Close();
            }
            else
            {
                MessageBox.Show("Not found");
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
        /// <nodoc />
        internal void RenderMarkDown(MarkDownWriter writer)
        {
            writer.WriteRaw("### <span style=\"font - family:consolas; monospace\">");
            writer.WriteText(PipDescription);
            writer.WriteRaw("</span> failed with exit code ");
            writer.WriteLineRaw(ExitCode.ToString(CultureInfo.InvariantCulture));

            writer.StartDetails("Pip Details");
            writer.StartTable();
            WriteKeyValuePair(writer, "PipHash:", SemiStablePipId, true);
            WriteKeyValuePair(writer, "Pip:", PipDescription, true);
            WriteKeyValuePair(writer, "Spec:", SpecPath, true);
            WriteKeyValuePair(writer, "Tool:", ToolName, true);
            WriteKeyValuePair(writer, "Exit Code:", ExitCode.ToString(CultureInfo.InvariantCulture), true);
            writer.EndTable();
            writer.EndDetails();

            if (!string.IsNullOrEmpty(Output))
            {
                writer.WritePre(Output);
            }
        }
Beispiel #14
0
 /// <summary>
 /// Object iterface.
 /// </summary>
 /// <returns>String representation of this object.</returns>
 public override string ToString()
 {
     return(ExitCode.ToString());
 }
Beispiel #15
0
        private void btnRestore_Click(object sender, EventArgs e)
        {
            //Check if folder for restoring exists
            if (!Directory.Exists(txtRestoreLocal.Text))
            {
                MessageBox.Show("Folder not found!");
                return;
            }
            //Look at os
            string op;

            if (Environment.Is64BitOperatingSystem)
            {
                op = "amd64";
            }
            else
            {
                op = "x86";
            }

            //Find root
            string root = Path.GetPathRoot(Environment.SystemDirectory);
            //Set up base args
            string args = txtRestoreLocal.Text + " /i:" + root + "\\USMT\\" + op + "\\migdocs.xml /i:" + root + "\\USMT\\" + op + "\\migapp.xml /i:" + root + "\\USMT\\" + op + "\\wallpaper.xml /config:" + root + "\\USMT\\" + op + "\\config.xml /l:" + root + "\\USMT\\" + op + "\\load.log /progress:" + root + "\\USMT\\" + op + "\\progress.log /c /v:13 ";

            if (boxLAC.Checked && txtPassword.Text == "")
            {
                args += " /LAC";
            }
            else if (boxLAC.Checked)
            {
                args += " /LAC:" + txtPassword.Text;
            }
            if (boxLAC.Checked && boxLAE.Checked)
            {
                args += " /LAE";
            }
            //Check if key is needed and what user entered
            if (decryptBtn.Checked)
            {
                if (!decryptBox.Equals(""))
                {
                    args += " /decrypt /key:" + decryptBox.Text;
                }
                else
                {
                    MessageBox.Show("Enter a key");
                }
            }
            //Restore all no techs otherwise restore all
            if (restoreNoTechBtn.Checked)
            {
                args += " /ue:iowa\\*_*";
            }
            else if (btnDateRestore.Checked)
            {
                int x;
                if (Int32.TryParse(txtRestoreDate.Text, out x))
                {
                    if (x < 0)
                    {
                        MessageBox.Show("Enter in a positive number of days", "Error");
                        return;
                    }
                    args += " /uel:" + txtRestoreDate.Text;
                }
                else if (Regex.IsMatch(daysBox.Text, "^\\d{4}\\/(0?[1-9]|1[012])\\/(0?[1-9]|[12][0-9]|3[01])$"))
                {
                    args += " /uel:" + txtRestoreDate.Text;
                }
                else
                {
                    MessageBox.Show("Enter in day in correct format", "Error");
                    return;
                }
            }
            if (Directory.Exists(root + "\\USMT\\" + op))
            {
                Directory.Delete(root + "\\USMT\\" + op, true);
            }
            //Ask to go
            DialogResult result = MessageBox.Show("Please Confirm Your Details", "Confirm", MessageBoxButtons.OKCancel);

            if (result == DialogResult.OK)
            {
                this.Visible = false;
                moveDIR(Directory.GetCurrentDirectory() + "\\" + op, root + "\\USMT\\" + op);

                int ExitCode;
                ProcessStartInfo ProcessInfo;
                Process          Process;

                ProcessInfo           = new ProcessStartInfo(root + "\\USMT\\" + op + "\\loadstate.exe");
                ProcessInfo.Arguments = args;
                ProcessInfo.Verb      = "runas";

                try
                {
                    Process = Process.Start(ProcessInfo);
                    Process.WaitForExit();

                    ExitCode = Process.ExitCode;
                    Process.Close();
                }
                catch
                {
                    //If no privlages
                    MessageBox.Show("Must give elevated permssions", "ExecuteCommand");
                    this.Visible = true;
                    return;
                }

                //Sucessfully run
                this.Visible = true;
                if (ExitCode.ToString().Equals("0"))
                {
                    MessageBox.Show("Ran Sucessfully", "ExecuteCommand");
                }
                else
                {
                    MessageBox.Show("Exit Code: " + ExitCode.ToString(), "ExecuteCommand");
                }
            }
        }
        /// <summary>
        /// Prints usage instructions to the Console, and returns the int value for the ExitCode passed in
        /// </summary>
        private static int PrintUsage(ExitCode exitCode)
        {
            ConsoleColor originalColor = Console.ForegroundColor;

            Console.WriteLine("");
            Console.WriteLine("  WTV (When The Version) Automatic date-based version numbering for .Net projects");
            Console.WriteLine("  Andrew Freemantle - www.fatlemon.co.uk/wtv");
            Console.WriteLine("");

            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("    Error: " + exitCode.ToString().Replace("_", " "));

            Console.ForegroundColor = originalColor;
            Console.WriteLine("");
            Console.WriteLine("  Usage: WTV  \"file-in\"  \"file-out\"  [\"path to SubWCrev.exe\"  \"SVN working-copy-path\"]");
            Console.WriteLine("   \"file-in\"  can contain the following placeholders:");
            Console.WriteLine("     {DD}    - Day");
            Console.WriteLine("     {MM}    - Month");
            Console.WriteLine("     {YYYY}  - Year");
            Console.WriteLine("     {SVN}   - SubVersion revision (must specify the path to SubWCrev.exe and working copy path)");
            Console.WriteLine("");
            Console.WriteLine("  Example Pre-Build command: (remove the line breaks)");
            Console.WriteLine("    \"C:\\Path\\To\\WTV.exe\"");
            Console.WriteLine("      \"$(ProjectDir)Properties\\AssemblyInfo.Template.cs\"");
            Console.WriteLine("      \"$(ProjectDir)Properties\\AssemblyInfo.cs\"");
            Console.WriteLine("      \"C:\\Program Files\\TortoiseSVN\\bin\\SubWCRev.exe\"");
            Console.WriteLine("      \"$(SolutionDir).\"");

            return (int)exitCode;
        }
Beispiel #17
0
 private static void ExitWith(ExitCode exitCode)
 {
     Console.Error.WriteLine("Exiting with {0}", exitCode.ToString());
     System.Environment.Exit((int)exitCode);
     throw new InvalidOperationException("Unreachable");
 }
Beispiel #18
0
 public void OnExitCode(ExitCode exitCode)
 {
     _exitCode = exitCode;
     _log.Info(() => new Text("Exit code: ", Color.Header) + new Text(exitCode.ToString(), exitCode.Value == 0 ? Color.Success : Color.Error));
 }
Beispiel #19
0
        public override ReturnCode Execute(
            Interpreter interpreter,
            IClientData clientData,
            ArgumentList arguments,
            ref Result result
            )
        {
            ReturnCode code = ReturnCode.Ok;

            if (interpreter != null)
            {
                if (arguments != null)
                {
                    if (arguments.Count >= 2)
                    {
                        OptionDictionary options = new OptionDictionary(
                            new IOption[] {
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-debug", null),                  // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-commandline", null),            // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-dequote", null),                // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-quoteall", null),               // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-unicode", null),                // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-ignorestderr", null),           // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-killonerror", null),            // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-keepnewline", null),            // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-noexitcode", null),             // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-nocapture", null),              // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-shell", null),                  // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-nocarriagereturns", null),      // simple switch
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, "-trimall", null),                // simple switch
                            new Option(typeof(ExitCode), OptionFlags.MustHaveEnumValue,
                                       Index.Invalid, Index.Invalid, "-success", null), // success exit code
                            new Option(null, OptionFlags.MustHaveValue, Index.Invalid,
                                       Index.Invalid, "-domainname", null),
                            new Option(null, OptionFlags.MustHaveValue, Index.Invalid,
                                       Index.Invalid, "-username", null),
                            new Option(null, OptionFlags.MustHaveSecureStringValue, Index.Invalid,
                                       Index.Invalid, "-password", null),
                            new Option(null, OptionFlags.MustHaveListValue, Index.Invalid,
                                       Index.Invalid, "-preprocessarguments", null), // command
                            new Option(null, OptionFlags.MustHaveValue, Index.Invalid,
                                       Index.Invalid, "-directory", null),           // directory name
                            new Option(null, OptionFlags.MustHaveValue, Index.Invalid,
                                       Index.Invalid, "-processid", null),           // varName for processId
                            new Option(null, OptionFlags.MustHaveValue, Index.Invalid,
                                       Index.Invalid, "-exitcode", null),            // varName for exitCode
                            new Option(null, OptionFlags.MustHaveValue, Index.Invalid,
                                       Index.Invalid, "-stdin", null),               // varName for StdIn input
                            new Option(null, OptionFlags.MustHaveValue, Index.Invalid,
                                       Index.Invalid, "-stdout", null),              // varName for StdOut output
                            new Option(null, OptionFlags.MustHaveValue, Index.Invalid,
                                       Index.Invalid, "-stderr", null),              // varName for StdErr output
                            new Option(typeof(EventFlags), OptionFlags.MustHaveEnumValue,
                                       Index.Invalid, Index.Invalid, "-eventflags",
                                       new Variant(interpreter.EngineEventFlags)),
                            new Option(null, OptionFlags.None, Index.Invalid,
                                       Index.Invalid, Option.EndOfOptions, null)
                        });

                        int argumentIndex = Index.Invalid;

                        code = interpreter.GetOptions(options, arguments, 0, 1,
                                                      Index.Invalid, true, ref argumentIndex, ref result);

                        if (code == ReturnCode.Ok)
                        {
                            if (argumentIndex != Index.Invalid)
                            {
                                bool debug = false;

                                if (options.IsPresent("-debug"))
                                {
                                    debug = true;
                                }

                                bool commandLine = false;

                                if (options.IsPresent("-commandline"))
                                {
                                    commandLine = true;
                                }

                                bool dequote = false;

                                if (options.IsPresent("-dequote"))
                                {
                                    dequote = true;
                                }

                                bool quoteAll = false;

                                if (options.IsPresent("-quoteall"))
                                {
                                    quoteAll = true;
                                }

                                bool captureExitCode = true;

                                if (options.IsPresent("-noexitcode"))
                                {
                                    captureExitCode = false;
                                }

                                bool captureInput  = true;
                                bool captureOutput = true;

                                if (options.IsPresent("-nocapture"))
                                {
                                    captureInput  = false;
                                    captureOutput = false;
                                }

                                bool useUnicode = false;

                                if (options.IsPresent("-unicode"))
                                {
                                    useUnicode = true;
                                }

                                bool ignoreStdErr = false;

                                if (options.IsPresent("-ignorestderr"))
                                {
                                    ignoreStdErr = true;
                                }

                                bool killOnError = false;

                                if (options.IsPresent("-killonerror"))
                                {
                                    killOnError = true;
                                }

                                bool keepNewLine = false;

                                if (options.IsPresent("-keepnewline"))
                                {
                                    keepNewLine = true;
                                }

                                bool carriageReturns = true;

                                if (options.IsPresent("-nocarriagereturns"))
                                {
                                    carriageReturns = false;
                                }

                                bool trimAll = false;

                                if (options.IsPresent("-trimall"))
                                {
                                    trimAll = true;
                                }

                                bool useShellExecute = false;

                                if (options.IsPresent("-shell"))
                                {
                                    useShellExecute = true;
                                }

                                Variant  value           = null;
                                ExitCode?successExitCode = null;

                                if (options.IsPresent("-success", ref value))
                                {
                                    successExitCode = (ExitCode)value.Value;
                                }

                                string domainName = null;

                                if (options.IsPresent("-domainname", ref value))
                                {
                                    domainName = value.ToString();
                                }

                                string userName = null;

                                if (options.IsPresent("-username", ref value))
                                {
                                    userName = value.ToString();
                                }

                                SecureString password = null;

                                if (options.IsPresent("-password", ref value))
                                {
                                    password = (SecureString)value.Value;
                                }

                                string directory = null;

                                if (options.IsPresent("-directory", ref value))
                                {
                                    directory = value.ToString();
                                }

                                string processIdVarName = null;

                                if (options.IsPresent("-processid", ref value))
                                {
                                    processIdVarName = value.ToString();
                                }

                                string exitCodeVarName = null;

                                if (options.IsPresent("-exitcode", ref value))
                                {
                                    exitCodeVarName = value.ToString();
                                }

                                string stdInVarName = null;

                                if (options.IsPresent("-stdin", ref value))
                                {
                                    stdInVarName = value.ToString();
                                }

                                string stdOutVarName = null;

                                if (options.IsPresent("-stdout", ref value))
                                {
                                    stdOutVarName = value.ToString();
                                }

                                string stdErrVarName = null;

                                if (options.IsPresent("-stderr", ref value))
                                {
                                    stdErrVarName = value.ToString();
                                }

                                EventFlags eventFlags = interpreter.EngineEventFlags;

                                if (options.IsPresent("-eventflags", ref value))
                                {
                                    eventFlags = (EventFlags)value.Value;
                                }

                                StringList list = null;

                                if (options.IsPresent("-preprocessarguments", ref value))
                                {
                                    list = (StringList)value.Value;
                                }

                                int  argumentStopIndex = arguments.Count - 1;
                                bool background        = false;

                                if (arguments[arguments.Count - 1] ==
                                    Characters.Ampersand.ToString())
                                {
                                    argumentStopIndex--;
                                    background = true;
                                }

                                string execFileName = arguments[argumentIndex];

                                if (!PathOps.IsRemoteUri(execFileName))
                                {
                                    execFileName = PathOps.GetNativePath(execFileName);
                                }

                                string execArguments = null;

                                if ((argumentIndex + 1) < arguments.Count)
                                {
                                    if (commandLine)
                                    {
                                        execArguments = RuntimeOps.BuildCommandLine(
                                            ArgumentList.GetRangeAsStringList(arguments,
                                                                              argumentIndex + 1, argumentStopIndex,
                                                                              dequote),
                                            quoteAll);
                                    }
                                    else
                                    {
                                        execArguments = ListOps.Concat(arguments,
                                                                       argumentIndex + 1, argumentStopIndex);
                                    }
                                }

                                Result input = null;

                                if ((code == ReturnCode.Ok) && !useShellExecute &&
                                    captureInput && (stdInVarName != null))
                                {
                                    code = interpreter.GetVariableValue(VariableFlags.None,
                                                                        stdInVarName, ref input, ref result);
                                }

                                if (debug)
                                {
                                    TraceOps.DebugTrace(String.Format(
                                                            "Execute: interpreter = {0}, domainName = {1}, userName = {2}, " +
                                                            "password = {3}, execFileName = {4}, execArguments = {5}, " +
                                                            "directory = {6}, input = {7}, eventFlags = {8}, debug = {9}, " +
                                                            "commandLine = {10}, dequote = {11}, quoteAll = {12}, " +
                                                            "useShellExecute = {13}, captureExitCode = {14}, " +
                                                            "captureInput = {15}, captureOutput = {16}, useUnicode = {17}, " +
                                                            "ignoreStdErr = {18}, killOnError = {19}, keepNewLine = {20}, " +
                                                            "carriageReturns = {21}, trimAll = {22}, background = {23}, " +
                                                            "successExitCode = {24}, processIdVarName = {25}, exitCodeVarName = {26}, " +
                                                            "stdInVarName = {27}, stdOutVarName = {28}, stdErrVarName = {29}",
                                                            FormatOps.InterpreterNoThrow(interpreter), FormatOps.WrapOrNull(domainName),
                                                            FormatOps.WrapOrNull(userName), FormatOps.WrapOrNull(password),
                                                            FormatOps.WrapOrNull(execFileName), FormatOps.WrapOrNull(execArguments),
                                                            FormatOps.WrapOrNull(directory), FormatOps.WrapOrNull(input),
                                                            FormatOps.WrapOrNull(eventFlags), debug, commandLine, dequote, quoteAll,
                                                            useShellExecute, captureExitCode, captureInput, captureOutput, useUnicode,
                                                            ignoreStdErr, killOnError, keepNewLine, carriageReturns, trimAll, background,
                                                            FormatOps.WrapOrNull(successExitCode), FormatOps.WrapOrNull(processIdVarName),
                                                            FormatOps.WrapOrNull(exitCodeVarName), FormatOps.WrapOrNull(stdInVarName),
                                                            FormatOps.WrapOrNull(stdOutVarName), FormatOps.WrapOrNull(stdErrVarName)),
                                                        typeof(Exec).Name, TracePriority.Command);
                                }

                                int      processId = 0;
                                ExitCode exitCode  = ResultOps.SuccessExitCode();
                                Result   error     = null;

                                if (code == ReturnCode.Ok)
                                {
                                    if (list != null)
                                    {
                                        list.Add(execFileName);
                                        list.Add(directory);
                                        list.Add(execArguments);

                                        code = interpreter.EvaluateScript(list.ToString(), ref result);

                                        if (code == ReturnCode.Return)
                                        {
                                            execArguments = result;
                                            code          = ReturnCode.Ok;
                                        }
                                        else if (code == ReturnCode.Continue)
                                        {
                                            code = ReturnCode.Ok;
                                            goto done;
                                        }
                                    }

                                    if (code == ReturnCode.Ok)
                                    {
                                        code = ProcessOps.ExecuteProcess(
                                            interpreter, domainName, userName, password, execFileName,
                                            execArguments, directory, input, eventFlags, useShellExecute,
                                            captureExitCode, captureOutput, useUnicode, ignoreStdErr,
                                            killOnError, keepNewLine, background, !background,
                                            ref processId, ref exitCode, ref result, ref error);
                                    }
                                }

done:

                                if (debug)
                                {
                                    TraceOps.DebugTrace(String.Format(
                                                            "Execute: interpreter = {0}, domainName = {1}, userName = {2}, " +
                                                            "password = {3}, execFileName = {4}, execArguments = {5}, " +
                                                            "directory = {6}, input = {7}, eventFlags = {8}, debug = {9}, " +
                                                            "commandLine = {10}, dequote = {11}, quoteAll = {12}, " +
                                                            "useShellExecute = {13}, captureExitCode = {14}, " +
                                                            "captureInput = {15}, captureOutput = {16}, useUnicode = {17}, " +
                                                            "ignoreStdErr = {18}, killOnError = {19}, keepNewLine = {20}, " +
                                                            "carriageReturns = {21}, trimAll = {22}, background = {23}, " +
                                                            "successExitCode = {24}, processIdVarName = {25}, exitCodeVarName = {26}, " +
                                                            "stdInVarName = {27}, stdOutVarName = {28}, stdErrVarName = {29}, " +
                                                            "processId = {30}, exitCode = {31}, result = {32}, error = {33}",
                                                            FormatOps.InterpreterNoThrow(interpreter), FormatOps.WrapOrNull(domainName),
                                                            FormatOps.WrapOrNull(userName), FormatOps.WrapOrNull(password),
                                                            FormatOps.WrapOrNull(execFileName), FormatOps.WrapOrNull(execArguments),
                                                            FormatOps.WrapOrNull(directory), FormatOps.WrapOrNull(input),
                                                            FormatOps.WrapOrNull(eventFlags), debug, commandLine, dequote, quoteAll,
                                                            useShellExecute, captureExitCode, captureInput, captureOutput, useUnicode,
                                                            ignoreStdErr, killOnError, keepNewLine, carriageReturns, trimAll, background,
                                                            FormatOps.WrapOrNull(successExitCode), FormatOps.WrapOrNull(processIdVarName),
                                                            FormatOps.WrapOrNull(exitCodeVarName), FormatOps.WrapOrNull(stdInVarName),
                                                            FormatOps.WrapOrNull(stdOutVarName), FormatOps.WrapOrNull(stdErrVarName),
                                                            processId, exitCode, FormatOps.WrapOrNull(true, true, result),
                                                            FormatOps.WrapOrNull(true, true, error)), typeof(Exec).Name,
                                                        TracePriority.Command);
                                }

                                //
                                // NOTE: Even upon failure, always set the variable to contain
                                //       process Id, if applicable.
                                //
                                if (processIdVarName != null)
                                {
                                    /* IGNORED */
                                    interpreter.SetVariableValue( /* EXEMPT */
                                        VariableFlags.NoReady, processIdVarName,
                                        processId.ToString(), null);
                                }

                                if (code == ReturnCode.Ok)
                                {
                                    //
                                    // NOTE: Remove all carriage returns from output (leaving
                                    //       only line feeds as line separators)?
                                    //
                                    if (!carriageReturns)
                                    {
                                        if (!String.IsNullOrEmpty(result))
                                        {
                                            result = result.Replace(
                                                Characters.CarriageReturnString,
                                                String.Empty);
                                        }

                                        if (!String.IsNullOrEmpty(error))
                                        {
                                            error = error.Replace(
                                                Characters.CarriageReturnString,
                                                String.Empty);
                                        }
                                    }

                                    //
                                    // NOTE: Remove all surrounding whitespace from the output?
                                    //
                                    if (trimAll)
                                    {
                                        if (!String.IsNullOrEmpty(result))
                                        {
                                            result = result.Trim();
                                        }

                                        if (!String.IsNullOrEmpty(error))
                                        {
                                            error = error.Trim();
                                        }
                                    }

                                    //
                                    // NOTE: Now, "result" contains any StdOut output and "error"
                                    //        contains any StdErr output.
                                    //
                                    if ((code == ReturnCode.Ok) && !background &&
                                        captureExitCode && (exitCodeVarName != null))
                                    {
                                        code = interpreter.SetVariableValue(VariableFlags.None,
                                                                            exitCodeVarName, exitCode.ToString(), null, ref error);
                                    }

                                    if ((code == ReturnCode.Ok) && !useShellExecute &&
                                        !background && captureOutput && (stdOutVarName != null))
                                    {
                                        code = interpreter.SetVariableValue(VariableFlags.None,
                                                                            stdOutVarName, result, null, ref error);
                                    }

                                    if ((code == ReturnCode.Ok) && !useShellExecute &&
                                        !background && captureOutput && (stdErrVarName != null))
                                    {
                                        code = interpreter.SetVariableValue(VariableFlags.None,
                                                                            stdErrVarName, error, null, ref error);
                                    }

                                    //
                                    // NOTE: If they specified a "success" exit code, make sure
                                    //       that is the same as the exit code we actually got
                                    //       from the process.
                                    //
                                    if ((code == ReturnCode.Ok) && !background && captureExitCode &&
                                        (successExitCode != null) && (exitCode != successExitCode))
                                    {
                                        /* IGNORED */
                                        interpreter.SetVariableValue( /* EXEMPT */
                                            Engine.ErrorCodeVariableFlags, TclVars.ErrorCode,
                                            StringList.MakeList(
                                                "CHILDSTATUS", processId, exitCode),
                                            null);

                                        Engine.SetErrorCodeSet(interpreter, true);

                                        error = "child process exited abnormally";
                                        code  = ReturnCode.Error;
                                    }

                                    if (code != ReturnCode.Ok)
                                    {
                                        //
                                        // NOTE: Transfer error to command result.
                                        //
                                        result = error;
                                    }
                                }
                                else
                                {
                                    //
                                    // NOTE: Transfer error to command result.
                                    //
                                    result = error;
                                }
                            }
                            else
                            {
                                result = "wrong # args: should be \"exec ?options? arg ?arg ...?\"";
                                code   = ReturnCode.Error;
                            }
                        }
                    }
                    else
                    {
                        result = "wrong # args: should be \"exec ?options? arg ?arg ...?\"";
                        code   = ReturnCode.Error;
                    }
                }
                else
                {
                    result = "invalid argument list";
                    code   = ReturnCode.Error;
                }
            }
            else
            {
                result = "invalid interpreter";
                code   = ReturnCode.Error;
            }

            return(code);
        }
        public virtual bool EvaluateResults(string state)
        {
            switch (ExitCode)
            {
            case AutomationExitCode.None:
                Logging.Info(Logfiles.AutomationRunner, LogOptions.MethodName, "Task: {0} ID: {1} State: {2}, ExitCode: {3}", Command, ID, state, ExitCode);
                return(true);

            case AutomationExitCode.ComparisonNoFilesToUpdate:
                Logging.Info("The task {0} (ID {1} reported exit code {2}. The Sequence will stop, but a success will be reported", Command, ID, ExitCode.ToString());
                return(true);

            default:
                Logging.Error(Logfiles.AutomationRunner, LogOptions.MethodName, "Error in task {0} execution! ID: {1} Exit code: {2}, ErrorMessage: {3}", Command, ID, ExitCode, string.IsNullOrEmpty(ErrorMessage) ? "(empty)" : ErrorMessage);
                return(false);
            }
        }
Beispiel #21
0
 public override string ToString()
 {
     return(ExitCode.ToString(CultureInfo.InvariantCulture));
 }
Beispiel #22
0
        public ExitCode ScheduleReport(ref Report[] pReports, bool pSetPrompts, DateTime pDate, string pPath, string pOutFormat, bool pWaitEnd, bool pCleanup, string pNotifEmail)
        {
            _cancel = false;
            _sessionmanager.InitProgress(3, pWaitEnd ? 50 : 80, pReports.Length);
            _sessionmanager.ResetSessionTimeOut();
            if (pReports == null)
            {
                throw new Exception("The <Reports> argument is null ! ");
            }
            _sessionmanager.Log("Starts to Schedule reports " + Func.getTime());
            ExitCode      exitcode    = ExitCode.SUCCEED;
            List <Report> waitreports = new List <Report>();

            pOutFormat = pOutFormat == null ? string.Empty : pOutFormat.ToLower();
            foreach (Report report in pReports)
            {
                string instanceCuid = null;
                try
                {
                    _sessionmanager.Log("Schedule report " + report.ToLongName());
                    report.Instance = new Instance {
                        Cuid = instanceCuid
                    };
                    waitreports.Add(report);
                }
                catch (Exception ex)
                {
                    exitcode = ExitCode.HASERROR;
                    if (report.Instance == null)
                    {
                        report.Instance = new Instance();
                    }
                    report.LOG = _sessionmanager.ParseException(ex);
                }
                _sessionmanager.IncProgress();
                if (_cancel)
                {
                    return(ExitCode.CANCELED);
                }
            }

            _sessionmanager.InitProgress(pWaitEnd ? 51 : 81, 100, waitreports.Count);
            if (pWaitEnd)
            {
                _sessionmanager.Log("Wait for reports to be created...");
            }
            else
            {
                _sessionmanager.Log("Get reports status for created reports...");
            }

            if (_cancel)
            {
                return(ExitCode.CANCELED);
            }
            while (waitreports.Count != 0)
            {
                for (int i = waitreports.Count - 1; i != -1; i--)
                {
                    try
                    {
                        waitreports[i].Instance.Id     = Rand.Number(1, 10000);
                        waitreports[i].Instance.Date   = Rand.DateFromNow(-1, "yyyy/MM/dd");
                        waitreports[i].Instance.Status = Rand.List("PENDING", "COMPLETE", "RUNNING", "COMPLETE", "FAILURE", "COMPLETE");
                        if (waitreports[i].Instance.Status != "PENDING" && waitreports[i].Instance.Status != "RUNNING")
                        {
                            if (pWaitEnd)
                            {
                                _sessionmanager.IncProgress();
                            }
                            if (_cancel)
                            {
                                return(ExitCode.CANCELED);
                            }
                            if (waitreports[i].Instance.Status == "FAILURE")
                            {
                                waitreports[i].Instance.Status += ": [ErrorMessage]";
                                _sessionmanager.Log(waitreports[i].Instance.Status);
                                exitcode = ExitCode.HASERROR;
                            }
                            else if (waitreports[i].Instance.Status == "COMPLETE")
                            {
                                waitreports[i].Instance.Time = Rand.Time("00:00:01", "00:10:00");
                            }
                            waitreports.Remove(waitreports[i]);
                            _sessionmanager.Log("Done for report " + Rand.String(10));
                        }
                    }
                    catch (Exception ex)
                    {
                        exitcode                       = ExitCode.HASERROR;
                        waitreports[i].LOG             = _sessionmanager.ParseException(ex);
                        waitreports[i].Instance.Status = _sessionmanager.ParseException(ex);
                        _sessionmanager.Log(" Error: " + _sessionmanager.ParseException(ex));

                        exitcode = ExitCode.HASERROR;
                        _sessionmanager.Log("Failed for report " + Rand.String(10));
                    }
                    if (!pWaitEnd)
                    {
                        _sessionmanager.IncProgress();
                    }
                    if (_cancel)
                    {
                        return(ExitCode.CANCELED);
                    }
                }
                if (pWaitEnd == false)
                {
                    break;
                }

                Waiter.Wait(1000 + (waitreports.Count * 100), ref _cancel);
                if (_cancel)
                {
                    return(ExitCode.CANCELED);
                }
                waitreports.RemoveAt(0);
                _sessionmanager.ResetSessionTimeOut();
            }
            if (pWaitEnd)
            {
                _sessionmanager.Log("Remaining reports : " + waitreports.Count);
            }
            _sessionmanager.Log("End of reports scheduling - " + Func.getTime());
            if (pNotifEmail != string.Empty)
            {
                string msg = _sessionmanager.GetLogText();
                _sessionmanager.Log("  Email=" + pNotifEmail);
                _sessionmanager.Log("  Subject=" + "[Business Objects] Scheduling result: " + exitcode.ToString());
                _sessionmanager.Log("  Message=" + msg);
            }
            return(exitcode);
        }
Beispiel #23
0
        private static ExitCode ShowWidget()
        {
            if (!MiGfx.Components.Register())
            {
                ErrorMessage = "Unable to register MiGfx components";
                return(ExitCode.InitFail);
            }

            LoadSettings();

            SFML.Graphics.Texture ptr = Theme.PointerTexture,
                                  bg  = Theme.BackgroundTexture,
                                  ico = Theme.DefaultIcon;
            SFML.Graphics.Font fnt    = Theme.Font;

            if (ptr == null)
            {
                ErrorMessage = "Unable to load pointer texture from \"" + Theme.PointerPath + "\"";
                return(ExitCode.OnLoadFail);
            }
            if (bg == null)
            {
                ErrorMessage = "Unable to load background texture from \"" + Theme.BackgroundPath + "\"";
                return(ExitCode.OnLoadFail);
            }
            if (ico == null)
            {
                ErrorMessage = "Unable to load default icon texture from \"" + Theme.DefaultIconPath + "\"";
                return(ExitCode.OnLoadFail);
            }
            if (fnt == null)
            {
                ErrorMessage = "Unable to load font from \"" + Theme.TextStyle.FontPath + "\"";
                return(ExitCode.OnLoadFail);
            }

            Vector2u cellsize;
            {
                uint csize = GetCellSize();

                cellsize.X = csize;
                cellsize.Y = FolderSettings.DisplayType == IconDisplayType.IconOnly ?
                             csize : csize / 3 * 4;
            }

            WindowSettings settings = new WindowSettings()
            {
                Width  = (cellsize.X * FolderSettings.GridCells.X) + (uint)(ptr.Size.X * Theme.PointerScale.X),
                Height = (cellsize.Y * FolderSettings.GridCells.Y) + 3
            };

            VideoMode desk = VideoMode.DesktopMode;

            while (settings.Width > desk.Width)
            {
                if (FolderSettings.GridCells.X == 1)
                {
                    break;
                }

                FolderSettings.GridCells -= new Vector2u(1, 0);
                settings.Width            = (cellsize.X * FolderSettings.GridCells.X) + (uint)(ptr.Size.X * Theme.PointerScale.X);
            }
            while (settings.Height > desk.Height)
            {
                if (FolderSettings.GridCells.Y == 1)
                {
                    break;
                }

                FolderSettings.GridCells -= new Vector2u(0, 1);
                settings.Height           = (cellsize.Y * FolderSettings.GridCells.Y) + 3;
            }

            if (InitialMousePosition.X + settings.Width + 20 >= desk.Width)
            {
                PointerDirection = MiGfx.Direction.Right;
            }
            else
            {
                PointerDirection = MiGfx.Direction.Left;
            }

            ExitCode e = ExitCode.UnexpectedFail;

            using (WidgetWindow window = new WidgetWindow(settings))
                e = window.Run <WidgetState>();

            SaveSettings();

            if (e != ExitCode.Success)
            {
                ErrorMessage = string.Format("Popcon Widget failed!\nExitCode: {0}", e.ToString());
            }

            return(e);
        }