public static void Main(string[] args)
        {
            var services = GetAllServices();

            using (var host = new WebHost())
            {
                host.Start(services);

                Console.WriteLine("Web host started");

                var serviceProvider = host.HostServiceProvider;
                var valueHolder = serviceProvider.GetService<IValueHolder>();

                valueHolder.AddOne();
                valueHolder.AddOne();
                valueHolder.AddOne();
                valueHolder.AddOne();
                Console.WriteLine($"Current value: {valueHolder.Get()}");

                while (true)
                {
                    Thread.Sleep(100);
                }
            }
        }
Exemple #2
0
#pragma warning restore 649

        public void Execute(IEnumerable<string> arguments)
        {
            Tracing.Info("taste - testing a site locally");

            parameters.Parse(arguments);

            if (string.IsNullOrWhiteSpace(parameters.Template))
            {
                parameters.DetectFromDirectory(templateEngines.Engines);
            }

            engine = templateEngines[parameters.Template];

            if (engine == null)
                return;

            var context = Generator.BuildContext(parameters.Path);
            engine.Initialize();
            engine.Process(context);

            var watcher = new SimpleFileSystemWatcher();
            watcher.OnChange(parameters.Path, WatcherOnChanged);

            var w = new WebHost(engine.GetOutputDirectory(parameters.Path), new FileContentProvider(),Convert.ToInt32(parameters.Port));
            w.Start();

            Tracing.Info(string.Format("Browse to http://localhost:{0}/ to test the site.", parameters.Port));
            Tracing.Info("Press 'Q' to stop the web host...");
            ConsoleKeyInfo key;
            do
            {
                key = Console.ReadKey();
            }
            while (key.Key != ConsoleKey.Q);
        }
Exemple #3
0
#pragma warning restore 649

        public void Execute(IEnumerable<string> arguments)
        {
            Tracing.Info("taste - testing a site locally");

            parameters.Parse(arguments);

            var context = Generator.BuildContext(parameters.Path);
            if (string.IsNullOrWhiteSpace(parameters.Template))
            {
                parameters.DetectFromDirectory(templateEngines.Engines, context);
            }

            engine = templateEngines[parameters.Template];

            if (engine == null)
            {
                Tracing.Info(string.Format("template engine {0} not found - (engines: {1})", parameters.Template,
                                           string.Join(", ", templateEngines.Engines.Keys)));

                return;
            }

            engine.Initialize();
            engine.Process(context, skipFileOnError: true);
            foreach (var t in transforms)
                t.Transform(context);
            var watcher = new SimpleFileSystemWatcher();
            watcher.OnChange(parameters.Path, WatcherOnChanged);

            var w = new WebHost(engine.GetOutputDirectory(parameters.Path), new FileContentProvider(), Convert.ToInt32(parameters.Port));
            w.Start();

            var url = string.Format("http://localhost:{0}/", parameters.Port);
            if (parameters.LaunchBrowser)
            {
                Tracing.Info(string.Format("Opening {0} in default browser...", url));
                try
                {
                    Process.Start(url);
                }
                catch (Exception)
                {
                    Tracing.Info(string.Format("Failed to launch {0}.", url));
                }
            }
            else
            {
                Tracing.Info(string.Format("Browse to {0} to view the site.", url));
            }
      
            Tracing.Info("Press 'Q' to stop the web host...");
            ConsoleKeyInfo key;
            do
            {
                key = Console.ReadKey();
            }
            while (key.Key != ConsoleKey.Q);
            Console.WriteLine();
        }
 public void GivenIHaveACleanSiteBasedOn(string siteFolder) {
     _webHost = new WebHost();
     Host.Initialize(siteFolder, "/");
     var shuttle = new Shuttle();
     Host.Execute(() => {
         log4net.Config.BasicConfigurator.Configure(new CastleAppender());
         HostingTraceListener.SetHook(msg => shuttle._sink.Receive(msg));
     });
     _messages = shuttle._sink;
 }
Exemple #5
0
        public void Execute(string[] arguments)
        {
            Settings.Parse(arguments);
            Console.WriteLine("Port: " + Port);
            Console.WriteLine("Debug: " + Debug);

            var f = new FileContentProvider();
            var w = new WebHost(Directory.GetCurrentDirectory(), f);
            w.Start();
            Console.ReadLine();
        }
Exemple #6
0
        public void Execute(string[] arguments)
        {
            Tracing.Info("taste - testing a site locally");
            Settings.Parse(arguments);
            if (Port == 0)
            {
                Port = 8080;
            }

            Tracing.Info("Port: " + Port);
            Tracing.Info("Debug: " + Debug);

            var f = new FileContentProvider();
            var w = new WebHost(Directory.GetCurrentDirectory(), f);
            w.Start();

            Tracing.Info("Press 'Q' to stop the process");
            ConsoleKeyInfo key;
            do
            {
                key = Console.ReadKey();
            }
            while (key.Key != ConsoleKey.Q);
        }
Exemple #7
0
 public void GivenIHaveACleanSiteBasedOn(string siteFolder, string virtualDirectory) {
     _webHost = new WebHost(_orchardTemp);
     Host.Initialize(siteFolder, virtualDirectory ?? "/", _dynamicCompilationOption);
     var shuttle = new Shuttle();
     Host.Execute(() => {
         log4net.Config.BasicConfigurator.Configure(new CastleAppender());
         HostingTraceListener.SetHook(msg => shuttle._sink.Receive(msg));
     });
     _messages = shuttle._sink;
 }
Exemple #8
0
 public void CleanOutTheOldWebHost() {
     if (_webHost != null) {
         _webHost.Clean();
         _webHost = null;
     }
 }
 public void GivenIHaveACleanSiteBasedOn(string siteFolder, string virtualDirectory) {
     _webHost = new WebHost(_orchardTemp);
     Host.Initialize(siteFolder, virtualDirectory ?? "/", _dynamicCompilationOption);
     var shuttle = new Shuttle();
     Host.Execute(() => Executor(shuttle));
     _messages = shuttle._sink;
 }
        /// <summary>
        /// Called if a new host was added to the hosts collection.
        /// </summary>
        /// <param name="host">The added host.</param>
        internal void HostAdded(WebHost host)
        {
            WebController controller = Controller.GetControllerFor(host);

            // No listener is listening on the hosts port.
            if (controller == null)
            {
                controller = host.Protocol.CreateController(this, new IPEndPoint(IPAddress.Loopback, host.Port));

                _controller.Add(controller);

                controller.Start();
            }
        }
        /// <summary>
        /// Called if a host was removes from the hosts collection.
        /// </summary>
        /// <param name="host">The removed host.</param>
        internal void HostRemoved(WebHost host)
        {
            WebController controller = Controller.GetControllerFor(host);

            foreach (var h in Hosts)
            {
                if (h == host)
                    continue;

                if (Controller.GetControllerFor(h) == controller)
                    return;
            }

            controller.Stop();

            _controller.Remove(controller);
        }
Exemple #12
0
 public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
 WebHost.CreateDefaultBuilder(args)
 .UseStartup <Startup>()
 .UseClassifiedAdsLogger();
 public static IWebHost BuildWebHost(string[] args) =>
     WebHost.CreateDefaultBuilder(args)
         .UseStartup<Startup>()
         .Build();
 public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
 WebHost.CreateDefaultBuilder(args)
 // Need to add a certificate to use HTTPS
 // .UseUrls("http://*:5000", "https://*:5001") // Must specify here for use inside Containers
 .UseUrls("http://*:5000")
 .UseStartup <Startup>();
Exemple #15
0
 public static IWebHostBuilder CreateWebHostBuilder(string[] args)
 {
     return(WebHost.CreateDefaultBuilder(args).UseStartup <Startup>());
 }
Exemple #16
0
        public void Execute(string[] arguments)
        {
            Tracing.Info("taste - testing a site locally");
            Settings.Parse(arguments);
            if (Port == 0)
            {
                Port = 8080;
            }

            var f = new FileContentProvider();
            if (string.IsNullOrWhiteSpace(Path))
            {
                Path = Directory.GetCurrentDirectory();
            }

            if (string.IsNullOrWhiteSpace(Engine))
            {
                Engine = InferEngineFromDirectory(Path);
            }

            engine = templateEngines[Engine];

            if (engine == null)
                return;

            var context = new SiteContext { Folder = Path };
            engine.Initialize();
            engine.Process(context);

            var watcher = new SimpleFileSystemWatcher();
            watcher.OnChange(Path, WatcherOnChanged);

            var w = new WebHost(engine.GetOutputDirectory(Path), f);
            w.Start();

            Tracing.Info("Press 'Q' to stop the web host...");
            ConsoleKeyInfo key;
            do
            {
                key = Console.ReadKey();
            }
            while (key.Key != ConsoleKey.Q);
        }
Exemple #17
0
 private static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
 WebHost.CreateDefaultBuilder(args)
 .UseKestrel()
 .UseContentRoot(Directory.GetCurrentDirectory())
 .UseStartup <Startup>();