Exemplo n.º 1
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.º 2
0
 public static CSharpFile Obtain(string file)
 {
     if (m_Pool.ContainsKey(file))
       {
     return (CSharpFile) m_Pool[file];
       }
       CSharpFile file2 = new CSharpFile(file);
       m_Pool.Add(file, file2);
       return file2;
 }
Exemplo n.º 3
0
 public void GenerateSnippetInterface(CSharpFile docFile, ServiceModel srv)
 {
     docFile.Description = string.Format("Interface for '{0}' entity.", srv.MappingName);
       docFile.Usings.Add("Grepton.Runtime");
       docFile.Usings.Add("Grepton.Runtime.DBTypes");
       CSharpTypeDef typeDef = new CSharpInterfaceDef();
       docFile.InnerTypes.Add(typeDef);
       typeDef.Comment.Summary = docFile.Description;
       typeDef.HeaderLine = string.Format("public interface I{0}: I{0}Base", srv.MappingName);
 }
Exemplo n.º 4
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.º 5
0
 public void GenerateSnippetDocument(CSharpFile docFile, DataEntityModel de, string className)
 {
     GenerateSnippetDocument(docFile, de, className, className);
 }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
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);
       }
 }
Exemplo n.º 8
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)";
 }
Exemplo n.º 9
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");
 }
Exemplo n.º 10
0
 public void GenerateBaseInterface(CSharpFile docFile, ServiceModel srv)
 {
     docFile.Description = string.Format("Base interface for '{0}' entity.", srv.MappingName);
       docFile.Usings.Add("Grepton.Runtime");
       docFile.Usings.Add("Grepton.Runtime.DBTypes");
       CSharpTypeDef typeDef = new CSharpInterfaceDef();
       docFile.InnerTypes.Add(typeDef);
       typeDef.Comment.Summary = docFile.Description;
       typeDef.HeaderLine = string.Format("public interface I{0}Base", srv.MappingName);
       if (!m_Arch.DisableBaseInterfaces)
       {
     foreach (OperationModel model in srv.Operations)
     {
       IOperationCodeGenerator codeGenerator = model.GetCodeGenerator();
       if (codeGenerator.WantGenerateServiceMethod())
       {
     codeGenerator.GenerateInterface(typeDef);
       }
     }
       }
 }
Exemplo n.º 11
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);
 }