PageRenderTime 58ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Condor.Core/Infrastructure/CommonGenerators.cs

http://github.com/kahanu/CondorXE
C# | 120 lines | 104 code | 8 blank | 8 comment | 0 complexity | 3e88fc3d03d21bb9356a902fde882512 MD5 | raw file
  1. using System;
  2. using System.Linq;
  3. using MyMeta;
  4. namespace Condor.Core.Infrastructure
  5. {
  6. public class CommonGenerators : RenderBase, Condor.Core.Interfaces.ICommonGenerators
  7. {
  8. #region ctors
  9. private readonly RequestContext _context;
  10. /// <summary>
  11. /// This class renders commonly used data code such as:
  12. /// -- DaoCRUDInterface
  13. /// -- DaoInterfaces
  14. /// -- ServiceCRUDInterface
  15. /// -- ServiceInterfaces
  16. /// </summary>
  17. /// <param name="context"></param>
  18. public CommonGenerators(RequestContext context) : base(context.Zeus.Output)
  19. {
  20. this._context = context;
  21. }
  22. #endregion
  23. #region Members
  24. public void RenderDaoCRUDInterface()
  25. {
  26. _output.autoTabLn("using System;");
  27. _output.autoTabLn("using System.Linq;");
  28. _output.autoTabLn("using System.Collections.Generic;");
  29. _output.autoTabLn("");
  30. _output.autoTabLn("namespace " + _script.Settings.DataOptions.DataObjectsNamespace + ".Interfaces");
  31. _output.autoTabLn("{");
  32. _output.tabLevel++;
  33. _output.autoTabLn("public interface ICRUD" + _script.Settings.DataOptions.ClassSuffix.Name + "<T>");
  34. _output.autoTabLn("{");
  35. _output.tabLevel++;
  36. _output.autoTabLn("#region CRUD Methods");
  37. _output.autoTabLn("");
  38. _output.autoTabLn("List<T> GetAll();");
  39. _output.autoTabLn("void Insert(T model);");
  40. _output.autoTabLn("void Delete(T model);");
  41. _output.autoTabLn("void Update(T model);");
  42. _output.autoTabLn("");
  43. _output.autoTabLn("#endregion");
  44. _output.tabLevel--;
  45. _output.autoTabLn("");
  46. _output.autoTabLn("}");
  47. _output.tabLevel--;
  48. _output.autoTabLn("}");
  49. }
  50. public void RenderDaoInterface(ITable table)
  51. {
  52. _output.autoTabLn("using System;");
  53. _output.autoTabLn("using System.Linq;");
  54. _output.autoTabLn("using System.Collections.Generic;");
  55. _output.autoTabLn("");
  56. _output.autoTabLn("using " + _script.Settings.BusinessObjects.BusinessObjectsNamespace + ";");
  57. _output.autoTabLn("");
  58. _output.autoTabLn("namespace " + _script.Settings.DataOptions.DataObjectsNamespace + ".Interfaces");
  59. _output.autoTabLn("{");
  60. _output.tabLevel++;
  61. _output.autoTabLn("public interface I" + StringFormatter.CleanUpClassName(table.Name) + _script.Settings.DataOptions.ClassSuffix.Name + " : ICRUD" + _script.Settings.DataOptions.ClassSuffix.Name + "<" + _context.Utility.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(table.Name)) + ">");
  62. _output.autoTabLn("{");
  63. _output.tabLevel++;
  64. _output.autoTabLn("" + _context.Utility.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(table.Name)) + " GetById(" + StringFormatter.CamelCasing(_context.Utility.RenderConcreteMethodParameters(table)) + ");");
  65. _output.autoTabLn("List<" + _context.Utility.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(table.Name)) + "> GetAll(string sortExpression, int startRowIndex, int maximumRows);");
  66. _output.tabLevel--;
  67. _output.autoTabLn("}");
  68. _output.tabLevel--;
  69. _output.autoTabLn("}");
  70. }
  71. public void RenderServiceCRUDInterface()
  72. {
  73. _output.autoTabLn("using System;");
  74. _output.autoTabLn("using System.Collections.Generic;");
  75. _output.autoTabLn("using System.Linq;");
  76. _output.autoTabLn("");
  77. _output.autoTabLn("");
  78. _output.autoTabLn("namespace " + _script.Settings.ServiceLayer.ServiceNamespace);
  79. _output.autoTabLn("{");
  80. _output.autoTabLn(" public interface ICRUDService<T>");
  81. _output.autoTabLn(" {");
  82. _output.autoTabLn(" List<T> GetAll();");
  83. _output.autoTabLn(" void Insert(T model);");
  84. _output.autoTabLn(" void Update(T model);");
  85. _output.autoTabLn(" void Delete(T model);");
  86. _output.autoTabLn(" }");
  87. _output.autoTabLn("}");
  88. }
  89. public void RenderServiceInterface(ITable table)
  90. {
  91. _output.autoTabLn("using System;");
  92. _output.autoTabLn("using System.Collections.Generic;");
  93. _output.autoTabLn("using System.Linq;");
  94. _output.autoTabLn("");
  95. _output.autoTabLn("");
  96. _output.autoTabLn("namespace " + _script.Settings.ServiceLayer.ServiceNamespace + ".Interfaces");
  97. _output.autoTabLn("{");
  98. _output.tabLevel++;
  99. _output.autoTabLn("public interface I" + StringFormatter.CleanUpClassName(table.Name) + "Service : ICRUDService<" + _context.Utility.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(table.Name)) + ">");
  100. _output.autoTabLn("{");
  101. _output.tabLevel++;
  102. _output.autoTabLn(_context.Utility.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(table.Name)) + " GetById(" + _context.Utility.RenderConcreteMethodParameters(table) + ");");
  103. _output.autoTabLn("List<" + _context.Utility.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(table.Name)) + "> GetAll(string sortExpression, int startRowIndex, int maximumRows);");
  104. _output.autoTabLn("int GetCount();");
  105. _output.tabLevel--;
  106. _output.autoTabLn("}");
  107. _output.tabLevel--;
  108. _output.autoTabLn("}");
  109. }
  110. #endregion
  111. }
  112. }