/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
- #region Copyright (c) 2006-2011 Widgetsphere LLC, All Rights Reserved
- //--------------------------------------------------------------------- *
- // Widgetsphere LLC *
- // Copyright (c) 2006-2011 All Rights reserved *
- // *
- // *
- //This file and its contents are protected by United States and *
- //International copyright laws. Unauthorized reproduction and/or *
- //distribution of all or any portion of the code contained herein *
- //is strictly prohibited and will result in severe civil and criminal *
- //penalties. Any violations of this copyright will be prosecuted *
- //to the fullest extent possible under law. *
- // *
- //THE SOURCE CODE CONTAINED HEREIN AND IN RELATED FILES IS PROVIDED *
- //TO THE REGISTERED DEVELOPER FOR THE PURPOSES OF EDUCATION AND *
- //TROUBLESHOOTING. UNDER NO CIRCUMSTANCES MAY ANY PORTION OF THE SOURCE *
- //CODE BE DISTRIBUTED, DISCLOSED OR OTHERWISE MADE AVAILABLE TO ANY *
- //THIRD PARTY WITHOUT THE EXPRESS WRITTEN CONSENT OF WIDGETSPHERE LLC *
- // *
- //UNDER NO CIRCUMSTANCES MAY THE SOURCE CODE BE USED IN WHOLE OR IN *
- //PART, AS THE BASIS FOR CREATING A PRODUCT THAT PROVIDES THE SAME, OR *
- //SUBSTANTIALLY THE SAME, FUNCTIONALITY AS ANY WIDGETSPHERE PRODUCT. *
- // *
- //THE REGISTERED DEVELOPER ACKNOWLEDGES THAT THIS SOURCE CODE *
- //CONTAINS VALUABLE AND PROPRIETARY TRADE SECRETS OF WIDGETSPHERE, *
- //INC. THE REGISTERED DEVELOPER AGREES TO EXPEND EVERY EFFORT TO *
- //INSURE ITS CONFIDENTIALITY. *
- // *
- //THE END USER LICENSE AGREEMENT (EULA) ACCOMPANYING THE PRODUCT *
- //PERMITS THE REGISTERED DEVELOPER TO REDISTRIBUTE THE PRODUCT IN *
- //EXECUTABLE FORM ONLY IN SUPPORT OF APPLICATIONS WRITTEN USING *
- //THE PRODUCT. IT DOES NOT PROVIDE ANY RIGHTS REGARDING THE *
- //SOURCE CODE CONTAINED HEREIN. *
- // *
- //THIS COPYRIGHT NOTICE MAY NOT BE REMOVED FROM THIS FILE. *
- //--------------------------------------------------------------------- *
- #endregion
-
- using System;
- using System.Linq;
- using System.Text;
- using Widgetsphere.Generator.Models;
-
- namespace Widgetsphere.Generator.DAL.ProjectItemGenerators.BusinessViewLINQ
- {
- class BusinessViewLINQGeneratedTemplate : DomainProjectTemplate
- {
- private readonly StringBuilder sb = new StringBuilder();
- private readonly CustomView _currentView;
-
- public BusinessViewLINQGeneratedTemplate(ModelRoot model, CustomView currentView)
- {
- _model = model;
- _currentView = currentView;
- }
-
- #region BaseClassTemplate overrides
- public override string FileName
- {
- get { return string.Format("{0}.Generated.cs", _currentView.PascalName); }
- }
-
- public string ParentItemName
- {
- get
- {
- return string.Format("{0}.cs", _currentView.PascalName);
- }
- }
-
- public override string FileContent
- {
- get
- {
- GenerateContent();
- return sb.ToString();
- }
- }
- #endregion
-
- #region GenerateContent
-
- private void GenerateContent()
- {
- try
- {
- Widgetsphere.Generator.GenerationHelper.AppendCopyrightInCode(sb, _model);
- this.AppendUsingStatements();
- sb.AppendLine("namespace " + this.GetLocalNamespace() + ".Business.LINQ");
- sb.AppendLine("{");
- this.AppendClass();
- sb.AppendLine("}");
- }
- catch (Exception ex)
- {
- throw;
- }
-
- }
-
- #endregion
-
- #region namespace / objects
-
- public void AppendUsingStatements()
- {
- sb.AppendLine("using System;");
- sb.AppendLine("using System.Data;");
- sb.AppendLine("using System.Linq;");
- sb.AppendLine("using System.Data.Linq;");
- sb.AppendLine("using System.Linq.Expressions;");
- sb.AppendLine("using System.Data.Linq.Mapping;");
- sb.AppendLine("using System.Collections;");
- sb.AppendLine("using System.Collections.Generic;");
- sb.AppendLine("using Widgetsphere.Core.DataAccess;");
- sb.AppendLine();
- }
-
- private void AppendClass()
- {
- try
- {
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// This is a helper object for running LINQ queries on the " + _currentView.PascalName + " collection.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" [Serializable()]");
- sb.AppendLine(" [Table(Name = \"" + _currentView.DatabaseName + "\")]");
- sb.AppendLine(" public partial class " + _currentView.PascalName + "Query : Widgetsphere.Core.DataAccess.IBusinessObjectLINQQuery");
- sb.AppendLine(" {");
- sb.AppendLine(" #region Properties");
- foreach (var column in _currentView.GetColumns().OrderBy(x => x.PascalName))
- {
- var description = column.Description.Trim();
- if (!string.IsNullOrEmpty(description)) description += "\r\n ///";
- description += "(Maps to the '" + _currentView.DatabaseName + "." + _currentView.DatabaseName + "' database field)";
-
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// " + description);
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" [Column(Name = \"" + column.DatabaseName + "\", DbType = \"" + column.DatabaseTypeRaw + "\", CanBeNull = " + column.AllowNull.ToString().ToLower() + ", IsPrimaryKey = false)]");
- sb.AppendLine(" public virtual " + column.GetCodeType(true) + " " + column.PascalName + " { get; set; }");
- }
- sb.AppendLine();
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- sb.AppendLine(" }");
- sb.AppendLine();
- }
- catch (Exception ex)
- {
- throw;
- }
- }
-
- #endregion
-
- }
- }