PageRenderTime 57ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/branches/v41/Source/Widgetsphere.Generator.DAL/ProjectItemGenerators/BusinessCollection/BusinessCollectionGeneratedTemplate.cs

#
C# | 1496 lines | 1313 code | 123 blank | 60 comment | 93 complexity | 8a74916c5c83ae6d1854e662addb38fc MD5 | raw file
Possible License(s): JSON, CC-BY-SA-3.0

Large files files are truncated, but you can click here to view the full file

  1. #region Copyright (c) 2006-2011 Widgetsphere LLC, All Rights Reserved
  2. //--------------------------------------------------------------------- *
  3. // Widgetsphere LLC *
  4. // Copyright (c) 2006-2011 All Rights reserved *
  5. // *
  6. // *
  7. //This file and its contents are protected by United States and *
  8. //International copyright laws. Unauthorized reproduction and/or *
  9. //distribution of all or any portion of the code contained herein *
  10. //is strictly prohibited and will result in severe civil and criminal *
  11. //penalties. Any violations of this copyright will be prosecuted *
  12. //to the fullest extent possible under law. *
  13. // *
  14. //THE SOURCE CODE CONTAINED HEREIN AND IN RELATED FILES IS PROVIDED *
  15. //TO THE REGISTERED DEVELOPER FOR THE PURPOSES OF EDUCATION AND *
  16. //TROUBLESHOOTING. UNDER NO CIRCUMSTANCES MAY ANY PORTION OF THE SOURCE *
  17. //CODE BE DISTRIBUTED, DISCLOSED OR OTHERWISE MADE AVAILABLE TO ANY *
  18. //THIRD PARTY WITHOUT THE EXPRESS WRITTEN CONSENT OF WIDGETSPHERE LLC *
  19. // *
  20. //UNDER NO CIRCUMSTANCES MAY THE SOURCE CODE BE USED IN WHOLE OR IN *
  21. //PART, AS THE BASIS FOR CREATING A PRODUCT THAT PROVIDES THE SAME, OR *
  22. //SUBSTANTIALLY THE SAME, FUNCTIONALITY AS ANY WIDGETSPHERE PRODUCT. *
  23. // *
  24. //THE REGISTERED DEVELOPER ACKNOWLEDGES THAT THIS SOURCE CODE *
  25. //CONTAINS VALUABLE AND PROPRIETARY TRADE SECRETS OF WIDGETSPHERE, *
  26. //INC. THE REGISTERED DEVELOPER AGREES TO EXPEND EVERY EFFORT TO *
  27. //INSURE ITS CONFIDENTIALITY. *
  28. // *
  29. //THE END USER LICENSE AGREEMENT (EULA) ACCOMPANYING THE PRODUCT *
  30. //PERMITS THE REGISTERED DEVELOPER TO REDISTRIBUTE THE PRODUCT IN *
  31. //EXECUTABLE FORM ONLY IN SUPPORT OF APPLICATIONS WRITTEN USING *
  32. //THE PRODUCT. IT DOES NOT PROVIDE ANY RIGHTS REGARDING THE *
  33. //SOURCE CODE CONTAINED HEREIN. *
  34. // *
  35. //THIS COPYRIGHT NOTICE MAY NOT BE REMOVED FROM THIS FILE. *
  36. //--------------------------------------------------------------------- *
  37. #endregion
  38. using System;
  39. using System.Collections.Generic;
  40. using System.Linq;
  41. using System.Text;
  42. using Widgetsphere.Generator.Common.Util;
  43. using Widgetsphere.Generator.Models;
  44. namespace Widgetsphere.Generator.DAL.ProjectItemGenerators.BusinessCollection
  45. {
  46. class BusinessCollectionGeneratedTemplate : DomainProjectTemplate
  47. {
  48. private readonly StringBuilder sb = new StringBuilder();
  49. private readonly Table _currentTable;
  50. public BusinessCollectionGeneratedTemplate(ModelRoot model, Table currentTable)
  51. {
  52. _model = model;
  53. _currentTable = currentTable;
  54. }
  55. #region BaseClassTemplate overrides
  56. public override string FileName
  57. {
  58. get { return string.Format("{0}Collection.Generated.cs", _currentTable.PascalName); }
  59. }
  60. public string ParentItemName
  61. {
  62. get { return string.Format("{0}Collection.cs", _currentTable.PascalName); }
  63. }
  64. public override string FileContent
  65. {
  66. get
  67. {
  68. GenerateContent();
  69. return sb.ToString();
  70. }
  71. }
  72. #endregion
  73. #region GenerateContent
  74. private void GenerateContent()
  75. {
  76. try
  77. {
  78. Widgetsphere.Generator.GenerationHelper.AppendCopyrightInCode(sb, _model);
  79. this.AppendUsingStatements();
  80. sb.AppendLine("namespace " + this.GetLocalNamespace() + ".Business.Objects");
  81. sb.AppendLine("{");
  82. this.AppendClass();
  83. this.AppendSearchClass();
  84. this.AppendPagingClass();
  85. sb.AppendLine("}");
  86. }
  87. catch (Exception ex)
  88. {
  89. throw;
  90. }
  91. }
  92. #endregion
  93. #region namespace / objects
  94. public void AppendUsingStatements()
  95. {
  96. sb.AppendLine("using System;");
  97. sb.AppendLine("using System.Data;");
  98. sb.AppendLine("using System.Xml;");
  99. sb.AppendLine("using System.Collections;");
  100. sb.AppendLine("using System.Runtime.Serialization;");
  101. sb.AppendLine("using System.ComponentModel;");
  102. sb.AppendLine("using " + this.GetLocalNamespace() + ".Business.Rules;");
  103. sb.AppendLine("using " + this.GetLocalNamespace() + ".Business.SelectCommands;");
  104. sb.AppendLine("using " + this.GetLocalNamespace() + ".Domain.Objects;");
  105. sb.AppendLine("using Widgetsphere.Core.DataAccess;");
  106. sb.AppendLine("using Widgetsphere.Core.Util;");
  107. sb.AppendLine("using Widgetsphere.Core.Logging;");
  108. sb.AppendLine("using Widgetsphere.Core.Exceptions;");
  109. sb.AppendLine("using " + this.GetLocalNamespace() + ".Business.LINQ;");
  110. sb.AppendLine("using System.IO;");
  111. sb.AppendLine("using System.Collections.Generic;");
  112. sb.AppendLine("using System.Linq.Expressions;");
  113. sb.AppendLine("using System.Data.Linq;");
  114. sb.AppendLine("using System.Linq;");
  115. sb.AppendLine("using System.Text;");
  116. sb.AppendLine("using Widgetsphere.Core.EventArgs;");
  117. sb.AppendLine("using System.Text.RegularExpressions;");
  118. sb.AppendLine();
  119. }
  120. private void AppendClass()
  121. {
  122. var baseClass = "Widgetsphere.Core.DataAccess.BusinessCollectionPersistableBase";
  123. var baseInterface = "Widgetsphere.Core.DataAccess.IPersistableBusinessCollection";
  124. if (_currentTable.Immutable)
  125. {
  126. baseClass = "Widgetsphere.Core.DataAccess.BusinessCollectionBase";
  127. baseInterface = "Widgetsphere.Core.DataAccess.IBusinessCollection";
  128. }
  129. if (_currentTable.ParentTable != null)
  130. baseClass = _currentTable.ParentTable.PascalName + "Collection";
  131. var additional40Interface = string.Empty;
  132. if (_model.FrameworkVersion == FrameworkVersionConstants.v40)
  133. additional40Interface = ", System.Collections.Specialized.INotifyCollectionChanged";
  134. sb.AppendLine(" /// <summary>");
  135. sb.AppendLine(" /// The collection to hold '" + _currentTable.PascalName + "' entities");
  136. StringHelper.WriteGeneratedCommentSection(1, sb, _currentTable.Description);
  137. sb.AppendLine(" /// </summary>");
  138. sb.AppendLine(" [Serializable()]");
  139. sb.AppendLine(" " + this.ClassScope + " partial class " + _currentTable.PascalName + "Collection : " + baseClass + ", " + baseInterface + ", System.IDisposable, System.ComponentModel.IListSource, System.Collections.IList, System.Collections.IEnumerator, System.Collections.Generic.IEnumerable<" + this.GetLocalNamespace() + ".Business.Objects." + _currentTable.PascalName + ">, Widgetsphere.Core.DataAccess.IWrappingClass" + additional40Interface);
  140. sb.AppendLine(" {");
  141. this.AppendMemberVariables();
  142. this.AppendConstructors();
  143. this.AppendProperties();
  144. this.AppendOperatorIndexer();
  145. this.AppendMethods();
  146. //this.AppendIListImplementation();
  147. this.AppendRegionIBusinessCollectionExplicit();
  148. //this.AppendRegionGetFilteredList();
  149. this.AppendRegionGetDatabaseFieldName();
  150. this.AppendClassEnumerator();
  151. this.AppendRegionSearch();
  152. this.AppendRegionCustomSelectByRules();
  153. this.AppendRegionSelectByDates();
  154. this.AppendRegionEnumerator();
  155. this.AppendInterfaces();
  156. this.Append40Features();
  157. sb.AppendLine(" }");
  158. sb.AppendLine();
  159. }
  160. private void AppendRegionSearch()
  161. {
  162. if (!_model.SupportLegacySearchObject)
  163. {
  164. sb.AppendLine(" #region Search Members");
  165. sb.AppendLine();
  166. sb.AppendLine(" /// <summary>");
  167. sb.AppendLine(" /// Creates a search object to query this collection.");
  168. sb.AppendLine(" /// </summary>");
  169. sb.AppendLine(" IBusinessObjectSearch IBusinessCollection.CreateSearchObject(SearchType searchType)");
  170. sb.AppendLine(" {");
  171. sb.AppendLine(" throw new Exception(\"This functionality is not supported because the model did not support legacy search objects.\");");
  172. sb.AppendLine(" }");
  173. sb.AppendLine();
  174. sb.AppendLine(" #endregion");
  175. sb.AppendLine();
  176. }
  177. else
  178. {
  179. sb.AppendLine(" #region Search Members");
  180. sb.AppendLine();
  181. sb.AppendLine(" /// <summary>");
  182. sb.AppendLine(" /// Creates a search object to query this collection.");
  183. sb.AppendLine(" /// </summary>");
  184. sb.AppendLine(" IBusinessObjectSearch IBusinessCollection.CreateSearchObject(SearchType searchType)");
  185. sb.AppendLine(" {");
  186. sb.AppendLine(" return (IBusinessObjectSearch)this.CreateSearchObject(searchType);");
  187. sb.AppendLine(" }");
  188. sb.AppendLine();
  189. sb.AppendLine(" /// <summary>");
  190. sb.AppendLine(" /// Creates a search object to query this collection.");
  191. sb.AppendLine(" /// </summary>");
  192. if (_model.Database.AllowZeroTouch)
  193. {
  194. if (_currentTable.ParentTable == null)
  195. sb.AppendLine(" public virtual IBusinessObjectSearch CreateSearchObject(SearchType searchType)");
  196. else
  197. sb.AppendLine(" public new IBusinessObjectSearch CreateSearchObject(SearchType searchType)");
  198. sb.AppendLine(" {");
  199. sb.AppendLine(" return null;");
  200. sb.AppendLine(" }");
  201. }
  202. else
  203. {
  204. if (_currentTable.ParentTable == null)
  205. sb.AppendLine(" public virtual " + _currentTable.PascalName + "Search CreateSearchObject(SearchType searchType)");
  206. else
  207. sb.AppendLine(" public new " + _currentTable.PascalName + "Search CreateSearchObject(SearchType searchType)");
  208. sb.AppendLine(" {");
  209. sb.AppendLine(" return new " + _currentTable.PascalName + "Search(searchType);");
  210. sb.AppendLine(" }");
  211. }
  212. sb.AppendLine();
  213. sb.AppendLine(" #endregion");
  214. sb.AppendLine();
  215. }
  216. }
  217. private void AppendRegionSelectByDates()
  218. {
  219. sb.AppendLine(" #region Select By Dates");
  220. sb.AppendLine();
  221. if (_currentTable.Generated && _currentTable.AllowCreateAudit)
  222. {
  223. sb.AppendLine(" /// <summary>");
  224. sb.AppendLine(" /// Select objects by their created date.");
  225. sb.AppendLine(" /// </summary>");
  226. sb.AppendLine(" /// <param name=\"startDate\">The inclusive date on which to start the search.</param>");
  227. sb.AppendLine(" /// <param name=\"endDate\">The inclusive date on which to end the search.</param>");
  228. sb.AppendLine(" /// <param name=\"modifier\">The identifier used for the create and modify audits.</param>");
  229. if (_currentTable.ParentTable == null)
  230. sb.AppendLine(" public static " + _currentTable.PascalName + "Collection SelectByCreatedDateRange(DateTime? startDate, DateTime? endDate, string modifier)");
  231. else
  232. sb.AppendLine(" public new static " + _currentTable.PascalName + "Collection SelectByCreatedDateRange(DateTime? startDate, DateTime? endDate, string modifier)");
  233. sb.AppendLine(" {");
  234. if (_model.Database.AllowZeroTouch)
  235. {
  236. //If zero-touch then use LINQ
  237. sb.AppendLine(" return " + _currentTable.PascalName + "Collection.RunSelect(x => ((startDate == null) || startDate <= x.CreatedDate) && ((endDate == null) || x.CreatedDate <= endDate));");
  238. }
  239. else
  240. {
  241. sb.AppendLine(" var subDomain = new SubDomain(modifier);");
  242. sb.AppendLine(" var selectCommand = new " + _currentTable.PascalName + "SelectByCreatedDateRange(startDate, endDate);");
  243. sb.AppendLine(" subDomain.AddSelectCommand(selectCommand);");
  244. sb.AppendLine(" subDomain.RunSelectCommands();");
  245. sb.AppendLine(" return subDomain.GetCollection<" + _currentTable.PascalName + "Collection>();");
  246. }
  247. sb.AppendLine(" }");
  248. sb.AppendLine();
  249. }
  250. if (_currentTable.Generated && _currentTable.AllowModifiedAudit)
  251. {
  252. sb.AppendLine(" /// <summary>");
  253. sb.AppendLine(" /// Select objects by their modified date.");
  254. sb.AppendLine(" /// </summary>");
  255. sb.AppendLine(" /// <param name=\"startDate\">The inclusive date on which to start the search.</param>");
  256. sb.AppendLine(" /// <param name=\"endDate\">The inclusive date on which to end the search.</param>");
  257. sb.AppendLine(" /// <param name=\"modifier\">The identifier used for the create and modify audits.</param>");
  258. if (_currentTable.ParentTable == null)
  259. sb.AppendLine(" public static " + _currentTable.PascalName + "Collection SelectByModifiedDateRange(DateTime? startDate, DateTime? endDate, string modifier)");
  260. else
  261. sb.AppendLine(" public new static " + _currentTable.PascalName + "Collection SelectByModifiedDateRange(DateTime? startDate, DateTime? endDate, string modifier)");
  262. sb.AppendLine(" {");
  263. if (_model.Database.AllowZeroTouch)
  264. {
  265. //If zero-touch then use LINQ
  266. sb.AppendLine(" return " + _currentTable.PascalName + "Collection.RunSelect(x => ((startDate == null) || startDate <= x.ModifiedDate) && ((endDate == null) || x.ModifiedDate <= endDate));");
  267. }
  268. else
  269. {
  270. sb.AppendLine(" var subDomain = new SubDomain(modifier);");
  271. sb.AppendLine(" var selectCommand = new " + _currentTable.PascalName + "SelectByModifiedDateRange(startDate, endDate);");
  272. sb.AppendLine(" subDomain.AddSelectCommand(selectCommand);");
  273. sb.AppendLine(" subDomain.RunSelectCommands();");
  274. sb.AppendLine(" return subDomain.GetCollection<" + _currentTable.PascalName + "Collection>();");
  275. }
  276. sb.AppendLine(" }");
  277. sb.AppendLine();
  278. }
  279. sb.AppendLine(" #endregion");
  280. sb.AppendLine();
  281. }
  282. private void AppendRegionCustomSelectByRules()
  283. {
  284. if (_model.Database.AllowZeroTouch) return;
  285. if (_currentTable.CustomRetrieveRules.Count == 0)
  286. return;
  287. sb.AppendLine(" #region CustomSelectBy CustomRules");
  288. sb.AppendLine();
  289. //Create a method for all custom retrieve rules
  290. foreach (Reference reference in _currentTable.CustomRetrieveRules)
  291. {
  292. var rule = (CustomRetrieveRule)reference.Object;
  293. if (rule.Generated)
  294. {
  295. #region Overload
  296. sb.AppendLine(" /// <summary>");
  297. sb.AppendLine(" /// Select rows based on the '" + rule.PascalName + "' custom retrieve rule for the '" + _currentTable.DatabaseName + "' table.");
  298. sb.AppendLine(" /// </summary>");
  299. sb.Append(" public static " + _currentTable.PascalName + "Collection SelectBy" + rule.PascalName + "(");
  300. if (rule.UseSearchObject)
  301. {
  302. sb.Append(_currentTable.PascalName + "Search " + _currentTable.CamelName);
  303. if (rule.Parameters.Count > 0)
  304. sb.Append(", ");
  305. }
  306. foreach (var parameter in rule.GeneratedParameters)
  307. {
  308. if (parameter.IsOutputParameter)
  309. sb.Append("out ");
  310. sb.Append(parameter.GetCodeType() + " " + parameter.CamelName);
  311. if (rule.GeneratedParameters.IndexOf(parameter) < rule.GeneratedParameters.Count() - 1)
  312. sb.Append(", ");
  313. }
  314. sb.AppendLine(")");
  315. sb.AppendLine(" {");
  316. sb.Append(" return SelectBy" + rule.PascalName + "(");
  317. if (rule.UseSearchObject)
  318. {
  319. sb.Append(_currentTable.CamelName);
  320. if (rule.Parameters.Count > 0)
  321. sb.Append(", ");
  322. }
  323. foreach (var parameter in rule.GeneratedParameters)
  324. {
  325. if (parameter.IsOutputParameter)
  326. sb.Append("out ");
  327. sb.Append(parameter.CamelName + ", ");
  328. }
  329. sb.AppendLine("string.Empty);");
  330. sb.AppendLine(" }");
  331. sb.AppendLine();
  332. #endregion
  333. sb.AppendLine(" /// <summary>");
  334. sb.AppendLine(" /// Select rows based on the '" + rule.PascalName + "' custom retrieve rule for the '" + _currentTable.DatabaseName + "' table.");
  335. sb.AppendLine(" /// </summary>");
  336. sb.Append(" public static " + _currentTable.PascalName + "Collection SelectBy" + rule.PascalName + "(");
  337. if (rule.UseSearchObject)
  338. {
  339. sb.Append(_currentTable.PascalName + "Search " + _currentTable.CamelName);
  340. if (rule.Parameters.Count > 0)
  341. sb.Append(", ");
  342. }
  343. foreach (var parameter in rule.GeneratedParameters)
  344. {
  345. if (parameter.IsOutputParameter)
  346. sb.Append("out ");
  347. sb.Append(parameter.GetCodeType() + " " + parameter.CamelName + ", ");
  348. }
  349. sb.AppendLine("string modifier)");
  350. sb.AppendLine(" {");
  351. sb.AppendLine(" var subDomain = new SubDomain(modifier);");
  352. sb.Append(" var selectCommand = new " + _currentTable.PascalName + "CustomSelectBy" + rule.PascalName + "(");
  353. if (rule.UseSearchObject)
  354. {
  355. sb.Append(_currentTable.CamelName);
  356. if (rule.Parameters.Count > 0)
  357. sb.Append(", ");
  358. }
  359. foreach (var parameter in rule.GeneratedParameters)
  360. {
  361. if (!parameter.IsOutputParameter)
  362. {
  363. sb.Append(parameter.CamelName + ", ");
  364. }
  365. }
  366. if (sb.ToString().EndsWith(", ")) sb.Remove(sb.ToString().Length - 2, 2);
  367. sb.AppendLine(");");
  368. sb.AppendLine(" subDomain.AddSelectCommand(selectCommand);");
  369. sb.AppendLine(" subDomain.RunSelectCommands();");
  370. foreach (var parameter in rule.GeneratedParameters)
  371. {
  372. if (parameter.IsOutputParameter)
  373. {
  374. sb.AppendLine(" " + parameter.CamelName + " = selectCommand." + parameter.PascalName + ";");
  375. }
  376. }
  377. sb.AppendLine(" return subDomain.GetCollection<" + _currentTable.PascalName + "Collection>();");
  378. sb.AppendLine(" }");
  379. sb.AppendLine();
  380. }
  381. }
  382. sb.AppendLine(" #endregion");
  383. sb.AppendLine();
  384. }
  385. private void AppendInterfaces()
  386. {
  387. sb.AppendLine(" #region IDisposable Members");
  388. sb.AppendLine();
  389. sb.AppendLine(" void IDisposable.Dispose()");
  390. sb.AppendLine(" {");
  391. sb.AppendLine();
  392. sb.AppendLine(" }");
  393. sb.AppendLine();
  394. sb.AppendLine(" #endregion");
  395. sb.AppendLine();
  396. }
  397. private void Append40Features()
  398. {
  399. if (_model.FrameworkVersion != FrameworkVersionConstants.v40) return;
  400. sb.AppendLine(" #region Framework 4.0 Functionality");
  401. sb.AppendLine();
  402. sb.AppendLine(" /// <summary>");
  403. sb.AppendLine(" /// ");
  404. sb.AppendLine(" /// </summary>");
  405. sb.AppendLine(" public event System.Collections.Specialized.NotifyCollectionChangedEventHandler CollectionChanged;");
  406. sb.AppendLine();
  407. sb.AppendLine(" /// <summary>");
  408. sb.AppendLine(" /// ");
  409. sb.AppendLine(" /// </summary>");
  410. sb.AppendLine(" /// <param name=\"e\"></param>");
  411. sb.AppendLine(" protected virtual void OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)");
  412. sb.AppendLine(" {");
  413. sb.AppendLine(" if (this.CollectionChanged != null)");
  414. sb.AppendLine(" this.CollectionChanged(this, e);");
  415. sb.AppendLine(" }");
  416. sb.AppendLine();
  417. sb.AppendLine(" #endregion");
  418. sb.AppendLine();
  419. }
  420. private void AppendRegionEnumerator()
  421. {
  422. sb.AppendLine(" #region IEnumerator Members");
  423. sb.AppendLine();
  424. sb.AppendLine(" object System.Collections.IEnumerator.Current");
  425. sb.AppendLine(" {");
  426. sb.AppendLine(" get { return this.GetEnumerator().Current; }");
  427. sb.AppendLine(" }");
  428. sb.AppendLine();
  429. sb.AppendLine(" bool System.Collections.IEnumerator.MoveNext()");
  430. sb.AppendLine(" {");
  431. sb.AppendLine(" return this.GetEnumerator().MoveNext();");
  432. sb.AppendLine(" }");
  433. sb.AppendLine();
  434. sb.AppendLine(" void System.Collections.IEnumerator.Reset()");
  435. sb.AppendLine(" {");
  436. sb.AppendLine(" this.GetEnumerator().Reset();");
  437. sb.AppendLine(" }");
  438. sb.AppendLine();
  439. sb.AppendLine(" #endregion");
  440. sb.AppendLine();
  441. sb.AppendLine(" #region IEnumerable<" + _currentTable.PascalName + "> Members");
  442. sb.AppendLine();
  443. sb.AppendLine(" IEnumerator<" + _currentTable.PascalName + "> IEnumerable<" + _currentTable.PascalName + ">.GetEnumerator()");
  444. sb.AppendLine(" {");
  445. sb.AppendLine(" var retval = new List<" + _currentTable.PascalName + ">();");
  446. sb.AppendLine(" foreach (" + _currentTable.PascalName + " item in this)");
  447. sb.AppendLine(" {");
  448. sb.AppendLine(" retval.Add(item);");
  449. sb.AppendLine(" }");
  450. sb.AppendLine(" return retval.GetEnumerator();");
  451. sb.AppendLine(" }");
  452. sb.AppendLine();
  453. sb.AppendLine(" #endregion");
  454. sb.AppendLine();
  455. }
  456. private void AppendRegionIBusinessCollectionExplicit()
  457. {
  458. if (!_currentTable.Immutable)
  459. {
  460. sb.AppendLine(" #region IPersistableBusinessCollection Explicit Members");
  461. sb.AppendLine();
  462. sb.AppendLine(" /// <summary>");
  463. sb.AppendLine(" /// Returns an item in this collection by index.");
  464. sb.AppendLine(" /// </summary>");
  465. sb.AppendLine(" /// <param name=\"index\">The zero-based index of the element to get or set. </param>");
  466. sb.AppendLine(" /// <returns>The element at the specified index.</returns>");
  467. sb.AppendLine(" IPersistableBusinessObject IPersistableBusinessCollection.this[int index]");
  468. sb.AppendLine(" {");
  469. sb.AppendLine(" get { return this[index]; }");
  470. sb.AppendLine(" }");
  471. sb.AppendLine();
  472. sb.AppendLine(" void IPersistableBusinessCollection.AddItem(IPersistableBusinessObject newItem)");
  473. sb.AppendLine(" {");
  474. sb.AppendLine(" this.AddItem((" + _currentTable.PascalName + ")newItem);");
  475. sb.AppendLine(" }");
  476. sb.AppendLine();
  477. sb.AppendLine(" IPersistableBusinessObject IPersistableBusinessCollection.NewItem()");
  478. sb.AppendLine(" {");
  479. sb.AppendLine(" return this.NewItem();");
  480. sb.AppendLine(" }");
  481. sb.AppendLine();
  482. sb.AppendLine(" #endregion");
  483. sb.AppendLine();
  484. }
  485. sb.AppendLine(" #region IBusinessCollection Explicit Members");
  486. sb.AppendLine();
  487. sb.AppendLine(" /// <summary>");
  488. sb.AppendLine(" /// Returns an item in this collection by index.");
  489. sb.AppendLine(" /// </summary>");
  490. sb.AppendLine(" /// <param name=\"index\">The zero-based index of the element to get or set. </param>");
  491. sb.AppendLine(" /// <returns>The element at the specified index.</returns>");
  492. sb.AppendLine(" IBusinessObject IBusinessCollection.this[int index]");
  493. sb.AppendLine(" {");
  494. sb.AppendLine(" get { return this[index]; }");
  495. sb.AppendLine(" }");
  496. sb.AppendLine();
  497. sb.AppendLine(" Enum IBusinessCollection.Collection");
  498. sb.AppendLine(" {");
  499. sb.AppendLine(" get { return this.Collection; }");
  500. sb.AppendLine(" }");
  501. sb.AppendLine();
  502. sb.AppendLine(" Type IBusinessCollection.ContainedType");
  503. sb.AppendLine(" {");
  504. sb.AppendLine(" get { return this.ContainedType; }");
  505. sb.AppendLine(" }");
  506. sb.AppendLine();
  507. sb.AppendLine(" SubDomainBase IBusinessCollection.SubDomain");
  508. sb.AppendLine(" {");
  509. sb.AppendLine(" get { return this.SubDomain; }");
  510. sb.AppendLine(" }");
  511. sb.AppendLine();
  512. sb.AppendLine(" Type ITyped.GetContainedType()");
  513. sb.AppendLine(" {");
  514. sb.AppendLine(" return typeof(" + _currentTable.PascalName + ");");
  515. sb.AppendLine(" }");
  516. sb.AppendLine();
  517. sb.AppendLine(" #endregion");
  518. sb.AppendLine();
  519. }
  520. private void AppendRegionGetFilteredList()
  521. {
  522. sb.AppendLine(" #region GetFilteredList");
  523. sb.AppendLine();
  524. sb.AppendLine(" /// <summary>");
  525. sb.AppendLine(" /// Returns a list filtered on the specified field with the specified value.");
  526. sb.AppendLine(" /// </summary>");
  527. sb.AppendLine(" [Obsolete(\"Use a LINQ query for more robust functionality\")]");
  528. sb.AppendLine(" public BusinessObjectList<" + _currentTable.PascalName + "> GetFilteredList(" + _currentTable.PascalName + ".FieldNameConstants field, object value)");
  529. sb.AppendLine(" {");
  530. sb.AppendLine(" var retval = new BusinessObjectList<" + _currentTable.PascalName + ">();");
  531. sb.AppendLine(" if (value == null)");
  532. sb.AppendLine(" return retval;");
  533. sb.AppendLine();
  534. sb.AppendLine(" string fieldName = string.Empty;");
  535. sb.AppendLine(" switch (field)");
  536. sb.AppendLine(" {");
  537. foreach (var column in _currentTable.GeneratedColumns)
  538. {
  539. sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + column.PascalName + ": fieldName = \"" + column.DatabaseName + "\"; break;");
  540. }
  541. if (_currentTable.AllowCreateAudit)
  542. {
  543. sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + _model.Database.CreatedByPascalName + ": fieldName = \"" + _model.Database.CreatedByPascalName + "\"; break;");
  544. sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + _model.Database.CreatedDatePascalName + ": fieldName = \"" + _model.Database.CreatedDatePascalName + "\"; break;");
  545. }
  546. if (_currentTable.AllowModifiedAudit)
  547. {
  548. sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + _model.Database.ModifiedByPascalName + ": fieldName = \"" + _model.Database.ModifiedByPascalName + "\"; break;");
  549. sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + _model.Database.ModifiedDatePascalName + ": fieldName = \"" + _model.Database.ModifiedDatePascalName + "\"; break;");
  550. }
  551. sb.AppendLine(" }");
  552. sb.AppendLine();
  553. sb.AppendLine(" DataRow[] rows = null;");
  554. sb.AppendLine(" if (value == null)");
  555. sb.AppendLine(" {");
  556. sb.AppendLine(" rows = this.wrappedClass.Select(fieldName + \" IS NULL\");");
  557. sb.AppendLine(" }");
  558. sb.AppendLine(" else");
  559. sb.AppendLine(" {");
  560. sb.AppendLine(" string tick = string.Empty;");
  561. sb.AppendLine(" if ((this.wrappedClass.Columns[fieldName].DataType == typeof(string)) || (this.wrappedClass.Columns[fieldName].DataType == typeof(Guid)))");
  562. sb.AppendLine(" tick = \"'\";");
  563. sb.AppendLine();
  564. sb.AppendLine(" rows = this.wrappedClass.Select(fieldName + \" = \" + tick + value.ToString().Replace(\"'\", \"''\") + tick);");
  565. sb.AppendLine(" }");
  566. sb.AppendLine();
  567. sb.AppendLine(" foreach (DataRow dr in rows)");
  568. sb.AppendLine(" retval.Add(new " + _currentTable.PascalName + "((Domain" + _currentTable.PascalName + ")dr));");
  569. sb.AppendLine();
  570. sb.AppendLine(" return retval;");
  571. sb.AppendLine(" }");
  572. sb.AppendLine();
  573. sb.AppendLine(" #endregion");
  574. sb.AppendLine();
  575. }
  576. private void AppendRegionGetDatabaseFieldName()
  577. {
  578. sb.AppendLine(" #region GetDatabaseFieldName");
  579. sb.AppendLine();
  580. sb.AppendLine(" /// <summary>");
  581. sb.AppendLine(" /// Returns the actual database name of the specified field.");
  582. sb.AppendLine(" /// </summary>");
  583. sb.AppendLine(" internal static string GetDatabaseFieldName(" + _currentTable.PascalName + ".FieldNameConstants field)");
  584. sb.AppendLine(" {");
  585. sb.AppendLine(" return GetDatabaseFieldName(field.ToString());");
  586. sb.AppendLine(" }");
  587. sb.AppendLine();
  588. sb.AppendLine(" /// <summary>");
  589. sb.AppendLine(" /// Returns the actual database name of the specified field.");
  590. sb.AppendLine(" /// </summary>");
  591. sb.AppendLine(" internal " + (_currentTable.ParentTable == null ? "" : "new ") + "static string GetDatabaseFieldName(string field)");
  592. sb.AppendLine(" {");
  593. sb.AppendLine(" switch (field)");
  594. sb.AppendLine(" {");
  595. foreach (var column in _currentTable.GeneratedColumns)
  596. {
  597. if (column.Generated)
  598. sb.AppendLine(" case \"" + column.PascalName + "\": return \"" + column.Name + "\";");
  599. }
  600. if (_currentTable.AllowCreateAudit)
  601. {
  602. sb.AppendLine(" case \"" + _model.Database.CreatedByPascalName + "\": return \"" + _model.Database.CreatedByColumnName + "\";");
  603. sb.AppendLine(" case \"" + _model.Database.CreatedDatePascalName + "\": return \"" + _model.Database.CreatedDateColumnName + "\";");
  604. }
  605. if (_currentTable.AllowModifiedAudit)
  606. {
  607. sb.AppendLine(" case \"" + _model.Database.ModifiedByPascalName + "\": return \"" + _model.Database.ModifiedByColumnName + "\";");
  608. sb.AppendLine(" case \"" + _model.Database.ModifiedDatePascalName + "\": return \"" + _model.Database.ModifiedDateColumnName + "\";");
  609. }
  610. if (_currentTable.AllowTimestamp)
  611. {
  612. sb.AppendLine(" case \"" + _model.Database.TimestampPascalName + "\": return \"" + _model.Database.TimestampColumnName + "\";");
  613. }
  614. sb.AppendLine(" }");
  615. sb.AppendLine(" return string.Empty;");
  616. sb.AppendLine(" }");
  617. sb.AppendLine();
  618. sb.AppendLine(" #endregion");
  619. sb.AppendLine();
  620. }
  621. private void AppendSearchClass()
  622. {
  623. if (_model.Database.AllowZeroTouch) return;
  624. if (!_model.SupportLegacySearchObject) return;
  625. var validColumns = GetValidSearchColumns();
  626. if (validColumns.Count() != 0)
  627. {
  628. sb.AppendLine(" #region " + _currentTable.PascalName + "Search");
  629. sb.AppendLine();
  630. sb.AppendLine(" /// <summary>");
  631. sb.AppendLine(" /// The search object for the " + _currentTable.PascalName + "Collection.");
  632. sb.AppendLine(" /// </summary>");
  633. sb.AppendLine(" [Serializable]");
  634. sb.AppendLine(" public partial class " + _currentTable.PascalName + "Search : IBusinessObjectSearch");
  635. sb.AppendLine(" {");
  636. sb.AppendLine();
  637. sb.AppendLine(" private int _maxRowCount = 0;");
  638. //foreach (var column in validColumns.OrderBy(x => x.Name))
  639. //{
  640. // sb.AppendLine(" private " + column.GetCodeType(true, true) + " _" + column.CamelName + ";");
  641. //}
  642. sb.AppendLine(" private SearchType _searchType;");
  643. sb.AppendLine();
  644. sb.AppendLine(" /// <summary>");
  645. sb.AppendLine(" /// Determines the maximum number of rows that are returned. Use 0 for no limit.");
  646. sb.AppendLine(" /// </summary>");
  647. sb.AppendLine(" public int MaxRowCount");
  648. sb.AppendLine(" {");
  649. sb.AppendLine(" get { return _maxRowCount; }");
  650. sb.AppendLine(" set { _maxRowCount = value; }");
  651. sb.AppendLine(" }");
  652. sb.AppendLine();
  653. sb.AppendLine(" /// <summary>");
  654. sb.AppendLine(" /// Determines the maximum number of rows that are returned. Use 0 for no limit.");
  655. sb.AppendLine(" /// </summary>");
  656. sb.AppendLine(" int IBusinessObjectSearch.MaxRowCount");
  657. sb.AppendLine(" {");
  658. sb.AppendLine(" get { return this.MaxRowCount; }");
  659. sb.AppendLine(" set { this.MaxRowCount = value; }");
  660. sb.AppendLine(" }");
  661. sb.AppendLine();
  662. sb.AppendLine(" /// <summary>");
  663. sb.AppendLine(" /// Determines the type of search to be performed.");
  664. sb.AppendLine(" /// </summary>");
  665. sb.AppendLine(" public SearchType SearchType");
  666. sb.AppendLine(" {");
  667. sb.AppendLine(" get { return _searchType; }");
  668. sb.AppendLine(" }");
  669. sb.AppendLine();
  670. sb.AppendLine(" /// <summary>");
  671. sb.AppendLine(" /// A search object for the '" + _currentTable.PascalName + "' collection.");
  672. sb.AppendLine(" /// </summary>");
  673. sb.AppendLine(" public " + _currentTable.PascalName + "Search(SearchType searchType) ");
  674. sb.AppendLine(" {");
  675. sb.AppendLine(" _searchType = searchType;");
  676. sb.AppendLine(" }");
  677. sb.AppendLine();
  678. sb.AppendLine(" void IBusinessObjectSearch.SetValue(Enum field, object value)");
  679. sb.AppendLine(" {");
  680. sb.AppendLine(" this.SetValue((" + _currentTable.PascalName + ".FieldNameConstants)field, value);");
  681. sb.AppendLine(" }");
  682. sb.AppendLine();
  683. sb.AppendLine(" /// <summary>");
  684. sb.AppendLine(" /// Set the specified value on this object.");
  685. sb.AppendLine(" /// </summary>");
  686. sb.AppendLine(" public void SetValue(" + _currentTable.PascalName + ".FieldNameConstants field, object value)");
  687. sb.AppendLine(" {");
  688. foreach (var column in validColumns.OrderBy(x => x.Name))
  689. {
  690. sb.AppendLine(" if (field == " + _currentTable.PascalName + ".FieldNameConstants." + column.PascalName + ") this." + column.PascalName + " = (" + column.GetCodeType(false) + ")value;");
  691. }
  692. sb.AppendLine(" }");
  693. sb.AppendLine();
  694. foreach (var column in validColumns.OrderBy(x => x.Name))
  695. {
  696. sb.AppendLine(" /// <summary>");
  697. sb.AppendLine(" /// This field determines the value of the '" + column.PascalName + "' field on the '" + _currentTable.PascalName + "' object when this search object is applied.");
  698. sb.AppendLine(" /// </summary>");
  699. sb.AppendLine(" public " + column.GetCodeType(true, true) + " " + column.PascalName + " { get; set; }");
  700. sb.AppendLine();
  701. }
  702. sb.AppendLine(" }");
  703. sb.AppendLine();
  704. sb.AppendLine(" #endregion ");
  705. sb.AppendLine();
  706. }
  707. }
  708. private void AppendPagingClass()
  709. {
  710. sb.AppendLine(" #region " + _currentTable.PascalName + "Paging");
  711. sb.AppendLine();
  712. sb.AppendLine(" /// <summary>");
  713. sb.AppendLine(" /// The paging object for the " + _currentTable.PascalName + " collection");
  714. sb.AppendLine(" /// </summary>");
  715. sb.AppendLine(" [Serializable]");
  716. sb.AppendLine(" " + this.ClassScope + " partial class " + _currentTable.PascalName + "Paging : Widgetsphere.Core.DataAccess.PagingBase<" + _currentTable.PascalName + "PagingFieldItem, " + this.GetLocalNamespace() + ".Business.Objects." + _currentTable.PascalName + ".FieldNameConstants>");
  717. sb.AppendLine(" {");
  718. sb.AppendLine();
  719. sb.AppendLine(" #region Constructors");
  720. sb.AppendLine();
  721. sb.AppendLine(" /// <summary>");
  722. sb.AppendLine(" /// Creates a paging object");
  723. sb.AppendLine(" /// </summary>");
  724. sb.AppendLine(" public " + _currentTable.PascalName + "Paging()");
  725. sb.AppendLine(" : this(1, 10, null)");
  726. sb.AppendLine(" {");
  727. sb.AppendLine(" }");
  728. sb.AppendLine();
  729. sb.AppendLine(" /// <summary>");
  730. sb.AppendLine(" /// Creates a paging object");
  731. sb.AppendLine(" /// </summary>");
  732. sb.AppendLine(" /// <param name=\"pageIndex\">The page number to load</param>");
  733. sb.AppendLine(" /// <param name=\"recordsperPage\">The number of records per page.</param>");
  734. sb.AppendLine(" public " + _currentTable.PascalName + "Paging(int pageIndex, int recordsperPage)");
  735. sb.AppendLine(" : this(pageIndex, recordsperPage, null)");
  736. sb.AppendLine(" {");
  737. sb.AppendLine(" }");
  738. sb.AppendLine();
  739. sb.AppendLine(" /// <summary>");
  740. sb.AppendLine(" /// Creates a paging object");
  741. sb.AppendLine(" /// </summary>");
  742. sb.AppendLine(" /// <param name=\"pageIndex\">The page number to load</param>");
  743. sb.AppendLine(" /// <param name=\"recordsperPage\">The number of records per page.</param>");
  744. sb.AppendLine(" /// <param name=\"field\">The field on which to sort.</param>");
  745. sb.AppendLine(" /// <param name=\"ascending\">Determines the sorted direction.</param>");
  746. sb.AppendLine(" public " + _currentTable.PascalName + "Paging(int pageIndex, int recordsperPage, " + this.GetLocalNamespace() + ".Business.Objects." + _currentTable.PascalName + ".FieldNameConstants field, bool ascending)");
  747. sb.AppendLine(" : this(pageIndex, recordsperPage, new " + _currentTable.PascalName + "PagingFieldItem(field, ascending))");
  748. sb.AppendLine(" {");
  749. sb.AppendLine(" }");
  750. sb.AppendLine();
  751. sb.AppendLine(" /// <summary>");
  752. sb.AppendLine(" /// Creates a paging object");
  753. sb.AppendLine(" /// </summary>");
  754. sb.AppendLine(" /// <param name=\"pageIndex\">The page number to load</param>");
  755. sb.AppendLine(" /// <param name=\"recordsperPage\">The number of items per page.</param>");
  756. sb.AppendLine(" /// <param name=\"orderByField\">The field on which to sort.</param>");
  757. sb.AppendLine(" public " + _currentTable.PascalName + "Paging(int pageIndex, int recordsperPage, " + _currentTable.PascalName + "PagingFieldItem orderByField)");
  758. sb.AppendLine(" : base(pageIndex, recordsperPage, orderByField)");
  759. sb.AppendLine(" {");
  760. sb.AppendLine(" }");
  761. sb.AppendLine();
  762. sb.AppendLine(" #endregion");
  763. sb.AppendLine();
  764. sb.AppendLine(" }");
  765. sb.AppendLine();
  766. sb.AppendLine(" /// <summary>");
  767. sb.AppendLine(" /// A field sort object for the " + _currentTable.PascalName + "Paging object.");
  768. sb.AppendLine(" /// </summary>");
  769. sb.AppendLine(" [Serializable]");
  770. sb.AppendLine(" " + this.ClassScope + " partial class " + _currentTable.PascalName + "PagingFieldItem : Widgetsphere.Core.DataAccess.PagingFieldItem<" + this.GetLocalNamespace() + ".Business.Objects." + _currentTable.PascalName + ".FieldNameConstants>");
  771. sb.AppendLine(" {");
  772. sb.AppendLine(" /// <summary>");
  773. sb.AppendLine(" /// Create a sorting field object for the " + _currentTable.PascalName + "Paging object.");
  774. sb.AppendLine(" /// </summary>");
  775. sb.AppendLine(" /// <param name=\"field\">The field on which to sort.</param>");
  776. sb.AppendLine(" public " + _currentTable.PascalName + "PagingFieldItem(" + this.GetLocalNamespace() + ".Business.Objects." + _currentTable.PascalName + ".FieldNameConstants field)");
  777. sb.AppendLine(" : base(field)");
  778. sb.AppendLine(" {");
  779. sb.AppendLine(" this.Field = field;");
  780. sb.AppendLine(" }");
  781. sb.AppendLine();
  782. sb.AppendLine(" /// <summary>");
  783. sb.AppendLine(" /// Create a sorting field object for the " + _currentTable.PascalName + "Paging object.");
  784. sb.AppendLine(" /// </summary>");
  785. sb.AppendLine(" /// <param name=\"field\">The field on which to sort.</param>");
  786. sb.AppendLine(" /// <param name=\"ascending\">Determines the direction of the sort.</param>");
  787. sb.AppendLine(" public " + _currentTable.PascalName + "PagingFieldItem(" + this.GetLocalNamespace() + ".Business.Objects." + _currentTable.PascalName + ".FieldNameConstants field, bool ascending)");
  788. sb.AppendLine(" : this(field)");
  789. sb.AppendLine(" {");
  790. sb.AppendLine(" this.Ascending = ascending;");
  791. sb.AppendLine(" }");
  792. sb.AppendLine();
  793. sb.AppendLine(" }");
  794. sb.AppendLine();
  795. sb.AppendLine(" #endregion");
  796. sb.AppendLine();
  797. }
  798. private IEnumerable<Column> GetValidSearchColumns()
  799. {
  800. var allColumns = _currentTable.GetColumnsFullHierarchy().Where(x => x.Generated).ToList();
  801. var validColumns = new List<Column>();
  802. foreach (var column in allColumns.OrderBy(x => x.Name))
  803. {
  804. if (!(column.DataType == System.Data.SqlDbType.Binary ||
  805. column.DataType == System.Data.SqlDbType.Image ||
  806. column.DataType == System.Data.SqlDbType.NText ||
  807. column.DataType == System.Data.SqlDbType.Text ||
  808. column.DataType == System.Data.SqlDbType.Timestamp ||
  809. column.DataType == System.Data.SqlDbType.Udt ||
  810. column.DataType == System.Data.SqlDbType.VarBinary ||
  811. column.DataType == System.Data.SqlDbType.Variant ||
  812. column.DataType == System.Data.SqlDbType.Money))
  813. {
  814. validColumns.Add(column);
  815. }
  816. }
  817. return validColumns;
  818. }
  819. private void AppendClassEnumerator()
  820. {
  821. sb.AppendLine(" #region IEnumerator");
  822. sb.AppendLine();
  823. sb.AppendLine(" /// <summary>");
  824. sb.AppendLine(" /// An strongly-typed enumerator for the '" + _currentTable.PascalName + "' object collection");
  825. sb.AppendLine(" /// </summary>");
  826. sb.AppendLine(" public partial class " + _currentTable.PascalName + "Enumerator : System.Collections.IEnumerator ");
  827. sb.AppendLine(" {");
  828. sb.AppendLine(" private System.Collections.IEnumerator internalEnumerator;");
  829. sb.AppendLine(" internal " + _currentTable.PascalName + "Enumerator(IEnumerator icg)");
  830. sb.AppendLine(" {");
  831. sb.AppendLine(" internalEnumerator = icg;");
  832. sb.AppendLine(" }");
  833. sb.AppendLine();
  834. sb.AppendLine(" #region IEnumerator Members");
  835. sb.AppendLine();
  836. sb.AppendLine(" /// <summary>");
  837. sb.AppendLine(" /// Reset the enumerator to the first object in this collection");
  838. sb.AppendLine(" /// </summary>");
  839. sb.AppendLine(" public void Reset()");
  840. sb.AppendLine(" {");
  841. sb.AppendLine(" try");
  842. sb.AppendLine(" {");
  843. sb.AppendLine(" internalEnumerator.Reset();");
  844. sb.AppendLine(" }");
  845. Globals.AppendBusinessEntryCatch(sb);
  846. sb.AppendLine(" }");
  847. sb.AppendLine();
  848. sb.AppendLine(" /// <summary>");
  849. sb.AppendLine(" /// Gets the current element in the collection.");
  850. sb.AppendLine(" /// </summary>");
  851. sb.AppendLine(" /// <returns>The current element in the collection.</returns>");
  852. sb.AppendLine(" public object Current");
  853. sb.AppendLine(" {");
  854. sb.AppendLine(" get");
  855. sb.AppendLine(" {");
  856. sb.AppendLine(" try");
  857. sb.AppendLine(" {");
  858. sb.AppendLine(" return new " + _currentTable.PascalName + "((" + this.GetLocalNamespace() + ".Domain.Objects.Domain" + _currentTable.PascalName + ")internalEnumerator.Current);");
  859. sb.AppendLine(" }");
  860. Globals.AppendBusinessEntryCatch(sb, true);
  861. sb.AppendLine(" }");
  862. sb.AppendLine(" }");
  863. sb.AppendLine();
  864. sb.AppendLine(" /// <summary>");
  865. sb.AppendLine(" /// Advances the enumerator to the next element of the collection.");
  866. sb.AppendLine(" /// </summary>");
  867. sb.AppendLine(" public bool MoveNext()");
  868. sb.AppendLine(" {");
  869. sb.AppendLine(" try");
  870. sb.AppendLine(" {");
  871. sb.AppendLine(" bool movedNext = internalEnumerator.MoveNext();");
  872. sb.AppendLine(" if (movedNext)");
  873. sb.AppendLine(" {");
  874. sb.AppendLine(" " + this.GetLocalNamespace() + ".Domain.Objects.Domain" + _currentTable.PascalName + " currentRow = (" + this.GetLocalNamespace() + ".Domain.Objects.Domain" + _currentTable.PascalName + ")internalEnumerator.Current;");
  875. sb.AppendLine(" while (currentRow.RowState == System.Data.DataRowState.Deleted || currentRow.RowState == System.Data.DataRowState.Detached)");
  876. sb.AppendLine(" {");
  877. sb.AppendLine(" movedNext = internalEnumerator.MoveNext();");
  878. sb.AppendLine(" if (!movedNext) break;");
  879. sb.AppendLine(" currentRow = (" + this.GetLocalNamespace() + ".Domain.Objects.Domain" + _currentTable.PascalName + ")internalEnumerator.Current;");
  880. sb.AppendLine(" }");
  881. sb.AppendLine(" }");
  882. sb.AppendLine(" return movedNext;");
  883. sb.AppendLine(" }");
  884. Globals.AppendBusinessEntryCatch(sb);
  885. sb.AppendLine(" }");
  886. sb.AppendLine();
  887. sb.AppendLine(" #endregion");
  888. sb.AppendLine();
  889. sb.AppendLine(" }");
  890. sb.AppendLine();
  891. sb.AppendLine(" #endregion");
  892. sb.AppendLine();
  893. }
  894. #endregion
  895. #region append member variables
  896. public void AppendMemberVariables()
  897. {
  898. sb.AppendLine(" #region Member Variables");
  899. sb.AppendLine();
  900. if (_currentTable.ParentTable == null)
  901. {
  902. sb.AppendLine(" internal Domain" + _currentTable.PascalName + "Collection wrappedClass;");
  903. sb.AppendLine();
  904. sb.AppendLine(" /// <summary>");
  905. sb.AppendLine(" /// The parent subdomain object");
  906. sb.AppendLine(" /// </summary>");
  907. sb.AppendLine(" protected SubDomain _subDomain = null;");
  908. }
  909. else
  910. {
  911. sb.AppendLine(" internal new Domain" + _currentTable.PascalName + "Collection wrappedClass;");
  912. }
  913. sb.AppendLine();
  914. sb.AppendLine(" #endregion");
  915. sb.AppendLine();
  916. }
  917. #endregion
  918. #region append constructors
  919. public void AppendConstructors()
  920. {
  921. sb.AppendLine(" #region Constructor / Initialize");
  922. sb.AppendLine();
  923. AppendConstructorDomainClass();
  924. AppendConstructorModifier();
  925. AppendConstructorDefault();
  926. sb.AppendLine(" #endregion");
  927. sb.AppendLine();
  928. }
  929. private void AppendConstructorDomainClass()
  930. {
  931. if (_currentTable.ParentTable == null)
  932. {
  933. sb.AppendLine(" internal " + _currentTable.PascalName + "Collection(Domain" + _currentTable.PascalName + "Collection classToWrap)");
  934. sb.AppendLine(" {");
  935. sb.AppendLine(" _subDomain = classToWrap.SubDomain;");
  936. sb.AppendLine(" wrappedClass = classToWrap;");
  937. sb.AppendLine(" }");
  938. }
  939. else
  940. {
  941. sb.AppendLine(" internal " + _currentTable.PascalName + "Collection(Domain" + _currentTable.PascalName + "Collection classToWrap):base(classToWrap)");
  942. sb.AppendLine(" {");
  943. sb.AppendLine(" wrappedClass = classToWrap;");
  944. sb.AppendLine(" base.wrappedClass = wrappedClass;");
  945. sb.AppendLine(" }");
  946. }
  947. sb.AppendLine();
  948. }
  949. private void AppendConstructorModifier()
  950. {
  951. sb.AppendLine(" /// <summary>");
  952. sb.AppendLine(" /// Constructor that enables you to specify a modifier");
  953. sb.AppendLine(" /// </summary>");
  954. sb.AppendLine(" /// <param name=\"modifier\">Used in audit operations to track changes</param>");
  955. sb.AppendLine(" public " + _currentTable.PascalName + "Collection(string modifier)");
  956. sb.AppendLine(" {");
  957. sb.AppendLine(" _subDomain = new SubDomain(modifier);");
  958. sb.AppendLine(" ResetWrappedClass((Domain" + _currentTable.PascalName + "Collection)_subDomain.GetDomainCollection(Collections." + _currentTable.PascalName + "Collection));");
  959. sb.AppendLine(" }");
  960. sb.AppendLine();
  961. }
  962. private void AppendConstructorDefault()
  963. {
  964. sb.AppendLine(" /// <summary>");
  965. sb.AppendLine(" /// The default constructor");
  966. sb.AppendLine(" /// </summary>");
  967. sb.AppendLine(" public " + _currentTable.PascalName + "Collection() ");
  968. sb.AppendLine(" {");
  969. sb.AppendLine(" _subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);");
  970. sb.AppendLine(" ResetWrappedClass((Domain" + _currentTable.PascalName + "Collection)_subDomain.GetDomainCollection(Collections." + _currentTable.PascalName + "Collection));");
  971. sb.AppendLine(" }");
  972. sb.AppendLine();
  973. }
  974. #endregion
  975. #region append properties
  976. private string ClassScope
  977. {
  978. get
  979. {
  980. var classScope = "public";
  981. if (_currentTable.AssociativeTable) classScope = "internal";
  982. return classScope;
  983. }
  984. }
  985. private void AppendProperties()
  986. {
  987. sb.AppendLine(" #region Property Implementations");
  988. sb.AppendLine();
  989. AppendPropertyWrappedClass();
  990. AppendPropertyModifier();
  991. AppendPropertySubDomain();
  992. AppendPropertyCount();
  993. AppendPropertyContainedType();
  994. AppendPropertyCollection();
  995. sb.AppendLine();
  996. sb.AppendLine(" #endregion");
  997. sb.AppendLine();
  998. }
  999. private void AppendPropertyWrappedClass()
  1000. {
  1001. sb.AppendLine(" /// <summary>");
  1002. sb.AppendLine(" /// Returns the internal object that this object wraps");
  1003. sb.AppendLine(" /// </summary>");
  1004. sb.AppendLine(" [System.ComponentModel.Browsable(false)]");
  1005. if (_currentTable.ParentTable == null)
  1006. sb.AppendLine(" internal virtual object WrappedClass");
  1007. else
  1008. sb.AppendLine(" internal override object WrappedClass");
  1009. sb.AppendLine(" {");
  1010. sb.AppendLine(" get { return wrappedClass ; }");
  1011. sb.AppendLine(" set { wrappedClass = (Domain" + _currentTable.PascalName + "Collection)value ; }");
  1012. sb.AppendLine(" }");
  1013. sb.AppendLine();
  1014. sb.AppendLine(" //WrappingClass Interface");
  1015. sb.AppendLine(" object Widgetsphere.Core.DataAccess.IWrappingClass.WrappedClass");
  1016. sb.AppendLine(" {");
  1017. sb.AppendLine(" get { return this.WrappedClass; }");
  1018. sb.AppendLine(" set { this.WrappedClass = value; }");
  1019. sb.AppendLine(" }");
  1020. sb.AppendLine();
  1021. }
  1022. private void AppendPropertySubDomain()
  1023. {
  1024. if (_currentTable.ParentTable != null)
  1025. return;
  1026. sb.AppendLine(" /// <summary>");
  1027. sb.AppendLine(" /// A reference to the SubDomain that holds this collection");
  1028. sb.AppendLine(" /// </summary>");
  1029. sb.AppendLine(" public SubDomain SubDomain");
  1030. sb.AppendLine(" {");
  1031. sb.AppendLine(" get");
  1032. sb.AppendLine(" {");
  1033. sb.AppendLine(" try");
  1034. sb.AppendLine(" {");
  1035. sb.AppendLine(" return wrappedClass.SubDomain;");
  1036. sb.AppendLine(" }");
  1037. Globals.AppendBusinessEntryCatch(sb, true);
  1038. sb.AppendLine(" }");
  1039. sb.AppendLine(" }");
  1040. sb.AppendLine();
  1041. }
  1042. private void AppendPropertyModifier()
  1043. {
  1044. if (_currentTable.ParentTable != null)
  1045. return;
  1046. sb.AppendLine(" /// <summary>");
  1047. sb.AppendLine(" /// Specifies a modifier string to be used in the audit functionality");
  1048. sb.AppendLine(" /// </summary>");
  1049. sb.AppendLine(" public string Modifier");
  1050. sb.AppendLine(" {");
  1051. sb.AppendLine(" get");
  1052. sb.AppendLine(" {");
  1053. sb.AppendLine(" try");
  1054. sb.AppendLine(" {");
  1055. sb.AppendLine(" return wrappedClass.Modifier;");
  1056. sb.AppendLine(" }");
  1057. Globals.AppendBusinessEntryCatch(sb, true);
  1058. sb.AppendLine(" }");
  1059. sb.AppendLine(" internal set { wrappedClass.Modifier = value; }");
  1060. sb.AppendLine(" }");
  1061. sb.AppendLine();
  1062. }
  1063. private void AppendPropertyCount()
  1064. {
  1065. sb.AppendLine(" /// <summary>");
  1066. sb.AppendLine(" /// Returns the number of items in this collection");
  1067. sb.AppendLine(" /// </summary>");
  1068. sb.AppendLine(" public override int Count");
  1069. sb.AppendLine(" {");
  1070. sb.AppendLine(" get");
  1071. sb.AppendLine(" {");
  1072. sb.AppendLine(" try");
  1073. sb.AppendLine(" {");
  1074. sb.AppendLine(" lock (wrappedClass.SubDomain)");
  1075. sb.AppendLine(" {");
  1076. sb.AppendLine(" DataTable dt = wrappedClass.GetChanges(DataRowState.Deleted);");
  1077. sb.AppendLine(" if (dt == null) return wrappedClass.Count;");
  1078. sb.AppendLine(" else return wrappedClass.Count - dt.Rows.Count;");
  1079. sb.AppendLine(" }");
  1080. sb.AppendLine(" }");
  1081. Globals.AppendBusinessEntryCatch(sb, true);
  1082. sb.AppendLine(" }");
  1083. sb.AppendLine(" }");
  1084. sb.AppendLine();
  1085. }
  1086. private void AppendPropertyContainedType()
  1087. {
  1088. sb.AppendLine(" /// <summary>");
  1089. s

Large files files are truncated, but you can click here to view the full file