Exemplo n.º 1
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);
     }
       }
 }
Exemplo n.º 2
0
 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(");");
 }
Exemplo n.º 3
0
 private void GenerateSelectDispsetAll(CSharpMethodDef srvMethod)
 {
     if (m_Table.DispFields.Count > 0)
       {
     srvMethod.Comment.Summary = string.Format("Get all {0} displayset records from database.", m_Table.MappingName);
     srvMethod.HeaderLine = string.Format("public virtual {0}DispsetContainer {0}{1}", m_Table.MappingName, m_Type);
     srvMethod.Attributes.Add(string.Format("ImplicitPmc(\"{0}{1}\")", m_Table.MappingName, m_Type));
     TextWriter writer = srvMethod.Writer;
     writer.WriteLine("{0}DispsetContainer result;", m_Table.MappingName);
     writer.WriteLine("DataSet entitySet = m_DataContext.{0}();", base.m_DataLayer.SelectDispsetAllSpName(m_Table));
     writer.WriteLine("result = new {0}DispsetContainer(entitySet.Tables[0]);", m_Table.MappingName);
       }
 }
Exemplo n.º 4
0
 private void GenerateSelectBy(CSharpMethodDef srvMethod)
 {
     srvMethod.Comment.Summary = string.Format("Get the {0} child records by '{1}'.", m_Assoc.Child.MappingName,                                                m_Assoc.ParentRole);
       string str = string.Format("SelectChildrenBy{0}", m_Assoc.ParentRole);
       srvMethod.Attributes.Add(string.Format("ImplicitPmc(\"{0}\")", str));
       srvMethod.HeaderLine = string.Format("public virtual {0}Container {1}", m_Assoc.Child.MappingName, str);
       GenerationHelper.AddMethodParams(srvMethod, m_Assoc.Parent.PKFields);
       TextWriter tw = srvMethod.Writer;
       tw.WriteLine("{0}Container result;", m_Assoc.Child.MappingName);
       tw.Write("DataSet entitySet = m_DataContext.{0}(", base.m_DataLayer.SelectBySpName(m_Assoc));
       GenerationHelper.EnumerateParams(tw, m_Assoc.Parent.PKFields, "{0}Val");
       tw.WriteLine(");");
       tw.WriteLine("result = new {0}Container(entitySet.Tables[0]);", m_Assoc.Child.MappingName);
 }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
0
        public void GenerateInterface(object outObj)
        {
            CSharpInterfaceDef def = outObj as CSharpInterfaceDef;
              CSharpMethodDef method = new CSharpMethodDef();
              string str = null;
              switch (m_Type)
              {
            case AssocOperationType.SelectBy:
              method.Comment.Summary = string.Format("Get the {0} child records by '{1}'.", m_Assoc.Child.MappingName,                                                 m_Assoc.ParentRole);
              str = string.Format("SelectChildrenBy{0}", m_Assoc.ParentRole);
              method.HeaderLine = string.Format("{0}Container {1}", m_Assoc.Child.MappingName, str);
              GenerationHelper.AddMethodParams(method, m_Assoc.Parent.PKFields);
              break;

            case AssocOperationType.DeleteBy:
              method.Comment.Summary = string.Format("Delete the {0} child records by '{1}'.", m_Assoc.Child.MappingName,                                                 m_Assoc.ParentRole);
              str = string.Format("DeleteChildrenBy{0}", m_Assoc.ParentRole);
              method.HeaderLine = string.Format("{0}Container {1}", m_Assoc.Child.MappingName, str);
              method.HeaderLine = string.Format("void {0}", str);
              GenerationHelper.AddMethodParams(method, m_Assoc.Parent.PKFields);
              break;
              }
              method.Abstract = true;
              def.Methods.Add(method);
        }
Exemplo n.º 7
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;");
       }
 }
Exemplo n.º 8
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));
     }
       }
 }
Exemplo n.º 9
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);
     }
       }
 }
Exemplo n.º 10
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)";
     }
       }
 }
Exemplo n.º 11
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(";");
       }
 }
Exemplo n.º 12
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);
 }
Exemplo n.º 13
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);
 }
Exemplo n.º 14
0
 public void GenerateServiceFactoryInterface(VSNetCSharpProject bdProj)
 {
     string projectName = bdProj.ProjectName;
       string sFIntFileName = GenerationHelper.GetSFIntFileName();
       string str3 = m_Arch.BusinessDocsLayer.FullPath + sFIntFileName;
       bdProj.AddFile(sFIntFileName);
       CSharpFile file = CSharpFilePool.Obtain(str3);
       file.NameSpace = bdProj.ProjectName;
       TraceInfoEvent.Raise("Adding service factory interface.");
       file.Description = "Service factory interface.";
       CSharpInterfaceDef typeDef = new CSharpInterfaceDef();
       file.InnerTypes.Add(typeDef);
       typeDef.Comment.Summary = file.Description;
       typeDef.HeaderLine = "public interface IServiceFactory";
       foreach (ServiceLayerModel model in m_Arch.ServiceLayers)
       {
     foreach (ServiceModel model2 in model.Services)
     {
       CSharpMethodDef def2 = new CSharpMethodDef();
       def2.Comment.Summary = string.Format("Gets the service interface for '{0}'.", model2.MappingName);
       def2.HeaderLine = string.Format("I{0} Get{0}", model2.MappingName);
       typeDef.Methods.Add(def2);
     }
       }
 }
Exemplo n.º 15
0
 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");
 }
Exemplo n.º 16
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);
       }
 }
Exemplo n.º 17
0
 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);
       }
 }
Exemplo n.º 18
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);
 }
Exemplo n.º 19
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);
     }
       }
 }
Exemplo n.º 20
0
        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);
        }
Exemplo n.º 21
0
 private void GenerateDeleteBy(CSharpMethodDef srvMethod)
 {
     srvMethod.Comment.Summary = string.Format("Delete the {0} child records by '{1}'.", m_Assoc.Child.MappingName,                                                m_Assoc.ParentRole);
       string str = string.Format("DeleteChildrenBy{0}", m_Assoc.ParentRole);
       srvMethod.Attributes.Add(string.Format("ImplicitPmc(\"{0}\")", str));
       srvMethod.HeaderLine = string.Format("public virtual void {0}", str);
       GenerationHelper.AddMethodParams(srvMethod, m_Assoc.Parent.PKFields);
       TextWriter tw = srvMethod.Writer;
       tw.Write("m_DataContext.{0}(", base.m_DataLayer.DeleteBySpName(m_Assoc));
       GenerationHelper.EnumerateParams(tw, m_Assoc.Parent.PKFields, "{0}Val");
       tw.WriteLine(");");
 }
Exemplo n.º 22
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(");");
 }
Exemplo n.º 23
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;");
       }
 }
Exemplo n.º 24
0
 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("}");
     }
       }
 }
Exemplo n.º 25
0
        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);
        }
Exemplo n.º 26
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("}");
 }
Exemplo n.º 27
0
 private void GenerateSelect(CSharpMethodDef srvMethod)
 {
     srvMethod.Comment.Summary = string.Format("Get the {0} record by its primary key.", m_Table.MappingName);
       srvMethod.HeaderLine = string.Format("public virtual {0} {0}{1}", m_Table.MappingName, m_Type);
       srvMethod.Attributes.Add(string.Format("ImplicitPmc(\"{0}{1}\")", m_Table.MappingName, m_Type));
       GenerationHelper.AddMethodParams(srvMethod, m_Table.PKFields);
       srvMethod.Comment.Returns = string.Format("{0} obtained from the database, or null, if not found",                                                m_Table.MappingName);
       TextWriter tw = srvMethod.Writer;
       tw.WriteLine("{0} result = null;", m_Table.MappingName);
       tw.Write("DataSet entitySet = m_DataContext.{0}(", base.m_DataLayer.SelectSpName(m_Table));
       GenerationHelper.EnumerateParams(tw, m_Table.PKFields, "{0}Val");
       tw.WriteLine(");");
       tw.WriteLine("if (entitySet.Tables[0].Rows.Count != 0)");
       tw.WriteLine("{");
       tw.WriteLine("  result = new {0}(entitySet);", m_Table.MappingName);
       tw.WriteLine("}");
 }
Exemplo n.º 28
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("}");
 }
Exemplo n.º 29
0
 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();");
 }
Exemplo n.º 30
0
 public void GenerateInterface(object outObj)
 {
     CSharpInterfaceDef def = outObj as CSharpInterfaceDef;
       CSharpMethodDef method = new CSharpMethodDef();
       method.Comment.Summary = string.Format("Get the '{0}' records by '{1}' association.", m_RightAssoc.Parent.Name,                                             m_LeftAssoc.Name);
       method.HeaderLine = string.Format("{0}Container {0}AssignBy{1}", m_RightAssoc.Parent.Name, m_LeftAssoc.Name);
       GenerationHelper.AddMethodParams(method, m_LeftAssoc.Parent.PKFields);
       method.Abstract = true;
       def.Methods.Add(method);
 }