예제 #1
0
        private void Initialize(CommandHostContext context) {
            context.Arguments = new OrchardParametersParser().Parse(new CommandParametersParser().Parse(_args));
            context.Logger = new Logger(context.Arguments.Verbose, _output);

            // Perform some argument validation and display usage if something is incorrect
            context.DisplayUsageHelp = context.Arguments.Switches.ContainsKey("?");
            if (context.DisplayUsageHelp)
                return;

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

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

            if (string.IsNullOrEmpty(context.Arguments.WorkingDirectory))
                context.Arguments.WorkingDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);

            LogInfo(context, "Working directory: \"{0}\"", context.Arguments.WorkingDirectory);

            LogInfo(context, "Detecting orchard installation root directory...");
            context.OrchardDirectory = GetOrchardDirectory(context.Arguments.WorkingDirectory);
            LogInfo(context, "Orchard root directory: \"{0}\"", context.OrchardDirectory.FullName);

            LogInfo(context, "Creating ASP.NET AppDomain for command agent...");
            context.CommandHost = CreateWorkerAppDomainWithHost(context.Arguments.VirtualPath, context.OrchardDirectory.FullName, typeof(CommandHost));

            LogInfo(context, "Starting Orchard session");
            context.StartSessionResult = context.CommandHost.StartSession(_input, _output);
        }
예제 #2
0
        public void Shutdown(CommandHostContext context) {
            try {
                if (context.CommandHost != null) {
                    LogInfo(context, "Shutting down Orchard session...");
                    context.CommandHost.StopSession(_input, _output);
                }
            }
            catch (AppDomainUnloadedException) {
                LogInfo(context, "   (AppDomain already unloaded)");
            }

            if (context.CommandHost != null) {
                LogInfo(context, "Shutting down ASP.NET AppDomain...");
                ApplicationManager.GetApplicationManager().ShutdownAll();
            }
        }
예제 #3
0
 public CommandReturnCodes ExecuteInteractive(CommandHostContext context) {
     _output.WriteLine("Type \"?\" for help, \"exit\" to exit, \"cls\" to clear screen");
     while (true) {
         var command = ReadCommand(context);
         switch (command.ToLowerInvariant()) {
             case "quit":
             case "q":
             case "exit":
             case "e":
                 return 0;
             case "help":
             case "?":
                 DisplayInteractiveHelp();
                 break;
             case "cls":
                 Console.Clear();
                 break;
             default:
                 context = RunCommand(context, command);
                 break;
         }
     }
 }
예제 #4
0
 private CommandReturnCodes ExecuteResponseFiles(CommandHostContext context) {
     var responseLines = new ResponseFiles.ResponseFiles().ReadFiles(context.Arguments.ResponseFiles);
     return context.CommandHost.RunCommands(_input, _output, context.Logger, responseLines.ToArray());
 }
예제 #5
0
 private CommandReturnCodes ExecuteSingleCommand(CommandHostContext context) {
     return context.CommandHost.RunCommand(_input, _output, context.Logger, context.Arguments);
 }
예제 #6
0
 private CommandReturnCodes RunCommandInSession(CommandHostContext context, string command) {
     try {
         var args = new OrchardParametersParser().Parse(new CommandParametersParser().Parse(new CommandLineParser().Parse(command)));
         return context.CommandHost.RunCommandInSession(_input, _output, context.Logger, args);
     }
     catch (AppDomainUnloadedException) {
         _output.WriteLine("AppDomain of Orchard session has been unloaded. (Retrying...)");
         return context.RetryResult;
     }
 }
예제 #7
0
        private CommandHostContext RunCommand(CommandHostContext context, string command) {
            if (string.IsNullOrWhiteSpace(command))
                return context;

            CommandReturnCodes result = RunCommandInSession(context, command);
            if (result == context.RetryResult) {
                _commandHostContextProvider.Shutdown(context);
                context = CommandHostContext();
                result = RunCommandInSession(context, command);
                if (result != CommandReturnCodes.Ok)
                    _output.WriteLine("Command returned non-zero result: {0}", result);
            }
            return context;
        }
예제 #8
0
 private string ReadCommand(CommandHostContext context) {
     _output.WriteLine();
     _output.Write("orchard> ");
     return _input.ReadLine();
 }
예제 #9
0
 private void LogInfo(CommandHostContext context, string format, params object[] args) {
     if (context.Logger != null)
         context.Logger.LogInfo(format, args);
 }
예제 #10
0
 public CommandHostContext CreateContext() {
     var context = new CommandHostContext { RetryResult = CommandReturnCodes.Retry };
     Initialize(context);
     return context;
 }