public Dictionary <string, string> GenerateEntityCode(string szNamespace, DatabaseTableCollection dbTableCollection) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); foreach (DatabaseTable dbTable in dbTableCollection.DatabaseTables) { StringBuilder sb = new StringBuilder(); sb.AppendLine("/*************************************************"); sb.AppendLine(string.Format("*{0} Entity", dbTable.CsEntityName)); sb.AppendLine(string.Format("* Generation Date: {0}", DateTime.Now)); sb.AppendLine("*************************************************/"); sb.AppendLine(); sb.AppendLine("using System;"); sb.AppendLine("using System.Text;"); sb.AppendLine(); sb.AppendLine("namespace " + szNamespace + ".Lib.Domain"); sb.AppendLine("{"); sb.AppendLine(string.Format(" public class {0}: EntityBase, IAggregateRoot", dbTable.CsEntityName)); sb.AppendLine(" {"); GeneratePropertiesCodeRegion(dbTable, sb); sb.AppendLine(); GenerateCtorsCodeRegion(dbTable, sb); GenerateNestedClassMetadataCodeRegion(dbTable, sb); sb.AppendLine(" }"); sb.AppendLine("}"); dictionary.Add(dbTable.CsEntityName, sb.ToString()); } if (_gloOptions.TargetPlatform == Platform.netFramework11) { dictionary.Add("NullableWrappers", NullableWrapperTypeGenerator.GetAllNullableClasses(szNamespace)); } return(dictionary); }
private void btnGenerate_Click(object sender, EventArgs e) { try { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); if (string.IsNullOrEmpty(this.txtNamespace.Text) || this.tvwTables.Nodes.Count == 0) { return; } List <TreeNode> listTables = (from TreeNode treeNode in tvwTables.Nodes[0].Nodes where treeNode.Checked select treeNode).ToList(); DatabaseTableCollection dbTableCollection = new DatabaseTableCollection(options, listTables, ConnectionProvider.GetDbConnection()); string text = this.txtNamespace.Text; DateTime now = DateTime.Now; this.txtSPs.Text = this.gloSQLScript = new StoredProcedureGenerator(this.options).GenerateSpScripts(dbTableCollection, now); this.txtDataSupertype.Text = this.gloDataSupertype = new DataLayerGenerator(this.options).GenerateDataLayerSupertypeCode(this.txtNamespace.Text); this.txtBusinessLayerSupertype.Text = this._gloBusinessSupertype = new BusinessLayerGenerator(this.options).GenerateBusinessLayerSupertypeCode(this.txtNamespace.Text); this._gloDictEntities = new EntityLayerGenerator(this.options).GenerateEntityCode(text, dbTableCollection); StringBuilder stringBuilder1 = new StringBuilder(); foreach (string str in this._gloDictEntities.Values) { stringBuilder1.AppendLine(str); } this.txtEntities.Text = stringBuilder1.ToString(); _gloDictDataLayer = new DataLayerGenerator(this.options).GenerateDataLayerCode(text, dbTableCollection); StringBuilder stringBuilder2 = new StringBuilder(); foreach (string str in this._gloDictDataLayer.Values) { stringBuilder2.AppendLine(str); } txtDataLayer.Text = stringBuilder2.ToString(); _gloDictDataLayerInterface = new DataLayerInterfaceGenerator(this.options).GenerateDataLayerCode(text, dbTableCollection); StringBuilder stringBuilderIData = new StringBuilder(); foreach (string str in this._gloDictDataLayerInterface.Values) { stringBuilderIData.AppendLine(str); } this.txtIDataLayer.Text = stringBuilderIData.ToString(); this._gloDictBusinessLayer = new BusinessLayerGenerator(this.options).GenerateBusinessLayerCode(text, dbTableCollection); StringBuilder stringBuilder3 = new StringBuilder(); foreach (string str in this._gloDictBusinessLayer.Values) { stringBuilder3.AppendLine(str); } this.txtDomainLogic.Text = stringBuilder3.ToString(); this._gloDictBusinessLayerInterface = new BusinessLayerInterfaceGenerator(this.options).GenerateBusinessLayerCode(text, dbTableCollection); StringBuilder stringBuilderIService = new StringBuilder(); foreach (string str in this._gloDictBusinessLayerInterface.Values) { stringBuilderIService.AppendLine(str); } txtIDomainLogic.Text = stringBuilderIService.ToString(); this._gloDictInfrastructure = new Dictionary <string, string>(); this._gloDictInfrastructure.Add("NullabletypeBase", NullableWrapperTypeGenerator.GetNullableAbstractBase(text)); StringBuilder stringBuilder4 = new StringBuilder(); foreach (string str in this._gloDictInfrastructure.Values) { stringBuilder4.AppendLine(str); } this.txtInfrastructure.Text = stringBuilder4.ToString(); stopwatch.Stop(); this.lblGenerationInfo.Text = "Processing Time: " + (object)stopwatch.ElapsedMilliseconds + "ms"; this.tabControlOutput.SelectedTab = this.tabPageSPs; } catch (SqlException ex) { this.lblGenerationInfo.Text = ex.Message; } catch (Exception ex) { int num = (int)MessageBox.Show(ex.Message, this.messageTextProvider.GetMessage(MessageTypes.Error), MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); } }