private void GenerateSelect(CSharpTypeDef srvDef, CSharpMethodDef srvMethod) { srvMethod.Comment.Summary = string.Format("Get the {0} record by its primary key.", m_Doc.Name); srvMethod.HeaderLine = string.Format("public virtual {0} {0}{1}", m_Doc.Name, m_Type); srvMethod.Attributes.Add(string.Format("ImplicitPmc(\"{0}{1}\")", m_Doc.Name, m_Type)); GenerationHelper.AddMethodParams(srvMethod, m_Doc.RootEntity.PKFields); srvMethod.Comment.Returns = string.Format("{0} obtained from the database, or null, if not found", m_Doc.Name); TextWriter tw = srvMethod.Writer; tw.WriteLine("int count;"); tw.WriteLine("{0} result = null;", m_Doc.Name); tw.Write("DataSet entitySet = m_DataContext.{0}(", base.m_DataLayer.SelectSpName(m_Doc.RootEntity)); GenerationHelper.EnumerateParams(tw, m_Doc.RootEntity.PKFields, "{0}Val"); tw.WriteLine(", out count);"); tw.WriteLine("if (count != 0)"); tw.WriteLine("{"); tw.WriteLine(" result = new {0}(entitySet.Tables[0].Rows[0]);", m_Doc.Name); foreach (DocumentRelationModel model in m_Doc.ParentRelations) { CSharpMethodDef def = new CSharpMethodDef(); srvDef.Methods.Add(def); string str = model.Document.IsSimple ? model.Document.RootEntity.MappingName : model.Document.Name; string parentRole = model.Association.ParentRole; def.Comment.Summary = string.Format("Load parent field by '{0}'", parentRole); def.HeaderLine = string.Format("public virtual void Load{0}", parentRole); def.AddParam("ownerEntity", m_Doc.Name, "Entity that owns the parent field."); TextWriter writer = def.Writer; writer.WriteLine("{0}Service srv = new {0}Service(m_DataContext);", str); writer.Write("ownerEntity.{0} = srv.{1}Select(", parentRole, str); GenerationHelper.EnumerateParams(writer, model.Association.ForeignFields, "ownerEntity.{0}"); writer.WriteLine(");"); tw.WriteLine(" Load{0}(result);", parentRole); } foreach (DocumentRelationModel model2 in m_Doc.ChildRelations) { CSharpMethodDef def2 = new CSharpMethodDef(); srvDef.Methods.Add(def2); string childRole = model2.Association.ChildRole; def2.Comment.Summary = string.Format("Load child container by '{0}'", childRole); def2.HeaderLine = string.Format("public virtual void Load{0}", childRole); def2.AddParam("ownerEntity", m_Doc.Name, "Entity that owns the child container."); TextWriter writer3 = def2.Writer; if (model2.Document.IsSimple) { writer3.WriteLine("{0}Service srv = new {0}Service(m_DataContext);", m_Doc.RootEntity.MappingName); writer3.Write("ownerEntity.{0} = srv.SelectChildrenBy{1}(", childRole, model2.Association.Name); GenerationHelper.EnumerateParams(writer3, m_Doc.RootEntity.PKFields, "ownerEntity.{0}"); writer3.WriteLine(");"); } else { DataEntityModel rootEntity = model2.Document.RootEntity; writer3.WriteLine("{0}Service srv = new {0}Service(m_DataContext);", m_Doc.RootEntity.MappingName); writer3.WriteLine("{0}Service childSrv = new {0}Service(m_DataContext);", model2.Document.Name); writer3.Write("{0}Container allChildren = srv.SelectChildrenBy{1}(", rootEntity.MappingName, model2.Association.Name); GenerationHelper.EnumerateParams(writer3, m_Doc.RootEntity.PKFields, "ownerEntity.{0}"); writer3.WriteLine(");"); writer3.WriteLine("ownerEntity.{0} = new {1}Container();", childRole, model2.Document.Name); writer3.WriteLine("foreach ({0} childDoc in allChildren.All)", rootEntity.MappingName); writer3.WriteLine("{"); writer3.WriteLine(" {0} childInstance = new {0}(childDoc);", model2.Document.Name); foreach (DocumentRelationModel model4 in model2.Document.ParentRelations) { writer3.WriteLine(" Load{0}(childInstance);", model4.Association.ParentRole); } foreach (DocumentRelationModel model5 in model2.Document.ChildRelations) { writer3.WriteLine(" childSrv.Load{0}(childInstance);", model5.Association.ChildRole); } writer3.WriteLine(" ownerEntity.{0}.Add(childInstance);", childRole); writer3.WriteLine("}"); } tw.WriteLine(" Load{0}(result);", childRole); } tw.WriteLine("}"); }
private void GenerateUpdate(CSharpMethodDef srvMethod) { srvMethod.Comment.Summary = string.Format("Update a record of {0}.", m_Doc.Name); srvMethod.HeaderLine = string.Format("public virtual void {0}{1}", m_Doc.Name, m_Type); srvMethod.Attributes.Add(string.Format("ImplicitPmc(\"{0}{1}\")", m_Doc.Name, m_Type)); srvMethod.AddParam("entity", m_Doc.Name, "Entity to update"); }
public void GenerateDispsetDocument(CSharpFile docFile, DataEntityModel de) { CSharpTypeDef typeDef = new CSharpTypeDef(); docFile.InnerTypes.Add(typeDef); typeDef.Comment.Summary = docFile.Description; typeDef.HeaderLine = string.Format("public class {0}Dispset: BusinessDocument", de.MappingName); typeDef.Attributes.Add("Serializable"); foreach (DataFieldModel model in de.DispFields) { string normalizedName = model.NormalizedName; CSharpFieldDef def2 = new CSharpFieldDef(); typeDef.Fields.Add(def2); def2.Attributes.Add(string.Format("BindingField(\"{0}\")", model.MappingName)); def2.DefLine = string.Format("protected {0} m_{1} = new {0}();", SqlTypeMap.GetDBTypeFromFullName(model.TypeString), normalizedName); def2.CommentLine = string.Format("Member representing field '{0}'", model.MappingName); CSharpPropertyDef def3 = new CSharpPropertyDef(); typeDef.Properties.Add(def3); def3.Comment.Summary = string.Format("Access information for field '{0}'", model.MappingName); def3.HeaderLine = string.Format("public {0} {1}", SqlTypeMap.GetDBTypeFromFullName(model.TypeString), normalizedName); def3.GetWriter.WriteLine(string.Format("return m_{0};", normalizedName)); } CSharpMethodDef def4 = new CSharpMethodDef(); typeDef.Ctors.Add(def4); def4.Comment.Summary = "DataRow setup constructor"; def4.HeaderLine = string.Format("public {0}Dispset", de.MappingName); def4.AddParam("dataRow", "DataRow", "DataRow containing document data."); def4.HeaderTrailer = ": base(dataRow)"; CSharpMethodDef def5 = new CSharpMethodDef(); typeDef.Methods.Add(def5); def5.Comment.Summary = "Loads field values into member fields."; def5.HeaderLine = "public override void LoadFrom"; def5.AddParam("dataRow", "DataRow", "DataRow containing document data."); foreach (DataFieldModel model2 in de.DispFields) { switch (SqlTypeMap.GetDBTypeFromFullName(model2.TypeString)) { case "bool": { def5.Writer.WriteLine("m_{0} = (bool)dataRow[\"{1}\"];", model2.NormalizedName, model2.MappingName); continue; } case "object": { def5.Writer.WriteLine("m_{0} = dataRow[\"{1}\"];", model2.NormalizedName, model2.MappingName); continue; } } def5.Writer.WriteLine("m_{0}.Value = dataRow[\"{1}\"];", model2.NormalizedName, model2.MappingName); } }
private void GenerateInsert(CSharpMethodDef srvMethod) { srvMethod.Comment.Summary = string.Format("Insert a record of {0}.", m_Doc.Name); srvMethod.HeaderLine = string.Format("public virtual void {0}{1}", m_Doc.Name, m_Type); srvMethod.Attributes.Add(string.Format("ImplicitPmc(\"{0}{1}\")", m_Doc.Name, m_Type)); srvMethod.AddParam("entity", m_Doc.Name, "Entity to insert"); TextWriter tw = srvMethod.Writer; tw.Write("m_DataContext.{0}(", base.m_DataLayer.InsertSpName(m_Doc.RootEntity)); GenerationHelper.EnumerateParams(tw, m_Doc.RootEntity.InsertParamFields, "entity.{0}"); tw.WriteLine(");"); foreach (DocumentRelationModel model in m_Doc.ChildRelations) { tw.WriteLine(); tw.WriteLine("// --- Insert child entities by '{0}'", model.Association.Name); if (model.Document.IsSimple) { DataEntityModel rootEntity = model.Document.RootEntity; tw.WriteLine("foreach ({0} child in entity.{1}.Current)", rootEntity.MappingName, model.Association.ChildRole); tw.WriteLine("{"); for (int i = 0; i < m_Doc.RootEntity.PKFields.Count; i++) { if (!model.Association.ForeignFields[i].IsPKField && !model.Association.ForeignFields[i].IsCalculated) { tw.WriteLine(" child.{0} = entity.{1};", model.Association.ForeignFields[i].NormalizedName, m_Doc.RootEntity.PKFields[i].NormalizedName); } } tw.Write(" m_DataContext.{0}{1}Insert(", m_Doc.RootEntity.Parent.Prefix, rootEntity.MappingName); GenerationHelper.EnumerateParams(tw, rootEntity.InsertParamFields, " child.{0}"); tw.WriteLine(");"); tw.WriteLine("}"); } } }
private CSharpTypeDef GetTypeDef(DataAccessModel daLayer, string id ) { CSharpFile file = CSharpFilePool.Obtain(Path.Combine(daLayer.FullPath, GenerationHelper.GetDataContextName(id))); file.NameSpace = daLayer.NameSpace; file.Description = "Class implementing data access methods."; file.Usings.Add("System.Data"); file.Usings.Add("System.Data.SqlClient"); file.Usings.Add("Grepton.Runtime"); file.Usings.Add("Grepton.Runtime.DBTypes"); file.Usings.Add("Grepton.Runtime.SqlServer"); file.Usings.Add("Grepton.Runtime.BusinessHosting"); file.Usings.Add("Grepton.Diagnostics.EventSchema"); file.Usings.Add("Grepton.Diagnostics.Pmc"); file.Usings.Add(m_Arch.UtilityLayer.NameSpace); CSharpTypeDef typeDef = new CSharpTypeDef(); file.InnerTypes.Add(typeDef); typeDef.Attributes.Add("ImplicitPmc"); typeDef.Comment.Summary = file.Description; typeDef.HeaderLine = string.Format("public class {0}: Base{0}", daLayer.DataContextName); CSharpMethodDef def2 = new CSharpMethodDef(); typeDef.Ctors.Add(def2); def2.Comment.Summary = "This constructor creates a stored procedure interface that uses the database connection as specified in the application configuration file."; def2.HeaderLine = string.Format("public {0}", daLayer.DataContextName); def2.HeaderTrailer = ": base()"; CSharpMethodDef def3 = new CSharpMethodDef(); typeDef.Ctors.Add(def3); def3.Comment.Summary = "This constructor creates a stored procedure interface that uses tha database connection as specified in the constructor parameter."; def3.HeaderLine = string.Format("public {0}", daLayer.DataContextName); def3.AddParam("sqlConn", "SqlConnection", "SQL Server connection to use."); def3.HeaderTrailer = ": base(sqlConn)"; file = CSharpFilePool.Obtain(Path.Combine(daLayer.FullPath, GenerationHelper.GetBaseDataContextName(id))); file.NameSpace = daLayer.NameSpace; file.Description = "Class implementing data access methods."; file.Usings.Add("System.Data"); file.Usings.Add("System.Data.SqlClient"); file.Usings.Add("Grepton.Runtime"); file.Usings.Add("Grepton.Runtime.DBTypes"); file.Usings.Add("Grepton.Runtime.SqlServer"); file.Usings.Add("Grepton.Runtime.BusinessHosting"); file.Usings.Add("Grepton.Diagnostics.EventSchema"); file.Usings.Add("Grepton.Diagnostics.Pmc"); file.Usings.Add(m_Arch.UtilityLayer.NameSpace); typeDef = new CSharpTypeDef(); file.InnerTypes.Add(typeDef); typeDef.Attributes.Add("ImplicitPmc"); typeDef.Comment.Summary = file.Description; typeDef.HeaderLine = string.Format("public partial class Base{0}: SqlDataContextBase", daLayer.DataContextName); def2 = new CSharpMethodDef(); typeDef.Ctors.Add(def2); def2.Comment.Summary = "This constructor creates a stored procedure interface that uses the database connection as specified in the application configuration file."; def2.HeaderLine = string.Format("public Base{0}", daLayer.DataContextName); def2.Writer.WriteLine("m_Connection = Configuration.{0}Connection;", daLayer.ConfigKeyName); def3 = new CSharpMethodDef(); typeDef.Ctors.Add(def3); def3.Comment.Summary = "This constructor creates a stored procedure interface that uses tha database connection as specified in the constructor parameter."; def3.HeaderLine = string.Format("public Base{0}", daLayer.DataContextName); def3.AddParam("sqlConn", "SqlConnection", "SQL Server connection to use."); def3.HeaderTrailer = ": base(sqlConn)"; return typeDef; }
private void GenerateInsert(CSharpMethodDef srvMethod) { srvMethod.Comment.Summary = string.Format("Insert a record of {0}.", m_Table.MappingName); srvMethod.HeaderLine = string.Format("public virtual void {0}{1}", m_Table.MappingName, m_Type); srvMethod.Attributes.Add(string.Format("ImplicitPmc(\"{0}{1}\")", m_Table.MappingName, m_Type)); srvMethod.AddParam("entity", m_Table.MappingName, "Entity to insert"); TextWriter tw = srvMethod.Writer; tw.Write("m_DataContext.{0}(", base.m_DataLayer.InsertSpName(m_Table)); GenerationHelper.EnumerateParams(tw, m_Table.InsertParamFields, "entity.{0}"); tw.WriteLine(");"); }
private void AddXmlConstructor(DataEntityModel de, CSharpTypeDef ownerClass) { CSharpMethodDef def = new CSharpMethodDef(); ownerClass.Ctors.Add(def); def.Comment.Summary = "XmlNode setup constructor"; def.HeaderLine = string.Format("public {0}Base", de.MappingName); def.AddParam("node", "XmlNode", "XmlNode containing document data."); TextWriter writer = def.Writer; foreach (DataFieldModel model in de.Fields) { if (model.IsPKField) { writer.WriteLine("m_{0} = new {1}(node.Attributes[\"{0}\"]);", model.NormalizedName, SqlTypeMap.GetDBTypeFromFullName(model.TypeString)); } else { if (SqlTypeMap.GetDBTypeFromFullName(model.TypeString) == "bool") { writer.WriteLine("m_{0} = Convert.ToBoolean(node.SelectSingleNode(\"{0}\").InnerText);", model.NormalizedName); continue; } writer.WriteLine("m_{0} = new {1}(node.SelectSingleNode(\"{0}\"));", model.NormalizedName, SqlTypeMap.GetDBTypeFromFullName(model.TypeString)); } } }
private void GenerateSpMethod(CSharpTypeDef dcClass, string spName, DataFieldContainer dataFields, string packageName, bool hasRetVal, bool returnsDataSet) { CSharpMethodDef def = new CSharpMethodDef(); dcClass.Methods.Add(def); def.Comment.Summary = string.Format("Calls stored procedure '{0}'", spName); def.Attributes.Add(string.Format("ImplicitPmc(\"{0}\")", spName)); if (returnsDataSet) { def.HeaderLine = string.Format("public DataSet {0}", spName); def.Comment.Returns = "Resulting DataSet from the stored procedure."; } else { def.HeaderLine = string.Format("public void {0}", spName); } foreach (DataFieldModel model in dataFields) { int length = (model.TypeString.IndexOf("(") > 0) ? model.TypeString.IndexOf("(") : model.TypeString.Length; string index = model.TypeString.Substring(0, length).ToLower(); def.AddParam(model.NormalizedName, OracleTypeMap.GetDBType(index), string.Format("{0} parameter.", model.MappingName)); } if (hasRetVal) { CSharpMethodparamDef def2 = new CSharpMethodparamDef("retVal", "int"); def2.Direction = MethodParamDir.Out; def.Params.Add(def2); def.Comment.AddParam("retVal", "SP return value."); } TextWriter writer = def.Writer; writer.WriteLine("TraceCallEnterEvent.Raise();"); writer.WriteLine("OracleCommand oraComm = PrepareSPCall(\"{0}\");", packageName + "." + spName); writer.WriteLine(); int num2 = 1; foreach (DataFieldModel model2 in dataFields) { int num3 = (model2.TypeString.IndexOf("(") > 0) ? model2.TypeString.IndexOf("(") : model2.TypeString.Length; string str2 = model2.TypeString.Substring(0, num3).ToLower(); writer.WriteLine(string.Format("OracleParameter p{0} = oraComm.Parameters.Add(\"i{1}\", OracleType.{2});", num2, model2.Name, OracleTypeMap.GetNetOracleTypeWithSize(str2, model2.MaxLength))); writer.WriteLine(string.Format("p{0}.Direction = ParameterDirection.Input;", num2)); if (OracleTypeMap.GetDBType(str2).ToLower() == "bool") { writer.WriteLine(string.Format("p{0}.Value = {1};", num2, model2.NormalizedName)); } else { writer.WriteLine(string.Format("p{0}.Value = {1}.Value;", num2, model2.NormalizedName)); } num2++; } if (returnsDataSet) { writer.WriteLine(string.Format( "OracleParameter p{0} = oraComm.Parameters.Add(\"oresult\", OracleType.Cursor);", num2)); writer.WriteLine(string.Format("p{0}.Direction = ParameterDirection.Output;", num2)); } if (hasRetVal) { writer.WriteLine("OracleParameter returnValue = oraComm.Parameters.Add(\"returnValue\", OracleType.Number);"); writer.WriteLine("returnValue.Direction = ParameterDirection.Output;"); } writer.WriteLine("//TraceDbCommandEvent.Raise(oraComm);"); if (returnsDataSet) { writer.WriteLine("DataSet Result = new DataSet();"); } writer.WriteLine("try"); writer.WriteLine("{"); if (returnsDataSet) { writer.WriteLine(" OracleDataAdapter oraAdapt = new OracleDataAdapter(oraComm);"); writer.WriteLine(" oraAdapt.Fill(Result);"); writer.WriteLine(" TraceCallReturnEvent.Raise();"); } else { writer.WriteLine(" oraComm.ExecuteNonQuery();"); writer.WriteLine(" TraceCallReturnEvent.Raise();"); } writer.WriteLine("}"); writer.WriteLine("catch (OracleException e)"); writer.WriteLine("{"); writer.WriteLine(" TraceCallReturnEvent.Raise(false);"); writer.WriteLine(" throw e;"); writer.WriteLine("}"); writer.WriteLine("finally"); writer.WriteLine("{"); writer.WriteLine(" FinishSPCall();"); writer.WriteLine("}"); num2 = 0; if (hasRetVal) { writer.WriteLine("retVal = Convert.ToInt32(returnValue.Value);"); writer.WriteLine("TraceInfoEvent.Raise(\"RetVal: {0}\", retVal);"); } if (returnsDataSet) { writer.WriteLine("return Result;"); } }
private void AddCopyConstructor(DataEntityModel de, CSharpTypeDef ownerClass, string className, string baseClassName, bool emptyBase) { CSharpMethodDef def = new CSharpMethodDef(); ownerClass.Ctors.Add(def); def.Comment.Summary = "Copy constructor."; def.HeaderLine = string.Format("public {0}", className); def.AddParam("origInstance", baseClassName, "Original document data to copy."); if (emptyBase) { def.HeaderTrailer = ": base()"; TextWriter writer = def.Writer; foreach (DataFieldModel model in de.Fields) { writer.WriteLine("this.m_{0} = origInstance.m_{0};", model.NormalizedName); } } else { def.HeaderTrailer = ": base(origInstance)"; } if (de.Fields.Count > de.PKFields.Count) { def = new CSharpMethodDef(); ownerClass.Ctors.Add(def); def.Comment.Summary = "Copy constructor."; def.HeaderLine = string.Format("public {0}", className); GenerationHelper.AddMethodParams(def, de.PKFields); def.AddParam("origInstance", baseClassName, "Original document data to copy."); if (emptyBase) { def.HeaderTrailer = ": base()"; TextWriter writer2 = def.Writer; foreach (DataFieldModel model2 in de.Fields) { if (model2.IsPKField) { writer2.WriteLine("this.m_{0} = {0}Val;", model2.NormalizedName); } else { writer2.WriteLine("this.m_{0} = origInstance.m_{0};", model2.NormalizedName); } } } else { def.HeaderTrailer = ": base("; int num = 0; foreach (DataFieldModel model3 in de.PKFields) { if (num > 0) { def.HeaderTrailer = def.HeaderTrailer + ", "; } def.HeaderTrailer = def.HeaderTrailer + string.Format("{0}Val", model3.NormalizedName); num++; } def.HeaderTrailer = def.HeaderTrailer + ", origInstance)"; } } }
private void AddMethods(DataEntityModel de, CSharpTypeDef baseClass) { CSharpMethodDef def = new CSharpMethodDef(); baseClass.Methods.Add(def); def.Comment.Summary = "Resets data field modification exceptions."; def.HeaderLine = "public void ResetExceptions"; foreach (DataFieldModel model in de.UpdateSetFields) { def.Writer.WriteLine("m_{0}Error = null;", model.NormalizedName); } CSharpMethodDef def2 = new CSharpMethodDef(); baseClass.Methods.Add(def2); def2.Comment.Summary = "Loads field values into member fields."; def2.HeaderLine = "public override void LoadFrom"; def2.AddParam("dataRow", "DataRow", "DataRow containing document data."); foreach (DataFieldModel model2 in de.Fields) { switch (SqlTypeMap.GetDBTypeFromFullName(model2.TypeString)) { case "bool": { def2.Writer.WriteLine("m_{0} = (bool)dataRow[\"{1}\"];", model2.NormalizedName, model2.Name); continue; } case "object": { def2.Writer.WriteLine("m_{0} = dataRow[\"{1}\"];", model2.NormalizedName, model2.Name); continue; } } def2.Writer.WriteLine("m_{0}.Value = dataRow[\"{1}\"];", model2.NormalizedName, model2.Name); } CSharpMethodDef def3 = new CSharpMethodDef(); baseClass.Methods.Add(def3); def3.Comment.Summary = "Obtains the hash string for this instance."; def3.Comment.Returns = "Hash string of this instance."; def3.HeaderLine = "public override string HashString"; TextWriter writer = def3.Writer; def3.Writer.Write("return "); int num = 0; foreach (DataFieldModel model3 in de.PKFields) { if (num > 0) { writer.WriteLine(" + \"<#>\" +"); writer.Write(" "); } writer.Write("m_{0}.ToString()", model3.NormalizedName); num++; } if (num == 0) { writer.WriteLine("String.Empty;"); } else { writer.WriteLine(";"); } }
private void AddConstructors(DataEntityModel de, CSharpTypeDef baseClass) { CSharpMethodDef def = new CSharpMethodDef(); baseClass.Ctors.Add(def); def.Comment.Summary = "Primary key based constructor"; def.HeaderLine = string.Format("public {0}Base", de.MappingName); def.HeaderTrailer = ": base()"; GenerationHelper.AddMethodParams(def, de.ConstructorFields); def.Writer.WriteLine("ResetExceptions();"); foreach (DataFieldModel model in de.ConstructorFields) { def.Writer.WriteLine("m_{0} = {0}Val;", model.NormalizedName); } CSharpMethodDef def2 = new CSharpMethodDef(); baseClass.Ctors.Add(def2); def2.Comment.Summary = "DataRow setup constructor"; def2.HeaderLine = string.Format("public {0}Base", de.MappingName); def2.AddParam("dataRow", "DataRow", "DataRow containing document data."); def2.HeaderTrailer = ": base(dataRow)"; CSharpMethodDef def3 = new CSharpMethodDef(); baseClass.Ctors.Add(def3); def3.Comment.Summary = "DataSet setup constructor"; def3.HeaderLine = string.Format("public {0}Base", de.MappingName); def3.AddParam("dataSet", "DataSet", "DataSet containing document data."); def3.HeaderTrailer = ": base(dataSet)"; AddXmlConstructor(de, baseClass); string className = string.Format("{0}Base", de.MappingName); AddCopyConstructor(de, baseClass, className, className, true); }
public void GenerateSnippetConstructors(CSharpTypeDef snippetClass, DataEntityModel de, string className, string copyClassName) { CSharpMethodDef def = new CSharpMethodDef(); snippetClass.Ctors.Add(def); def.Comment.Summary = "Primary key based constructor"; def.HeaderLine = string.Format("public {0}", className); def.HeaderTrailer = ": base("; int num = 0; foreach (DataFieldModel model in de.ConstructorFields) { if (num > 0) { def.HeaderTrailer = def.HeaderTrailer + ", "; } string name = string.Format("{0}Val", model.NormalizedName); string comment = string.Format("Value of '{0}' field", model.MappingName); def.AddParam(name, SqlTypeMap.GetDBTypeFromFullName(model.TypeString), comment); def.HeaderTrailer = def.HeaderTrailer + name; num++; } def.HeaderTrailer = def.HeaderTrailer + ")"; CSharpMethodDef def2 = new CSharpMethodDef(); snippetClass.Ctors.Add(def2); def2.Comment.Summary = "DataRow setup constructor"; def2.HeaderLine = string.Format("public {0}", className); def2.AddParam("dataRow", "DataRow", "DataRow containing document data."); def2.HeaderTrailer = ": base(dataRow)"; CSharpMethodDef def3 = new CSharpMethodDef(); snippetClass.Ctors.Add(def3); def3.Comment.Summary = "DataSet setup constructor"; def3.HeaderLine = string.Format("public {0}", className); def3.AddParam("dataSet", "DataSet", "DataSet containing document data."); def3.HeaderTrailer = ": base(dataSet)"; CSharpMethodDef def4 = new CSharpMethodDef(); snippetClass.Ctors.Add(def4); def4.Comment.Summary = "XmlNode setup constructor"; def4.HeaderLine = string.Format("public {0}", className); def4.AddParam("node", "XmlNode", "XmlNode containing document data."); def4.HeaderTrailer = ": base(node)"; AddCopyConstructor(de, snippetClass, className, copyClassName, false); }
public void GenerateServiceFactoryClass(VSNetCSharpProject bdProj) { string projectName = bdProj.ProjectName; string sFClassFileName = GenerationHelper.GetSFClassFileName(); string str3 = m_Arch.BusinessDocsLayer.FullPath + sFClassFileName; bdProj.AddFile(sFClassFileName); CSharpFile file = CSharpFilePool.Obtain(str3); file.NameSpace = bdProj.ProjectName; TraceInfoEvent.Raise("Adding service factory class."); file.Description = "Service factory class."; file.Usings.Add("System.Collections.Specialized"); file.Usings.Add("System.Configuration"); file.Usings.Add("Grepton.Helpers"); file.Usings.Add("Grepton.Runtime"); file.Usings.Add("Grepton.Runtime.BusinessHosting"); file.Usings.Add("Grepton.Diagnostics.Exceptions"); CSharpTypeDef typeDef = new CSharpTypeDef(); file.InnerTypes.Add(typeDef); typeDef.Comment.Summary = file.Description; typeDef.HeaderLine = "public class ServiceFactory"; CSharpFieldDef def2 = new CSharpFieldDef(); def2.DefLine = "static IServiceFactory m_ServiceFactory;"; typeDef.Fields.Add(def2); CSharpMethodDef def3 = new CSharpMethodDef(); typeDef.Ctors.Add(def3); def3.Comment.Summary = "Initializes the service factory"; def3.HeaderLine = "static ServiceFactory"; TextWriter writer = def3.Writer; writer.WriteLine("try"); writer.WriteLine("{"); writer.WriteLine(" SetFactory(null);"); writer.WriteLine("}"); writer.WriteLine("catch (Exception ex)"); writer.WriteLine("{"); writer.WriteLine(" ExceptionManager.Publish(ex);"); writer.WriteLine("}"); CSharpMethodDef def4 = new CSharpMethodDef(); typeDef.Methods.Add(def4); def4.Comment.Summary = "Initializes the service factory dispatcher"; def4.HeaderLine = "public static void SetFactory"; def4.AddParam("className", "string", "Service factory class name."); writer = def4.Writer; writer.WriteLine("try"); writer.WriteLine("{"); writer.WriteLine(" if (className == null || className == String.Empty)"); writer.WriteLine(" {"); writer.WriteLine(" className = ((NameValueCollection)ConfigurationSettings."); writer.WriteLine(" GetConfig(\"ServiceFactory\"))[\"class\"];"); writer.WriteLine(" }"); writer.WriteLine(" DynamicType plugIn = new DynamicType(className);"); writer.WriteLine(" m_ServiceFactory = (IServiceFactory)plugIn.CreateInstance();"); writer.WriteLine("}"); writer.WriteLine("catch (Exception ex)"); writer.WriteLine("{"); writer.WriteLine(" ExceptionManager.Publish(ex);"); writer.WriteLine(" throw ex;"); writer.WriteLine("}"); foreach (ServiceLayerModel model in m_Arch.ServiceLayers) { foreach (ServiceModel model2 in model.Services) { CSharpMethodDef def5 = new CSharpMethodDef(); def5.Comment.Summary = string.Format("Gets the service interface for '{0}'.", model2.MappingName); def5.HeaderLine = string.Format("public static I{0} Get{0}", model2.MappingName); def5.Writer.WriteLine("return m_ServiceFactory.Get{0}();", model2.MappingName); typeDef.Methods.Add(def5); } } }
public static void AddMethodParams(CSharpMethodDef method, DataFieldContainer cont) { foreach (DataFieldModel model in cont) { string name = string.Format("{0}Val", model.NormalizedName); string comment = string.Format("Value of '{0}' field", model.MappingName); method.AddParam(name, SqlTypeMap.GetDBTypeFromFullName(model.TypeString), comment); } }
public void GenerateBaseService(CSharpFile docFile, ServiceModel srv) { docFile.Description = string.Format("Base service for '{0}' entity.", srv.MappingName); docFile.Usings.Add("System.Data"); docFile.Usings.Add("Grepton.Runtime"); docFile.Usings.Add("Grepton.Runtime.DBTypes"); docFile.Usings.Add("Grepton.Runtime.BusinessHosting"); docFile.Usings.Add("Grepton.Diagnostics.EventSchema"); docFile.Usings.Add("Grepton.Diagnostics.Exceptions"); docFile.Usings.Add("Grepton.Diagnostics.Pmc"); docFile.Usings.Add(srv.Parent.DataAccessLayer.NameSpace); docFile.Usings.Add(m_Arch.BusinessDocsLayer.NameSpace); CSharpTypeDef typeDef = new CSharpTypeDef(); docFile.InnerTypes.Add(typeDef); typeDef.Attributes.Add("ImplicitPmc"); typeDef.Comment.Summary = docFile.Description; typeDef.HeaderLine = string.Format("public class {0}Base: BusinessService, I{0}Base", srv.MappingName); CSharpFieldDef def2 = new CSharpFieldDef(); typeDef.Fields.Add(def2); def2.DefLine = string.Format("protected {0} m_DataContext;", srv.Parent.DataAccessLayer.DataContextName); def2.CommentLine = "Data context of this service instance."; CSharpMethodDef def3 = new CSharpMethodDef(); typeDef.Ctors.Add(def3); def3.HeaderLine = string.Format("public {0}Base", srv.MappingName); def3.Comment.Summary = string.Format("Creates the {0} with a default data context.", srv.MappingName); def3.Writer.WriteLine("m_DataContext = new {0}();", srv.Parent.DataAccessLayer.DataContextName); CSharpMethodDef def4 = new CSharpMethodDef(); typeDef.Ctors.Add(def4); def4.HeaderLine = string.Format("public {0}Base", srv.MappingName); def4.AddParam("dataContext", srv.Parent.DataAccessLayer.DataContextName, "Data context of the service."); def4.Comment.Summary = string.Format("Creates the {0} with the specified data context.", srv.MappingName); def4.Writer.WriteLine("m_DataContext = dataContext;"); foreach (OperationModel model in srv.Operations) { IOperationCodeGenerator codeGenerator = model.GetCodeGenerator(); if (codeGenerator.WantGenerateServiceMethod()) { codeGenerator.GenerateServiceMethod(typeDef); } } }
public void GenerateDataContext(DataAccessModel daLayer) { CSharpFile file = CSharpFilePool.Obtain(Path.Combine(daLayer.FullPath, GenerationHelper.GetDataContextName(""))); file.NameSpace = daLayer.NameSpace; file.Description = "Class implementing data access methods."; file.Usings.Add("System.Data"); file.Usings.Add("System.Data.OracleClient"); file.Usings.Add("Grepton.Runtime"); file.Usings.Add("Grepton.Runtime.DBTypes"); file.Usings.Add("Grepton.Runtime.SqlServer"); file.Usings.Add("Grepton.Runtime.BusinessHosting"); file.Usings.Add("Grepton.Diagnostics.EventSchema"); file.Usings.Add("Grepton.Diagnostics.Pmc"); file.Usings.Add(m_Arch.UtilityLayer.NameSpace); CSharpTypeDef typeDef = new CSharpTypeDef(); file.InnerTypes.Add(typeDef); typeDef.Attributes.Add("ImplicitPmc"); typeDef.Comment.Summary = file.Description; typeDef.HeaderLine = string.Format("public class {0}: Base{0}", daLayer.DataContextName); CSharpMethodDef def2 = new CSharpMethodDef(); typeDef.Ctors.Add(def2); def2.Comment.Summary = "This constructor creates a stored procedure interface that uses the database connection as specified in the application configuration file."; def2.HeaderLine = string.Format("public {0}", daLayer.DataContextName); def2.HeaderTrailer = ": base()"; CSharpMethodDef def3 = new CSharpMethodDef(); typeDef.Ctors.Add(def3); def3.Comment.Summary = "This constructor creates a stored procedure interface that uses the database connection as specified in the constructor parameter."; def3.HeaderLine = string.Format("public {0}", daLayer.DataContextName); def3.AddParam("oraConn", "OracleConnection", "Oracle connection to use."); def3.HeaderTrailer = ": base(oraConn)"; file = CSharpFilePool.Obtain(Path.Combine(daLayer.FullPath, GenerationHelper.GetBaseDataContextName(""))); file.NameSpace = daLayer.NameSpace; file.Description = "Class implementing data access methods."; file.Usings.Add("System.Data"); file.Usings.Add("System.Data.OracleClient"); file.Usings.Add("Grepton.Runtime"); file.Usings.Add("Grepton.Runtime.DBTypes"); file.Usings.Add("Grepton.Runtime.SqlServer"); file.Usings.Add("Grepton.Runtime.BusinessHosting"); file.Usings.Add("Grepton.Diagnostics.EventSchema"); file.Usings.Add("Grepton.Diagnostics.Pmc"); file.Usings.Add(m_Arch.UtilityLayer.NameSpace); typeDef = new CSharpTypeDef(); file.InnerTypes.Add(typeDef); typeDef.Attributes.Add("ImplicitPmc"); typeDef.Comment.Summary = file.Description; typeDef.HeaderLine = string.Format("public class Base{0}: Oracle8DataContextBase", daLayer.DataContextName); def2 = new CSharpMethodDef(); typeDef.Ctors.Add(def2); def2.Comment.Summary = "This constructor creates a stored procedure interface that uses the database connection as specified in the application configuration file."; def2.HeaderLine = string.Format("public Base{0}", daLayer.DataContextName); def2.HeaderTrailer = ": base(Configuration.AppDatabaseConnection)"; def3 = new CSharpMethodDef(); typeDef.Ctors.Add(def3); def3.Comment.Summary = "This constructor creates a stored procedure interface that uses tha database connection as specified in the constructor parameter."; def3.HeaderLine = string.Format("public Base{0}", daLayer.DataContextName); def3.AddParam("oraConn", "OracleConnection", "Oracle Server connection to use."); def3.HeaderTrailer = ": base(oraConn)"; foreach (DataEntityModel model in daLayer.Entities) { string packageName = ((Oracle8DataAccessModel) daLayer).PackageName; TraceInfoEvent.Raise(string.Format("Adding method for '{0}'", daLayer.DeleteSpName(model))); GenerateSpMethod(typeDef, daLayer.DeleteSpName(model), model.PKFields, packageName, false, false); TraceInfoEvent.Raise(string.Format("Adding method for '{0}'", daLayer.InsertSpName(model))); GenerateSpMethod(typeDef, daLayer.InsertSpName(model), model.InsertParamFields, packageName, false, false); TraceInfoEvent.Raise(string.Format("Adding method for '{0}'", daLayer.SelectAllSpName(model))); GenerateSpMethod(typeDef, daLayer.SelectAllSpName(model), new DataFieldContainer(), packageName, false, true); TraceInfoEvent.Raise(string.Format("Adding method for '{0}'", daLayer.SelectDispsetAllSpName(model))); GenerateSpMethod(typeDef, daLayer.SelectDispsetAllSpName(model), new DataFieldContainer(), packageName, false, true); TraceInfoEvent.Raise(string.Format("Adding method for '{0}'", daLayer.SelectSpName(model))); GenerateSpMethod(typeDef, daLayer.SelectSpName(model), model.PKFields, packageName, false, true); TraceInfoEvent.Raise(string.Format("Adding method for '{0}'", daLayer.UpdateSpName(model))); GenerateSpMethod(typeDef, daLayer.UpdateSpName(model), model.UpdateParamFields, packageName, true, false); GenerateSpMethod(typeDef, daLayer.UpdateSpName(model), model.UpdateParamFields, packageName, false, false); foreach (AssocModel model2 in model.ParentAssocs) { TraceInfoEvent.Raise(string.Format("Adding method for '{0}'", daLayer.DeleteBySpName(model2))); GenerateSpMethod(typeDef, daLayer.DeleteBySpName(model2), model2.ForeignFields, packageName, true, false); GenerateSpMethod(typeDef, daLayer.DeleteBySpName(model2), model2.ForeignFields, packageName, false, false); TraceInfoEvent.Raise(string.Format("Adding method for '{0}'", daLayer.SelectBySpName(model2))); GenerateSpMethod(typeDef, daLayer.SelectBySpName(model2), model2.ForeignFields, packageName, false, true); } } }
public void GenerateSnippetService(CSharpFile docFile, ServiceModel srv) { docFile.Description = string.Format("Base service for '{0}' entity.", srv.MappingName); docFile.Usings.Add("System.Data"); docFile.Usings.Add("Grepton.Runtime"); docFile.Usings.Add("Grepton.Runtime.DBTypes"); docFile.Usings.Add("Grepton.Runtime.BusinessHosting"); docFile.Usings.Add("Grepton.Diagnostics.EventSchema"); docFile.Usings.Add("Grepton.Diagnostics.Exceptions"); docFile.Usings.Add(srv.Parent.DataAccessLayer.NameSpace); docFile.Usings.Add(m_Arch.BusinessDocsLayer.NameSpace); CSharpTypeDef typeDef = new CSharpTypeDef(); docFile.InnerTypes.Add(typeDef); typeDef.Comment.Summary = docFile.Description; typeDef.HeaderLine = string.Format("public class {0}: {0}Base, I{0}", srv.MappingName); CSharpMethodDef def2 = new CSharpMethodDef(); typeDef.Ctors.Add(def2); def2.HeaderLine = string.Format("public {0}", srv.MappingName); def2.HeaderTrailer = ": base()"; def2.Comment.Summary = string.Format("Creates the {0} with a default data context.", srv.MappingName); CSharpMethodDef def3 = new CSharpMethodDef(); typeDef.Ctors.Add(def3); def3.HeaderLine = string.Format("public {0}", srv.MappingName); def3.HeaderTrailer = ": base(dataContext)"; def3.AddParam("dataContext", srv.Parent.DataAccessLayer.DataContextName, "Data context of the service."); def3.Comment.Summary = string.Format("Creates the {0} with the specified data context.", srv.MappingName); }
private void GenerateSpMethod(CSharpTypeDef dcClass, SqlSpInfo spInfo, bool hasRetVal, bool returnsDataSet) { CSharpMethodDef def = new CSharpMethodDef(); dcClass.Methods.Add(def); def.Comment.Summary = string.Format("Calls stored procedure '{0}'", spInfo.Name); def.Attributes.Add(string.Format("ImplicitPmc(\"{0}\")", spInfo.Name)); if (returnsDataSet) { def.HeaderLine = string.Format("public DataSet {0}", spInfo.Name); def.Comment.Returns = "Resulting DataSet from the stored procedure."; } else { def.HeaderLine = string.Format("public void {0}", spInfo.Name); } foreach (SqlSpParamInfo info in spInfo.Parameters) { if (info.Direction != ParameterDirection.ReturnValue) { if (info.Direction == ParameterDirection.Output) { CSharpMethodparamDef def2 = new CSharpMethodparamDef(info.NormalName, SqlTypeMap.GetDBType(info.Type)); def2.Direction = MethodParamDir.Ref; def.Params.Add(def2); def.Comment.AddParam(info.NormalName, string.Format("{0} parameter.", info.Name)); } else { def.AddParam(info.NormalName, SqlTypeMap.GetDBType(info.Type), string.Format("{0} parameter.", info.Name)); } } } if (hasRetVal) { CSharpMethodparamDef def3 = new CSharpMethodparamDef("retVal", "int"); def3.Direction = MethodParamDir.Out; def.Params.Add(def3); def.Comment.AddParam("retVal", "SP return value."); } TextWriter writer = def.Writer; writer.WriteLine("TraceCallEnterEvent.Raise();"); writer.WriteLine("SqlCommand sqlComm = PrepareSPCall(\"[dbo].[{0}]\");", spInfo.Name); if (hasRetVal) { writer.WriteLine("SqlParameter returnValue = sqlComm.Parameters.Add(\"@RETURNVALUE\", SqlDbType.Int);"); writer.WriteLine("returnValue.Direction = ParameterDirection.ReturnValue;"); } int num = 1; foreach (SqlSpParamInfo info2 in spInfo.Parameters) { if (info2.Direction == ParameterDirection.ReturnValue) { continue; } writer.WriteLine(string.Format("SqlParameter p{0} = sqlComm.Parameters.Add(\"{1}\", {2});", num, info2.Name, info2.SqlParamTypeName)); if (info2.Direction == ParameterDirection.Output) { writer.WriteLine(string.Format("p{0}.Direction = ParameterDirection.Output;", num)); } else if (SqlTypeMap.GetDBType(info2.Type).ToLower() == "bool") { writer.WriteLine(string.Format("p{0}.Value = {1};", num, info2.NormalName)); } else if (SqlTypeMap.GetDBType(info2.Type).ToLower() == "dbdecimal") { writer.WriteLine(string.Format("p{0}.Precision = {1};", num, info2.Precision)); writer.WriteLine(string.Format("p{0}.Scale = {1};", num, info2.Scale)); writer.WriteLine(string.Format("p{0}.Value = {1};", num, info2.NormalName)); } else { writer.WriteLine(string.Format("p{0}.Value = {1}.Value;", num, info2.NormalName)); } num++; } writer.WriteLine("TraceDbCommandEvent.Raise(sqlComm);"); if (returnsDataSet) { writer.WriteLine("DataSet Result = new DataSet();"); } writer.WriteLine("try"); writer.WriteLine("{"); if (returnsDataSet) { writer.WriteLine(" SqlDataAdapter sqlAdapt = new SqlDataAdapter(sqlComm);"); writer.WriteLine(" sqlAdapt.Fill(Result);"); writer.WriteLine(" TraceCallReturnEvent.Raise();"); } else { writer.WriteLine(" sqlComm.ExecuteNonQuery();"); writer.WriteLine(" TraceCallReturnEvent.Raise();"); } writer.WriteLine("}"); writer.WriteLine("catch (SqlException e)"); writer.WriteLine("{"); writer.WriteLine(" TraceCallReturnEvent.Raise(false);"); writer.Write(" SqlErrorHandler.Handle(e, "); if (spInfo.Parameters.Count > 1) { writer.WriteLine(string.Format("{0}.ToString());", spInfo.Parameters[1].NormalName)); } else { writer.WriteLine("\"<unknown>\");"); } writer.WriteLine("}"); writer.WriteLine("finally"); writer.WriteLine("{"); writer.WriteLine(" FinishSPCall();"); writer.WriteLine("}"); num = 0; foreach (SqlSpParamInfo info3 in spInfo.Parameters) { if (info3.Direction == ParameterDirection.Output) { writer.WriteLine(string.Format("{0}.Value = p{1}.Value;", info3.NormalName, num)); } num++; } if (hasRetVal) { writer.WriteLine("retVal = (int)returnValue.Value;"); writer.WriteLine("TraceInfoEvent.Raise(\"RetVal: {0}\", retVal);"); } if (returnsDataSet) { writer.WriteLine("return Result;"); } }
public void GenerateInterface(object outObj) { CSharpInterfaceDef def = outObj as CSharpInterfaceDef; CSharpMethodDef method = new CSharpMethodDef(); switch (m_Type) { case DocOperationType.Select: method.Comment.Summary = string.Format("Get the {0} document by its primary key.", m_Doc.Name); method.HeaderLine = string.Format("{0} {0}{1}", m_Doc.Name, m_Type); GenerationHelper.AddMethodParams(method, m_Doc.RootEntity.PKFields); break; case DocOperationType.Insert: method.Comment.Summary = string.Format("Insert a {0} document.", m_Doc.Name); method.HeaderLine = string.Format("void {0}{1}", m_Doc.Name, m_Type); method.AddParam("entity", m_Doc.Name, "Entity to insert"); break; case DocOperationType.Update: method.Comment.Summary = string.Format("Update a {0} document.", m_Doc.Name); method.HeaderLine = string.Format("void {0}{1}", m_Doc.Name, m_Type); method.AddParam("entity", m_Doc.Name, "Entity to update"); break; case DocOperationType.Delete: method.Comment.Summary = string.Format("Delete the {0} document by its primary key.", m_Doc.Name); method.HeaderLine = string.Format("void {0}{1}", m_Doc.Name, m_Type); method.AddParam("entity", m_Doc.Name, "Entity to delete"); break; case DocOperationType.SelectAll: method.Comment.Summary = string.Format("Get all {0} documents from database.", m_Doc.Name); method.HeaderLine = string.Format("{0}Container {0}{1}", m_Doc.Name, m_Type); break; } method.Abstract = true; def.Methods.Add(method); }
public void GenerateInterface(object outObj) { CSharpInterfaceDef def = outObj as CSharpInterfaceDef; CSharpMethodDef method = new CSharpMethodDef(); switch (m_Type) { case TableOperationType.Select: method.Comment.Summary = string.Format("Get the {0} record by its primary key.", m_Table.MappingName); method.HeaderLine = string.Format("{0} {0}{1}", m_Table.MappingName, m_Type); GenerationHelper.AddMethodParams(method, m_Table.PKFields); break; case TableOperationType.Insert: method.Comment.Summary = string.Format("Insert a record of {0}.", m_Table.MappingName); method.HeaderLine = string.Format("void {0}{1}", m_Table.MappingName, m_Type); method.AddParam("entity", m_Table.MappingName, "Entity to insert"); break; case TableOperationType.Update: method.Comment.Summary = string.Format("Update a record of {0}.", m_Table.MappingName); method.HeaderLine = string.Format("void {0}{1}", m_Table.MappingName, m_Type); method.AddParam("entity", m_Table.MappingName, "Entity to update"); break; case TableOperationType.Delete: method.Comment.Summary = string.Format("Delete the {0} record by its primary key.", m_Table.MappingName); method.HeaderLine = string.Format("void {0}{1}", m_Table.MappingName, m_Type); method.AddParam("entity", m_Table.MappingName, "Entity to delete"); break; case TableOperationType.SelectAll: method.Comment.Summary = string.Format("Get all {0} records from database.", m_Table.MappingName); method.HeaderLine = string.Format("{0}Container {0}{1}", m_Table.MappingName, m_Type); break; case TableOperationType.SelectDispsetAll: if (m_Table.DispFields.Count <= 0) { return; } method.Comment.Summary = string.Format("Get all {0} displayset record from database.", m_Table.MappingName); method.HeaderLine = string.Format("{0}DispsetContainer {0}{1}", m_Table.MappingName, m_Type); break; } method.Abstract = true; def.Methods.Add(method); }
private void GenerateDelete(CSharpTypeDef srvDef, CSharpMethodDef srvMethod) { srvMethod.Comment.Summary = string.Format("Delete the {0} record by its primary key.", m_Doc.Name); srvMethod.HeaderLine = string.Format("public virtual void {0}{1}", m_Doc.Name, m_Type); srvMethod.Attributes.Add(string.Format("ImplicitPmc(\"{0}{1}\")", m_Doc.Name, m_Type)); srvMethod.AddParam("entity", m_Doc.Name, "Entity to delete"); TextWriter tw = srvMethod.Writer; foreach (DocumentRelationModel model in m_Doc.ChildRelations) { CSharpMethodDef def = new CSharpMethodDef(); srvDef.Methods.Add(def); string childRole = model.Association.ChildRole; def.Comment.Summary = string.Format("Delete child container by '{0}'", childRole); def.HeaderLine = string.Format("public virtual void Delete{0}", childRole); def.AddParam("ownerEntity", m_Doc.Name, "Entity that owns the child container."); TextWriter writer = def.Writer; if (model.Document.IsSimple) { writer.WriteLine("{0}Service srv = new {0}Service(m_DataContext);", m_Doc.RootEntity.MappingName); writer.Write("srv.DeleteChildrenBy{1}(", childRole, model.Association.Name); GenerationHelper.EnumerateParams(writer, m_Doc.RootEntity.PKFields, "ownerEntity.{0}"); writer.WriteLine(");"); } else { DataEntityModel rootEntity = model.Document.RootEntity; writer.WriteLine("{0}Service srv = new {0}Service(m_DataContext);", m_Doc.RootEntity.MappingName); writer.WriteLine("{0}Service childSrv = new {0}Service(m_DataContext);", model.Document.Name); writer.Write("{0}Container allChildren = srv.SelectChildrenBy{1}(", rootEntity.MappingName, model.Association.Name); GenerationHelper.EnumerateParams(writer, m_Doc.RootEntity.PKFields, "ownerEntity.{0}"); writer.WriteLine(");"); writer.WriteLine("foreach ({0} childDoc in allChildren.All)", rootEntity.MappingName); writer.WriteLine("{"); writer.WriteLine(" {0} childInstance = new {0}(childDoc);", model.Document.Name); writer.WriteLine(" childSrv.{0}Delete(childInstance);", model.Document.Name); writer.WriteLine("}"); } tw.WriteLine("Delete{0}(entity);", childRole); } tw.Write("m_DataContext.{0}(", base.m_DataLayer.DeleteSpName(m_Doc.RootEntity)); GenerationHelper.EnumerateParams(tw, m_Doc.RootEntity.PKFields, "entity.{0}"); tw.WriteLine(");"); }
private void GenerateUpdate(CSharpMethodDef srvMethod) { srvMethod.Comment.Summary = string.Format("Update a record of {0}.", m_Table.MappingName); srvMethod.HeaderLine = string.Format("public virtual void {0}{1}", m_Table.MappingName, m_Type); srvMethod.Attributes.Add(string.Format("ImplicitPmc(\"{0}{1}\")", m_Table.MappingName, m_Type)); srvMethod.AddParam("entity", m_Table.MappingName, "Entity to update"); TextWriter tw = srvMethod.Writer; tw.WriteLine("int count;"); tw.Write("m_DataContext.{0}(", base.m_DataLayer.UpdateSpName(m_Table)); GenerationHelper.EnumerateParams(tw, m_Table.UpdateParamFields, "entity.{0}"); tw.WriteLine(", out count);"); tw.WriteLine("if (count == 0) throw new ServiceUpdateException();"); }
public void GenerateDispsetContainer(CSharpFile docFile, DataEntityModel de) { CSharpTypeDef typeDef = new CSharpTypeDef(); docFile.InnerTypes.Add(typeDef); typeDef.Comment.Summary = string.Format("This class represents a container of {0} display set.", de.MappingName); string str = string.Format("{0}DispsetContainer", de.MappingName); typeDef.HeaderLine = string.Format("public class {0}: DocumentContainer", str); typeDef.Attributes.Add("Serializable"); if (de.PKFields.Count == de.ConstructorFields.Count) { typeDef.Attributes.Add("SupportsFullKey(true)"); } else { typeDef.Attributes.Add("SupportsFullKey(false)"); } typeDef.Attributes.Add(string.Format("SupportedType(typeof({0}Dispset))", de.MappingName)); CSharpMethodDef def2 = new CSharpMethodDef(); typeDef.Ctors.Add(def2); def2.Comment.Summary = "Default constructor"; def2.HeaderLine = string.Format("public {0}", str); def2.HeaderTrailer = ": base()"; CSharpMethodDef def3 = new CSharpMethodDef(); typeDef.Ctors.Add(def3); def3.Comment.Summary = "DataTable setup constructor"; def3.HeaderLine = string.Format("public {0}", str); def3.AddParam("dataTable", "DataTable", "DataTable containing document data."); def3.HeaderTrailer = ": base(dataTable)"; }