TinySite.Program.Run C# (CSharp) Méthode

Run() public méthode

public Run ( CommandLine commandLine ) : void
commandLine CommandLine
Résultat void
        public void Run(CommandLine commandLine)
        {
            var config = this.LoadConfig(commandLine.SitePath, commandLine.OutputPath);

            var lastRunState = this.LoadLastRunState(commandLine.SitePath);

            switch (commandLine.Command)
            {
                case ProcessingCommand.Render:
                    {
                        var engines = RenderingEngine.Load();
                        var command = new RunRenderCommand(config, lastRunState, engines);
                        lastRunState = command.Execute();
                    }
                    break;

                case ProcessingCommand.Serve:
                    {
                        var command = new RunServeCommand(config, commandLine.Port);
                        command.Execute();
                    }
                    break;

                case ProcessingCommand.Watch:
                    {
                        var engines = RenderingEngine.Load();
                        var command = new RunWatchCommand(config, commandLine.Port, lastRunState, engines);
                        command.Execute();
                    }
                    break;

                default:
                    throw new InvalidOperationException($"Unknown ProcessingCommand: {commandLine.Command}");
            }

            this.SaveLastRunState(commandLine.SitePath, lastRunState);
        }

Usage Example

Exemple #1
0
        public static int Main(string[] args)
        {
            // Parse the command line and if there are any errors, bail.
            //
            var commandLine = CommandLine.Parse(args);

            if (commandLine.Help)
            {
                CommandLine.DisplayHelp();
                return 0;
            }

            if (commandLine.Errors.Any())
            {
                foreach (var error in commandLine.Errors)
                {
                    Console.WriteLine(error);
                }

                return -2;
            }

            // Run the program.
            //
            try
            {
                Console.WriteLine("Processing site: {0}", Path.GetFullPath(commandLine.SitePath));

                var program = new Program();

                using (var capture = Statistics.Current.Start(StatisticTiming.Overall))
                {
                    program.Run(commandLine);
                }

                if (commandLine.ReportStatistics)
                {
                    Statistics.Current.Report();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}", e);
                return -1;
            }

            return 0;
        }