/// <summary>
		/// 
		/// </summary>
		/// <param name="ctx"></param>
		/// <param name="tag"></param>
		/// <param name="parameterObject"></param>
		/// <returns></returns>
		public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject)
		{
			if (parameterObject == null) 
			{
				return true;
			} 
			else 
			{
				string propertyName = ((BaseTag)tag).Property;
				object value = null;
				if (propertyName != null && propertyName.Length>0) 
				{
					value = ObjectProbe.GetMemberValue(parameterObject, propertyName, this.AccessorFactory);
				} 
				else 
				{
					value = parameterObject;
				}
				if (value is ICollection) 
				{
					return ((value == null) || (((ICollection) value).Count< 1));
				} 
				else if (value != null && typeof(Array).IsAssignableFrom(value.GetType())) //value.GetType().IsArray
				{
					return ((Array) value).GetLength(0) == 0;
				}
				else 
				{
					return ((value == null) || (System.Convert.ToString(value).Equals("")));
				}
			}
		}
		/// <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 (propertyName != null && propertyName.Length>0) 
				{
					collection = ObjectProbe.GetMemberValue(parameterObject, propertyName, this.AccessorFactory);
				} 
				else 
				{
					collection = parameterObject;
				}
				iterate = new IterateContext(collection);
				ctx.AddAttribute(tag, iterate);
			}
			if (iterate != null && iterate.HasNext) 
			{
				return BaseTagHandler.INCLUDE_BODY;
			} 
			else 
			{
				return BaseTagHandler.SKIP_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) 
		{
			ctx.FirstNonDynamicTagWithPrepend = null ;
			if (tag.IsPrependAvailable) 
			{
				ctx.IsOverridePrepend = true;
			}
			return BaseTagHandler.INCLUDE_BODY;
		}
        /// <summary>
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="tag"></param>
        /// <param name="parameterObject"></param>
        /// <returns></returns>
		public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject)
		{
			if (parameterObject == null) 
			{
				return false;
			} 
			else 
			{
				return ObjectProbe.HasReadableProperty(parameterObject, ((BaseTag)tag).Property);
			}		
		}
		/// <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) 
		{
			if (IsCondition(ctx, tag, parameterObject)) 
			{
				return BaseTagHandler.INCLUDE_BODY;
			} 
			else 
			{
				return BaseTagHandler.SKIP_BODY;
			}
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ctx"></param>
		/// <param name="tag"></param>
		/// <param name="parameterObject"></param>
		/// <returns></returns>
		public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject)
		{
			if (parameterObject == null) 
			{
				return true;
			} 
			else 
			{
				string propertyName = ((BaseTag)tag).Property;
				object value;
				if (propertyName != null && propertyName.Length>0 ) 
				{
					value = ObjectProbe.GetMemberValue(parameterObject, propertyName, this.AccessorFactory);
				} 
				else 
				{
					value = parameterObject;
				}
				return (value == null);
			}		
		}
Beispiel #7
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ctx"></param>
		/// <param name="tag"></param>
		/// <param name="parameterObject"></param>
		/// <returns></returns>
		public virtual int DoStartFragment(SqlTagContext ctx, SqlTag tag, object parameterObject) 
		{
			return BaseTagHandler.INCLUDE_BODY;
		}
Beispiel #8
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ctx"></param>
		/// <param name="tag"></param>
		/// <param name="parameterObject"></param>
		/// <param name="bodyContent"></param>
		public virtual void DoPrepend(SqlTagContext ctx, SqlTag tag, object parameterObject, StringBuilder bodyContent) 
		{
			if (tag.IsPrependAvailable) 
			{
				if (bodyContent.ToString().Trim().Length > 0) 
				{
					if (ctx.IsOverridePrepend && tag == ctx.FirstNonDynamicTagWithPrepend) 
					{
						ctx.IsOverridePrepend = false;
					} 
					else 
					{
						bodyContent.Insert(0, tag.Prepend);
					}
				} 
				else 
				{
					if (ctx.FirstNonDynamicTagWithPrepend != null) 
					{
						ctx.FirstNonDynamicTagWithPrepend = null;
						ctx.IsOverridePrepend =true;
					}
				}
			}
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ctx"></param>
		/// <param name="tag"></param>
		/// <param name="parameterObject"></param>
		/// <returns></returns>
		public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject)
		{
			return (this.Compare(ctx, tag, parameterObject) == 0);
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ctx"></param>
		/// <param name="tag"></param>
		/// <param name="parameterObject"></param>
		/// <returns></returns>
		public abstract bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject);
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ctx"></param>
		/// <param name="tag"></param>
		/// <param name="parameterObject"></param>
		/// <returns></returns>
		public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject)
		{
			return (parameterObject != null);
		}
		/// <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 BaseTagHandler.REPEAT_BODY;
			} 
			else 
			{
				return BaseTagHandler.INCLUDE_BODY;
			}
		}
Beispiel #14
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ctx"></param>
		/// <param name="tag"></param>
		/// <param name="parameterObject"></param>
		/// <param name="bodyContent"></param>
		/// <returns></returns>
		public virtual int DoEndFragment(SqlTagContext ctx, SqlTag tag, object parameterObject, StringBuilder bodyContent) 
		{
			return BaseTagHandler.INCLUDE_BODY;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ctx"></param>
		/// <param name="tag"></param>
		/// <param name="parameterObject"></param>
		/// <returns></returns>
		public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject)
		{
			return !base.IsCondition(ctx, tag, parameterObject);
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ctx"></param>
		/// <param name="tag"></param>
		/// <param name="parameterObject"></param>
		/// <returns></returns>
		public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject)
		{
			long x = this.Compare(ctx, tag, parameterObject);
			return ((x >= 0) && (x != ConditionalTagHandler.NOT_COMPARABLE));
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ctx"></param>
		/// <param name="sqlTag"></param>
		/// <param name="parameterObject"></param>
		/// <returns></returns>
		protected long Compare(SqlTagContext ctx, SqlTag sqlTag, object parameterObject)
		{
			Conditional tag = (Conditional)sqlTag;
			string propertyName = tag.Property;
			string comparePropertyName = tag.CompareProperty;
			string compareValue = tag.CompareValue;

			object value1 = null;
			Type type = null;
			if (propertyName != null && propertyName.Length > 0) 
			{
				value1 = ObjectProbe.GetMemberValue(parameterObject, propertyName, this.AccessorFactory);
				type = value1.GetType();
			} 
			else 
			{
				value1 = parameterObject;
				if (value1 != null) 
				{
					type = parameterObject.GetType();
				} 
				else 
				{
					type = typeof(object);
				}
			}
			if (comparePropertyName != null && comparePropertyName.Length > 0) 
			{
                object value2 = ObjectProbe.GetMemberValue(parameterObject, comparePropertyName, this.AccessorFactory);
				return CompareValues(type, value1, value2);
			} 
			else if (compareValue != null && compareValue != "") 
			{
				return CompareValues(type, value1, compareValue);
			} 
			else 
			{
				throw new DataMapperException("Error comparing in conditional fragment.  Uknown 'compare to' values.");
			}
		}