PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/Plugins/GizmoBeach.Components/ServiceLayer/EntLibValidationServiceLayerObjects.cs

http://github.com/kahanu/CondorXE
C# | 305 lines | 272 code | 33 blank | 0 comment | 0 complexity | 7b63de52006fe07579aa068e83c54240 MD5 | raw file
  1. using System;
  2. using System.Linq;
  3. using Condor.Core;
  4. using Condor.Core.Interfaces;
  5. using MyMeta;
  6. namespace GizmoBeach.Components.ServiceLayer
  7. {
  8. public class EntLibValidationServiceLayerObjects : RenderBase, IServiceObjects
  9. {
  10. #region ctors
  11. private readonly RequestContext _context;
  12. public EntLibValidationServiceLayerObjects(RequestContext context)
  13. : base(context.Zeus.Output)
  14. {
  15. this._context = context;
  16. }
  17. #endregion
  18. #region IRenderObject Members
  19. public void Render()
  20. {
  21. _context.Dialog.InitDialog(_context.Database.Tables.Count);
  22. _context.FileList.Add("");
  23. _context.FileList.Add("Generated EntLibValidation Service Layer interfaces: ");
  24. RenderServiceCRUDInterface();
  25. foreach (string tableName in _script.Tables)
  26. {
  27. _context.Dialog.Display("Adding I" + tableName + "Service Interface");
  28. ITable table = _context.Database.Tables[tableName];
  29. RenderInterface(table);
  30. }
  31. _context.Dialog.InitDialog(_context.Database.Tables.Count);
  32. _context.FileList.Add("");
  33. _context.FileList.Add("Generated EntLibValidation Service Layer Base classes: ");
  34. foreach (string tableName in _script.Tables)
  35. {
  36. _context.Dialog.Display("Adding " + tableName + "ServiceBase class");
  37. ITable table = _context.Database.Tables[tableName];
  38. RenderServiceBaseClass(table);
  39. }
  40. _context.Dialog.InitDialog(_context.Database.Tables.Count);
  41. _context.FileList.Add("");
  42. _context.FileList.Add("Generated EntLibValidation Service Layer classes: ");
  43. foreach (string tableName in _script.Tables)
  44. {
  45. _context.Dialog.Display("Adding " + tableName + "Service class");
  46. ITable table = _context.Database.Tables[tableName];
  47. RenderConcreteClass(table);
  48. }
  49. }
  50. #endregion
  51. #region Private Methods
  52. private void RenderConcreteClass(ITable table)
  53. {
  54. _hdrUtil.WriteClassHeader(_output);
  55. try
  56. {
  57. GenTable genTable = new GenTable(table, _context);
  58. string sortColumn = genTable.GetFirstStringColumnName();
  59. _output.autoTabLn("using System;");
  60. _output.autoTabLn("using System.Collections.Generic;");
  61. _output.autoTabLn("using System.Linq;");
  62. _output.autoTabLn("using System.Text;");
  63. _output.autoTabLn("");
  64. _output.autoTabLn("using " + _script.Settings.BusinessObjects.BusinessObjectsNamespace + ";");
  65. _output.autoTabLn("using " + _script.Settings.ServiceLayer.ServiceNamespace + ".Interfaces;");
  66. _output.autoTabLn("using " + _script.Settings.DataOptions.DataObjectsNamespace + ";");
  67. _output.autoTabLn("using " + _script.Settings.DataOptions.DataObjectsNamespace + ".Interfaces;");
  68. _output.autoTabLn("");
  69. _output.autoTabLn("namespace " + _script.Settings.ServiceLayer.ServiceNamespace);
  70. _output.autoTabLn("{");
  71. _output.autoTabLn(" public class " + StringFormatter.CleanUpClassName(table.Name) + "Service : " + StringFormatter.CleanUpClassName(table.Name) + "ServiceBase, I" + StringFormatter.CleanUpClassName(table.Name) + "Service");
  72. _output.autoTabLn(" {");
  73. _output.autoTabLn("");
  74. _output.tabLevel++;
  75. _output.autoTabLn("#region Dependency Injection");
  76. _output.tabLevel++;
  77. _output.autoTabLn("");
  78. _output.tabLevel--;
  79. _output.autoTabLn("public " + StringFormatter.CleanUpClassName(table.Name) + "Service(I" + StringFormatter.CleanUpClassName(table.Name) + _script.Settings.DataOptions.ClassSuffix.Name + " " + StringFormatter.CleanUpClassName(table.Name) + _script.Settings.DataOptions.ClassSuffix.Name + "):base(" + StringFormatter.CleanUpClassName(table.Name) + _script.Settings.DataOptions.ClassSuffix.Name + ")");
  80. _output.autoTabLn("{");
  81. _output.autoTabLn("}");
  82. _output.autoTabLn("");
  83. _output.autoTabLn("#endregion");
  84. _output.tabLevel--;
  85. _output.autoTabLn("");
  86. _output.tabLevel++;
  87. _output.autoTabLn("#region I" + StringFormatter.CleanUpClassName(table.Name) + "Service Members");
  88. _output.tabLevel--;
  89. _output.autoTabLn("");
  90. _output.tabLevel++;
  91. _output.autoTabLn("public List<" + _context.Utility.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(table.Name)) + "> GetAll(string sortExpression, int startRowIndex, int maximumRows)");
  92. _output.autoTabLn("{");
  93. _output.tabLevel++;
  94. _output.autoTabLn("if (string.IsNullOrEmpty(sortExpression))");
  95. _output.tabLevel++;
  96. _output.autoTabLn("sortExpression = \"" + sortColumn + "\";");
  97. _output.tabLevel--;
  98. _output.tabLevel--;
  99. _output.autoTabLn("");
  100. _output.tabLevel++;
  101. _output.autoTabLn("return " + StringFormatter.CamelCasing(StringFormatter.CleanUpClassName(table.Name)) + _script.Settings.DataOptions.ClassSuffix.Name + ".GetAll(sortExpression, startRowIndex, maximumRows);");
  102. _output.tabLevel--;
  103. _output.autoTabLn("}");
  104. _output.tabLevel--;
  105. _output.autoTabLn("");
  106. _output.tabLevel++;
  107. _output.autoTabLn("public int GetCount()");
  108. _output.autoTabLn("{");
  109. _output.tabLevel++;
  110. _output.autoTabLn("return " + StringFormatter.CamelCasing(StringFormatter.CleanUpClassName(table.Name)) + _script.Settings.DataOptions.ClassSuffix.Name + ".GetAll().Count;");
  111. _output.tabLevel--;
  112. _output.autoTabLn("}");
  113. _output.autoTabLn("");
  114. _output.autoTabLn("public " + _context.Utility.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(table.Name)) + " GetById(int Id)");
  115. _output.autoTabLn("{");
  116. _output.tabLevel++;
  117. _output.autoTabLn("return " + StringFormatter.CamelCasing(StringFormatter.CleanUpClassName(table.Name)) + _script.Settings.DataOptions.ClassSuffix.Name + ".GetById(Id);");
  118. _output.tabLevel--;
  119. _output.autoTabLn("}");
  120. _output.tabLevel--;
  121. _output.autoTabLn("");
  122. _output.tabLevel++;
  123. _output.autoTabLn("#endregion");
  124. _output.tabLevel--;
  125. _output.autoTabLn(" }");
  126. _output.autoTabLn("}");
  127. _context.FileList.Add(" " + StringFormatter.CleanUpClassName(table.Name) + "Service.cs");
  128. SaveOutput(CreateFullPath(_script.Settings.ServiceLayer.ServiceNamespace, StringFormatter.CleanUpClassName(table.Name) + "Service.cs"), SaveActions.DontOverwrite);
  129. }
  130. catch (Exception ex)
  131. {
  132. throw new Exception("Error rendering ServiceLayer Concrete class - " + ex.Message);
  133. }
  134. }
  135. private void RenderServiceBaseClass(ITable table)
  136. {
  137. _hdrUtil.WriteClassHeader(_output);
  138. try
  139. {
  140. _output.autoTabLn("using System.Collections.Generic;");
  141. _output.autoTabLn("using System.Linq;");
  142. _output.autoTabLn("using " + _script.Settings.BusinessObjects.BusinessObjectsNamespace + ";");
  143. _output.autoTabLn("using " + _script.Settings.ServiceLayer.ServiceNamespace + ".Interfaces;");
  144. _output.autoTabLn("using " + _script.Settings.DataOptions.DataObjectsNamespace + ";");
  145. _output.autoTabLn("using " + _script.Settings.DataOptions.DataObjectsNamespace + ".Interfaces;");
  146. _output.autoTabLn("");
  147. _output.autoTabLn("namespace " + _script.Settings.ServiceLayer.ServiceNamespace);
  148. _output.autoTabLn("{");
  149. _output.autoTabLn(" public class " + StringFormatter.CleanUpClassName(table.Name) + "ServiceBase : ICRUDService<" + _context.Utility.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(table.Name)) + ">");
  150. _output.autoTabLn(" {");
  151. _output.tabLevel++;
  152. _output.autoTabLn("#region Dependency Injection");
  153. _output.autoTabLn("");
  154. _output.autoTabLn("protected I" + StringFormatter.CleanUpClassName(table.Name) + _script.Settings.DataOptions.ClassSuffix.Name + " " + StringFormatter.CamelCasing(StringFormatter.CleanUpClassName(table.Name)) + _script.Settings.DataOptions.ClassSuffix.Name + ";");
  155. _output.tabLevel--;
  156. _output.autoTabLn("");
  157. _output.tabLevel++;
  158. _output.autoTabLn("public " + StringFormatter.CleanUpClassName(table.Name) + "ServiceBase(I" + StringFormatter.CleanUpClassName(table.Name) + _script.Settings.DataOptions.ClassSuffix.Name + " " + StringFormatter.CleanUpClassName(table.Name) + _script.Settings.DataOptions.ClassSuffix.Name + ")");
  159. _output.autoTabLn("{");
  160. _output.tabLevel++;
  161. _output.autoTabLn("this." + StringFormatter.CamelCasing(StringFormatter.CleanUpClassName(table.Name)) + _script.Settings.DataOptions.ClassSuffix.Name + " = " + StringFormatter.CleanUpClassName(table.Name) + _script.Settings.DataOptions.ClassSuffix.Name + ";");
  162. _output.tabLevel--;
  163. _output.autoTabLn("}");
  164. _output.autoTabLn("");
  165. _output.autoTabLn("#endregion");
  166. _output.tabLevel--;
  167. _output.autoTabLn("");
  168. _output.tabLevel++;
  169. _output.autoTabLn("public List<" + _context.Utility.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(table.Name)) + "> GetAll()");
  170. _output.autoTabLn("{");
  171. _output.tabLevel++;
  172. _output.autoTabLn("return " + StringFormatter.CamelCasing(StringFormatter.CleanUpClassName(table.Name)) + _script.Settings.DataOptions.ClassSuffix.Name + ".GetAll().ToList();");
  173. _output.tabLevel--;
  174. _output.autoTabLn("}");
  175. _output.tabLevel--;
  176. _output.autoTabLn("");
  177. _output.tabLevel++;
  178. _output.autoTabLn("public void Insert(" + _context.Utility.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(table.Name)) + " model)");
  179. _output.autoTabLn("{");
  180. _output.tabLevel++;
  181. _output.autoTabLn("EntLibValidation.Validator<" + _context.Utility.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(table.Name)) + ">.Validate(model);");
  182. _output.autoTabLn("" + StringFormatter.CamelCasing(StringFormatter.CleanUpClassName(table.Name)) + _script.Settings.DataOptions.ClassSuffix.Name + ".Insert(model);");
  183. _output.tabLevel--;
  184. _output.autoTabLn("}");
  185. _output.tabLevel--;
  186. _output.autoTabLn("");
  187. _output.tabLevel++;
  188. _output.autoTabLn("public void Update(" + _context.Utility.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(table.Name)) + " model)");
  189. _output.autoTabLn("{");
  190. _output.tabLevel++;
  191. _output.autoTabLn("EntLibValidation.Validator<" + _context.Utility.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(table.Name)) + ">.Validate(model);");
  192. _output.autoTabLn("" + StringFormatter.CamelCasing(StringFormatter.CleanUpClassName(table.Name)) + _script.Settings.DataOptions.ClassSuffix.Name + ".Update(model);");
  193. _output.tabLevel--;
  194. _output.autoTabLn("}");
  195. _output.tabLevel--;
  196. _output.autoTabLn("");
  197. _output.tabLevel++;
  198. _output.autoTabLn("public void Delete(" + _context.Utility.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(table.Name)) + " model)");
  199. _output.autoTabLn("{");
  200. _output.tabLevel++;
  201. _output.autoTabLn("EntLibValidation.Validator<" + _context.Utility.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(table.Name)) + ">.Validate(model);");
  202. _output.autoTabLn("" + StringFormatter.CamelCasing(StringFormatter.CleanUpClassName(table.Name)) + _script.Settings.DataOptions.ClassSuffix.Name + ".Delete(model);");
  203. _output.tabLevel--;
  204. _output.autoTabLn("}");
  205. _output.tabLevel--;
  206. _output.autoTabLn(" }");
  207. _output.autoTabLn("}");
  208. _context.FileList.Add(" " + StringFormatter.CleanUpClassName(table.Name) + "ServiceBase.cs");
  209. SaveOutput(CreateFullPath(_script.Settings.ServiceLayer.ServiceNamespace + "\\Generated", StringFormatter.CleanUpClassName(table.Name) + "ServiceBase.cs"), SaveActions.Overwrite);
  210. }
  211. catch (Exception ex)
  212. {
  213. throw new Exception("Error rendering ServiceBase class - " + ex.Message);
  214. }
  215. }
  216. private void RenderInterface(ITable table)
  217. {
  218. _hdrUtil.WriteClassHeader(_output);
  219. try
  220. {
  221. _output.autoTabLn("using System;");
  222. _output.autoTabLn("using System.Collections.Generic;");
  223. _output.autoTabLn("using System.Linq;");
  224. _output.autoTabLn("using System.Text;");
  225. _output.autoTabLn("");
  226. _output.autoTabLn("using " + _script.Settings.BusinessObjects.BusinessObjectsNamespace + ";");
  227. _output.autoTabLn("");
  228. _output.autoTabLn("namespace " + _script.Settings.ServiceLayer.ServiceNamespace);
  229. _output.autoTabLn("{");
  230. _output.autoTabLn(" public interface I" + StringFormatter.CleanUpClassName(table.Name) + "Service : ICRUDService<" + _context.Utility.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(table.Name)) + ">");
  231. _output.autoTabLn(" {");
  232. _output.tabLevel++;
  233. _output.autoTabLn(_context.Utility.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(table.Name)) + " GetById(" + _context.Utility.RenderConcreteMethodParameters(table) + ");");
  234. _output.autoTabLn("List<" + _context.Utility.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(table.Name)) + "> GetAll(string sortExpression, int startRowIndex, int maximumRows);");
  235. _output.autoTabLn("int GetCount();");
  236. _output.tabLevel--;
  237. _output.autoTabLn(" }");
  238. _output.autoTabLn("}");
  239. _context.FileList.Add(" I" + StringFormatter.CleanUpClassName(table.Name) + "Service.cs");
  240. SaveOutput(CreateFullPath(_script.Settings.ServiceLayer.ServiceNamespace + "\\Interfaces", "I" + StringFormatter.CleanUpClassName(table.Name) + "Service.cs"), SaveActions.DontOverwrite);
  241. }
  242. catch (Exception ex)
  243. {
  244. throw new Exception("Error rendering RenderServiceLayerInterface - " + ex.Message);
  245. }
  246. }
  247. private void RenderServiceCRUDInterface()
  248. {
  249. _hdrUtil.WriteClassHeader(_output);
  250. _output.autoTabLn("using System;");
  251. _output.autoTabLn("using System.Collections.Generic;");
  252. _output.autoTabLn("using System.Linq;");
  253. _output.autoTabLn("using System.Text;");
  254. _output.autoTabLn("");
  255. _output.autoTabLn("using " + _script.Settings.BusinessObjects.BusinessObjectsNamespace + ";");
  256. _output.autoTabLn("");
  257. _output.autoTabLn("namespace " + _script.Settings.ServiceLayer.ServiceNamespace);
  258. _output.autoTabLn("{");
  259. _output.autoTabLn(" public interface ICRUDService<T>");
  260. _output.autoTabLn(" {");
  261. _output.autoTabLn(" List<T> GetAll();");
  262. _output.autoTabLn(" void Insert(T model);");
  263. _output.autoTabLn(" void Update(T model);");
  264. _output.autoTabLn(" void Delete(T model);");
  265. _output.autoTabLn(" }");
  266. _output.autoTabLn("}");
  267. _context.FileList.Add(" ICRUDService.cs");
  268. SaveOutput(CreateFullPath(_script.Settings.ServiceLayer.ServiceNamespace + "\\Interfaces", "ICRUDService.cs"), SaveActions.Overwrite);
  269. }
  270. #endregion
  271. }
  272. }