public static void Main(string[] args) { arguments = new Arguments(); if (Parser.ParseArgumentsWithUsage(args, arguments) && arguments.IsValid()) { LoadReferences(); DeleteExistingOutputFile(); List<string> sources = GetSources(); Console.Out.WriteLine(string.Format("Castle.Tools.CodeGenerator: Parsing {0} sources...", sources.Count)); ParseSources(sources); List<string> controllerSources = GetControllerSources(); Console.Out.WriteLine(string.Format("Castle.Tools.CodeGenerator: Parsing {0} controller sources...", controllerSources.Count)); ParseControllerSources(controllerSources); List<string> viewSources = GetViewSources(); Console.Out.WriteLine(string.Format("Castle.Tools.CodeGenerator: Parsing {0} view sources...", viewSources.Count)); ParseViewSources(viewSources); string rootNamespace = GetRootNamespace(); Console.Out.WriteLine(string.Format("Castle.Tools.CodeGenerator: Using root namespace: {0}", rootNamespace)); string serviceType = typeof(ICodeGeneratorServices).FullName; string nameSpace = rootNamespace + "." + arguments.OutputNamespace; Generator generator = new Generator(nameSpace, arguments.OutputFilePath, serviceType, logger, namingService, sourceGenerator, treeCreationService); generator.Execute(); } }
public override bool Execute() { this.Log.LogMessage(MessageImportance.High, "OutputFile: {0}", this.OutputFile); this.Log.LogMessage(MessageImportance.High, "Namespace: {0}", this.Namespace); this.Log.LogMessage(MessageImportance.High, "ControllerSources: {0}", this.ControllerSources.Length); this.Log.LogMessage(MessageImportance.High, "ViewSources: {0}", this.ViewSources.Length); this.Log.LogMessage(MessageImportance.High, "ViewComponentSources: {0}", this.ViewComponentSources.Length); this.Log.LogMessage(MessageImportance.High, "Loading References..."); if (Debug) System.Diagnostics.Debugger.Launch(); foreach (ITaskItem reference in _assemblyReferences) { try { Assembly.LoadFrom(reference.ItemSpec); Log.LogMessage(MessageImportance.Low, "Loaded: {0}", reference.ItemSpec); } catch (Exception ex) { this.Log.LogMessage(MessageImportance.High, "Error loading reference: '{0}': {1}", reference.ItemSpec, ex.Message); } } if (File.Exists(this.OutputFile)) { File.Delete(this.OutputFile); } this.Log.LogMessage(MessageImportance.High, "Parsing Sources..."); foreach (ITaskItem ti in this.Sources) { string filePath = ti.GetMetadata("FullPath"); if (File.Exists(filePath)) { TypeInspectionVisitor visitor = new TypeInspectionVisitor(_typeResolver); _service.Parse(visitor, filePath); } } foreach (ITaskItem item in this.ViewComponentSources) { _typeResolver.Clear(); ViewComponentVisitor visitor = new ViewComponentVisitor(_logger, _typeResolver, _treeService); string filePath = item.GetMetadata("FullPath"); visitor.VisitCompilationUnit(_sourceStorage.GetParsedSource(filePath).CompilationUnit, null); } foreach (ITaskItem item in this.ControllerSources) { _typeResolver.Clear(); ControllerVisitor visitor = new ControllerVisitor(_logger, _typeResolver, _treeService); string filePath = item.GetMetadata("FullPath"); visitor.VisitCompilationUnit(_sourceStorage.GetParsedSource(filePath).CompilationUnit, null); } foreach (ITaskItem bi in this.ViewSources) { string filePath = bi.GetMetadata("FullPath"); _viewSourceMapper.AddViewSource(filePath); } this.Log.LogMessage(MessageImportance.High, "Generating {0}", this.OutputFile); Generator generator = new Generator(Namespace, OutputFile, ServiceTypeName, _logger, _naming, _source, _treeService); generator.Execute(); _generatedItems.Add(new TaskItem(this.OutputFile)); return true; }