- Home
- LLBLGen Pro
- Custom Templates
LPT template in V2.0
Joined: 01-Apr-2005
I'm trying to write an lpt template for V2.0 but the resulting files only contain \n as line endings even though the template file has \r\n as line endings. If I take an old 1.0 lpt template and run it in 2.0 I also get \n line endings. It seams something have changed or am I missing something?
My task, templatebinding and (pre alfa) template follows:
<task name="CDR.Tasks.Adapter.BLL.CoreServiceClassesGenerator" assemblyFilename="SD.LLBLGen.Pro.LptParser.dll" taskPerformerClass="SD.LLBLGen.Pro.LptParser.DotNetTemplateEngine"
description="Generates the core services classes." isOptional="true">
<supportedPlatforms/>
<supportedTemplateGroups/>
<dependencies>
<dependency name="CDR.Tasks.Adapter.BLL.CoreDirectoryCreator"/>
<dependency name="CDR.Tasks.Adapter.BLL.ServiceBase"/>
</dependencies>
<parameters>
<parameter name="destinationFolder" defaultValue="BusinessLogicLayer\Core" isOptional="false" description="The folder to generate the code in"/>
<parameter name="filenameFormat" defaultValue="[elementName]Service.[extension]" isOptional="false" description="The destination file format specification"/>
<parameter name="templateID" defaultValue="CDR_CoreServiceTemplate" isOptional="false" description="The ID of the template to use." valueType="templateID"/>
<parameter name="emitType" defaultValue="allEntities" isOptional="false" description="The type of code generation to perform." valueType="emitType"/>
<parameter name="templateBindingDefinitionName" defaultValue="" isOptional="true" description="The name of the TemplateBindings from which to pick the templateID specified. Specifying this parameter will always force the templateID to be picked from the templateBindings with the name specified."/>
<parameter name="failWhenExistent" defaultValue="false" isOptional="true" description="Flag to signal what to do when the destination file already exists." valueType="boolean"/>
<parameter name="usePartialClasses" defaultValue="true" isOptional="false" description="Flag to signal if partial classes should be used" valueType="boolean"/>
</parameters>
</task>
<templateBinding templateID="CDR_CoreServiceTemplate" filename="CDRSharedTemplates\Net2.x\C#\BLL_CoreService.lpt" templateLanguage="C#" />
<[ System.Text ]>
using System;
using System.Transactions;
using System.Collections.Generic;
using System.Security.Permissions;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
using <%=BaseNameSpace%>.DAL;
using <%=BaseNameSpace%>.DAL.DatabaseSpecific;
using <%=BaseNameSpace%>.DAL.EntityClasses;
using <%=BaseNameSpace%>.DAL.FactoryClasses;
using <%=BaseNameSpace%>.DAL.HelperClasses;
using <%=BaseNameSpace%>.BLL;
using SD.LLBLGen.Pro.ORMSupportClasses;
<%=DotNetTemplateEngine.GetUserCodeRegion("AdditionalNamespaces", "//").Trim()%>
namespace <%=BaseNameSpace%>.BLL.Core
{
/// <summary>
/// Core service class for the entity '<%=ObjectName%>'.<br/>
/// </summary>
public <% if (_parameters["usePartialClasses"].Value == "true") __outputWriter.Write("partial");%> class <%=ObjectName%>Service : ServiceBase<%="\n"+DotNetTemplateEngine.GetUserCodeRegion("AdditionalInterfaces", "//")%>
{
#region Class Member Declarations
<%=DotNetTemplateEngine.GetUserCodeRegion("PrivateMembers", "//")%>
#endregion
/// <summary> Static CTor. Is executed before the first instance of this service class or derived classes is constructed. </summary>
static <%=ObjectName%>Service()
{
}
/// <summary> CTor</summary>
public <%=ObjectName%>Service()
{
}
#region Read Region
/// <summary>
/// Retrieves an entity object from persistent storage by using looking up it's primary key(s).
/// </summary>
/// <returns>A populated entity.</returns>
[AuthorizationPermission(SecurityAction.Demand, Context = "Everyone")]
public virtual <%=ObjectName%>Entity Fetch( <%=BuildPrimaryKeyParameterList()%> )
{
using (ServiceDataAdapter adapter = new ServiceDataAdapter())
{
<%=ObjectName%>Entity entity = new <%=ObjectName%>Entity( <%=BuildPrimaryKeyList()%> );
if (adapter.FetchEntity(entity, prefetch))
return entity;
else
return null;
}
}
[AuthorizationPermission(SecurityAction.Demand, Context = "Everyone")]
public EntityCollection<<%=ObjectName%>Entity> FetchAll()
{
EntityCollection<<%=ObjectName%>Entity> collection =
new EntityCollection<<%=ObjectName%>Entity>(new <%=ObjectName%>EntityFactory());
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
adapter.FetchEntityCollection(collection, null);
}
return collection;
}
[AuthorizationPermission(SecurityAction.Demand, Context = "Everyone")]
public int CountAll()
{
using (ServiceDataAdapter adapter = new ServiceDataAdapter())
{
<%=ObjectName%>Entity entity = new <%=ObjectName%>Entity();
return adapter.GetDbCount(entity.Fields, null, null);
}
}
[AuthorizationPermission(SecurityAction.Demand, Context = "Everyone")]
public void SaveWork(UnitOfWork2 uow)
{
if (!ValidateUnitOfWork(uow)) throw new ApplicationException("Invalid argument exception");
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
uow.Commit(adapter, true);
}
}
#endregion
#region Save Region
/// <summary>
/// Saves a '<%=ObjectName%>' entity.
/// </summary>
/// <param name="entity">Entity to save</param>
/// <param name="refetchAfterSave">Determines if the entity should be re-fetched.</param>
/// <param name="messages">MessageCollection</param>
/// <returns>The re-fetched <see cref="<%=ObjectName%>"/> or null if refetchAfterSave is false.</returns>
[AuthorizationPermission(SecurityAction.Demand, Context = "Nobody")]
public <%=ObjectName%>Entity Save(<%=ObjectName%>Entity entity, bool refetchAfterSave, out MessageCollection messages)
{
messages=new MessageCollection();
using(ServiceDataAdapter adapter = new ServiceDataAdapter())
{
try
{
adapter.SaveEntity(entity, refetchAfterSave);
adapter.Commit();
}
catch(Exception ex)
{
adapter.Rollback();
if (ExceptionPolicy.HandleException(ex,"Service")) throw;
}
}
return refetchAfterSave ? entity : null;
}
#endregion
#region Custom Core Service code
<%=DotNetTemplateEngine.GetUserCodeRegion("CustomCoreServiceCode", "//")%>
#endregion
<%if(DotNetTemplateEngine.GetUserCodeRegion("ValidateUnitOfWorkCode", "//") == string.Empty){%>
private bool ValidateUnitOfWork(UnitOfWork2 uow)
{
uow.ConstructSaveProcessQueues();
foreach (UnitOfWorkElement2 element in uow.GetEntityElementsToDelete())
{
if (!(element.Entity is <%=ObjectName%>Entity)) return false;
}
foreach (ActionQueueElement<IEntity2> element in uow.GetInsertQueue())
{
if (!(element.Entity is <%=ObjectName%>Entity)) return false;
}
foreach (ActionQueueElement<IEntity2> element in uow.GetUpdateQueue())
{
if (!(element.Entity is <%=ObjectName%>Entity)) return false;
}
return true;
}
<%}else{%>
<%=DotNetTemplateEngine.GetUserCodeRegion("ValidateUnitOfWorkCode", "//")%>
<%}%>
#region Included code
<# Custom_CoreServiceTemplate #>
#endregion
}
}
<~
public string GetUnitOfWorkValidation()
{
string validationCode = DotNetTemplateEngine.GetUserCodeRegion("ValidateUnitOfWorkCode", "//");
if (validationCode == null)
{
}
return validationCode;
}
public bool FieldsContains(EntityFieldsCollection fields, string fieldName)
{
return FieldsContains(fields, fieldName, false);
}
public bool FieldsContains(EntityFieldsCollection fields, string fieldName, bool endsWith)
{
foreach (EntityFieldDefinition field in Entity.Fields)
{
if (endsWith)
{
if (field.FieldName.EndsWith(fieldName))
return true;
} else if (field.FieldName == fieldName)
return true;
}
return false;
}
public EntityDefinition Entity
{
get
{
EntityDefinition e = _activeObject as EntityDefinition;
if (e != null)
return e;
return null;
}
}
public string CoreNamespace
{
get
{
try
{
return BaseNameSpace.Substring( 0, BaseNameSpace.LastIndexOf(".") );
}
catch
{
return BaseNameSpace;
}
}
}
public string BaseNameSpace { get { return _executingGenerator.ProjectDefinition.RootNameSpace; } }
public static string CamelCase(string s)
{
if (s.Length > 0)
s = string.Concat(s.Substring(0, 1).ToLower(), s.Substring(1));
return s;
}
public string BuildPrimaryKeyParameterList()
{
return BuildFieldParameterList(Entity.PrimaryKeyFields);
}
public string BuildPrimaryKeyList()
{
return BuildFieldList(Entity.PrimaryKeyFields);
}
public string StripLastComma(string s)
{
if (s.Length > 2)
return s.Substring(0, s.Length - 2);
return s;
}
public string ObjectName
{
get
{
if(_activeObject==null)
{
return "no active object";
}
EntityDefinition e = _activeObject as EntityDefinition;
if(e!=null)
{
return e.Name;
}
TypedListDefinition tl = _activeObject as TypedListDefinition;
if(tl!=null)
{
return tl.Name;
}
TypedViewDefinition tv = _activeObject as TypedViewDefinition;
if(tv!=null)
{
return tv.Name;
}
SPCallDefinition sc = _activeObject as SPCallDefinition;
if(sc!=null)
{
return sc.Name;
}
// unknown object
return "Unknown";
}
}
public string BuildFieldList(ArrayList fields)
{
string toReturn = string.Empty;
foreach (EntityFieldDefinition field in fields)
{
toReturn += string.Format("{0}, ", CamelCase(field.FieldName));
}
return StripLastComma(toReturn);
}
public string BuildFieldParameterList(ArrayList fields)
{
string toReturn = string.Empty;
foreach (EntityFieldDefinition field in fields)
{
toReturn += string.Format("{0} {1}, ", field.DotNetType.Name, CamelCase(field.FieldName));
}
return StripLastComma(toReturn);
}
public string ConcatenateFieldNames(ArrayList fields)
{
StringBuilder sb = new StringBuilder();
foreach (EntityFieldDefinition field in fields)
{
sb.Append(field.FieldName);
}
return sb.ToString();
}
public string SelectTableName(EntityDefinition entity, FieldRelationPair fieldRelationPair)
{
if (fieldRelationPair.Relation == null)
return entity.Name;
else
return fieldRelationPair.Relation.RelationEndPoint.Name;
}
public string BuildParamComments(ArrayList fields)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < fields.Count; i++)
{
FormatParamCommentLine(((EntityFieldDefinition)fields[i]).FieldName, (i == fields.Count - 1), sb);
}
return sb.ToString();
}
public static void FormatParamCommentLine(string fieldName, bool isLast, StringBuilder sb)
{
sb.AppendFormat("/// <param name=\"{0}\"><c>{1}</c>.</param>{2}",
CamelCase(fieldName),
fieldName,
isLast == true ? string.Empty : Environment.NewLine + "\t\t");
}
////////////////////////////////////////////////////////////////////
// Fetch Using Related Unique Constraints Support Methods
// Marcus Mac Innes
//
////////////////////////////////////////////////////////////////////
/// <summary>
/// Builds a string containing Parameter Names
/// from a list of <c>FieldRelationPair</c>s.
/// </summary>
/// <param name="fieldRelationPairs">An ArrayList of <c>FieldRelationPair</c>s.</param>
/// <returns>Parameter names</returns>
public string BuildFieldRelationList(ArrayList fieldRelationPairs)
{
string toReturn = string.Empty;
foreach (FieldRelationPair fieldRelationPair in fieldRelationPairs)
{
toReturn += string.Format("{0}, ", CamelCase(FormatFieldRelation(fieldRelationPair)));
}
return StripLastComma(toReturn);
}
/// <summary>
/// Builds a string containing .NET Type and Parameter Names
/// from a list of <c>FieldRelationPair</c>s.
/// </summary>
/// <param name="fieldRelationPairs">An ArrayList of <c>FieldRelationPair</c>s.</param>
/// <returns>.NET Type and Parameter Names</returns>
public string BuildFieldRelationParameterList(ArrayList fieldRelationPairs)
{
string toReturn = string.Empty;
foreach (FieldRelationPair fieldRelationPair in fieldRelationPairs)
{
toReturn += string.Format("{0} {1}, ", fieldRelationPair.Field.DotNetType.Name, CamelCase(FormatFieldRelation(fieldRelationPair)));
}
return StripLastComma(toReturn);
}
/// <summary>
/// Builds a partial method name from
/// from a list of <c>FieldRelationPair</c>s.
/// </summary>
/// <param name="fieldRelationPairs">An ArrayList of <c>FieldRelationPair</c>s.</param>
/// <returns>A partial method name</returns>
public string ConcatenateFieldRelationNames(ArrayList fieldRelationPairs)
{
StringBuilder sb = new StringBuilder();
foreach (FieldRelationPair fieldRelationPair in fieldRelationPairs)
{
if (fieldRelationPair.Relation != null)
sb.Append("_");
sb.Append(FormatFieldRelation(fieldRelationPair));
}
return sb.ToString();
}
/// <summary>
/// Builds param comments
/// from a list of <c>FieldRelationPair</c>s.
/// </summary>
/// <param name="fieldRelationPairs">An ArrayList of <c>FieldRelationPair</c>s.</param>
/// <returns>param comments.</returns>
public string BuildParamFieldRelationComments(ArrayList fieldRelationPairs)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < fieldRelationPairs.Count; i++)
{
FieldRelationPair fieldRelationPair = (FieldRelationPair)fieldRelationPairs[i];
if (fieldRelationPair.Relation == null)
{
sb.AppendFormat("/// <param name=\"{0}\"><c>{1}</c></param>{2}",
CamelCase(FormatFieldRelation(fieldRelationPair)),
fieldRelationPair.Field.FieldName,
i == fieldRelationPairs.Count - 1 ? string.Empty : Environment.NewLine + "\t\t");
}
else
{
sb.AppendFormat("/// <param name=\"{0}\"><c>{1}Entity.{2}</c></param>{3}",
CamelCase(FormatFieldRelation(fieldRelationPair)),
fieldRelationPair.Relation.RelationEndPoint.Name,
fieldRelationPair.Field.FieldName,
i == fieldRelationPairs.Count - 1 ? string.Empty : Environment.NewLine + "\t\t");
}
}
return sb.ToString();
}
/// <summary>
/// Build a formatted string from a <c>FieldRelationPair</c>
/// </summary>
/// <param name="fieldRelationPair">Specifies the <c>FieldRelationPair</c> to be formatted.</param>
/// <returns>A formatted <c>FieldRelationPair</c></returns>
public string FormatFieldRelation(FieldRelationPair fieldRelationPair)
{
if (fieldRelationPair.Relation == null)
return fieldRelationPair.Field.FieldName;
else
return fieldRelationPair.Relation.RelationEndPoint.Name + fieldRelationPair.Field.FieldName;
}
/// <summary>
/// Creates the groups of related UC field relation pairs.
/// </summary>
/// <param name="entity">Entity.</param>
/// <returns>Group of related UC field relation pairs</returns>
/// <remarks>This method examines the Unique Constrains (UCs) on the specified
/// entity. If any of the fields which make up a UC are found to be related keys
/// to other tables, those tables are examined for the presents of one or more UC.
/// If related UC are found, the local fields are mapped to all possible groups
/// of related UCs and this list is returned.
/// Methods can then be generated which have the ability to lookup an Entity
/// based on a UC defined in a related table.
/// </remarks>
public ArrayList CreateGroupsOfRelatedUCFieldRelationPairs(EntityDefinition entity)
{
Hashtable fieldMap = new Hashtable();
Hashtable fieldIsMapped = new Hashtable();
ArrayList mappedUCFieldGroups = new ArrayList();
ArrayList ucGroups = new ArrayList();
// Foreach Unique Constraint
foreach (ArrayList ucFieldGroup in entity.UniqueConstraints.GetValueList())
{
bool hasRelatedUCFields = false;
ArrayList ucGroup = new ArrayList();
ArrayList nonRelationFields = GetFieldNotInvolvedInRelations(ucFieldGroup, entity.Relations);
// Do 2 passes so that we can add local field first and Related Field 2nd
// which makes the Method names and parameter list better.
foreach (EntityFieldDefinition field in ucFieldGroup)
{
bool isLocal = nonRelationFields.Contains(field);
if (fieldMap.Contains(field))
{
if (isLocal)
ucGroup.Add(fieldMap[field]);
}
else
{
bool isMapped;
ArrayList mappedFieldLists = MapToRelatedUCFields(entity, field, out isMapped);
fieldMap.Add(field, mappedFieldLists);
fieldIsMapped.Add(field, isMapped);
if (isLocal)
ucGroup.Add(mappedFieldLists);
}
}
bool isRelatedUCFieldMapped = false;
foreach (EntityFieldDefinition field in ucFieldGroup)
{
bool isLocal = nonRelationFields.Contains(field);
if (!isLocal)
{
ucGroup.Add(fieldMap[field]);
if ((bool)fieldIsMapped[field])
isRelatedUCFieldMapped = true;
hasRelatedUCFields = true;
}
}
if (hasRelatedUCFields && isRelatedUCFieldMapped)
ucGroups.Add(ucGroup);
}
foreach (ArrayList ucGroup in ucGroups)
{
int[] groupIndex = new int[ucGroup.Count];
for (int i = 0; i < ucGroup.Count; i++)
{
groupIndex[i] = 0;
}
bool isDone = false;
while (isDone == false)
{
ArrayList fieldRelationPairs = new ArrayList();
for (int i = 0; i < ucGroup.Count; i++)
{
ArrayList ucFieldLists = (ArrayList)ucGroup[i];
ArrayList mappedFields = (ArrayList)ucFieldLists[groupIndex[i]];
fieldRelationPairs.AddRange(mappedFields);
}
mappedUCFieldGroups.Add(fieldRelationPairs);
for (int i = ucGroup.Count - 1; i >= 0; i--)
{
if (groupIndex[i]++ == ((ArrayList)ucGroup[i]).Count - 1)
{
groupIndex[i] = 0;
if (i == 0)
isDone = true;
}
else
break;
}
}
}
return mappedUCFieldGroups;
}
/// <summary>
/// Maps to related UC fields.
/// </summary>
/// <param name="entity">Entity.</param>
/// <param name="field">Field to map.</param>
/// <param name="isMapped">Indicates whether the field was mapped to a related
/// UC field or not .</param>
/// <returns>A list of groups of related UC fields which are mapped to the specified input field.</returns>
private ArrayList MapToRelatedUCFields(EntityDefinition entity, EntityFieldDefinition field, out bool isMapped)
{
ArrayList mappedFieldLists = new ArrayList();
isMapped = false;
// Check if one or more Unique Constraint Fields are relations to other tables
foreach (EntityRelation relation in entity.Relations)
{
if (relation.FieldRelations != null && relation.FieldRelations.Count > 0)
{
if (relation.FieldRelations[0].RelationStartField == field)
{
// Only interested in non-hidden, ...ToOne type relations with a Single field in relationship
if (!relation.RelationIsHidden &&
(relation.RelationType == EntityRelationType.OneToOne ||
relation.RelationType == EntityRelationType.ManyToOne) &&
relation.FieldRelations.Count == 1)
{
// Only interested if the related table has one or more UC fields
if (relation.RelationEndPoint.UniqueConstraints != null && relation.RelationEndPoint.UniqueConstraints.Count > 0)
{
foreach (ArrayList relatedUCFieldList in relation.RelationEndPoint.UniqueConstraints.GetValueList())
{
ArrayList mappedFields = new ArrayList();
foreach (EntityFieldDefinition ucField in relatedUCFieldList)
{
mappedFields.Add(new FieldRelationPair(ucField, relation));
}
mappedFieldLists.Add(mappedFields);
}
isMapped = true;
break;
}
}
}
}
}
if (!isMapped)
{
ArrayList mappedFields = new ArrayList();
mappedFields.Add(new FieldRelationPair(field, null));
mappedFieldLists.Add(mappedFields);
}
return mappedFieldLists;
}
/// <summary>
/// Examines the specified list of fields and removes any fields that are
/// involved in a "whole" relationship with another table.
/// </summary>
/// <param name="ucFieldList">List of fields.</param>
/// <param name="relations">Relations.</param>
/// <returns>Remaining fields.</returns>
private ArrayList GetFieldNotInvolvedInRelations(ArrayList ucFieldList, EntityRelationCollection relations)
{
ArrayList nonRelatedFieldList = (ArrayList)ucFieldList.Clone();
if (nonRelatedFieldList.Count > 0)
{
foreach (EntityRelation relation in relations)
{
if (relation.FieldRelations != null)
{
foreach (EntityFieldRelation fieldRelation in relation.FieldRelations)
{
if (nonRelatedFieldList.Contains(fieldRelation.RelationStartField))
nonRelatedFieldList.Remove(fieldRelation.RelationStartField);
if (nonRelatedFieldList.Count == 0)
break;
}
if (nonRelatedFieldList.Count == 0)
break;
}
}
}
return nonRelatedFieldList;
}
/// <summary>
/// Creates a list the unique relations from the supplied list
/// of <c>FieldRelationPair</c>s.
/// </summary>
/// <param name="fieldRelationPairs">An ArrayList of <c>FieldRelationPair</c>s.</param>
/// <returns>List the unique relations</returns>
public ArrayList GetUniqueRelations(ArrayList fieldRelationPairs)
{
ArrayList relations = new ArrayList();
foreach (FieldRelationPair fieldRelationPair in fieldRelationPairs)
{
if (fieldRelationPair.Relation != null)
{
if (!relations.Contains(fieldRelationPair.Relation))
relations.Add(fieldRelationPair.Relation);
}
}
return relations;
}
/// <summary>
/// Gets a list of <c>FieldRelationPair</c>s that are writable and not nullable
/// </summary>
/// <param name="entity">Specifies the <c>EntityDefinition</c> to examine.</param>
/// <returns>An ArrayList of <c>FieldRelationPair</c>s.</returns>
public ArrayList GetMinimalFieldRelationPairs(EntityDefinition entity)
{
ArrayList fieldRelationPairs = new ArrayList();
foreach (FieldRelationPair fieldRelationPair in GetWritableFieldRelationPairs(entity))
{
if (!fieldRelationPair.Field.MappedFieldIsNullable)
fieldRelationPairs.Add(fieldRelationPair);
}
return fieldRelationPairs;
}
/// <summary>
/// Gets a list of <c>FieldRelationPair</c>s that are writable
/// </summary>
/// <param name="entity">Specifies the <c>EntityDefinition</c> to examine.</param>
/// <returns>An ArrayList of <c>FieldRelationPair</c>s.</returns>
public ArrayList GetWritableFieldRelationPairs(EntityDefinition entity)
{
ArrayList fieldRelationPairs = new ArrayList();
Hashtable relations = new Hashtable();
foreach (EntityFieldDefinition field in GetWritableFields(entity))
{
EntityRelation relation = GetRelationForField(field);
if (relation == null || relation.IsCustomRelation || (relation.FieldRelations != null && relation.FieldRelations.Count != 1))
fieldRelationPairs.Add(new FieldRelationPair(field, null));
else
{
if (!relations.Contains(relation.UtilizingPropertyName))
{
fieldRelationPairs.Add(new FieldRelationPair(field, relation));
relations.Add(relation.UtilizingPropertyName, relation);
}
}
}
return fieldRelationPairs;
}
private EntityRelation GetRelationForField(EntityFieldDefinition field)
{
if (field.MappedField.IsForeignKey)
{
EntityDefinition entity = field.ContainingEntity;
if (entity.Relations != null)
{
foreach (EntityRelation relation in entity.Relations)
{
if (relation.RelationType != EntityRelationType.OneToMany && !relation.RelationIsHidden && !relation.UtilizingPropertyIsHidden && relation.FieldRelations != null)
{
foreach (EntityFieldRelation fieldRelation in relation.FieldRelations)
{
if (field == fieldRelation.RelationStartField)
return relation;
}
}
}
}
}
return null;
}
public ArrayList GetWritableFields(EntityDefinition entity)
{
ArrayList fields = new ArrayList();
foreach (EntityFieldDefinition field in entity.Fields)
{
if (!field.IsIdentity && !field.IsReadOnly)
{
fields.Add(field);
}
}
return fields;
}
/// <summary>
/// Builds a paramter list used by the Create Entity methods
/// from a list of <c>FieldRelationPair</c>s.
/// </summary>
/// <param name="fieldRelationPairs">An ArrayList of <c>FieldRelationPair</c>s.</param>
/// <returns>.NET Type and Parameter Names</returns>
public string BuildCreateParameterList(ArrayList fieldRelationPairs)
{
string toReturn = string.Empty;
foreach (FieldRelationPair fieldRelationPair in fieldRelationPairs)
{
if (fieldRelationPair.Relation == null)
toReturn += string.Format("{0} {1}, ", fieldRelationPair.Field.DotNetType.Name, CamelCase(fieldRelationPair.Field.FieldName));
else
toReturn += string.Format("{0}Entity {1}, ", fieldRelationPair.Relation.RelationEndPoint.Name, CamelCase(fieldRelationPair.Relation.UtilizingPropertyName));
}
return StripLastComma(toReturn);
}
/// <summary>
/// Builds Create comments
/// from a list of <c>FieldRelationPair</c>s.
/// </summary>
/// <param name="fieldRelationPairs">An ArrayList of <c>FieldRelationPair</c>s.</param>
/// <returns>param comments.</returns>
public string BuildCreateComments(ArrayList fieldRelationPairs)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < fieldRelationPairs.Count; i++)
{
FieldRelationPair fieldRelationPair = (FieldRelationPair)fieldRelationPairs[i];
if (fieldRelationPair.Relation == null)
{
sb.AppendFormat("/// <param name=\"{0}\">{1}</param>{2}",
CamelCase(fieldRelationPair.Field.FieldName),
fieldRelationPair.Field.FieldName,
i == fieldRelationPairs.Count - 1 ? string.Empty : Environment.NewLine + "\t\t");
}
else
{
sb.AppendFormat("/// <param name=\"{0}\">{1} Entity</param>{2}",
CamelCase(fieldRelationPair.Relation.UtilizingPropertyName),
fieldRelationPair.Relation.UtilizingPropertyName,
i == fieldRelationPairs.Count - 1 ? string.Empty : Environment.NewLine + "\t\t");
}
}
return sb.ToString();
}
/// <summary>
/// FieldRelationPair class
/// </summary>
public class FieldRelationPair
{
public FieldRelationPair(EntityFieldDefinition field, EntityRelation relation)
{
Field = field;
Relation = relation;
}
public EntityFieldDefinition Field;
public EntityRelation Relation;
public static ArrayList ToFieldList(ArrayList fieldRelationPairs)
{
ArrayList toReturn = new ArrayList();
foreach (FieldRelationPair pair in fieldRelationPairs)
{
if (pair.Field != null)
toReturn.Add(pair.Field);
}
return toReturn;
}
public static ArrayList ToRelationList(ArrayList fieldRelationPairs)
{
ArrayList toReturn = new ArrayList();
foreach (FieldRelationPair pair in fieldRelationPairs)
{
if (pair.Relation != null)
toReturn.Add(pair.Relation);
}
return toReturn;
}
}
~>
Joined: 17-Aug-2003
If you check the templatesource file which contains the code executed to emit the output, you'll see it uses \n as line delimiter. Though as this is passed to the Write method of the output writer, it should convert it to a proper EOL token, as it's an escape character.
You run into problems with just \n ?
Joined: 01-Apr-2005
First of all nothing has changed. I have checked and only \n is used in version 1.0.2004.2 to. Because only \n is used I can’t open the resulting files in Notepad and to be able to do that would be nice. However, the problem is that the following template code:
<%=DotNetTemplateEngine.GetUserCodeRegion("PrivateMembers", "//")%>
Will emit an Environment.NewLine (DotNetTemplateEngine.cs) and that is defined as \r\n on my system. Now we have mixed line endings (both \n and \r\n) and that confuse Visual Studio 2005 so it shows its “Inconsistent Line Endings” dialog.
I think it would be better if the resulting files contained Environment.NewLine as line terminators but that might be to much to ask for. For now I think I will write a TDL template instead.
Joined: 17-Aug-2003
It's not a big problem for me to alter DotNetTemplateEngine.cs to use a different line-ending mechanism. Your issue with multiple line endings in a single file and that it then confuses vs.net is a good reason to make the change and see if it affects anything
I'll see if I can make the change and if so, it's fixed in the next build.