public static void GenerateSourceFor(SourceGeneratorOptions options) { var uml = new _UML(); var extent = new MofUriExtent("dm:///sourcegenerator"); var factory = new MofFactory(); // Creates the dotnet types to real MOF Types var dotNetProvider = new DotNetTypeGenerator(factory, uml); var package = factory.create(uml.Packages.__Package); package.set("name", options.Name); // Do the conversion var elements = new List<IElement>(); foreach (var type in options.Types) { var typeObject = dotNetProvider.CreateTypeFor(type); elements.Add(typeObject); } package.set(_UML._Packages._Package.packagedElement, elements); // Adds the package extent.elements().add(package); var sourceParser = new ElementSourceParser(uml); // Creates the class tree var classTreeGenerator = new ClassTreeGenerator(sourceParser) { Namespace = options.Namespace }; classTreeGenerator.Walk(extent); var sourceClass = classTreeGenerator.Result.ToString(); var pathOfClassTree = Path.ChangeExtension( Path.Combine( options.Path, options.Name), ".class.cs"); File.WriteAllText(pathOfClassTree, sourceClass); // Creates now the filler var fillerGenerator = new FillClassTreeByExtentCreator(options.Name + "Filler", sourceParser) { Namespace = options.Namespace, ClassNameOfTree = classTreeGenerator.UsedClassName }; fillerGenerator.Walk(extent); var sourceFiller = fillerGenerator.Result.ToString(); var pathOfFillerTree = Path.ChangeExtension( Path.Combine( options.Path, options.Name), ".filler.cs"); File.WriteAllText(pathOfFillerTree, sourceFiller); }
public static void Main(string[] args) { var factory = new MofFactory(); var umlExtent = new MofUriExtent("datenmeister:///uml"); var mofExtent = new MofUriExtent("datenmeister:///mof"); var primitiveTypeExtent = new MofUriExtent("datenmeister:///primitivetypes"); var loader = new SimpleLoader(factory); loader.Load(umlExtent, "data/UML.xmi"); loader.Load(mofExtent, "data/MOF.xmi"); loader.Load(primitiveTypeExtent, "data/PrimitiveTypes.xmi"); // Generates tree for UML var generator = new ClassTreeGenerator { Namespace = "DatenMeister" }; generator.Walk(umlExtent); var extentCreator = new FillClassTreeByExtentCreator("DatenMeister._UML") { Namespace = "DatenMeister.Filler" }; extentCreator.Walk(umlExtent); File.WriteAllText("../../uml.cs", generator.Result.ToString()); File.WriteAllText("../../FillTheUML.cs", extentCreator.Result.ToString()); Console.WriteLine("C# Code for UML written"); // Generates tree for MOF generator = new ClassTreeGenerator { Namespace = "DatenMeister" }; generator.Walk(mofExtent); extentCreator = new FillClassTreeByExtentCreator("DatenMeister._MOF") { Namespace = "DatenMeister.Filler" }; extentCreator.Walk(mofExtent); File.WriteAllText("../../mof.cs", generator.Result.ToString()); File.WriteAllText("../../FillTheMOF.cs", extentCreator.Result.ToString()); Console.WriteLine("C# Code for MOF written"); // Generates tree for PrimitiveTypes generator = new ClassTreeGenerator { Namespace = "DatenMeister" }; generator.Walk(primitiveTypeExtent); extentCreator = new FillClassTreeByExtentCreator("DatenMeister._PrimitiveTypes") { Namespace = "DatenMeister.Filler" }; extentCreator.Walk(primitiveTypeExtent); File.WriteAllText("../../primitivetypes.cs", generator.Result.ToString()); File.WriteAllText("../../FillThePrimitiveTypes.cs", extentCreator.Result.ToString()); Console.WriteLine("C# Code for PrimitiveTypes written"); #if !DEBUG File.Copy("../../primitivetypes.cs", "../../../DatenMeister/Filler/primitivetypes.cs", true); File.Copy("../../FillThePrimitiveTypes.cs", "../../../DatenMeister/Filler/FillThePrimitiveTypes.cs", true); File.Copy("../../mof.cs", "../../../DatenMeister/Filler/mof.cs", true); File.Copy("../../FillTheMOF.cs", "../../../DatenMeister/Filler/FillTheMOF.cs", true); File.Copy("../../uml.cs", "../../../DatenMeister/Filler/uml.cs", true); File.Copy("../../FillTheUML.cs", "../../../DatenMeister/Filler/FillTheUML.cs", true); #endif }