Beispiel #1
0
 public void GenerateCompoundDocument(CSharpFile docFile, BusinessDocModel bd)
 {
     docFile.Description = string.Format("Base business document class for '{0}' entity.", bd.Name);
       docFile.Usings.Add("System.Xml");
       docFile.Usings.Add("System.IO");
       docFile.Usings.Add("System.Data");
       docFile.Usings.Add("System.Data.SqlClient");
       docFile.Usings.Add("Grepton.Runtime");
       docFile.Usings.Add("Grepton.Runtime.DBTypes");
       docFile.Usings.Add("Grepton.Runtime.BusinessHosting");
       CSharpTypeDef typeDef = new CSharpTypeDef();
       docFile.InnerTypes.Add(typeDef);
       typeDef.Comment.Summary = docFile.Description;
       typeDef.HeaderLine = string.Format("public class {0}Base: {1}", bd.Name, bd.RootEntity.MappingName);
       typeDef.Attributes.Add("Serializable");
       GenerateSnippetConstructors(typeDef, bd.RootEntity, string.Format("{0}Base", bd.Name), bd.RootEntity.MappingName);
       foreach (DocumentRelationModel model in bd.ParentRelations)
       {
     CSharpFieldDef def2 = new CSharpFieldDef();
     typeDef.Fields.Add(def2);
     string str = model.Document.IsSimple ? model.Document.RootEntity.MappingName : model.Document.Name;
     string parentRole = model.Association.ParentRole;
     def2.CommentLine = string.Format("Parent document by '{0}'.", parentRole);
     def2.DefLine = string.Format("private {0} m_{1} = null;", str, parentRole);
     CSharpPropertyDef def3 = new CSharpPropertyDef();
     typeDef.Properties.Add(def3);
     def3.Comment.Summary = string.Format("Parent document by '{0}'", parentRole);
     def3.HeaderLine = string.Format("public {0} {1}", str, parentRole);
     def3.GetWriter.WriteLine(string.Format("return m_{0};", parentRole));
     def3.SetWriter.WriteLine(string.Format("m_{0} = value;", parentRole));
       }
       foreach (DocumentRelationModel model2 in bd.ChildRelations)
       {
     CSharpFieldDef def4 = new CSharpFieldDef();
     typeDef.Fields.Add(def4);
     string str3 = model2.Document.IsSimple ? model2.Document.RootEntity.MappingName : model2.Document.Name;
     string childRole = model2.Association.ChildRole;
     def4.CommentLine = string.Format("Child container by '{0}'.", childRole);
     def4.DefLine = string.Format("private {0}Container m_{1} = new {0}Container();", str3, childRole);
     CSharpPropertyDef def5 = new CSharpPropertyDef();
     typeDef.Properties.Add(def5);
     def5.Comment.Summary = string.Format("Child container by '{0}'", childRole);
     def5.HeaderLine = string.Format("public {0}Container {1}", str3, childRole);
     def5.GetWriter.WriteLine(string.Format("return m_{0};", childRole));
     def5.SetWriter.WriteLine(string.Format("m_{0} = value;", childRole));
       }
       GenerateContainerClass(docFile, bd.RootEntity, bd.Name, string.Format("{0}ContainerBase", bd.Name),                             "DocumentContainer");
 }
Beispiel #2
0
 private void GenerateSpsPartial(DataAccessModel daLayer, SqlSpInfo info2, CSharpTypeDef typeDef)
 {
     if (info2.Name.Substring(0, 3) != "dt_")
       {
     string prefix = daLayer.Prefix;
     if ((prefix == string.Empty) || (prefix == info2.Name.Substring(0, prefix.Length)))
     {
       bool returnsDataSet = (info2.ResultColumns != null) ||
                         ((Sql2000DataAccessModel) daLayer).IsInDynamicSp(info2.Name);
       TraceInfoEvent.Raise(string.Format("Adding method for '{0}'", info2.Name));
       GenerateSpMethod(typeDef, info2, true, returnsDataSet);
       GenerateSpMethod(typeDef, info2, false, returnsDataSet);
     }
       }
 }
Beispiel #3
0
 // Methods
 public void Add(CSharpTypeDef typeDef)
 {
     m_TypeDefs.Add(typeDef);
 }
Beispiel #4
0
 private void GenerateSelectAll(CSharpTypeDef srvDef, CSharpMethodDef srvMethod)
 {
     srvMethod.Comment.Summary = string.Format("Get all {0} documents from database.", m_Doc.Name);
       srvMethod.HeaderLine = string.Format("public virtual {0}Container {0}{1}", m_Doc.Name, m_Type);
       srvMethod.Attributes.Add(string.Format("ImplicitPmc(\"{0}{1}\")", m_Doc.Name, m_Type));
       srvMethod.Comment.Returns = string.Format("Container of {0} documents obtained from the database.", m_Doc.Name);
       TextWriter tw = srvMethod.Writer;
       tw.WriteLine("{0}Container result = new {0}Container();", m_Doc.Name);
       tw.WriteLine("{0}Service srv = new {0}Service();", m_Doc.RootEntity.MappingName);
       tw.WriteLine("{0}Container entities = srv.{0}SelectAll();", m_Doc.RootEntity.MappingName);
       tw.WriteLine("foreach({0} item in entities.All)", m_Doc.RootEntity.MappingName);
       tw.WriteLine("{");
       tw.Write("  result.Add({0}Select(", m_Doc.Name);
       GenerationHelper.EnumerateParams(tw, m_Doc.RootEntity.PKFields, "item.{0}");
       tw.WriteLine("));");
       tw.WriteLine("}");
 }
Beispiel #5
0
 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;");
       }
 }
Beispiel #6
0
 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);
 }
Beispiel #7
0
 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(");");
 }
Beispiel #8
0
 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);
 }
Beispiel #9
0
 public void GenerateSnippetDocument(CSharpFile docFile, DataEntityModel de, string className, string copyClassName)
 {
     docFile.Description = string.Format("Document class for '{0}' entity.", className);
       docFile.Usings.Add("System.Xml");
       docFile.Usings.Add("System.IO");
       docFile.Usings.Add("System.Data");
       docFile.Usings.Add("System.Data.SqlClient");
       docFile.Usings.Add("Grepton.Runtime");
       docFile.Usings.Add("Grepton.Runtime.DBTypes");
       docFile.Usings.Add("Grepton.Runtime.BusinessHosting");
       CSharpTypeDef typeDef = new CSharpTypeDef();
       docFile.InnerTypes.Add(typeDef);
       typeDef.Comment.Summary = docFile.Description;
       typeDef.HeaderLine = string.Format("public class {0}: {0}Base", className);
       typeDef.Attributes.Add("Serializable");
       typeDef.Attributes.Add(string.Format("EntityName(\"{0}\")", className));
       typeDef.Attributes.Add(string.Format("EntityDescription(\"{0} business document\")", className));
       GenerateSnippetConstructors(typeDef, de, className, copyClassName);
 }
Beispiel #10
0
 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);
     }
       }
 }
Beispiel #11
0
 public void GenerateSnippetConstructors(CSharpTypeDef snippetClass, DataEntityModel de, string className)
 {
     GenerateSnippetConstructors(snippetClass, de, className, className);
 }
Beispiel #12
0
 public void GenerateRemoteServiceFactory(VSNetCSharpProject bdProj)
 {
     string projectName = bdProj.ProjectName;
       string remoteSFClassFileName = GenerationHelper.GetRemoteSFClassFileName();
       string str3 = m_Arch.BusinessDocsLayer.FullPath + remoteSFClassFileName;
       bdProj.AddFile(remoteSFClassFileName);
       CSharpFile file = CSharpFilePool.Obtain(str3);
       file.NameSpace = bdProj.ProjectName;
       TraceInfoEvent.Raise("Adding remotes service factory class.");
       file.Description = "Remote 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");
       file.Usings.Add(m_Arch.BusinessDocsLayer.NameSpace);
       CSharpTypeDef typeDef = new CSharpTypeDef();
       file.InnerTypes.Add(typeDef);
       typeDef.Comment.Summary = file.Description;
       typeDef.HeaderLine = "public class RemoteServiceFactory: IServiceFactory";
       CSharpMethodDef def2 = new CSharpMethodDef();
       typeDef.Ctors.Add(def2);
       def2.Comment.Summary = "Initializes the service factory with URIs.";
       def2.HeaderLine = "static RemoteServiceFactory";
       foreach (ServiceLayerModel model in m_Arch.ServiceLayers)
       {
     foreach (ServiceModel model2 in model.Services)
     {
       CSharpFieldDef def3 = new CSharpFieldDef();
       def3.CommentLine = string.Format("URI for '{0}'", model2.MappingName);
       def3.DefLine = string.Format("private static string m_{0}Uri;", model2.MappingName);
       typeDef.Fields.Add(def3);
       CSharpMethodDef def4 = new CSharpMethodDef();
       def4.Comment.Summary = string.Format("Gets the service interface for '{0}'.", model2.MappingName);
       def4.HeaderLine = string.Format("public I{0} Get{0}", model2.MappingName);
       def4.Writer.WriteLine("return (I{0})Activator.GetObject(typeof(I{0}), m_{0}Uri);", model2.MappingName);
       typeDef.Methods.Add(def4);
       def2.Writer.WriteLine("m_{0}Uri = RemoteFactory.GetUri(\"{1}/{0}\");", model2.MappingName,                                model2.Parent.NameSpace);
     }
       }
 }
Beispiel #13
0
 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);
       }
 }
Beispiel #14
0
 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)";
 }
Beispiel #15
0
 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);
     }
       }
 }
Beispiel #16
0
 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);
 }
Beispiel #17
0
 public void GenerateLocalServiceFactory(VSNetCSharpProject bsProj, ServiceLayerModel svLayer)
 {
     string localSFClassFileName = GenerationHelper.GetLocalSFClassFileName();
       string str2 = svLayer.FullPath + localSFClassFileName;
       bsProj.AddFile(localSFClassFileName);
       CSharpFile file = CSharpFilePool.Obtain(str2);
       TraceInfoEvent.Raise("Adding local service factory class.");
       file.Description = "Local service factory class.";
       file.NameSpace = bsProj.ProjectName;
       file.Usings.Add("Grepton.Runtime");
       file.Usings.Add("Grepton.Runtime.DBTypes");
       file.Usings.Add("Grepton.Runtime.BusinessHosting");
       file.Usings.Add(m_Arch.BusinessDocsLayer.NameSpace);
       CSharpTypeDef typeDef = new CSharpTypeDef();
       file.InnerTypes.Add(typeDef);
       typeDef.Comment.Summary = file.Description;
       typeDef.HeaderLine = "public class LocalServiceFactory: IServiceFactory";
       foreach (ServiceModel model in svLayer.Services)
       {
     CSharpMethodDef def2 = new CSharpMethodDef();
     def2.Comment.Summary = string.Format("Gets the service interface for '{0}'.", model.MappingName);
     def2.HeaderLine = string.Format("public I{0} Get{0}", model.MappingName);
     def2.Writer.WriteLine("return new {0}();", model.MappingName);
     typeDef.Methods.Add(def2);
       }
 }
Beispiel #18
0
 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)";
     }
       }
 }
Beispiel #19
0
 public void GenerateConfigurationClass(VSNetCSharpProject utProj)
 {
     TraceInfoEvent.Raise("Adding configuration class.");
       utProj.AddFile(GenerationHelper.GetConfigClassFileName());
       CSharpFile file =
     CSharpFilePool.Obtain(Path.Combine(m_Arch.UtilityLayer.FullPath, GenerationHelper.GetConfigClassFileName()));
       file.NameSpace = m_Arch.UtilityLayer.NameSpace;
       file.Description = "Class handling configuration";
       file.Usings.Add("System.Data");
       file.Usings.Add("Grepton.Runtime");
       file.Usings.Add("Grepton.Runtime.BusinessHosting");
       CSharpTypeDef typeDef = new CSharpTypeDef();
       file.InnerTypes.Add(typeDef);
       typeDef.Comment.Summary = file.Description;
       typeDef.HeaderLine = "public class Configuration: ConfigurationBase";
       foreach (DataAccessModel model in m_Arch.DataLayers)
       {
     if ((model.UsingClause != string.Empty) && !file.Usings.Contains(model.UsingClause))
     {
       file.Usings.Add(model.UsingClause);
     }
     CSharpPropertyDef def2 = new CSharpPropertyDef();
     typeDef.Properties.Add(def2);
     def2.HeaderLine = string.Format("public static string {0}ConnStr", model.ConfigKeyName);
     def2.Comment.Summary = string.Format("Get connection string for '{0}'", model.LayerName);
     TextWriter getWriter = def2.GetWriter;
     getWriter.WriteLine("try");
     getWriter.WriteLine("{");
     getWriter.WriteLine("  return GetConfigString(CONFIG_SECTION, \"{0}\");", model.ConfigKeyName);
     getWriter.WriteLine("}");
     getWriter.WriteLine("catch");
     getWriter.WriteLine("{");
     getWriter.WriteLine("  return String.Empty;");
     getWriter.WriteLine("}");
     CSharpPropertyDef def3 = new CSharpPropertyDef();
     typeDef.Properties.Add(def3);
     def3.HeaderLine = string.Format("public static {0} {1}Connection", model.ConnectionClass, model.ConfigKeyName);
     def3.Comment.Summary = string.Format("Get connection instance for '{0}'", model.LayerName);
     getWriter = def3.GetWriter;
     getWriter.WriteLine("if ({0}ConnStr == String.Empty)", model.ConfigKeyName);
     getWriter.WriteLine("  return new {0}(@\"{1}\");", model.ConnectionClass, model.ConnectionString);
     getWriter.WriteLine("else");
     getWriter.WriteLine("  return new {0}({1}ConnStr);", model.ConnectionClass, model.ConfigKeyName);
       }
 }
Beispiel #20
0
 private void AddExtraProps(DataEntityModel de, CSharpTypeDef baseClass)
 {
     CSharpPropertyDef def = new CSharpPropertyDef();
       baseClass.Properties.Add(def);
       def.Comment.Summary = "Checks if all data fields are valid.";
       def.HeaderLine = "public override bool AllFieldsValid";
       TextWriter getWriter = def.GetWriter;
       getWriter.Write("return ");
       if (de.UpdateSetFields.Count == 0)
       {
     getWriter.Write("true");
       }
       else
       {
     int num = 0;
     foreach (DataFieldModel model in de.UpdateSetFields)
     {
       if (num > 0)
       {
     getWriter.WriteLine(" &&");
     getWriter.Write("  ");
       }
       getWriter.Write("m_{0}Error == null", model.NormalizedName);
       num++;
     }
       }
       getWriter.WriteLine(";");
       CSharpPropertyDef def2 = new CSharpPropertyDef();
       baseClass.Properties.Add(def2);
       def2.Comment.Summary = "Gets the XML string representation of this instance.";
       def2.HeaderLine = "public override string AsXmlString";
       getWriter = def2.GetWriter;
       getWriter.WriteLine("StringWriter sw = new StringWriter();");
       getWriter.WriteLine("XmlTextWriter xtw = new XmlTextWriter(sw);");
       getWriter.WriteLine("xtw.WriteStartElement(\"{0}\");", de.MappingName);
       foreach (DataFieldModel model2 in de.Fields)
       {
     if (model2.IsPKField)
     {
       getWriter.WriteLine("xtw.WriteAttributeString(\"{0}\", m_{0}.AsXmlString);", model2.NormalizedName);
     }
     else
     {
       if (SqlTypeMap.GetDBTypeFromFullName(model2.TypeString) == "DBString")
       {
     getWriter.WriteLine("xtw.WriteStartElement(\"{0}\");", model2.NormalizedName);
     getWriter.WriteLine("xtw.WriteCData(m_{0}.AsXmlString);", model2.NormalizedName);
     getWriter.WriteLine("xtw.WriteEndElement();");
     continue;
       }
       if (SqlTypeMap.GetDBTypeFromFullName(model2.TypeString) == "bool")
       {
     getWriter.WriteLine("xtw.WriteElementString(\"{0}\", m_{0}.ToString());", model2.NormalizedName);
     continue;
       }
       getWriter.WriteLine("xtw.WriteElementString(\"{0}\", m_{0}.AsXmlString);", model2.NormalizedName);
     }
       }
       getWriter.WriteLine("xtw.WriteEndElement();");
       getWriter.WriteLine("return sw.ToString();");
 }
Beispiel #21
0
 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("}");
 }
Beispiel #22
0
 private void AddInfoField(DataFieldModel fi, CSharpTypeDef baseClass)
 {
     string normalizedName = fi.NormalizedName;
       CSharpFieldDef def = new CSharpFieldDef();
       baseClass.Fields.Add(def);
       def.Attributes.Add(string.Format("BindingField(\"{0}\")", fi.Name));
       def.DefLine = string.Format("protected {0} m_{1} = new {0}();", SqlTypeMap.GetDBTypeFromFullName(fi.TypeString),                                  normalizedName);
       def.CommentLine = string.Format("Member representing field '{0}'", fi.MappingName);
       CSharpPropertyDef def2 = new CSharpPropertyDef();
       baseClass.Properties.Add(def2);
       def2.Comment.Summary = string.Format("Access information for field '{0}'", fi.MappingName);
       def2.HeaderLine = string.Format("public {0} {1}", SqlTypeMap.GetDBTypeFromFullName(fi.TypeString), normalizedName);
       def2.GetWriter.WriteLine(string.Format("return m_{0};", normalizedName));
       if ((!fi.IsPKField && !fi.IsIdentity) && !fi.IsCalculated)
       {
     TextWriter setWriter = def2.SetWriter;
     setWriter.WriteLine("try");
     setWriter.WriteLine("{");
     setWriter.WriteLine("  m_{0} = value;", normalizedName);
     setWriter.WriteLine("  m_{0}Modified = true;", normalizedName);
     setWriter.WriteLine("}");
     setWriter.WriteLine("catch (RuntimeException e)");
     setWriter.WriteLine("{");
     setWriter.WriteLine("  m_{0}Error = e;", normalizedName);
     setWriter.WriteLine("}");
     setWriter.WriteLine("catch (Exception e)");
     setWriter.WriteLine("{");
     setWriter.WriteLine("  m_{0}Error = new InvalidPropertyValueException(\"Internal Exception\", e);",                            normalizedName);
     setWriter.WriteLine("}");
     setWriter.WriteLine("SignModification();");
       }
 }
Beispiel #23
0
 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);
     }
       }
 }
Beispiel #24
0
 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(";");
       }
 }
Beispiel #25
0
 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;");
       }
 }
Beispiel #26
0
 private void AddModificationField(DataFieldModel fi, CSharpTypeDef baseClass)
 {
     string normalizedName = fi.NormalizedName;
       CSharpFieldDef def = new CSharpFieldDef();
       baseClass.Fields.Add(def);
       def.Attributes.Add("NonSerialized");
       def.DefLine = string.Format("private bool m_{0}Modified = false;", fi.NormalizedName);
       def.CommentLine = string.Format("Is the '{0}' field modified?", fi.MappingName);
       CSharpPropertyDef def2 = new CSharpPropertyDef();
       baseClass.Properties.Add(def2);
       def2.Comment.Summary = string.Format("Is the field '{0}' modified?", fi.MappingName);
       def2.HeaderLine = string.Format("public bool Is{0}Modified", normalizedName);
       def2.GetWriter.WriteLine(string.Format("return m_{0}Modified;", normalizedName));
       CSharpFieldDef def3 = new CSharpFieldDef();
       baseClass.Fields.Add(def3);
       def3.Attributes.Add("NonSerialized");
       def3.DefLine = string.Format("private RuntimeException m_{0}Error = null;", fi.NormalizedName);
       def3.CommentLine = string.Format("Exception raised when modifying '{0}'", fi.MappingName);
       CSharpPropertyDef def4 = new CSharpPropertyDef();
       baseClass.Properties.Add(def4);
       def4.Comment.Summary = string.Format("Is the field '{0}' valid?", fi.MappingName);
       def4.HeaderLine = string.Format("public bool Is{0}Valid", normalizedName);
       def4.GetWriter.WriteLine(string.Format("return m_{0}Error == null;", normalizedName));
       CSharpPropertyDef def5 = new CSharpPropertyDef();
       baseClass.Properties.Add(def5);
       def5.Comment.Summary = string.Format("Runtime exception field '{0}'", fi.MappingName);
       def5.HeaderLine = string.Format("public RuntimeException {0}Error", normalizedName);
       def5.GetWriter.WriteLine(string.Format("return m_{0}Error;", normalizedName));
 }
Beispiel #27
0
        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;
        }
Beispiel #28
0
 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));
     }
       }
 }
Beispiel #29
0
 public void Remove(CSharpTypeDef typeDef)
 {
     m_TypeDefs.Remove(typeDef);
 }
Beispiel #30
0
 public void GenerateBaseDocument(CSharpFile docFile, DataEntityModel de)
 {
     docFile.Description = string.Format("Base business document class for '{0}' entity.", de.MappingName);
       docFile.Usings.Add("System.Xml");
       docFile.Usings.Add("System.IO");
       docFile.Usings.Add("System.Data");
       docFile.Usings.Add("System.Data.SqlClient");
       docFile.Usings.Add("Grepton.Runtime");
       docFile.Usings.Add("Grepton.Runtime.DBTypes");
       docFile.Usings.Add("Grepton.Runtime.BusinessHosting");
       CSharpTypeDef typeDef = new CSharpTypeDef();
       docFile.InnerTypes.Add(typeDef);
       typeDef.Comment.Summary = docFile.Description;
       typeDef.HeaderLine = string.Format("public class {0}Base: BusinessDocument", de.MappingName);
       typeDef.Attributes.Add("Serializable");
       foreach (DataFieldModel model in de.Fields)
       {
     AddInfoField(model, typeDef);
     if ((!model.IsPKField && !model.IsIdentity) && !model.IsCalculated)
     {
       AddModificationField(model, typeDef);
     }
       }
       AddConstructors(de, typeDef);
       AddMethods(de, typeDef);
       AddExtraProps(de, typeDef);
 }