Exemple #1
0
        public static int Main(string[] args)
        {
            var runtime = new ConsoleRuntime();

            string configFile     = null;
            var    languages      = new List <String>();
            string knockoutPrefix = null;
            string outputFile     = null;

            var optionSet = new NDesk.Options.OptionSet()
            {
                { "language=", "", v => languages.Add(v) },
                { "knockoutPrefix=", "", v => knockoutPrefix = v },
                { "configFile=", "", v => configFile = v },
                { "outputFile=", "", v => outputFile = v }
            };

            optionSet.Parse(args);

            if (!File.Exists(configFile))
            {
                runtime.Error("config file '{0}' does not exist: use, e.g., /configFile=<configFile.xml>", configFile);
                return(-1);
            }

            runtime.Log("Reading config file: " + configFile);

            var assemblyLoader = new AssemblyLoader(runtime);

            var generators = languages.Select(language => GetGenerator(language, knockoutPrefix, runtime)).ToArray();

            var lines         = File.ReadAllLines(configFile);
            var fileGenerator = new FileGenerator(assemblyLoader);

            string fileContent;
            var    loaded = fileGenerator.TryGenerate(configFile, lines, runtime, generators, out fileContent);

            if (!loaded)
            {
                runtime.Error("Could not generate the file for " + configFile);
                return(-2);
            }

            var fullOutputFile = Path.GetFullPath(outputFile);

            if (!File.Exists(fullOutputFile) || File.ReadAllText(fullOutputFile) != fileContent)
            {
                runtime.Log("TypeWalker is writing a new version of " + fullOutputFile);
                File.WriteAllText(fullOutputFile, fileContent);
            }
            else
            {
                runtime.Log("TypeWalker output file is up to date: " + fullOutputFile);
            }

            return(0);
        }
Exemple #2
0
        public static int Main(string[] args)
        {
            var runtime = new ConsoleRuntime();

            string configFile = null;
            var languages = new List<String>();
            string knockoutPrefix = null;
            string outputFile = null;

            var optionSet = new NDesk.Options.OptionSet() {
                    { "language=", "", v => languages.Add(v) },
                    { "knockoutPrefix=", "", v => knockoutPrefix = v },
                    { "configFile=", "", v => configFile = v },
                    { "outputFile=", "", v => outputFile = v }
                };

            optionSet.Parse(args);

            if (!File.Exists (configFile))
            {
                runtime.Error("config file '{0}' does not exist: use, e.g., /configFile=<configFile.xml>", configFile);
                return -1;
            }

            runtime.Log("Reading config file: " + configFile);

            var assemblyLoader = new AssemblyLoader(runtime);

            var generators = languages.Select(language => GetGenerator(language, knockoutPrefix, runtime)).ToArray();

            var lines = File.ReadAllLines(configFile);
            var fileGenerator = new FileGenerator(assemblyLoader);

            string fileContent;
            var loaded = fileGenerator.TryGenerate(configFile, lines, runtime, generators, out fileContent);

            if (!loaded)
            {
                runtime.Error("Could not generate the file for " + configFile);
                return -2;
            }

            var fullOutputFile = Path.GetFullPath(outputFile);

            if (!File.Exists(fullOutputFile) || File.ReadAllText(fullOutputFile) != fileContent)
            {
                runtime.Log("TypeWalker is writing a new version of " + fullOutputFile);
                File.WriteAllText(fullOutputFile, fileContent);
            }
            else
            {
                runtime.Log("TypeWalker output file is up to date: " + fullOutputFile);
            }

            return 0;
        }