PageRenderTime 58ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/v41/Source/Widgetsphere.Generator.DAL/ProjectItemGenerators/BusinessViewLINQ/BusinessViewLINQGeneratedTemplate.cs

#
C# | 158 lines | 107 code | 16 blank | 35 comment | 1 complexity | a1869282465b0221039dbe4ed89f928d MD5 | raw file
Possible License(s): JSON, CC-BY-SA-3.0
  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.Linq;
  40. using System.Text;
  41. using Widgetsphere.Generator.Models;
  42. namespace Widgetsphere.Generator.DAL.ProjectItemGenerators.BusinessViewLINQ
  43. {
  44. class BusinessViewLINQGeneratedTemplate : DomainProjectTemplate
  45. {
  46. private readonly StringBuilder sb = new StringBuilder();
  47. private readonly CustomView _currentView;
  48. public BusinessViewLINQGeneratedTemplate(ModelRoot model, CustomView currentView)
  49. {
  50. _model = model;
  51. _currentView = currentView;
  52. }
  53. #region BaseClassTemplate overrides
  54. public override string FileName
  55. {
  56. get { return string.Format("{0}.Generated.cs", _currentView.PascalName); }
  57. }
  58. public string ParentItemName
  59. {
  60. get
  61. {
  62. return string.Format("{0}.cs", _currentView.PascalName);
  63. }
  64. }
  65. public override string FileContent
  66. {
  67. get
  68. {
  69. GenerateContent();
  70. return sb.ToString();
  71. }
  72. }
  73. #endregion
  74. #region GenerateContent
  75. private void GenerateContent()
  76. {
  77. try
  78. {
  79. Widgetsphere.Generator.GenerationHelper.AppendCopyrightInCode(sb, _model);
  80. this.AppendUsingStatements();
  81. sb.AppendLine("namespace " + this.GetLocalNamespace() + ".Business.LINQ");
  82. sb.AppendLine("{");
  83. this.AppendClass();
  84. sb.AppendLine("}");
  85. }
  86. catch (Exception ex)
  87. {
  88. throw;
  89. }
  90. }
  91. #endregion
  92. #region namespace / objects
  93. public void AppendUsingStatements()
  94. {
  95. sb.AppendLine("using System;");
  96. sb.AppendLine("using System.Data;");
  97. sb.AppendLine("using System.Linq;");
  98. sb.AppendLine("using System.Data.Linq;");
  99. sb.AppendLine("using System.Linq.Expressions;");
  100. sb.AppendLine("using System.Data.Linq.Mapping;");
  101. sb.AppendLine("using System.Collections;");
  102. sb.AppendLine("using System.Collections.Generic;");
  103. sb.AppendLine("using Widgetsphere.Core.DataAccess;");
  104. sb.AppendLine();
  105. }
  106. private void AppendClass()
  107. {
  108. try
  109. {
  110. sb.AppendLine(" /// <summary>");
  111. sb.AppendLine(" /// This is a helper object for running LINQ queries on the " + _currentView.PascalName + " collection.");
  112. sb.AppendLine(" /// </summary>");
  113. sb.AppendLine(" [Serializable()]");
  114. sb.AppendLine(" [Table(Name = \"" + _currentView.DatabaseName + "\")]");
  115. sb.AppendLine(" public partial class " + _currentView.PascalName + "Query : Widgetsphere.Core.DataAccess.IBusinessObjectLINQQuery");
  116. sb.AppendLine(" {");
  117. sb.AppendLine(" #region Properties");
  118. foreach (var column in _currentView.GetColumns().OrderBy(x => x.PascalName))
  119. {
  120. var description = column.Description.Trim();
  121. if (!string.IsNullOrEmpty(description)) description += "\r\n ///";
  122. description += "(Maps to the '" + _currentView.DatabaseName + "." + _currentView.DatabaseName + "' database field)";
  123. sb.AppendLine(" /// <summary>");
  124. sb.AppendLine(" /// " + description);
  125. sb.AppendLine(" /// </summary>");
  126. sb.AppendLine(" [Column(Name = \"" + column.DatabaseName + "\", DbType = \"" + column.DatabaseTypeRaw + "\", CanBeNull = " + column.AllowNull.ToString().ToLower() + ", IsPrimaryKey = false)]");
  127. sb.AppendLine(" public virtual " + column.GetCodeType(true) + " " + column.PascalName + " { get; set; }");
  128. }
  129. sb.AppendLine();
  130. sb.AppendLine(" #endregion");
  131. sb.AppendLine();
  132. sb.AppendLine(" }");
  133. sb.AppendLine();
  134. }
  135. catch (Exception ex)
  136. {
  137. throw;
  138. }
  139. }
  140. #endregion
  141. }
  142. }