Esempio n. 1
0
 public void GenerateConfigurationClass(VSNetCSharpProject utProj)
 {
     TraceInfoEvent.Raise("Adding configuration class.");
       utProj.AddFile(GenerationHelper.GetConfigClassFileName());
       CSharpFile file =
     CSharpFilePool.Obtain(Path.Combine(m_Arch.UtilityLayer.FullPath, GenerationHelper.GetConfigClassFileName()));
       file.NameSpace = m_Arch.UtilityLayer.NameSpace;
       file.Description = "Class handling configuration";
       file.Usings.Add("System.Data");
       file.Usings.Add("Grepton.Runtime");
       file.Usings.Add("Grepton.Runtime.BusinessHosting");
       CSharpTypeDef typeDef = new CSharpTypeDef();
       file.InnerTypes.Add(typeDef);
       typeDef.Comment.Summary = file.Description;
       typeDef.HeaderLine = "public class Configuration: ConfigurationBase";
       foreach (DataAccessModel model in m_Arch.DataLayers)
       {
     if ((model.UsingClause != string.Empty) && !file.Usings.Contains(model.UsingClause))
     {
       file.Usings.Add(model.UsingClause);
     }
     CSharpPropertyDef def2 = new CSharpPropertyDef();
     typeDef.Properties.Add(def2);
     def2.HeaderLine = string.Format("public static string {0}ConnStr", model.ConfigKeyName);
     def2.Comment.Summary = string.Format("Get connection string for '{0}'", model.LayerName);
     TextWriter getWriter = def2.GetWriter;
     getWriter.WriteLine("try");
     getWriter.WriteLine("{");
     getWriter.WriteLine("  return GetConfigString(CONFIG_SECTION, \"{0}\");", model.ConfigKeyName);
     getWriter.WriteLine("}");
     getWriter.WriteLine("catch");
     getWriter.WriteLine("{");
     getWriter.WriteLine("  return String.Empty;");
     getWriter.WriteLine("}");
     CSharpPropertyDef def3 = new CSharpPropertyDef();
     typeDef.Properties.Add(def3);
     def3.HeaderLine = string.Format("public static {0} {1}Connection", model.ConnectionClass, model.ConfigKeyName);
     def3.Comment.Summary = string.Format("Get connection instance for '{0}'", model.LayerName);
     getWriter = def3.GetWriter;
     getWriter.WriteLine("if ({0}ConnStr == String.Empty)", model.ConfigKeyName);
     getWriter.WriteLine("  return new {0}(@\"{1}\");", model.ConnectionClass, model.ConnectionString);
     getWriter.WriteLine("else");
     getWriter.WriteLine("  return new {0}({1}ConnStr);", model.ConnectionClass, model.ConfigKeyName);
       }
 }
Esempio n. 2
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));
 }
Esempio n. 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();");
       }
 }
Esempio n. 4
0
 private void AddExtraProps(DataEntityModel de, CSharpTypeDef baseClass)
 {
     CSharpPropertyDef def = new CSharpPropertyDef();
       baseClass.Properties.Add(def);
       def.Comment.Summary = "Checks if all data fields are valid.";
       def.HeaderLine = "public override bool AllFieldsValid";
       TextWriter getWriter = def.GetWriter;
       getWriter.Write("return ");
       if (de.UpdateSetFields.Count == 0)
       {
     getWriter.Write("true");
       }
       else
       {
     int num = 0;
     foreach (DataFieldModel model in de.UpdateSetFields)
     {
       if (num > 0)
       {
     getWriter.WriteLine(" &&");
     getWriter.Write("  ");
       }
       getWriter.Write("m_{0}Error == null", model.NormalizedName);
       num++;
     }
       }
       getWriter.WriteLine(";");
       CSharpPropertyDef def2 = new CSharpPropertyDef();
       baseClass.Properties.Add(def2);
       def2.Comment.Summary = "Gets the XML string representation of this instance.";
       def2.HeaderLine = "public override string AsXmlString";
       getWriter = def2.GetWriter;
       getWriter.WriteLine("StringWriter sw = new StringWriter();");
       getWriter.WriteLine("XmlTextWriter xtw = new XmlTextWriter(sw);");
       getWriter.WriteLine("xtw.WriteStartElement(\"{0}\");", de.MappingName);
       foreach (DataFieldModel model2 in de.Fields)
       {
     if (model2.IsPKField)
     {
       getWriter.WriteLine("xtw.WriteAttributeString(\"{0}\", m_{0}.AsXmlString);", model2.NormalizedName);
     }
     else
     {
       if (SqlTypeMap.GetDBTypeFromFullName(model2.TypeString) == "DBString")
       {
     getWriter.WriteLine("xtw.WriteStartElement(\"{0}\");", model2.NormalizedName);
     getWriter.WriteLine("xtw.WriteCData(m_{0}.AsXmlString);", model2.NormalizedName);
     getWriter.WriteLine("xtw.WriteEndElement();");
     continue;
       }
       if (SqlTypeMap.GetDBTypeFromFullName(model2.TypeString) == "bool")
       {
     getWriter.WriteLine("xtw.WriteElementString(\"{0}\", m_{0}.ToString());", model2.NormalizedName);
     continue;
       }
       getWriter.WriteLine("xtw.WriteElementString(\"{0}\", m_{0}.AsXmlString);", model2.NormalizedName);
     }
       }
       getWriter.WriteLine("xtw.WriteEndElement();");
       getWriter.WriteLine("return sw.ToString();");
 }
Esempio n. 5
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);
       }
 }
Esempio n. 6
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");
 }