/// <summary> /// Constructor /// </summary> public ViewObjectDataSource(Configuration configuration) { TypeName = GetType().ToString(); SelectCountMethod = "SelectCount"; SelectMethod = "Select"; EnablePaging = true; Config = configuration; SelectParameters.Add("configuration", TypeCode.Object, string.Empty); Selecting += OnSelecting; }
public override void Reset() { SelectParameters?.Reset(); OutputLocation?.Reset(); Days = 0; GlacierTier = RetrievalTier.Unknown; RequestTier = RetrievalTier.Unknown; RequestType = RestoreRequestType.Unknown; Description = null; RequestPayer = Payer.Unknown; VersionId = null; base.Reset(); }
private StringBuilder CreateRawCacheKey() { // Note: The cache key will contain information such as type names and // method names, however it will be stored in the internal cache, which is // not accessible to page developers, so it is secure. StringBuilder sb = new StringBuilder(CacheInternal.PrefixDataSourceControl, 1024); sb.Append(GetType().GetHashCode().ToString(CultureInfo.InvariantCulture)); sb.Append(":"); sb.Append(CacheDuration.ToString(CultureInfo.InvariantCulture)); sb.Append(':'); sb.Append(((int)CacheExpirationPolicy).ToString(CultureInfo.InvariantCulture)); sb.Append(":"); sb.Append(SqlCacheDependency); sb.Append(":"); sb.Append(TypeName); sb.Append(":"); sb.Append(SelectMethod); // Append parameter names and values if (SelectParameters.Count > 0) { sb.Append("?"); IDictionary parameters = SelectParameters.GetValues(Context, this); foreach (DictionaryEntry entry in parameters) { sb.Append(entry.Key.ToString()); if ((entry.Value != null) && (entry.Value != DBNull.Value)) { sb.Append("="); sb.Append(entry.Value.ToString()); } else { if (entry.Value == DBNull.Value) { sb.Append("(dbnull)"); } else { sb.Append("(null)"); } } sb.Append("&"); } } return(sb); }
private object[] GetParametersForSelect(DataSourceSelectArguments arguments) { var parameters = new List <object>(); foreach (DictionaryEntry entry in SelectParameters.GetValues(HttpContext.Current, owner)) { parameters.Add(entry.Value); } if (CanPage) { parameters.Add(arguments.MaximumRows); parameters.Add(arguments.StartRowIndex); } if ((!string.IsNullOrEmpty(arguments.SortExpression)) && (!InternalSort)) { parameters.Add(arguments.SortExpression); } return(parameters.ToArray()); }
protected override IEnumerable ExecuteSelect(DataSourceSelectArguments arguments) { var args = new TpObjectDataSourceEventArgs(); owner.OnSelecting(args); if (args.Cancel) { return(null); } object obj = args.BusinessObject ?? Source.GetDataFromSource(GetParametersForSelect(arguments)); if (arguments.RetrieveTotalRowCount && CanRetrieveTotalRowCount) { arguments.TotalRowCount = GetRowCount(obj); } args.SelectParams = SelectParameters.GetValues(HttpContext.Current, owner); if (obj == null) { return(null); } if (!(obj is IEnumerable)) { obj = new[] { obj }; } if (InternalSort && (!string.IsNullOrEmpty(arguments.SortExpression))) { obj = Sort((IEnumerable)obj, arguments.SortExpression); } args.BusinessObject = obj; owner.OnSelected(args); return((IEnumerable)obj); }
void OnPageLoadComplete(object sender, EventArgs e) { FilterParameters.UpdateValues(Context, this); SelectParameters.UpdateValues(Context, this); }
private void InitializeParameters(out string fetchXml, out QueryByAttribute query) { // merge the select parameters IOrderedDictionary parameters = QueryParameters.GetValues(_context, _owner); fetchXml = GetNonNullOrEmpty( parameters[_fetchXmlParameterName] as string, _owner.FetchXml); if (!string.IsNullOrEmpty(fetchXml)) { IOrderedDictionary selectParameters = SelectParameters.GetValues(_context, _owner); // apply select parameters replacement to the FetchXml foreach (DictionaryEntry entry in selectParameters) { if (entry.Key != null) { string key = entry.Key.ToString().Trim(); if (!key.StartsWith("@")) { key = "@" + key; } string value = "{0}".FormatWith(entry.Value); if (Owner.EncodeParametersEnabled) { value = AntiXssEncoder.XmlEncode(value); } fetchXml = Regex.Replace(fetchXml, key, value, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); } } } // process the QueryByAttribute query = null; if (_owner.QueryByAttribute != null && !string.IsNullOrEmpty(_owner.QueryByAttribute.EntityName)) { IOrderedDictionary selectParameters = SelectParameters.GetValues(_context, _owner); query = new QueryByAttribute(); query.EntityName = LookupParameter(selectParameters, _owner.QueryByAttribute.EntityName); query.Attributes.AddRange(CopyParameters(selectParameters, _owner.QueryByAttribute.Attributes)); query.Values.AddRange(CopyParameters(selectParameters, _owner.QueryByAttribute.Values)); if (_owner.QueryByAttribute.ColumnSet != null && _owner.QueryByAttribute.ColumnSet.Count > 0) { // specify individual columns to load query.ColumnSet = new ColumnSet(CopyParameters(selectParameters, _owner.QueryByAttribute.ColumnSet)); } else { // default to all columns query.ColumnSet = new ColumnSet(true); } if (_owner.QueryByAttribute.Orders != null && _owner.QueryByAttribute.Orders.Count > 0) { for (int i = 0; i < _owner.QueryByAttribute.Orders.Count; ++i) { OrderExpression order = new OrderExpression(); order.AttributeName = LookupParameter(selectParameters, _owner.QueryByAttribute.Orders[i].Value); string orderText = LookupParameter(selectParameters, _owner.QueryByAttribute.Orders[i].Text); if (orderText.StartsWith("desc", StringComparison.InvariantCultureIgnoreCase)) { order.OrderType = OrderType.Descending; } query.Orders.Add(order); } } // merge the select parameters string entityName = parameters[_entityNameParameterName] as string; if (!string.IsNullOrEmpty(entityName)) { query.EntityName = entityName; } // comma delimited string attributes = parameters[_attributesParameterName] as string; if (!string.IsNullOrEmpty(attributes)) { query.Attributes.Clear(); query.Attributes.AddRange(attributes.Split(',')); } // comma delimited string values = parameters[_valuesParameterName] as string; if (!string.IsNullOrEmpty(values)) { query.Values.Clear(); query.Values.AddRange(values.Split(',')); } // comma delimited string columnSet = parameters[_columnSetParameterName] as string; if (!string.IsNullOrEmpty(columnSet)) { if (string.Compare(columnSet, _allColumnsParameterValue, StringComparison.InvariantCultureIgnoreCase) == 0) { query.ColumnSet = new ColumnSet(true); } else { string[] parts = columnSet.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length > 0) { for (int i = 0; i < parts.Length; i++) { parts[i] = parts[i].Trim(); } query.ColumnSet.AddColumns(parts); } else { query.ColumnSet = new ColumnSet(true); } } } // comma delimited string orders = parameters[_ordersParameterName] as string; if (!string.IsNullOrEmpty(orders)) { QueryByAttribute queryByAttribute = query; AppendSortExpressionToQuery(orders, order => queryByAttribute.Orders.Add(order)); query = queryByAttribute; } // all remaining parameters are treated as key/value pairs Dictionary <string, object> extendedParameters = new Dictionary <string, object>(); if (query.Attributes != null) { for (int i = 0; i < query.Attributes.Count; ++i) { extendedParameters[query.Attributes[i]] = query.Values[i]; } } bool changed = false; foreach (string key in parameters.Keys) { // ignore special parameters if (!Array.Exists(_keywords, delegate(string value) { return(string.Compare(value, key, StringComparison.InvariantCultureIgnoreCase) == 0); })) { extendedParameters[key] = parameters[key]; changed = true; } } if (changed) { query.Attributes.Clear(); query.Values.Clear(); int i = 0; foreach (KeyValuePair <string, object> extendedParameter in extendedParameters) { query.Attributes[i] = extendedParameter.Key; query.Values[i] = extendedParameter.Value; ++i; } } } }
/// <summary> /// Evaluates the method parameters using model binding. /// </summary> /// <param name="dataSourceOperation">The datasource operation for which parameters are being evaluated.</param> /// <param name="modelDataSourceMethod">The ModelDataSourceMethod object for which the Parameter collection is being evaluated. The MethodInfo property should already be set on this object.</param> /// <param name="controlValues">The values from the data bound control.</param> /// <param name="isPageLoadComplete">This must be set to true only when this method is called in Page's LoadComplete event handler /// to evaluate the select method parameters that use custom value providers so that we can identify any changes /// to those and mark the data-bound control for data binding if necessary.</param> protected virtual void EvaluateMethodParameters(DataSourceOperation dataSourceOperation, ModelDataSourceMethod modelDataSourceMethod, IDictionary controlValues, bool isPageLoadComplete) { Debug.Assert(_owner.DataControl.Page != null); Debug.Assert(_owner.DataControl.TemplateControl != null); MethodInfo actionMethod = modelDataSourceMethod.MethodInfo; IModelBinder binder = ModelBinders.Binders.DefaultBinder; IValueProvider dataBoundControlValueProvider = GetValueProviderFromDictionary(controlValues); ModelBindingExecutionContext modelBindingExecutionContext = _owner.DataControl.Page.ModelBindingExecutionContext; //This is used by ControlValueProvider later. modelBindingExecutionContext.PublishService <Control>(_owner.DataControl); //This is done for the TryUpdateModel to work inside a Data Method. if (dataSourceOperation != DataSourceOperation.Select) { _owner.DataControl.Page.SetActiveValueProvider(dataBoundControlValueProvider); } foreach (ParameterInfo parameterInfo in actionMethod.GetParameters()) { object value = null; string modelName = parameterInfo.Name; if (parameterInfo.ParameterType == typeof(ModelMethodContext)) { //ModelMethodContext is a special parameter we pass in for enabling developer to call //TryUpdateModel when Select/Update/Delete/InsertMethods are on a custom class. value = new ModelMethodContext(_owner.DataControl.Page); } //Do not attempt model binding the out parameters else if (!parameterInfo.IsOut) { bool validateRequest; IValueProvider customValueProvider = GetCustomValueProvider(modelBindingExecutionContext, parameterInfo, ref modelName, out validateRequest); //When we are evaluating the parameter at the time of page load, we do not want to populate the actual ModelState //because there will be another evaluation at data-binding causing duplicate errors if model validation fails. ModelStateDictionary modelState = isPageLoadComplete ? new ModelStateDictionary() : _owner.DataControl.Page.ModelState; ModelBindingContext bindingContext = new ModelBindingContext() { ModelBinderProviders = ModelBinderProviders.Providers, ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(null, parameterInfo.ParameterType), ModelState = modelState, ModelName = modelName, ValueProvider = customValueProvider, ValidateRequest = validateRequest }; //Select parameters that take custom values providers are tracked by ViewState so that //we can detect any changes from previous page request and mark the data bound control for data binding if necessary. if (dataSourceOperation == DataSourceOperation.Select && customValueProvider != null && parameterInfo.ParameterType.IsSerializable) { if (!SelectParameters.ContainsKey(parameterInfo.Name)) { SelectParameters.Add(parameterInfo.Name, new MethodParameterValue()); } if (binder.BindModel(modelBindingExecutionContext, bindingContext)) { value = bindingContext.Model; } SelectParameters[parameterInfo.Name].UpdateValue(value); } else { if (isPageLoadComplete) { Debug.Assert(dataSourceOperation == DataSourceOperation.Select, "Only Select Operation should have been done immediately after page load"); //When this method is called as part of Page's LoadComplete event handler we do not have values in defaultValueProvider //(i.e., values from DataBoundControl), so we need not evaluate the parameters values. continue; } if (customValueProvider == null) { bindingContext.ValueProvider = dataBoundControlValueProvider; } if (binder.BindModel(modelBindingExecutionContext, bindingContext)) { value = bindingContext.Model; } } if (!isPageLoadComplete) { ValidateParameterValue(parameterInfo, value, actionMethod); } } modelDataSourceMethod.Parameters.Add(parameterInfo.Name, value); } }
public static void InitializeListConfig(this SelectParameters selectParameters, IListConfig config) { }
/// <devdoc> /// Event handler for the Page's LoadComplete event. /// Updates the parameters' values to possibly raise a DataSourceChanged event, causing bound controls to re-databind. /// </devdoc> private void LoadCompleteEventHandler(object sender, EventArgs e) { SelectParameters.UpdateValues(Context, this); FilterParameters.UpdateValues(Context, this); }
public string[] GetAdditionalValues(SelectParameters selectParameters) { throw new System.NotImplementedException(); }