예제 #1
0
        protected override bool CanLaunch(IArgumentHintResolver hintResolver)
        {
            string resolvedArgument = hintResolver.Resolve(this.Arguments, _allowMultiValueFields, " ");

            if (resolvedArgument == null)
            {
                return(false);
            }
            return(true);
        }
예제 #2
0
        protected override bool PerformLaunch(IArgumentHintResolver hintResolver)
        {
            string multiValueSeparator = _multiValueFieldSeparator;

            if (string.IsNullOrEmpty(multiValueSeparator))
            {
                multiValueSeparator = " ";
            }

            var command          = ExpandEnvironmentVariables(_command);
            var workingDirectory = ExpandEnvironmentVariables(_workingDirectory);
            var arguments        = ExpandEnvironmentVariables(_arguments);

            command          = hintResolver.Resolve(command, _allowMultiValueFields, multiValueSeparator);
            workingDirectory = hintResolver.Resolve(workingDirectory, _allowMultiValueFields, multiValueSeparator);
            arguments        = hintResolver.Resolve(arguments, _allowMultiValueFields, multiValueSeparator);

            ProcessStartInfo nfo;

            if (string.IsNullOrEmpty(arguments))
            {
                nfo = new ProcessStartInfo(command);
            }
            else
            {
                nfo = new ProcessStartInfo(command, arguments);
            }
            if (Directory.Exists(workingDirectory))
            {
                nfo.WorkingDirectory = workingDirectory;
            }

            switch (base.WindowStyle)
            {
            case WindowStyle.Minimized:
                nfo.WindowStyle = ProcessWindowStyle.Minimized;
                break;

            case WindowStyle.Maximized:
                nfo.WindowStyle = ProcessWindowStyle.Maximized;
                break;

            case WindowStyle.Hidden:
                nfo.WindowStyle = ProcessWindowStyle.Hidden;
                break;

            case WindowStyle.Normal:
            default:
                nfo.WindowStyle = ProcessWindowStyle.Normal;
                break;
            }

            if (!string.IsNullOrEmpty(this._username))
            {
                nfo.UserName = this._username;
                nfo.Domain   = this._domain;
                nfo.Password = this._password;
            }
            nfo.UseShellExecute = false;

            Process process = new Process();

            process.StartInfo = nfo;

            Platform.Log(LogLevel.Debug, "Command Line Execute: {2}> {0} {1}", nfo.FileName, nfo.Arguments, nfo.WorkingDirectory);

            bool result = process.Start();

            if (_waitForExit)
            {
                process.WaitForExit();
                process.Dispose();
            }

            return(result);
        }