Example #1
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));
 }
Example #2
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);
     }
       }
 }
Example #3
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();");
       }
 }
Example #4
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);
     }
       }
 }
Example #5
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);
     }
       }
 }
Example #6
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);
       }
 }
Example #7
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");
 }