Example #1
0
        public static void WriteFile(string fileName, string contents)
        {
            fileName = Path.GetFullPath(fileName);

            if (File.Exists(fileName))
            {
                if (!ConsoleHelpers.AskForYesNo($"The file '{fileName}' already exists! Overwrite?"))
                {
                    throw new Exception("The operation was aborted!");
                }
            }

            var directory = Path.GetDirectoryName(fileName);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            File.WriteAllText(fileName, contents, Encoding.UTF8);
            Console.WriteLine($"Created {fileName}");
        }
Example #2
0
        public static void Main(string[] args)
        {
            // get configuration
            var metadataService = new DotvvmProjectMetadataService();
            var metadata        = metadataService.FindInDirectory(Directory.GetCurrentDirectory());

            if (metadata == null)
            {
                Console.WriteLine("No DotVVM project metadata file (.dotvvm.json) was found on current path.");
                if (ConsoleHelpers.AskForYesNo("Is the current directory the root directory of DotVVM project?"))
                {
                    Console.WriteLine();
                    metadata = metadataService.CreateDefaultConfiguration(Directory.GetCurrentDirectory());
                    metadataService.Save(metadata);
                }
                else
                {
                    Console.WriteLine("There is no DotVVM project metadata file!");
                    Environment.Exit(1);
                }
            }

            // find applicable command
            var commands = new CommandBase[]
            {
                new AddPageCommand(),
                new AddMasterPageCommand(),
                new AddViewModelCommand(),
                new AddControlCommand(),
                new AddNswagCommand(),
                new RegenNswagCommand()

                //new GenerateUiTestStubCommand()
            };
            var arguments = new Arguments(args);
            var command   = commands.FirstOrDefault(c => c.TryConsumeArgs(arguments, metadata));

            // execute the command
            try
            {
                if (command != null)
                {
                    command.Handle(arguments, metadata);

                    // save project metadata
                    metadataService.Save(metadata);
                }
                else
                {
                    throw new InvalidCommandUsageException("Unknown command!");
                }
            }
            catch (InvalidCommandUsageException ex)
            {
                Console.WriteLine("Invalid Command Usage: " + ex);
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: " + ex.Message);
                Console.Error.WriteLine(ex.ToString());
                Environment.Exit(1);
            }
        }