public CodeEntityTypeDeclaration(WXMLCodeDomGeneratorSettings settings, WormCodeDomGenerator gen) { m_typeReference = new CodeTypeReference(); m_propertiesAccessor = new Dictionary <string, CodePropertiesAccessorTypeDeclaration>(); PopulateMembers += OnPopulateMembers; //_useType = useType; _settings = settings; _gen = gen; }
public Enumer(WXMLModel model, string ext) { _model = model; //Create the CodeCompileUnit from the passed-in XML file WXMLCodeDomGeneratorSettings settings = new WXMLCodeDomGeneratorSettings(); settings.EntitySchemaDefClassNameSuffix = "SchemaDef"; LinqToCodedom.CodeDomGenerator.Language language; switch (ext) { case ".cs": settings.LanguageSpecificHacks = LanguageSpecificHacks.CSharp; language = LinqToCodedom.CodeDomGenerator.Language.CSharp; break; case ".vb": settings.LanguageSpecificHacks = LanguageSpecificHacks.VisualBasic; language = LinqToCodedom.CodeDomGenerator.Language.VB; break; default: throw new NotSupportedException(ext); //case ".js": // settings.LanguageSpecificHacks = LanguageSpecificHacks.VisualBasic; // break; } settings.PrivateMembersPrefix = "m_"; //settings.Split = false; //ormObjectsDef.GenerateSchemaOnly WormCodeDomGenerator generator = new WormCodeDomGenerator(model, settings); if (model.GenerateSingleFile) { CodeCompileFileUnit compileUnit = generator.GetFullSingleUnit(language); _units = new List <Pair>() { new Pair() { Unit = compileUnit } }; } else { _units = new List <Pair>(); foreach (var entity in model.GetActiveEntities()) { _units.Add(new Pair() { Unit = generator.GetEntityCompileUnits(entity.Identifier, language)[0] }); } } }
private static Assembly CompileCode(CodeDomProvider prov, bool v35, WXMLCodeDomGeneratorSettings settings, WXMLModel model, params CodeCompileUnit[] units) { WormCodeDomGenerator gen = new WormCodeDomGenerator(model, settings); CompilerResults result; CompilerParameters prms = new CompilerParameters { GenerateExecutable = false, GenerateInMemory = true, IncludeDebugInformation = false, TreatWarningsAsErrors = false/*, * OutputAssembly = "testAssembly.dll"*/ }; prms.ReferencedAssemblies.Add("System.dll"); prms.ReferencedAssemblies.Add("System.Data.dll"); prms.ReferencedAssemblies.Add("System.XML.dll"); if (v35) { prms.ReferencedAssemblies.Add("System.Core.dll"); } if ((settings.GenerateMode.HasValue ? settings.GenerateMode.Value : model.GenerateMode) != GenerateModeEnum.EntityOnly) { //prms.ReferencedAssemblies.Add("CoreFramework.dll"); prms.ReferencedAssemblies.Add("Worm.Orm.dll"); if (model.LinqSettings != null && model.LinqSettings.Enable) { prms.ReferencedAssemblies.Add("Worm.Linq.dll"); } } prms.TempFiles.KeepFiles = true; CodeCompileUnit singleUnit = new CodeCompileUnit(); if (settings.SingleFile.HasValue ? settings.SingleFile.Value : model.GenerateSingleFile) { singleUnit = gen.GetFullSingleUnit(typeof(Microsoft.VisualBasic.VBCodeProvider).IsAssignableFrom(prov.GetType()) ? LinqToCodedom.CodeDomGenerator.Language.VB : LinqToCodedom.CodeDomGenerator.Language.CSharp); singleUnit.Namespaces.Add(new CodeNamespace("System")); singleUnit.Namespaces.Add(new CodeNamespace("System.Data")); singleUnit.Namespaces.Add(new CodeNamespace("System.Data.Linq")); singleUnit.Namespaces.Add(new CodeNamespace("System.Linq")); singleUnit.Namespaces.Add(new CodeNamespace("System.Linq.Expressions")); singleUnit.Namespaces.Add(new CodeNamespace("System.Collections.Generic")); var l = new List <CodeCompileUnit>(); l.Add(singleUnit); if (units != null) { l.AddRange(units); foreach (var item in units) { singleUnit.Namespaces.AddRange(item.Namespaces); } } result = prov.CompileAssemblyFromDom(prms, l.ToArray()); } else { Dictionary <string, CodeCompileFileUnit> dic = gen.GetCompileUnits(typeof(Microsoft.VisualBasic.VBCodeProvider).IsAssignableFrom(prov.GetType()) ? LinqToCodedom.CodeDomGenerator.Language.VB : LinqToCodedom.CodeDomGenerator.Language.CSharp); foreach (CodeCompileFileUnit unit in dic.Values) { singleUnit.Namespaces.AddRange(unit.Namespaces); } var l = new List <CodeCompileUnit>(dic.Values.OfType <CodeCompileUnit>()); if (units != null) { l.AddRange(units); foreach (var item in units) { singleUnit.Namespaces.AddRange(item.Namespaces); } } singleUnit.Namespaces.Add(new CodeNamespace("System")); singleUnit.Namespaces.Add(new CodeNamespace("System.Data")); singleUnit.Namespaces.Add(new CodeNamespace("System.Data.Linq")); singleUnit.Namespaces.Add(new CodeNamespace("System.Linq")); singleUnit.Namespaces.Add(new CodeNamespace("System.Linq.Expressions")); singleUnit.Namespaces.Add(new CodeNamespace("System.Collections.Generic")); result = prov.CompileAssemblyFromDom(prms, l.ToArray()); } prov.GenerateCodeFromCompileUnit(singleUnit, Console.Out, new CodeGeneratorOptions()); if (result.Errors.HasErrors) { StringBuilder sb = new StringBuilder(); foreach (CompilerError str in result.Errors) { sb.AppendLine(str.ToString()); } Assert.Fail(sb.ToString()); } return(result.CompiledAssembly); }
private static void GenerateMultipleFilesOutput(string outputFolder, WXMLModel model, CodeDomProvider codeDomProvider, bool separateFolder, IEnumerable <string> skipEntities, IEnumerable <string> processEntities, bool testRun, WormCodeDomGenerator gen) { List <string> errorList = new List <string>(); int totalEntities = 0; int totalFiles = 0; foreach (EntityDefinition entity in model.OwnEntities) { //bool skip = false; //if (processEntities.Length != 0) //{ // skip = true; // foreach (string processEntityId in processEntities) // { // if (processEntityId == entity.Identifier) // { // skip = false; // break; // } // } //} //foreach (string skipEntityId in skipEntities) //{ // if (skipEntityId == entity.Identifier) // { // skip = true; // break; // } //} if (skipEntities.Contains(entity.Identifier)) { continue; } if (processEntities.Count() > 0 && !processEntities.Contains(entity.Identifier)) { continue; } string privateFolder; if (separateFolder) { privateFolder = outputFolder + Path.DirectorySeparatorChar.ToString() + entity.Name + Path.DirectorySeparatorChar; } else { privateFolder = outputFolder + Path.DirectorySeparatorChar.ToString(); } var units = gen.GetEntityCompileUnits(entity.Identifier, typeof(VBCodeProvider).IsAssignableFrom(codeDomProvider.GetType()) ? LinqToCodedom.CodeDomGenerator.Language.VB : LinqToCodedom.CodeDomGenerator.Language.CSharp); Console.Write("."); if (!Directory.Exists(privateFolder)) { Directory.CreateDirectory(privateFolder); } foreach (var unit in units) { Console.Write("."); try { GenerateCode(codeDomProvider, unit, Path.GetFullPath(privateFolder + Path.DirectorySeparatorChar.ToString() + unit.Filename), testRun); Console.Write("."); totalFiles++; } catch (Exception exc) { Console.Write("."); errorList.Add( string.Format("Entity: {0}; file: {1}; message: {2}", entity.Identifier, unit.Filename, exc.Message)); } } totalEntities++; } try { var ctx = gen.GetLinqContextCompliteUnit(typeof(VBCodeProvider).IsAssignableFrom(codeDomProvider.GetType()) ? LinqToCodedom.CodeDomGenerator.Language.VB : LinqToCodedom.CodeDomGenerator.Language.CSharp); if (ctx != null) { GenerateCode(codeDomProvider, ctx, Path.GetFullPath( outputFolder + Path.DirectorySeparatorChar.ToString() + ctx.Filename ), testRun); Console.Write("."); totalFiles++; } } catch (Exception exc) { Console.Write("."); errorList.Add( string.Format("Linq context file failed to generate: {0}", exc.Message)); } Console.WriteLine(); Console.WriteLine("Result:"); Console.WriteLine("\t {0} entities processed", totalEntities); Console.WriteLine("\t {0} files generated", totalFiles); Console.WriteLine("\t {0} errors encountered", errorList.Count); if (errorList.Count != 0) { Console.WriteLine("Errors:"); foreach (string s in errorList) { Console.WriteLine("\t" + s); for (int i = 0; i < Console.WindowWidth; i++) { Console.Write("-"); } Console.WriteLine(); } } }
public CodeEntityTypeDeclaration(WXMLCodeDomGeneratorSettings settings, EntityDefinition entity, WormCodeDomGenerator gen) : this(settings, gen) { Entity = entity; m_typeReference.BaseType = FullName; entity.Items["TypeDeclaration"] = this; }