public DefaultHost(DefaultHostOptions options, IServiceProvider hostServices) { _projectDirectory = Path.GetFullPath(options.ApplicationBaseDirectory); _targetFramework = options.TargetFramework; Initialize(options, hostServices); }
private void Initialize(DefaultHostOptions options, IServiceProvider hostServices) { var cacheContextAccessor = new CacheContextAccessor(); var cache = new Cache(cacheContextAccessor); var namedCacheDependencyProvider = new NamedCacheDependencyProvider(); _applicationHostContext = new ApplicationHostContext( hostServices, _projectDirectory, options.PackageDirectory, options.Configuration, _targetFramework, cache, cacheContextAccessor, namedCacheDependencyProvider); Logger.TraceInformation("[{0}]: Project path: {1}", GetType().Name, _projectDirectory); Logger.TraceInformation("[{0}]: Project root: {1}", GetType().Name, _applicationHostContext.RootDirectory); Logger.TraceInformation("[{0}]: Packages path: {1}", GetType().Name, _applicationHostContext.PackagesDirectory); _project = _applicationHostContext.Project; if (Project == null) { throw new Exception("Unable to locate " + Project.ProjectFileName); } if (options.WatchFiles) { var watcher = new FileWatcher(_applicationHostContext.RootDirectory); _watcher = watcher; watcher.OnChanged += _ => { _shutdown.RequestShutdownWaitForDebugger(); }; } else { _watcher = NoopWatcher.Instance; } _applicationHostContext.AddService(typeof(IApplicationShutdown), _shutdown); _applicationHostContext.AddService(typeof(IRuntimeOptions), options); // TODO: Get rid of this and just use the IFileWatcher _applicationHostContext.AddService(typeof(IFileMonitor), _watcher); _applicationHostContext.AddService(typeof(IFileWatcher), _watcher); if (options.CompilationServerPort.HasValue) { // Change the project reference provider Project.DefaultCompiler = Project.DefaultDesignTimeCompiler; } CallContextServiceLocator.Locator.ServiceProvider = ServiceProvider; }
private void Initialize(DefaultHostOptions options, IServiceProvider hostServices) { _applicationHostContext = new ApplicationHostContext( hostServices, _projectDirectory, options.PackageDirectory, options.Configuration, _targetFramework); Trace.TraceInformation("[{0}]: Project path: {1}", GetType().Name, _projectDirectory); Trace.TraceInformation("[{0}]: Project root: {1}", GetType().Name, _applicationHostContext.RootDirectory); Trace.TraceInformation("[{0}]: Packages path: {1}", GetType().Name, _applicationHostContext.PackagesDirectory); _project = _applicationHostContext.Project; if (Project == null) { throw new Exception("Unable to locate " + Project.ProjectFileName); } if (options.WatchFiles) { var watcher = new FileWatcher(_applicationHostContext.RootDirectory); _watcher = watcher; watcher.OnChanged += _ => { _shutdown.RequestShutdownWaitForDebugger(); }; } else { _watcher = NoopWatcher.Instance; } var applicationEnvironment = new ApplicationEnvironment(Project, _targetFramework, options.Configuration); _applicationHostContext.AddService(typeof(IApplicationEnvironment), applicationEnvironment); _applicationHostContext.AddService(typeof(IApplicationShutdown), _shutdown); // TODO: Get rid of this and just use the IFileWatcher _applicationHostContext.AddService(typeof(IFileMonitor), _watcher); _applicationHostContext.AddService(typeof(IFileWatcher), _watcher); CallContextServiceLocator.Locator.ServiceProvider = ServiceProvider; }
private void Initialize(DefaultHostOptions options, IServiceProvider hostServices) { var cacheContextAccessor = new CacheContextAccessor(); var cache = new Cache(cacheContextAccessor); var namedCacheDependencyProvider = new NamedCacheDependencyProvider(); _applicationHostContext = new ApplicationHostContext( hostServices, _projectDirectory, options.PackageDirectory, options.Configuration, _targetFramework, cache, cacheContextAccessor, namedCacheDependencyProvider); Logger.TraceInformation("[{0}]: Project path: {1}", GetType().Name, _projectDirectory); Logger.TraceInformation("[{0}]: Project root: {1}", GetType().Name, _applicationHostContext.RootDirectory); Logger.TraceInformation("[{0}]: Packages path: {1}", GetType().Name, _applicationHostContext.PackagesDirectory); _project = _applicationHostContext.Project; if (Project == null) { throw new Exception("Unable to locate " + Project.ProjectFileName); } if (options.WatchFiles) { var watcher = new FileWatcher(_applicationHostContext.RootDirectory); _watcher = watcher; watcher.OnChanged += _ => { _shutdown.RequestShutdownWaitForDebugger(); }; } else { _watcher = NoopWatcher.Instance; } _applicationHostContext.AddService(typeof(IApplicationShutdown), _shutdown); // TODO: Get rid of this and just use the IFileWatcher _applicationHostContext.AddService(typeof(IFileMonitor), _watcher); _applicationHostContext.AddService(typeof(IFileWatcher), _watcher); if (options.CompilationServerPort.HasValue) { // Using this ctor because it works on mono, this is hard coded to ipv4 // right now. Mono will eventually have the dualmode overload var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(new IPEndPoint(IPAddress.Loopback, options.CompilationServerPort.Value)); var networkStream = new NetworkStream(socket); _applicationHostContext.AddService(typeof(IDesignTimeHostCompiler), new DesignTimeHostCompiler(_shutdown, _watcher, networkStream), includeInManifest: false); // Change the project reference provider Project.DefaultLanguageService = new TypeInformation( typeof(DefaultHost).GetTypeInfo().Assembly.GetName().Name, typeof(DesignTimeHostProjectReferenceProvider).FullName); } CallContextServiceLocator.Locator.ServiceProvider = ServiceProvider; }
private bool ParseArgs(string[] args, out DefaultHostOptions defaultHostOptions, out string[] outArgs, out int exitCode) { var app = new CommandLineApplication(throwOnUnexpectedArg: false); app.Name = "Microsoft.Framework.ApplicationHost"; app.FullName = app.Name; var optionWatch = app.Option("--watch", "Watch file changes", CommandOptionType.NoValue); var optionPackages = app.Option("--packages <PACKAGE_DIR>", "Directory containing packages", CommandOptionType.SingleValue); var optionConfiguration = app.Option("--configuration <CONFIGURATION>", "The configuration to run under", CommandOptionType.SingleValue); var optionCompilationServer = app.Option("--port <PORT>", "The port to the compilation server", CommandOptionType.SingleValue); var runCmdExecuted = false; app.HelpOption("-?|-h|--help"); var env = (IRuntimeEnvironment)_serviceProvider.GetService(typeof(IRuntimeEnvironment)); app.VersionOption("--version", () => env.GetShortVersion(), () => env.GetFullVersion()); var runCmd = app.Command("run", c => { // We don't actually execute "run" command here // We are adding this command for the purpose of displaying correct help information c.Description = "Run application"; c.OnExecute(() => { runCmdExecuted = true; return 0; }); }, addHelpCommand: false, throwOnUnexpectedArg: false); app.Execute(args); defaultHostOptions = null; outArgs = null; exitCode = 0; if (app.IsShowingInformation) { // If help option or version option was specified, exit immediately with 0 exit code return true; } else if (!(app.RemainingArguments.Any() || runCmdExecuted)) { // If no subcommand was specified, show error message // and exit immediately with non-zero exit code Console.WriteLine("Please specify the command to run"); exitCode = 2; return true; } defaultHostOptions = new DefaultHostOptions(); defaultHostOptions.WatchFiles = optionWatch.HasValue(); defaultHostOptions.PackageDirectory = optionPackages.Value(); defaultHostOptions.TargetFramework = _environment.RuntimeFramework; defaultHostOptions.Configuration = optionConfiguration.Value() ?? _environment.Configuration ?? "Debug"; defaultHostOptions.ApplicationBaseDirectory = _environment.ApplicationBasePath; var portValue = optionCompilationServer.Value() ?? Environment.GetEnvironmentVariable(EnvironmentNames.CompilationServerPort); int port; if (!string.IsNullOrEmpty(portValue) && int.TryParse(portValue, out port)) { defaultHostOptions.CompilationServerPort = port; } var remainingArgs = new List<string>(); if (runCmdExecuted) { // Later logic will execute "run" command // So we put this argment back after it was consumed by parser remainingArgs.Add("run"); remainingArgs.AddRange(runCmd.RemainingArguments); } else { remainingArgs.AddRange(app.RemainingArguments); } if (remainingArgs.Any()) { defaultHostOptions.ApplicationName = remainingArgs[0]; outArgs = remainingArgs.Skip(1).ToArray(); } else { outArgs = remainingArgs.ToArray(); } return false; }
private bool ParseArgs(string[] args, out DefaultHostOptions defaultHostOptions, out string[] outArgs) { var app = new CommandLineApplication(throwOnUnexpectedArg: false); app.Name = "k"; var optionWatch = app.Option("--watch", "Watch file changes", CommandOptionType.NoValue); var optionPackages = app.Option("--packages <PACKAGE_DIR>", "Directory containing packages", CommandOptionType.SingleValue); var optionConfiguration = app.Option("--configuration <CONFIGURATION>", "The configuration to run under", CommandOptionType.SingleValue); var runCmdExecuted = false; app.HelpOption("-?|-h|--help"); app.VersionOption("--version", GetVersion()); var runCmd = app.Command("run", c => { // We don't actually execute "run" command here // We are adding this command for the purpose of displaying correct help information c.Description = "Run application"; c.OnExecute(() => { runCmdExecuted = true; return 0; }); }, addHelpCommand: false, throwOnUnexpectedArg: false); app.Execute(args); if (!(app.IsShowingInformation || app.RemainingArguments.Any() || runCmdExecuted)) { app.ShowHelp(commandName: null); } defaultHostOptions = new DefaultHostOptions(); defaultHostOptions.WatchFiles = optionWatch.HasValue(); defaultHostOptions.PackageDirectory = optionPackages.Value(); defaultHostOptions.TargetFramework = _environment.TargetFramework; defaultHostOptions.Configuration = optionConfiguration.Value() ?? _environment.Configuration ?? "Debug"; defaultHostOptions.ApplicationBaseDirectory = _environment.ApplicationBasePath; var remainingArgs = new List<string>(); if (runCmdExecuted) { // Later logic will execute "run" command // So we put this argment back after it was consumed by parser remainingArgs.Add("run"); remainingArgs.AddRange(runCmd.RemainingArguments); } else { remainingArgs.AddRange(app.RemainingArguments); } if (remainingArgs.Any()) { defaultHostOptions.ApplicationName = remainingArgs[0]; outArgs = remainingArgs.Skip(1).ToArray(); } else { outArgs = remainingArgs.ToArray(); } return app.IsShowingInformation; }