public void OnBeforeFind(ActiveRecordDataSourceFindEventArgs e) { if (BeforeFind != null) { BeforeFind(this, e); } }
public void OnFindError(ActiveRecordDataSourceFindEventArgs e) { if (FindError != null) { FindError(this, e); } }
protected void CreateCriteriaFromFindParameters(ActiveRecordDataSourceFindEventArgs args) { IOrderedDictionary values = FindParameters.GetValues(HttpContext.Current, Source); for (int i = 0; i < FindParameters.Count; i++) { Parameter parameter = FindParameters[i]; if (parameter is NullParameter) { NullParameter nullParameter = (NullParameter)parameter; if (nullParameter.Expression == NullExpression.IsNull) { args.Criteria.Add(Expression.IsNull(parameter.Name)); } else if (nullParameter.Expression == NullExpression.IsNotNull) { args.Criteria.Add(Expression.IsNotNull(parameter.Name)); } } else { args.Criteria.Add(Expression.Eq(parameter.Name, values[i])); } } }
protected void CreateOrderFromFindParameters(ActiveRecordDataSourceFindEventArgs args, string expr) { if (String.IsNullOrEmpty(expr)) { return; } args.Order.AddRange(CreateOrderExpression(expr)); }
protected Array ExecuteCustomSelect(DataSourceSelectArguments arguments) { if (CanPage) arguments.AddSupportedCapabilities(DataSourceCapabilities.Page); if (CanSort) arguments.AddSupportedCapabilities(DataSourceCapabilities.Sort); if (CanRetrieveTotalRowCount) arguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount); ActiveRecordDataSourceFindEventArgs args = new ActiveRecordDataSourceFindEventArgs(); CreateOrderFromFindParameters(args, arguments.SortExpression); if (args.Order.Count <= 0) CreateOrderFromFindParameters(args, Source.DefaultSort); args.ModelType = BuildManager.GetType(Source.TypeName, false, true); Source.OnBeforeFind(args); if (args.Cancel) return null; bool useSlicedFind = false; int firstResult = 0; int maxResults = 0; if (CanPage) { useSlicedFind = true; firstResult = arguments.StartRowIndex; maxResults = arguments.MaximumRows; } else if (Source.DefaultMaximumRows > 0) { useSlicedFind = true; firstResult = 0; maxResults = Source.DefaultMaximumRows; } Dictionary<string, object> methodParameters = CreateMethodParametersFromFindParameters(); if (!String.IsNullOrEmpty(Source.FindMethodFirstResultParam) && useSlicedFind) methodParameters[Source.FindMethodFirstResultParam] = firstResult; if (!String.IsNullOrEmpty(Source.FindMethodMaxResultsParam) && useSlicedFind) methodParameters[Source.FindMethodMaxResultsParam] = maxResults; if (!String.IsNullOrEmpty(Source.FindMethodOrderParam) && CanSort) methodParameters[Source.FindMethodOrderParam] = args.Order.ToArray(); Array result = null; try { if (arguments.RetrieveTotalRowCount) arguments.TotalRowCount = ExecuteCount(args); MethodInfo findMethod; Dictionary<string, int> methodParameterNameToIndex; ResolveCustomFindMethod(args.ModelType, methodParameters, out findMethod, out methodParameterNameToIndex); if (findMethod == null) throw new ApplicationException(String.Format("Invalid custom find method '{0}'.", Source.FindMethod)); object[] findMethodArgs = new object[methodParameters.Keys.Count]; foreach (string key in methodParameters.Keys) findMethodArgs[methodParameterNameToIndex[key]] = methodParameters[key]; result = findMethod.Invoke(null, findMethodArgs) as Array; } catch (Exception e) { args.Exception = e; args.WasError = true; Source.OnFindError(args); if (Source.ThrowOnError && !args.DoNotThrow) throw; return null; } args.Result = result; Source.OnFind(args); return result; }
protected override IEnumerable ExecuteSelect(DataSourceSelectArguments arguments) { if (!String.IsNullOrEmpty(Source.FindMethod)) return ExecuteCustomSelect(arguments); if (CanPage) arguments.AddSupportedCapabilities(DataSourceCapabilities.Page); if (CanSort) arguments.AddSupportedCapabilities(DataSourceCapabilities.Sort); if (CanRetrieveTotalRowCount) arguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount); ActiveRecordDataSourceFindEventArgs args = new ActiveRecordDataSourceFindEventArgs(); CreateCriteriaFromFindParameters(args); CreateOrderFromFindParameters(args, arguments.SortExpression); //set default sort if (args.Order.Count <= 0) CreateOrderFromFindParameters(args, Source.DefaultSort); args.ModelType = BuildManager.GetType(Source.TypeName, false, true); Source.OnBeforeFind(args); if (args.Cancel) return null; Array result = null; try { if (arguments.RetrieveTotalRowCount) arguments.TotalRowCount = ExecuteCount(args); bool useSlicedFind = false; int firstResult = 0; int maxResults = 0; if (CanPage) { useSlicedFind = true; firstResult = arguments.StartRowIndex; maxResults = arguments.MaximumRows; } else if (Source.DefaultMaximumRows > 0) { useSlicedFind = true; firstResult = 0; maxResults = Source.DefaultMaximumRows; } if (useSlicedFind) result = ActiveRecordMediator.SlicedFindAll(args.ModelType, firstResult, maxResults, args.Order.ToArray(), args.Criteria.ToArray()); else result = ActiveRecordMediator.FindAll(args.ModelType, args.Order.ToArray(), args.Criteria.ToArray()); } catch (Exception e) { args.Exception = e; args.WasError = true; Source.OnFindError(args); if (Source.ThrowOnError && !args.DoNotThrow) throw; return null; } args.Result = result; Source.OnFind(args); return result; }
protected int ExecuteCount(ActiveRecordDataSourceFindEventArgs args) { IList result = ActiveRecordMediator.ExecuteQuery(new CountQuery(args.ModelType, args.Criteria.ToArray())) as IList; return Convert.ToInt32(result[0]); }
protected void CreateOrderFromFindParameters(ActiveRecordDataSourceFindEventArgs args, string expr) { if (String.IsNullOrEmpty(expr)) return; args.Order.AddRange(CreateOrderExpression(expr)); }
protected void CreateCriteriaFromFindParameters(ActiveRecordDataSourceFindEventArgs args) { IOrderedDictionary values = FindParameters.GetValues(HttpContext.Current, Source); for (int i = 0; i < FindParameters.Count; i++) { Parameter parameter = FindParameters[i]; if (parameter is NullParameter) { NullParameter nullParameter = (NullParameter)parameter; if (nullParameter.Expression == NullExpression.IsNull) args.Criteria.Add(Expression.IsNull(parameter.Name)); else if (nullParameter.Expression == NullExpression.IsNotNull) args.Criteria.Add(Expression.IsNotNull(parameter.Name)); } else { args.Criteria.Add(Expression.Eq(parameter.Name, values[i])); } } }
public void OnFindError(ActiveRecordDataSourceFindEventArgs e) { if (FindError != null) FindError(this, e); }
public void OnBeforeFind(ActiveRecordDataSourceFindEventArgs e) { if (BeforeFind != null) BeforeFind(this, e); }
protected Array ExecuteCustomSelect(DataSourceSelectArguments arguments) { if (CanPage) { arguments.AddSupportedCapabilities(DataSourceCapabilities.Page); } if (CanSort) { arguments.AddSupportedCapabilities(DataSourceCapabilities.Sort); } if (CanRetrieveTotalRowCount) { arguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount); } ActiveRecordDataSourceFindEventArgs args = new ActiveRecordDataSourceFindEventArgs(); CreateOrderFromFindParameters(args, arguments.SortExpression); if (args.Order.Count <= 0) { CreateOrderFromFindParameters(args, Source.DefaultSort); } args.ModelType = BuildManager.GetType(Source.TypeName, false, true); Source.OnBeforeFind(args); if (args.Cancel) { return(null); } bool useSlicedFind = false; int firstResult = 0; int maxResults = 0; if (CanPage) { useSlicedFind = true; firstResult = arguments.StartRowIndex; maxResults = arguments.MaximumRows; } else if (Source.DefaultMaximumRows > 0) { useSlicedFind = true; firstResult = 0; maxResults = Source.DefaultMaximumRows; } Dictionary <string, object> methodParameters = CreateMethodParametersFromFindParameters(); if (!String.IsNullOrEmpty(Source.FindMethodFirstResultParam) && useSlicedFind) { methodParameters[Source.FindMethodFirstResultParam] = firstResult; } if (!String.IsNullOrEmpty(Source.FindMethodMaxResultsParam) && useSlicedFind) { methodParameters[Source.FindMethodMaxResultsParam] = maxResults; } if (!String.IsNullOrEmpty(Source.FindMethodOrderParam) && CanSort) { methodParameters[Source.FindMethodOrderParam] = args.Order.ToArray(); } Array result = null; try { if (arguments.RetrieveTotalRowCount) { arguments.TotalRowCount = ExecuteCount(args); } MethodInfo findMethod; Dictionary <string, int> methodParameterNameToIndex; ResolveCustomFindMethod(args.ModelType, methodParameters, out findMethod, out methodParameterNameToIndex); if (findMethod == null) { throw new ApplicationException(String.Format("Invalid custom find method '{0}'.", Source.FindMethod)); } object[] findMethodArgs = new object[methodParameters.Keys.Count]; foreach (string key in methodParameters.Keys) { findMethodArgs[methodParameterNameToIndex[key]] = methodParameters[key]; } result = findMethod.Invoke(null, findMethodArgs) as Array; } catch (Exception e) { args.Exception = e; args.WasError = true; Source.OnFindError(args); if (Source.ThrowOnError && !args.DoNotThrow) { throw; } return(null); } args.Result = result; Source.OnFind(args); return(result); }
protected override IEnumerable ExecuteSelect(DataSourceSelectArguments arguments) { if (!String.IsNullOrEmpty(Source.FindMethod)) { return(ExecuteCustomSelect(arguments)); } if (CanPage) { arguments.AddSupportedCapabilities(DataSourceCapabilities.Page); } if (CanSort) { arguments.AddSupportedCapabilities(DataSourceCapabilities.Sort); } if (CanRetrieveTotalRowCount) { arguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount); } ActiveRecordDataSourceFindEventArgs args = new ActiveRecordDataSourceFindEventArgs(); CreateCriteriaFromFindParameters(args); CreateOrderFromFindParameters(args, arguments.SortExpression); //set default sort if (args.Order.Count <= 0) { CreateOrderFromFindParameters(args, Source.DefaultSort); } args.ModelType = BuildManager.GetType(Source.TypeName, false, true); Source.OnBeforeFind(args); if (args.Cancel) { return(null); } Array result = null; try { if (arguments.RetrieveTotalRowCount) { arguments.TotalRowCount = ExecuteCount(args); } bool useSlicedFind = false; int firstResult = 0; int maxResults = 0; if (CanPage) { useSlicedFind = true; firstResult = arguments.StartRowIndex; maxResults = arguments.MaximumRows; } else if (Source.DefaultMaximumRows > 0) { useSlicedFind = true; firstResult = 0; maxResults = Source.DefaultMaximumRows; } if (useSlicedFind) { result = ActiveRecordMediator.SlicedFindAll(args.ModelType, firstResult, maxResults, args.Order.ToArray(), args.Criteria.ToArray()); } else { result = ActiveRecordMediator.FindAll(args.ModelType, args.Order.ToArray(), args.Criteria.ToArray()); } } catch (Exception e) { args.Exception = e; args.WasError = true; Source.OnFindError(args); if (Source.ThrowOnError && !args.DoNotThrow) { throw; } return(null); } args.Result = result; Source.OnFind(args); return(result); }
protected int ExecuteCount(ActiveRecordDataSourceFindEventArgs args) { IList result = ActiveRecordMediator.ExecuteQuery(new CountQuery(args.ModelType, args.Criteria.ToArray())) as IList; return(Convert.ToInt32(result[0])); }