Exemplo n.º 1
0
        public OrchardParameters Parse(CommandParameters parameters) {

            var result = new OrchardParameters {
                Arguments = new List<string>(),
                ResponseFiles = new List<string>(),
                Switches = new Dictionary<string, string>()
            };

            foreach (var arg in parameters.Arguments) {
                // @response-file
                if (arg[0] == '@') {
                    var filename = arg.Substring(1);
                    if (string.IsNullOrEmpty(filename)) {
                        throw new ArgumentException("Incorrect syntax: response file name can not be empty");
                    }
                    result.ResponseFiles.Add(filename);
                }
                // regular argument
                else {
                    result.Arguments.Add(arg);
                }
            }

            foreach (var sw in parameters.Switches) {
                // Built-in switches
                switch (sw.Key.ToLowerInvariant()) {
                    case "wd":
                    case "workingdirectory":
                        result.WorkingDirectory = sw.Value;
                        break;

                    case "v":
                    case "verbose":
                        bool verbose;
                        if (!bool.TryParse(sw.Value, out verbose))
                            verbose = true;
                        result.Verbose = verbose;
                        break;

                    case "vp":
                    case "virtualpath":
                        result.VirtualPath = sw.Value;
                        break;

                    case "t":
                    case "tenant":
                        result.Tenant = sw.Value;
                        break;

                    default:
                        result.Switches.Add(sw.Key, sw.Value);
                        break;
                }
            }

            return result;
        }
Exemplo n.º 2
0
        public OrchardParameters Parse(CommandParameters parameters)
        {
            var result = new OrchardParameters {
                Arguments     = new List <string>(),
                ResponseFiles = new List <string>(),
                Switches      = new Dictionary <string, string>()
            };

            foreach (var arg in parameters.Arguments)
            {
                // @response-file
                if (arg[0] == '@')
                {
                    var filename = arg.Substring(1);
                    if (string.IsNullOrEmpty(filename))
                    {
                        throw new ArgumentException("Incorrect syntax: response file name can not be empty");
                    }
                    result.ResponseFiles.Add(filename);
                }
                // regular argument
                else
                {
                    result.Arguments.Add(arg);
                }
            }

            foreach (var sw in parameters.Switches)
            {
                // Built-in switches
                switch (sw.Key.ToLowerInvariant())
                {
                case "wd":
                case "workingdirectory":
                    result.WorkingDirectory = sw.Value;
                    break;

                case "v":
                case "verbose":
                    bool verbose;
                    if (!bool.TryParse(sw.Value, out verbose))
                    {
                        verbose = true;
                    }
                    result.Verbose = verbose;
                    break;

                case "vp":
                case "virtualpath":
                    result.VirtualPath = sw.Value;
                    break;

                case "t":
                case "tenant":
                    result.Tenant = sw.Value;
                    break;

                default:
                    result.Switches.Add(sw.Key, sw.Value);
                    break;
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        private int DoRun()
        {
            _arguments = new OrchardParametersParser().Parse(new CommandParametersParser().Parse(_args));
            _logger = new Logger(_arguments.Verbose, _output);

            // Perform some argument validation and display usage if something is incorrect
            bool showHelp = _arguments.Switches.ContainsKey("?");
            if (!showHelp) {
                showHelp = (!_arguments.Arguments.Any() && !_arguments.ResponseFiles.Any());
            }

            if (!showHelp) {
                showHelp = (_arguments.Arguments.Any() && _arguments.ResponseFiles.Any());
                if (showHelp) {
                    _output.WriteLine("Incorrect syntax: Response files cannot be used in conjunction with commands");
                }
            }

            if (showHelp) {
                return GeneralHelp();
            }

            if (string.IsNullOrEmpty(_arguments.VirtualPath))
                _arguments.VirtualPath = "/";
            LogInfo("Virtual path: \"{0}\"", _arguments.VirtualPath);

            if (string.IsNullOrEmpty(_arguments.WorkingDirectory))
                _arguments.WorkingDirectory = Environment.CurrentDirectory;
            LogInfo("Working directory: \"{0}\"", _arguments.WorkingDirectory);

            LogInfo("Detecting orchard installation root directory...");
            var orchardDirectory = GetOrchardDirectory(_arguments.WorkingDirectory);
            LogInfo("Orchard root directory: \"{0}\"", orchardDirectory.FullName);

            LogInfo("Creating ASP.NET AppDomain for command agent...");
            var host = (CommandHost)CreateWorkerAppDomainWithHost(_arguments.VirtualPath, orchardDirectory.FullName, typeof(CommandHost));

            LogInfo("Executing command in ASP.NET AppDomain...");
            var result = Execute(host);
            LogInfo("Return code for command: {0}", result);

            return result;
        }