Esempio n. 1
0
        private void LaunchBrowser(IBrowserLauncher browserLauncher, IDirectoryAccessor directoryAccessor, Uri uri)
        {
            if (StartupOptions.Uri != null &&
                !StartupOptions.Uri.IsAbsoluteUri)
            {
                uri = new Uri(uri, StartupOptions.Uri);
            }
            else if (StartupOptions.Uri == null)
            {
                var readmeFile = FindReadmeFileAtRoot();
                if (readmeFile != null)
                {
                    uri = new Uri(uri, readmeFile.ToString());
                }
            }

            browserLauncher.LaunchBrowser(uri);

            RelativeFilePath FindReadmeFileAtRoot()
            {
                var files = directoryAccessor
                            .GetAllFilesRecursively()
                            .Where(f => StringComparer.InvariantCultureIgnoreCase.Compare(f.FileName, "readme.md") == 0 && IsRoot(f.Directory))
                            .ToList();

                return(files.FirstOrDefault());
            }

            bool IsRoot(RelativeDirectoryPath path)
            {
                var isRoot = path == null || path == RelativeDirectoryPath.Root;

                return(isRoot);
            }
        }
Esempio n. 2
0
        public void Configure(
            IApplicationBuilder app,
            IHostApplicationLifetime lifetime,
            IBrowserLauncher browserLauncher,
            IDirectoryAccessor directoryAccessor,
            PackageRegistry packageRegistry)
        {
            using (var operation = Log.OnEnterAndConfirmOnExit())
            {
                lifetime.ApplicationStopping.Register(() => _disposables.Dispose());

                ConfigureForOrchestratorProxy(app);

                // Serve Blazor on the /LocalCodeRunner/blazor-console prefix
                app.Map("/LocalCodeRunner/blazor-console", blazor =>
                {
                    blazor.UseClientSideBlazorFiles <MLS.Blazor.Startup>();

                    blazor.UseRouting();

                    blazor.UseEndpoints(endpoints =>
                    {
                        endpoints.MapFallbackToClientSideBlazor <MLS.Blazor.Startup>("index.html");
                    });
                });


                var budget = new Budget();
                _disposables.Add(() => budget.Cancel());
                BlazorPackageConfiguration.Configure(app, app.ApplicationServices, packageRegistry, budget, !StartupOptions.IsLanguageService);

                app.UseMvc()
                .UseDefaultFiles()
                .UseStaticFilesFromToolLocationAndRootDirectory(directoryAccessor.GetFullyQualifiedRoot());

                operation.Succeed();

                if (StartupOptions.Mode == StartupMode.Try && !StartupOptions.IsJupyter)
                {
                    var uri = new Uri(app.ServerFeatures.Get <IServerAddressesFeature>().Addresses.First());
                    Clock.Current
                    .Schedule(_ => LaunchBrowser(browserLauncher, directoryAccessor, uri), TimeSpan.FromSeconds(1));
                }
            }
        }
Esempio n. 3
0
        public void Configure(
            IApplicationBuilder app,
            IApplicationLifetime lifetime,
            IBrowserLauncher browserLauncher,
            IDirectoryAccessor directoryAccessor,
            PackageRegistry packageRegistry)
        {
            using (var operation = Log.OnEnterAndConfirmOnExit())
            {
                lifetime.ApplicationStopping.Register(() => _disposables.Dispose());

                ConfigureForOrchestratorProxy(app);

                app.Map("/LocalCodeRunner/blazor-console", builder =>
                {
                    builder.UsePathBase("/LocalCodeRunner/blazor-console/");
                    builder.EnableCachingBlazorContent();
                    builder.UseBlazor <MLS.Blazor.Program>();
                });

                app.Map("/LocalCodeRunner/humanizer.api", builder =>
                {
                    builder.UsePathBase("/LocalCodeRunner/humanizer/");
                    builder.EnableCachingBlazorContent();
                    builder.UseBlazor <MLS.HumanizerRunner.Program>();
                });

                var budget = new Budget();
                _disposables.Add(() => budget.Cancel());
                BlazorPackageConfiguration.Configure(app, app.ApplicationServices, packageRegistry, budget, !StartupOptions.IsLanguageService);

                app.UseDefaultFiles()
                .UseStaticFilesFromToolLocation()
                .UseRouter(new StaticFilesProxyRouter())
                .UseMvc();

                operation.Succeed();

                if (StartupOptions.Mode == StartupMode.Try)
                {
                    Clock.Current
                    .Schedule(_ => LaunchBrowser(browserLauncher, directoryAccessor), TimeSpan.FromSeconds(1));
                }
            }
        }
Esempio n. 4
0
        private void LaunchBrowser(IBrowserLauncher browserLauncher, IDirectoryAccessor directoryAccessor)
        {
            var processName = Process.GetCurrentProcess().ProcessName;

            var uri = processName == "dotnet" ||
                      processName == "dotnet.exe"
                          ? new Uri("http://localhost:4242")
                          : new Uri("http://localhost:5000");

            if (StartupOptions.Uri != null &&
                !StartupOptions.Uri.IsAbsoluteUri)
            {
                uri = new Uri(uri, StartupOptions.Uri);
            }
            else if (StartupOptions.Uri == null)
            {
                var readmeFile = FindReadmeFileAtRoot();
                if (readmeFile != null)
                {
                    uri = new Uri(uri, readmeFile.ToString());
                }
            }

            browserLauncher.LaunchBrowser(uri);

            RelativeFilePath FindReadmeFileAtRoot()
            {
                var files = directoryAccessor.GetAllFilesRecursively().Where(f => (StringComparer.InvariantCultureIgnoreCase.Compare(f.FileName, "readme.md") == 0) && IsRoot(f.Directory)).ToList();

                return(files.FirstOrDefault());
            }

            bool IsRoot(RelativeDirectoryPath path)
            {
                var isRoot = path == null || path == RelativeDirectoryPath.Root;

                return(isRoot);
            }
        }
Esempio n. 5
0
 public void SetupTest()
 {
     mockProcessor = new DynamicMock(typeof (ICommandProcessor));
     processor = (ICommandProcessor) mockProcessor.MockInstance;
     mockLauncher = new DynamicMock(typeof(IBrowserLauncher));
     launcher = (IBrowserLauncher) mockLauncher.MockInstance;
     selenium = new DefaultSelenium(processor, launcher);
 }
Esempio n. 6
0
 public DefaultSelenium(ICommandProcessor processor, IBrowserLauncher launcher, string seleneseRunnerUrl)
 {
     this.processor = processor;
     this.launcher = launcher;
     this.seleneseRunnerUrl = seleneseRunnerUrl;
 }
Esempio n. 7
0
 public DefaultSelenium(ICommandProcessor processor, IBrowserLauncher launcher)
     : this(processor, launcher, SELENESE_RUNNER_URL)
 {
 }