/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <returns></returns> public override int DoStartFragment(SqlTagContext ctx, SqlTag tag, object parameterObject) { IterateContext iterate = (IterateContext)ctx.GetAttribute(tag); if (iterate == null) { string propertyName = ((BaseTag)tag).Property; object collection; if (!string.IsNullOrEmpty(propertyName)) { collection = ObjectProbe.GetMemberValue(parameterObject, propertyName, AccessorFactory); } else { collection = parameterObject; } iterate = new IterateContext(collection); ctx.AddAttribute(tag, iterate); } if (iterate.HasNext) { return(INCLUDE_BODY); } return(SKIP_BODY); }
public static string GetReflectedFullName(SqlTagContext ctx, BaseTag tag, string propertyName) { if (ctx == null) throw new ArgumentNullException("ctx"); if (tag == null) throw new ArgumentNullException("tag"); if (propertyName == null) throw new ArgumentNullException("propertyName"); var currentIteratorContext = ctx.GetAttribute(tag) as IterateContext; // is current tag an iterate? if (currentIteratorContext != null) { propertyName = String.Format("{0}[{1}]", propertyName, currentIteratorContext.Index); } var parentIteratorTag = FindParentIteratorTag(ctx, tag); // is current node a child of another iterate node? if (parentIteratorTag != null) return BuildReflectedFullName(ctx, parentIteratorTag, propertyName); return propertyName; }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <param name="bodyContent"></param> public override void DoPrepend(SqlTagContext ctx, SqlTag tag, object parameterObject, StringBuilder bodyContent) { IterateContext iterate = (IterateContext)ctx.GetAttribute(tag); if (iterate.IsFirst) { base.DoPrepend(ctx, tag, parameterObject, bodyContent); } }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <param name="bodyContent"></param> /// <remarks> /// Updated By: Richard Beacroft /// Updated Date: 11\10\2013 /// Description: Changed the index to check for. /// The "iterate" tag handler has been re-worked to ensure we read the next iterate context item /// before the child tag elements are processed. We need to do this to ensure that we can parse /// property expressions within tag elements nested within the iterate element. /// </remarks> public override void DoPrepend(SqlTagContext ctx, SqlTag tag, object parameterObject, StringBuilder bodyContent) { var iterate = (IterateContext)ctx.GetAttribute(tag); // because we move to the first item before we iterate, we need to check to see if this is the first item, by checking the Index = 1 and not 0. if (iterate.IsFirst) { base.DoPrepend(ctx, tag, parameterObject, bodyContent); } }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <param name="bodyContent"></param> /// <returns></returns> /// <remarks> /// Updated By: Richard Beacroft /// Updated Date: 11\10\2013 /// Description: Enables property iterate item paths to be replaced with full property paths, which will later be reflected. /// </remarks> public override int DoEndFragment(SqlTagContext ctx, SqlTag tag, object parameterObject, StringBuilder bodyContent) { IterateContext iterate = (IterateContext)ctx.GetAttribute(tag); if (iterate.IsCompleted) return INCLUDE_BODY; var iterateTag = ((Iterate)tag); var propertyName = iterateTag.Property; if (propertyName == null) propertyName = String.Empty; // build full reflection path if (!ReflectionMapper.ReplacePropertyIndexerWithFullName(ctx, iterateTag, bodyContent)) { string find = propertyName + ReflectionMapper.ENUMERATOR_PLACEHOLDER; string replace = propertyName + "[" + iterate.Index + "]"; //Parameter-index-Dynamic StringHandler.Replace(bodyContent, find, replace); } if (iterate.IsFirst) { if (iterateTag.Open != null) { bodyContent.Insert(0, ctx.ReplaceBindingVariables(iterateTag.Open)); bodyContent.Insert(0, ' '); } } if (iterate.IsLast) { if (iterateTag.Close != null) { bodyContent.Append(ctx.ReplaceBindingVariables(iterateTag.Close)); } } else { if (iterateTag.Conjunction != null) { bodyContent.Append(ctx.ReplaceBindingVariables(iterateTag.Conjunction)); bodyContent.Append(' '); } } if (iterate.HasNext) return REPEAT_BODY; iterate.IsCompleted = true; return INCLUDE_BODY; }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <returns></returns> /// Updated By: Richard Beacroft /// Updated Date: 11\10\2013 /// Description: Enables one to be able to have sql text within an iterate element that references the current item as "[]." /// This is then parsed, along with any reflection path suffix to get the object instance the used is interested in. /// and add it to an attributes collection for later use. public override int DoStartFragment(SqlTagContext ctx, SqlTag tag, object parameterObject) { var iterate = (IterateContext)ctx.GetAttribute(tag); if (iterate == null) { var baseTag = (BaseTag)tag; object collection; if (!string.IsNullOrEmpty(baseTag.Property)) { // this will either leave the property name as it is, or if it starts with "[].", the // current iterate context item value will be used, with the rest of the property name // walked to determine the field/property to get the value from. collection = _tagPropertyProbe.GetMemberPropertyValue(ctx, baseTag, parameterObject); } else { collection = parameterObject; } iterate = new IterateContext(collection); ctx.AddAttribute(tag, iterate); // if there is another item in the iterate array, then we need to include the body. if (iterate.MoveNext()) { return(INCLUDE_BODY); } iterate.IsCompleted = true; return(SKIP_BODY); } if (iterate.IsCompleted) { // reset the context to cater for nested iterations. ctx.RemoveAttibute(tag); // now re-process the tag which will re-add the now modified tag element back to the attributes collection. return(DoStartFragment(ctx, tag, parameterObject)); } else if (iterate.HasNext || iterate.IsLast) { if (iterate.MoveNext()) { return(INCLUDE_BODY); } } return(SKIP_BODY); }
private IterateContext FindParentIteratorContext(SqlTagContext ctx, BaseTag tag) { if (tag.Parent is Iterate) return ctx.GetAttribute(tag.Parent) as IterateContext; var parentBaseTag = tag.Parent as BaseTag; if (tag.Parent == null || parentBaseTag == null) return null; return FindParentIteratorContext(ctx, parentBaseTag); }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <param name="bodyContent"></param> /// <returns></returns> public override int DoEndFragment(SqlTagContext ctx, SqlTag tag, object parameterObject, StringBuilder bodyContent) { IterateContext iterate = (IterateContext)ctx.GetAttribute(tag); if (iterate.MoveNext()) { string propertyName = ((BaseTag)tag).Property; if (propertyName == null) { propertyName = ""; } string find = propertyName + "[]"; string replace = propertyName + "[" + iterate.Index + "]"; //Parameter-index-Dynamic Replace(bodyContent, find, replace); if (iterate.IsFirst) { string open = ((Iterate)tag).Open; if (open != null) { bodyContent.Insert(0, open); bodyContent.Insert(0, ' '); } } if (!iterate.IsLast) { string conjunction = ((Iterate)tag).Conjunction; if (conjunction != null) { bodyContent.Append(conjunction); bodyContent.Append(' '); } } if (iterate.IsLast) { string close = ((Iterate)tag).Close; if (close != null) { bodyContent.Append(close); } } return(REPEAT_BODY); } return(INCLUDE_BODY); }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <returns></returns> public override int DoStartFragment(SqlTagContext ctx, SqlTag tag, object parameterObject) { IterateContext iterate = (IterateContext) ctx.GetAttribute(tag); if (iterate == null) { string propertyName = ((BaseTag)tag).Property; object collection; if (!string.IsNullOrEmpty(propertyName)) { collection = ObjectProbe.GetMemberValue(parameterObject, propertyName, AccessorFactory); } else { collection = parameterObject; } iterate = new IterateContext(collection); ctx.AddAttribute(tag, iterate); } if (iterate.HasNext) { return INCLUDE_BODY; } return SKIP_BODY; }
private static string BuildReflectedFullName(SqlTagContext ctx, Iterate parentIteratorTag, string propertyName) { if (parentIteratorTag != null) { var parentIteratorContext = ctx.GetAttribute(parentIteratorTag) as IterateContext; var indexOfIndexer = propertyName.IndexOf(THIS_ENUMERATOR_PLACEHOLDER); if (parentIteratorContext == null) return propertyName; if (indexOfIndexer == 0) { // the property name is a reflection name relative to the iterate. propertyName = propertyName.Substring(indexOfIndexer + THIS_ENUMERATOR_PLACEHOLDER.Length); propertyName = String.Format("{0}[{1}].{2}", parentIteratorTag.Property, parentIteratorContext.Index, propertyName); var parentOrParentIteratorTag = FindParentIteratorTag(ctx, parentIteratorTag); if (parentOrParentIteratorTag != null) return BuildReflectedFullName(ctx, parentOrParentIteratorTag, propertyName); } else if (propertyName.IndexOf(ENUMERATOR_PLACEHOLDER) > -1) { return propertyName + "[" + parentIteratorContext.Index + "]"; //Parameter-Index-Dynamic } } return propertyName; }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <param name="bodyContent"></param> /// <returns></returns> /// <remarks> /// Updated By: Richard Beacroft /// Updated Date: 11\10\2013 /// Description: Enables property iterate item paths to be replaced with full property paths, which will later be reflected. /// </remarks> public override int DoEndFragment(SqlTagContext ctx, SqlTag tag, object parameterObject, StringBuilder bodyContent) { IterateContext iterate = (IterateContext)ctx.GetAttribute(tag); if (iterate.IsCompleted) { return(INCLUDE_BODY); } var iterateTag = ((Iterate)tag); var propertyName = iterateTag.Property; if (propertyName == null) { propertyName = String.Empty; } // build full reflection path if (!ReflectionMapper.ReplacePropertyIndexerWithFullName(ctx, iterateTag, bodyContent)) { string find = propertyName + ReflectionMapper.ENUMERATOR_PLACEHOLDER; string replace = propertyName + "[" + iterate.Index + "]"; //Parameter-index-Dynamic StringHandler.Replace(bodyContent, find, replace); } if (iterate.IsFirst) { if (iterateTag.Open != null) { bodyContent.Insert(0, ctx.ReplaceBindingVariables(iterateTag.Open)); bodyContent.Insert(0, ' '); } } if (iterate.IsLast) { if (iterateTag.Close != null) { bodyContent.Append(ctx.ReplaceBindingVariables(iterateTag.Close)); } } else { if (iterateTag.Conjunction != null) { bodyContent.Append(ctx.ReplaceBindingVariables(iterateTag.Conjunction)); bodyContent.Append(' '); } } if (iterate.HasNext) { return(REPEAT_BODY); } iterate.IsCompleted = true; return(INCLUDE_BODY); }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <returns></returns> /// Updated By: Richard Beacroft /// Updated Date: 11\10\2013 /// Description: Enables one to be able to have sql text within an iterate element that references the current item as "[]." /// This is then parsed, along with any reflection path suffix to get the object instance the used is interested in. /// and add it to an attributes collection for later use. public override int DoStartFragment(SqlTagContext ctx, SqlTag tag, object parameterObject) { var iterate = (IterateContext)ctx.GetAttribute(tag); if (iterate == null) { var baseTag = (BaseTag)tag; object collection; if (!string.IsNullOrEmpty(baseTag.Property)) { // this will either leave the property name as it is, or if it starts with "[].", the // current iterate context item value will be used, with the rest of the property name // walked to determine the field/property to get the value from. collection = _tagPropertyProbe.GetMemberPropertyValue(ctx, baseTag, parameterObject); } else { collection = parameterObject; } iterate = new IterateContext(collection); ctx.AddAttribute(tag, iterate); // if there is another item in the iterate array, then we need to include the body. if (iterate.MoveNext()) return INCLUDE_BODY; iterate.IsCompleted = true; return SKIP_BODY; } if (iterate.IsCompleted) { // reset the context to cater for nested iterations. ctx.RemoveAttibute(tag); // now re-process the tag which will re-add the now modified tag element back to the attributes collection. return DoStartFragment(ctx, tag, parameterObject); } else if (iterate.HasNext || iterate.IsLast) { if (iterate.MoveNext()) return INCLUDE_BODY; } return SKIP_BODY; }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <param name="bodyContent"></param> public override void DoPrepend(SqlTagContext ctx, SqlTag tag, object parameterObject, StringBuilder bodyContent) { IterateContext iterate = (IterateContext) ctx.GetAttribute(tag); if (iterate.IsFirst) { base.DoPrepend(ctx, tag, parameterObject, bodyContent); } }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <param name="bodyContent"></param> /// <returns></returns> public override int DoEndFragment(SqlTagContext ctx, SqlTag tag, object parameterObject, StringBuilder bodyContent) { IterateContext iterate = (IterateContext) ctx.GetAttribute(tag); if (iterate.MoveNext()) { string propertyName = ((BaseTag)tag).Property; if (propertyName == null) { propertyName = ""; } string find = propertyName + "[]"; string replace = propertyName + "[" + iterate.Index + "]";//Parameter-index-Dynamic Replace(bodyContent, find, replace); if (iterate.IsFirst) { string open = ((Iterate)tag).Open; if (open != null) { bodyContent.Insert(0,open); bodyContent.Insert(0,' '); } } if (!iterate.IsLast) { string conjunction = ((Iterate)tag).Conjunction; if (conjunction != null) { bodyContent.Append(conjunction); bodyContent.Append(' '); } } if (iterate.IsLast) { string close = ((Iterate)tag).Close; if (close != null) { bodyContent.Append(close); } } return REPEAT_BODY; } return INCLUDE_BODY; }