private static void Main( string[] args ) { DateTime start = DateTime.Now; if( ParseCommandLine( args ) ) return; // Was a directory provided as input? if( !File.Exists( GeneratorContext.InputFile ) && Directory.Exists( GeneratorContext.InputFile ) ) { DirectoryInfo inputDirectory = new DirectoryInfo( GeneratorContext.InputFile ); FileInfo[] extensionFiles = inputDirectory.GetFiles( "*.extgen" ); if( 0 == extensionFiles.Length ) { Log.Error( "A directory was provided as input, but it contained no .extgen files." ); return; } if( 1 < extensionFiles.Length ) { Log.Warn( "A directory was provided as input, but it contained more than 1 .extgen file." ); return; } GeneratorContext.InputFile = extensionFiles.First().FullName; } else if( !File.Exists( GeneratorContext.InputFile ) ) { Log.ErrorFormat( "The given input file '{0}' does not exist.", GeneratorContext.InputFile ); return; } if( string.IsNullOrEmpty( GeneratorContext.OutputDirectory ) ) { GeneratorContext.OutputDirectory = "output"; } if( string.IsNullOrEmpty( GeneratorContext.InputFile ) ) { Log.Fatal( "No input file given." ); return; } // Set the working directory to the directory name of the extension description Directory.SetCurrentDirectory( new FileInfo( GeneratorContext.InputFile ).DirectoryName ); // I hate small console windows! try { Console.WindowWidth = 160; Console.WindowHeight = 50; } catch( IOException ) { // Maybe there is no console window (stream redirection) } Log.InfoFormat( "Reading '{0}'...", GeneratorContext.InputFile ); string markup = File.ReadAllText( GeneratorContext.InputFile ); try { Log.Info( "Parsing..." ); Extension extension = ExtensionParser.Parse( markup, GeneratorContext.InputFile ); Log.InfoFormat( "Found extension definition for '{0}'", extension.Key ); Log.InfoFormat( "Compatibility level '{0}'", GeneratorContext.TargetVersion.Version ); string cacheFile = Path.Combine( Environment.CurrentDirectory, extension.Key + ".cache" ); GeneratorContext.OutputDirectory = Path.Combine( Environment.CurrentDirectory, GeneratorContext.OutputDirectory ); ExtensionGenerator generator = new ExtensionGenerator( GeneratorContext, extension ); AbstractGenerator.StartCachingSession( cacheFile ); generator.Generate(); AbstractGenerator.EndCachingSession( cacheFile ); Console.WriteLine( "{1} finished after {0}", DateTime.Now.Subtract( start ), "T3EG v." + Assembly.GetExecutingAssembly().GetName().Version ); } catch( ParserException parserException ) { Log.Error( parserException ); } catch( GeneratorException generatorException ) { Log.Error( generatorException ); } }
/// <summary> /// Helper construct to parse a given markup /// </summary> /// <param name="markup"></param> private void ParseMarkup( string markup ) { Extension extension = ExtensionParser.Parse( markup, "<unit test>" ); ExtensionGenerator generator = new ExtensionGenerator( Context.GetTemporaryContext(), extension ); generator.Generate(); }