Example #1
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);
        }
Example #2
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();
        }
Example #3
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);
        }
Example #4
0
        protected override Task <int> Execute(TasteCommandArguments arguments)
        {
            Tracing.Info("taste - testing a site locally");

            var context = Generator.BuildContext(arguments.Source, arguments.Destination, arguments.Drafts);

            if (arguments.CleanTarget && FileSystem.Directory.Exists(context.OutputFolder))
            {
                FileSystem.Directory.Delete(context.OutputFolder, true);
            }

            if (string.IsNullOrWhiteSpace(arguments.Template))
            {
                arguments.DetectFromDirectory(TemplateEngines.Engines, context);
            }

            engine = TemplateEngines[arguments.Template];

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

                return(Task.FromResult(1));
            }

            engine.Initialize();
            engine.Process(context, skipFileOnError: true);
            foreach (var t in Transforms)
            {
                t.Transform(context);
            }

            using (var watcher = new SimpleFileSystemWatcher(arguments.Destination))
            {
                watcher.OnChange(arguments.Source, file => WatcherOnChanged(file, arguments));

                using (var w = new WebHost(arguments.Destination, new FileContentProvider(), Convert.ToInt32(arguments.Port)))
                {
                    try
                    {
                        w.Start();
                    }
                    catch (System.Net.Sockets.SocketException)
                    {
                        Tracing.Info("Port {0} is already in use", arguments.Port);

                        return(Task.FromResult(1));
                    }

                    var url = string.Format("http://localhost:{0}/", arguments.Port);
                    if (arguments.LaunchBrowser)
                    {
                        Tracing.Info("Opening {0} in default browser...", url);
                        try
                        {
                            System.Diagnostics.Process.Start(url);
                        }
                        catch (Exception)
                        {
                            Tracing.Info("Failed to launch {0}.", url);
                        }
                    }
                    else
                    {
                        Tracing.Info("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();
                }
            }

            return(Task.FromResult(0));
        }
Example #5
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, parameters.IncludeDrafts);

            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();
        }
Example #6
0
        protected async override Task <int> Execute(TasteCommandArguments arguments)
        {
            Tracing.Info("taste - testing a site locally");

            var context = Generator.BuildContext(arguments.Source, arguments.Destination, arguments.Drafts);

            if (arguments.CleanTarget && FileSystem.Directory.Exists(context.OutputFolder))
            {
                FileSystem.Directory.Delete(context.OutputFolder, true);
            }

            if (string.IsNullOrWhiteSpace(arguments.Template))
            {
                arguments.DetectFromDirectory(TemplateEngines.Engines, context);
            }

            engine = TemplateEngines[arguments.Template];

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

                return(1);
            }

            engine.Initialize();
            engine.Process(context, skipFileOnError: true);
            foreach (var t in Transforms)
            {
                t.Transform(context);
            }

            using (var watcher = new SimpleFileSystemWatcher(arguments.Destination))
            {
                watcher.OnChange(arguments.Source, file => WatcherOnChanged(file, arguments));

                using (var w = new AspNetCoreWebHost(arguments.Destination, Convert.ToInt32(arguments.Port), arguments.Debug))
                {
                    try
                    {
                        await w.Start();
                    }
                    catch (IOException ex) when(ex.InnerException is AddressInUseException)
                    {
                        Tracing.Info("Port {0} is already in use", arguments.Port);

                        return(1);
                    }

                    var url = string.Format("http://localhost:{0}/", arguments.Port);
                    if (arguments.LaunchBrowser)
                    {
                        Tracing.Info("Opening {0} in default browser...", url);
                        try
                        {
                            // How to launch browser on netcore
                            // https://github.com/dotnet/corefx/issues/10361
                            var psi = new System.Diagnostics.ProcessStartInfo
                            {
                                FileName        = url,
                                UseShellExecute = true
                            };
                            System.Diagnostics.Process.Start(psi);
                        }
                        catch (Exception)
                        {
                            Tracing.Info("Failed to launch {0}.", url);
                        }
                    }
                    else
                    {
                        Tracing.Info("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();
                }
            }

            return(0);
        }