コード例 #1
0
ファイル: RunCommand.cs プロジェクト: FubuMvcArchive/FubuDocs
        public override bool Execute(RunInput input)
        {
            string runnerDirectory = Assembly.GetExecutingAssembly().Location.ParentDirectory();

            Task bottling = Task.Factory.StartNew(() => {
                if (!input.NoBottlingFlag)
                {
                    new BottleCommand().Execute(new BottleInput {
                        NoZipFlag = true
                    });
                }
            });

            Task cleaning     = Task.Factory.StartNew(() => cleanExplodedBottleContents(runnerDirectory));
            var  hostCleaning = Task.Factory.StartNew(() =>
            {
                if (input.HostFlag.IsNotEmpty())
                {
                    input.TryToCleanOutFubuContentFolder();
                }
            });

            Task.WaitAll(bottling, cleaning, hostCleaning);

            var directories = input.ToDirectories();

            var currentDirectory = Environment.CurrentDirectory;

            try
            {
                _application = new RemoteApplication(x => {
                    x.Setup.AppDomainInitializerArguments = new[] { JsonUtil.ToJson(directories) };
                    x.Setup.ApplicationBase = runnerDirectory;
                });

                _application.Start(input.ToRequest());

                tellUserWhatToDo();
                ConsoleKeyInfo key = Console.ReadKey();
                while (key.Key != ConsoleKey.Q)
                {
                    if (key.Key == ConsoleKey.R)
                    {
                        Environment.CurrentDirectory = currentDirectory;
                        new SnippetsCommand().Execute(new SnippetsInput());
                        _application.RecycleAppDomain();

                        ConsoleWriter.Write(ConsoleColor.Green, "Recycling successful!");

                        tellUserWhatToDo();
                    }

                    key = Console.ReadKey();

                    Console.WriteLine();
                    Console.WriteLine();
                }

                _application.Shutdown();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(true);
        }