private void GenerateCode(GenerationParameter parameter, ITemplateEngine templateEngine, string templateName, ref int genratedCount, ref int errorCount, ref int progressCount, AsyncOperation asyncOp) { foreach (string modelId in parameter.GenerationObjects.Keys) { string codeFileNamePath = PathHelper.GetCodeFileNamePath(ConfigManager.GenerationCodeOuputPath, ConfigManager.SettingsSection.Languages[parameter.Settings.Language].Alias, ConfigManager.SettingsSection.TemplateEngines[parameter.Settings.TemplateEngine].Name, ConfigManager.TemplateSection.Templates[templateName].DisplayName, parameter.Settings.Package, modelId); PathHelper.CreateCodeFileNamePath(codeFileNamePath); foreach (string objId in parameter.GenerationObjects[modelId]) { IMetaData modelObject = ModelManager.GetModelObject(parameter.Models[modelId], objId); TemplateData templateData = TemplateDataBuilder.Build(modelObject, parameter.Settings, templateName, parameter.Models[modelId].Database, modelId); if (templateData == null || !templateEngine.Run(templateData)) { errorCount++; } else { genratedCount++; } string currentCodeFileName = templateData == null ? string.Empty : templateData.CodeFileName; var args = new GenerationProgressChangedEventArgs(genratedCount, errorCount, currentCodeFileName, ++progressCount, asyncOp.UserSuppliedState); asyncOp.Post(this.onProgressReportDelegate, args); } } }
public static void GenerateCode(out string entitys, TreeView treeView, string[] templateNames, string tablePrefix, bool isOmitTablePrefix, bool isCamelCaseName) { entitys = ""; GenerationParameter parameter = new GenerationParameter( ModelManager.Clone(), GetGenerationObjects(treeView), GetGenerationSettings(templateNames, tablePrefix, isOmitTablePrefix, isCamelCaseName)); foreach (string modelId in parameter.GenerationObjects.Keys) { foreach (string objId in parameter.GenerationObjects[modelId]) { IMetaData modelObject = ModelManager.GetModelObject(parameter.Models[modelId], objId); TemplateData templateData = TemplateDataBuilder.Build(modelObject, parameter.Settings, "default", parameter.Models[modelId].Database, modelId); if (templateData == null) { throw new ArgumentNullException("Can not create template data!"); } string currentCodeFileName = templateData == null ? string.Empty : templateData.CodeFileName; if (modelObject is Table) { Table table = modelObject as Table; foreach (var column in table.Columns.Values) { string langType = column.LanguageType; string defaultValue = column.LanguageDefaultValue; string typeAlias = column.LanguageTypeAlias; entitys += string.Format("public {0} {1} {{get;set;}}\r\n\r\n\t\t", langType, column.DisplayName); } } else if (modelObject is PhysicalDataModel.View) { PhysicalDataModel.View view = modelObject as PhysicalDataModel.View; foreach (var column in view.Columns.Values) { string langType = column.LanguageType; string defaultValue = column.LanguageDefaultValue; string typeAlias = column.LanguageTypeAlias; entitys += string.Format("public {0} {1} {{get;set;}}}\r\n\r\n\t\t", langType, column.DisplayName); } } } } }