示例#1
0
        protected override void DoExecute(IProgressMonitor monitor, ExecutionContext context, ConfigurationSelector config)
        {
            //check XSP is available

            var configuration = (AspNetAppProjectConfiguration)GetConfiguration(config);
            var cmd           = CreateExecutionCommand(config, configuration);

            IConsole console          = null;
            var      operationMonitor = new AggregatedOperationMonitor(monitor);

            try {
                if (configuration.ExternalConsole)
                {
                    console = context.ExternalConsoleFactory.CreateConsole(!configuration.PauseConsoleOutput);
                }
                else
                {
                    console = context.ConsoleFactory.CreateConsole(!configuration.PauseConsoleOutput);
                }

                string url = String.Format("http://{0}:{1}", this.XspParameters.Address, this.XspParameters.Port);

                bool isXsp = true;                 //FIXME: fix this when it might not be true

                if (isXsp)
                {
                    console = new XspBrowserLauncherConsole(console, delegate {
                        BrowserLauncher.LaunchDefaultBrowser(url);
                    });
                }

                monitor.Log.WriteLine("Running web server...");

                var op = context.ExecutionHandler.Execute(cmd, console);
                operationMonitor.AddOperation(op);                  //handles cancellation

                if (!isXsp)
                {
                    BrowserLauncher.LaunchDefaultBrowser(url);
                }

                op.WaitForCompleted();

                monitor.Log.WriteLine("The web server exited with code: {0}", op.ExitCode);
            } catch (Exception ex) {
                monitor.ReportError("Could not launch web server.", ex);
            } finally {
                operationMonitor.Dispose();
                if (console != null)
                {
                    console.Dispose();
                }
            }
        }
        protected override void DoExecute(IProgressMonitor monitor, ExecutionContext context, ConfigurationSelector config)
        {
            //check XSP is available

            var configuration = (AspNetAppProjectConfiguration)GetConfiguration(config);
            var cmd           = CreateExecutionCommand(config, configuration);

            IConsole console          = null;
            var      operationMonitor = new AggregatedOperationMonitor(monitor);

            bool isXsp = true;             //FIXME: fix this when it might not be true - should delegate to the ExecutionHandler

            try {
                //HACK: check XSP exists first, because error UX is cleaner w/o displaying a blank console pad.
                if (isXsp)
                {
                    try {
                        AspNetExecutionHandler.GetXspPath((AspNetExecutionCommand)cmd);
                    } catch (UserException ex) {
                        MessageService.ShowError(
                            GettextCatalog.GetString("Could not launch ASP.NET web server"),
                            ex.Message);
                        throw;
                    }
                }

                if (configuration.ExternalConsole)
                {
                    console = context.ExternalConsoleFactory.CreateConsole(!configuration.PauseConsoleOutput);
                }
                else
                {
                    console = context.ConsoleFactory.CreateConsole(!configuration.PauseConsoleOutput);
                }

                string url = String.Format("http://{0}:{1}", this.XspParameters.Address, this.XspParameters.Port);


                if (isXsp)
                {
                    console = new XspBrowserLauncherConsole(console, delegate {
                        BrowserLauncher.LaunchDefaultBrowser(url);
                    });
                }

                monitor.Log.WriteLine("Running web server...");

                var op = context.ExecutionHandler.Execute(cmd, console);
                operationMonitor.AddOperation(op);                  //handles cancellation

                if (!isXsp)
                {
                    BrowserLauncher.LaunchDefaultBrowser(url);
                }

                op.WaitForCompleted();

                monitor.Log.WriteLine("The web server exited with code: {0}", op.ExitCode);
            } catch (Exception ex) {
                if (!(ex is UserException))
                {
                    LoggingService.LogError("Could not launch ASP.NET web server.", ex);
                }
                monitor.ReportError("Could not launch web server.", ex);
            } finally {
                operationMonitor.Dispose();
                if (console != null)
                {
                    console.Dispose();
                }
            }
        }
        protected async override Task OnExecute(ProgressMonitor monitor, ExecutionContext context, ConfigurationSelector configuration, SolutionItemRunConfiguration runConfiguration)
        {
            //check XSP is available

            var cfg = GetConfiguration(configuration);
            var cmd = CreateExecutionCommand(configuration, cfg);
            var browserExcTarget = context.ExecutionTarget as BrowserExecutionTarget;

            OperationConsole console = null;

            bool isXsp = true;             //FIXME: fix this when it might not be true - should delegate to the ExecutionHandler

            try {
                //HACK: check XSP exists first, because error UX is cleaner w/o displaying a blank console pad.
                if (isXsp)
                {
                    try {
                        AspNetExecutionHandler.GetXspPath((AspNetExecutionCommand)cmd);
                    } catch (UserException ex) {
                        MessageService.ShowError(
                            GettextCatalog.GetString("Could not launch ASP.NET web server"),
                            ex.Message);
                        throw;
                    }
                }

                console = context.ConsoleFactory.CreateConsole(monitor.CancellationToken);

                // The running Port value is now captured in the XspBrowserLauncherConsole object
                string url = String.Format("http://{0}", XspParameters.Address);


                if (isXsp)
                {
                    console = new XspBrowserLauncherConsole(console, delegate(string port) {
                        if (browserExcTarget != null)
                        {
                            browserExcTarget.DesktopApp.Launch(String.Format("{0}:{1}", url, port));
                        }
                        else
                        {
                            BrowserLauncher.LaunchDefaultBrowser(String.Format("{0}:{1}", url, port));
                        }
                    });
                }

                monitor.Log.WriteLine(GettextCatalog.GetString("Running web server..."));

                var op = context.ExecutionHandler.Execute(cmd, console);

                if (!isXsp)
                {
                    if (browserExcTarget != null)
                    {
                        browserExcTarget.DesktopApp.Launch(url);
                    }
                    else
                    {
                        BrowserLauncher.LaunchDefaultBrowser(url);
                    }
                }

                using (monitor.CancellationToken.Register(op.Cancel))
                    await op.Task;

                monitor.Log.WriteLine(GettextCatalog.GetString("The web server exited with code: {0}", op.ExitCode));
            } catch (Exception ex) {
                if (!(ex is UserException))
                {
                    LoggingService.LogError("Could not launch ASP.NET web server.", ex);
                }
                monitor.ReportError(GettextCatalog.GetString("Could not launch web server."), ex);
            } finally {
                if (console != null)
                {
                    console.Dispose();
                }
            }
        }
        public IProcessAsyncOperation Execute(ExecutionCommand command, IConsole console)
        {
            var cmd = (MoonlightExecutionCommand)command;

            return(BrowserLauncher.LaunchDefaultBrowser(cmd.Url));
        }