You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
@@ -0,0 +1,58 @@
|
||||
namespace System.Web.UI.WebControls {
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
public abstract class ContextDataSource : QueryableDataSource {
|
||||
private ContextDataSourceView _view;
|
||||
|
||||
internal ContextDataSource(IPage page)
|
||||
: base(page) {
|
||||
|
||||
}
|
||||
|
||||
internal ContextDataSource(ContextDataSourceView view)
|
||||
: base(view) {
|
||||
}
|
||||
|
||||
protected ContextDataSource() {
|
||||
}
|
||||
|
||||
private ContextDataSourceView View {
|
||||
get {
|
||||
if (_view == null) {
|
||||
_view = (ContextDataSourceView)GetView("DefaultView");
|
||||
}
|
||||
return _view;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string ContextTypeName {
|
||||
get {
|
||||
return View.ContextTypeName;
|
||||
}
|
||||
set {
|
||||
View.ContextTypeName = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected string EntitySetName {
|
||||
get {
|
||||
return View.EntitySetName;
|
||||
}
|
||||
set {
|
||||
View.EntitySetName = value;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string EntityTypeName {
|
||||
get {
|
||||
return View.EntityTypeName;
|
||||
}
|
||||
set {
|
||||
View.EntityTypeName = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="LinqDataSourceContextData.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.UI.WebControls {
|
||||
using System.Security.Permissions;
|
||||
|
||||
public class ContextDataSourceContextData {
|
||||
public ContextDataSourceContextData() {
|
||||
}
|
||||
|
||||
public ContextDataSourceContextData(object context) {
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public object Context {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public object EntitySet {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,257 @@
|
||||
namespace System.Web.UI.WebControls {
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Reflection;
|
||||
using System.Security.Permissions;
|
||||
using System.Web;
|
||||
using System.Web.Compilation;
|
||||
using System.Web.UI;
|
||||
|
||||
public abstract class ContextDataSourceView : QueryableDataSourceView {
|
||||
private string _entitySetName;
|
||||
private string _contextTypeName;
|
||||
|
||||
private Type _contextType;
|
||||
private string _entityTypeName;
|
||||
private Type _entityType;
|
||||
private Type _entitySetType;
|
||||
|
||||
private Control _owner;
|
||||
|
||||
protected static readonly object EventContextCreating = new object();
|
||||
protected static readonly object EventContextCreated = new object();
|
||||
protected static readonly object EventContextDisposing = new object();
|
||||
|
||||
protected ContextDataSourceView(DataSourceControl owner, string viewName, HttpContext context)
|
||||
: base(owner, viewName, context) {
|
||||
_owner = owner;
|
||||
}
|
||||
|
||||
internal ContextDataSourceView(DataSourceControl owner, string viewName, HttpContext context, IDynamicQueryable queryable)
|
||||
: base(owner, viewName, context, queryable) {
|
||||
}
|
||||
|
||||
public string EntitySetName {
|
||||
get {
|
||||
return _entitySetName ?? String.Empty;
|
||||
}
|
||||
set {
|
||||
if (_entitySetName != value) {
|
||||
_entitySetName = value;
|
||||
_entitySetType = null;
|
||||
OnDataSourceViewChanged(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public string EntityTypeName {
|
||||
get {
|
||||
return _entityTypeName ?? String.Empty;
|
||||
}
|
||||
set {
|
||||
if (_entityTypeName != value) {
|
||||
_entityTypeName = value;
|
||||
_entityType = null;
|
||||
OnDataSourceViewChanged(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override Type EntityType {
|
||||
get {
|
||||
string typeName = EntityTypeName;
|
||||
if (_entityType == null) {
|
||||
_entityType = GetDataObjectTypeByName(typeName) ?? GetDataObjectType(EntitySetType);
|
||||
}
|
||||
return _entityType;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string ContextTypeName {
|
||||
get {
|
||||
return _contextTypeName ?? String.Empty;
|
||||
}
|
||||
set {
|
||||
if (_contextTypeName != value) {
|
||||
_contextTypeName = value;
|
||||
_contextType = null;
|
||||
OnDataSourceViewChanged(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Type ContextType {
|
||||
get {
|
||||
if (_contextType == null && !String.IsNullOrEmpty(ContextTypeName)) {
|
||||
_contextType = DataSourceHelper.GetType(ContextTypeName);
|
||||
}
|
||||
return _contextType;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Current Context
|
||||
/// </summary>
|
||||
protected object Context {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Current EntitySet
|
||||
/// </summary>
|
||||
protected object EntitySet {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods",
|
||||
Justification = "The result of GetEntitySetType() is cached unless the EntitySetTypeName changes.")]
|
||||
protected Type EntitySetType {
|
||||
get {
|
||||
if (_entitySetType == null) {
|
||||
_entitySetType = GetEntitySetType();
|
||||
}
|
||||
return _entitySetType;
|
||||
}
|
||||
}
|
||||
|
||||
// Default implementation assumes the EntitySet is a property or field of the Context
|
||||
protected virtual Type GetEntitySetType() {
|
||||
MemberInfo mi = GetEntitySetMember(ContextType);
|
||||
if (mi.MemberType == MemberTypes.Property) {
|
||||
return ((PropertyInfo)mi).PropertyType;
|
||||
}
|
||||
else if (mi.MemberType == MemberTypes.Field) {
|
||||
return ((FieldInfo)mi).FieldType;
|
||||
}
|
||||
//
|
||||
throw new InvalidOperationException("EntitySet Type must be a field or property");
|
||||
}
|
||||
|
||||
private MemberInfo GetEntitySetMember(Type contextType) {
|
||||
string entitySetTypeName = EntitySetName;
|
||||
if (String.IsNullOrEmpty(entitySetTypeName)) {
|
||||
//
|
||||
return null;
|
||||
}
|
||||
|
||||
MemberInfo[] members = contextType.FindMembers(MemberTypes.Field | MemberTypes.Property,
|
||||
BindingFlags.Public | BindingFlags.Instance |
|
||||
BindingFlags.Static, /*filter*/null, /*filterCriteria*/null);
|
||||
|
||||
for (int i = 0; i < members.Length; i++) {
|
||||
if (String.Equals(members[i].Name, entitySetTypeName, StringComparison.OrdinalIgnoreCase)) {
|
||||
return members[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Type GetDataObjectTypeByName(string typeName) {
|
||||
Type entityType = null;
|
||||
if (!String.IsNullOrEmpty(typeName)) {
|
||||
entityType = BuildManager.GetType(typeName, /*throwOnFail*/ false, /*ignoreCase*/ true);
|
||||
}
|
||||
return entityType;
|
||||
}
|
||||
|
||||
protected virtual Type GetDataObjectType(Type type) {
|
||||
if (type.IsGenericType) {
|
||||
Type[] genericTypes = type.GetGenericArguments();
|
||||
if (genericTypes.Length == 1) {
|
||||
return genericTypes[0];
|
||||
}
|
||||
}
|
||||
//
|
||||
return typeof(object);
|
||||
}
|
||||
|
||||
protected virtual ContextDataSourceContextData CreateContext(DataSourceOperation operation) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override object GetSource(QueryContext context) {
|
||||
ContextDataSourceContextData contextData = CreateContext(DataSourceOperation.Select);
|
||||
if (contextData != null) {
|
||||
// Set the current context
|
||||
Context = contextData.Context;
|
||||
EntitySet = contextData.EntitySet;
|
||||
return EntitySet;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override int ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) {
|
||||
ContextDataSourceContextData contextData = null;
|
||||
try {
|
||||
contextData = CreateContext(DataSourceOperation.Update);
|
||||
if (contextData != null) {
|
||||
// Set the current context
|
||||
Context = contextData.Context;
|
||||
EntitySet = contextData.EntitySet;
|
||||
return base.ExecuteUpdate(keys, values, oldValues);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
DisposeContext();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected override int ExecuteDelete(IDictionary keys, IDictionary oldValues) {
|
||||
ContextDataSourceContextData contextData = null;
|
||||
try {
|
||||
contextData = CreateContext(DataSourceOperation.Delete);
|
||||
if (contextData != null) {
|
||||
// Set the current context
|
||||
Context = contextData.Context;
|
||||
EntitySet = contextData.EntitySet;
|
||||
return base.ExecuteDelete(keys, oldValues);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
DisposeContext();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected override int ExecuteInsert(IDictionary values) {
|
||||
ContextDataSourceContextData contextData = null;
|
||||
try {
|
||||
contextData = CreateContext(DataSourceOperation.Insert);
|
||||
if (contextData != null) {
|
||||
// Set the current context
|
||||
Context = contextData.Context;
|
||||
EntitySet = contextData.EntitySet;
|
||||
|
||||
return base.ExecuteInsert(values);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
DisposeContext();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected virtual void DisposeContext(object dataContext) {
|
||||
if (dataContext != null) {
|
||||
IDisposable disposableObject = dataContext as IDisposable;
|
||||
if (disposableObject != null) {
|
||||
disposableObject.Dispose();
|
||||
}
|
||||
dataContext = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void DisposeContext() {
|
||||
DisposeContext(Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,61 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="DataPagerCommandEventArgs.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace System.Web.UI.WebControls {
|
||||
public class DataPagerCommandEventArgs : CommandEventArgs {
|
||||
private DataPagerField _pagerField;
|
||||
private int _totalRowCount;
|
||||
private int _newMaximumRows = -1;
|
||||
private int _newStartRowIndex = -1;
|
||||
private DataPagerFieldItem _item;
|
||||
|
||||
[SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers", MessageId = "2#")]
|
||||
public DataPagerCommandEventArgs(DataPagerField pagerField, int totalRowCount, CommandEventArgs originalArgs, DataPagerFieldItem item) : base(originalArgs) {
|
||||
_pagerField = pagerField;
|
||||
_totalRowCount = totalRowCount;
|
||||
_item = item;
|
||||
}
|
||||
|
||||
public DataPagerFieldItem Item {
|
||||
get {
|
||||
return _item;
|
||||
}
|
||||
}
|
||||
|
||||
public int NewMaximumRows {
|
||||
get {
|
||||
return _newMaximumRows;
|
||||
}
|
||||
set {
|
||||
_newMaximumRows = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int NewStartRowIndex {
|
||||
get {
|
||||
return _newStartRowIndex;
|
||||
}
|
||||
set {
|
||||
_newStartRowIndex = value;
|
||||
}
|
||||
}
|
||||
|
||||
public DataPagerField PagerField {
|
||||
get {
|
||||
return _pagerField;
|
||||
}
|
||||
}
|
||||
|
||||
public int TotalRowCount {
|
||||
get {
|
||||
return _totalRowCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="DataPagerField.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
|
||||
namespace System.Web.UI.WebControls {
|
||||
public abstract class DataPagerField : IStateManager {
|
||||
private StateBag _stateBag;
|
||||
private bool _trackViewState;
|
||||
private DataPager _dataPager;
|
||||
|
||||
internal event EventHandler FieldChanged;
|
||||
|
||||
protected DataPagerField() {
|
||||
_stateBag = new StateBag();
|
||||
}
|
||||
|
||||
protected StateBag ViewState {
|
||||
get {
|
||||
return _stateBag;
|
||||
}
|
||||
}
|
||||
|
||||
protected bool IsTrackingViewState {
|
||||
get {
|
||||
return _trackViewState;
|
||||
}
|
||||
}
|
||||
|
||||
protected DataPager DataPager {
|
||||
get {
|
||||
return _dataPager;
|
||||
}
|
||||
}
|
||||
|
||||
protected bool QueryStringHandled {
|
||||
get {
|
||||
return DataPager.QueryStringHandled;
|
||||
}
|
||||
set {
|
||||
DataPager.QueryStringHandled = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected string QueryStringValue {
|
||||
get {
|
||||
return DataPager.QueryStringValue;
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
Category("Behavior"),
|
||||
DefaultValue(true),
|
||||
ResourceDescription("DataPagerField_Visible")
|
||||
]
|
||||
public bool Visible {
|
||||
get {
|
||||
object o = ViewState["Visible"];
|
||||
if (o != null) {
|
||||
return (bool)o;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
set {
|
||||
if (value != Visible) {
|
||||
ViewState["Visible"] = value;
|
||||
OnFieldChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected internal DataPagerField CloneField() {
|
||||
DataPagerField newField = CreateField();
|
||||
CopyProperties(newField);
|
||||
return newField;
|
||||
}
|
||||
|
||||
protected virtual void CopyProperties(DataPagerField newField) {
|
||||
newField.Visible = Visible;
|
||||
}
|
||||
|
||||
public abstract void CreateDataPagers(DataPagerFieldItem container, int startRowIndex, int maximumRows, int totalRowCount, int fieldIndex);
|
||||
|
||||
protected abstract DataPagerField CreateField();
|
||||
|
||||
[SuppressMessage("Microsoft.Design", "CA1055:UriReturnValuesShouldNotBeStrings",
|
||||
Justification="Return value matches HyperLink.NavigateUrl property type.")]
|
||||
protected string GetQueryStringNavigateUrl(int pageNumber) {
|
||||
return DataPager.GetQueryStringNavigateUrl(pageNumber);
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers", MessageId = "0#")]
|
||||
public abstract void HandleEvent(CommandEventArgs e);
|
||||
|
||||
protected virtual void LoadViewState(object savedState) {
|
||||
if (savedState != null) {
|
||||
object[] myState = (object[])savedState;
|
||||
|
||||
if (myState[0] != null)
|
||||
((IStateManager)ViewState).LoadViewState(myState[0]);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnFieldChanged() {
|
||||
if (FieldChanged != null) {
|
||||
FieldChanged(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected virtual object SaveViewState() {
|
||||
object state = ((IStateManager)ViewState).SaveViewState();
|
||||
|
||||
if ((state != null)) {
|
||||
return new object[1] {
|
||||
state
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
internal void SetDirty() {
|
||||
_stateBag.SetDirty(true);
|
||||
}
|
||||
|
||||
internal void SetDataPager(DataPager dataPager) {
|
||||
_dataPager = dataPager;
|
||||
}
|
||||
|
||||
protected virtual void TrackViewState() {
|
||||
_trackViewState = true;
|
||||
((IStateManager)ViewState).TrackViewState();
|
||||
}
|
||||
|
||||
#region IStateManager
|
||||
/// <internalonly/>
|
||||
/// <devdoc>
|
||||
/// Return true if tracking state changes.
|
||||
/// </devdoc>
|
||||
bool IStateManager.IsTrackingViewState {
|
||||
get {
|
||||
return IsTrackingViewState;
|
||||
}
|
||||
}
|
||||
|
||||
/// <internalonly/>
|
||||
/// <devdoc>
|
||||
/// Load previously saved state.
|
||||
/// </devdoc>
|
||||
void IStateManager.LoadViewState(object state) {
|
||||
LoadViewState(state);
|
||||
}
|
||||
|
||||
/// <internalonly/>
|
||||
/// <devdoc>
|
||||
/// Start tracking state changes.
|
||||
/// </devdoc>
|
||||
void IStateManager.TrackViewState() {
|
||||
TrackViewState();
|
||||
}
|
||||
|
||||
/// <internalonly/>
|
||||
/// <devdoc>
|
||||
/// Return object containing state changes.
|
||||
/// </devdoc>
|
||||
object IStateManager.SaveViewState() {
|
||||
return SaveViewState();
|
||||
}
|
||||
#endregion IStateManager
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="DataPagerFieldCollection.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using System.Web.Resources;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
|
||||
namespace System.Web.UI.WebControls {
|
||||
/// <summary>
|
||||
/// Summary description for DataPagerFieldCollection
|
||||
/// </summary>
|
||||
public class DataPagerFieldCollection : StateManagedCollection {
|
||||
private DataPager _dataPager;
|
||||
private static readonly Type[] knownTypes = new Type[] {
|
||||
typeof(NextPreviousPagerField),
|
||||
typeof(NumericPagerField),
|
||||
typeof(TemplatePagerField)
|
||||
};
|
||||
|
||||
public event EventHandler FieldsChanged;
|
||||
|
||||
public DataPagerFieldCollection(DataPager dataPager) {
|
||||
_dataPager = dataPager;
|
||||
}
|
||||
|
||||
/// <devdoc>
|
||||
/// <para>Gets a <see cref='System.Web.UI.WebControls.DataPagerField'/> at the specified index in the
|
||||
/// collection.</para>
|
||||
/// </devdoc>
|
||||
[
|
||||
Browsable(false)
|
||||
]
|
||||
public DataPagerField this[int index] {
|
||||
get {
|
||||
return ((IList)this)[index] as DataPagerField;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <devdoc>
|
||||
/// <para>Appends a <see cref='System.Web.UI.WebControls.DataPagerField'/> to the collection.</para>
|
||||
/// </devdoc>
|
||||
public void Add(DataPagerField field) {
|
||||
((IList)this).Add(field);
|
||||
}
|
||||
|
||||
/// <devdoc>
|
||||
/// <para>Provides a deep copy of the collection. Used mainly by design time dialogs to implement "cancel" rollback behavior.</para>
|
||||
/// </devdoc>
|
||||
public DataPagerFieldCollection CloneFields(DataPager pager) {
|
||||
|
||||
DataPagerFieldCollection fields = new DataPagerFieldCollection(pager);
|
||||
foreach (DataPagerField field in this) {
|
||||
fields.Add(field.CloneField());
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
|
||||
/// <devdoc>
|
||||
/// <para>Returns whether a DataPagerField is a member of the collection.</para>
|
||||
/// </devdoc>
|
||||
public bool Contains(DataPagerField field) {
|
||||
return ((IList)this).Contains(field);
|
||||
}
|
||||
|
||||
|
||||
/// <devdoc>
|
||||
/// <para>Copies the contents of the entire collection into an <see cref='System.Array' qualify='true'/> appending at
|
||||
/// the specified index of the <see cref='System.Array' qualify='true'/>.</para>
|
||||
/// </devdoc>
|
||||
public void CopyTo(DataPagerField[] array, int index) {
|
||||
((IList)this).CopyTo(array, index);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/// <devdoc>
|
||||
/// <para>Creates a known type of DataPagerField.</para>
|
||||
/// </devdoc>
|
||||
protected override object CreateKnownType(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return new NextPreviousPagerField();
|
||||
case 1:
|
||||
return new NumericPagerField();
|
||||
case 2:
|
||||
return new TemplatePagerField();
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(AtlasWeb.PagerFieldCollection_InvalidTypeIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <devdoc>
|
||||
/// <para>Returns an ArrayList of known DataPagerField types.</para>
|
||||
/// </devdoc>
|
||||
protected override Type[] GetKnownTypes() {
|
||||
return knownTypes;
|
||||
}
|
||||
|
||||
|
||||
/// <devdoc>
|
||||
/// <para>Returns the index of the first occurrence of a value in a <see cref='System.Web.UI.WebControls.DataPagerField'/>.</para>
|
||||
/// </devdoc>
|
||||
public int IndexOf(DataPagerField field) {
|
||||
return ((IList)this).IndexOf(field);
|
||||
}
|
||||
|
||||
|
||||
/// <devdoc>
|
||||
/// <para>Inserts a <see cref='System.Web.UI.WebControls.DataPagerField'/> to the collection
|
||||
/// at the specified index.</para>
|
||||
/// </devdoc>
|
||||
public void Insert(int index, DataPagerField field) {
|
||||
((IList)this).Insert(index, field);
|
||||
}
|
||||
|
||||
|
||||
/// <devdoc>
|
||||
/// Called when the Clear() method is complete.
|
||||
/// </devdoc>
|
||||
protected override void OnClearComplete() {
|
||||
OnFieldsChanged();
|
||||
}
|
||||
|
||||
/// <devdoc>
|
||||
/// </devdoc>
|
||||
void OnFieldChanged(object sender, EventArgs e) {
|
||||
OnFieldsChanged();
|
||||
}
|
||||
|
||||
/// <devdoc>
|
||||
/// </devdoc>
|
||||
void OnFieldsChanged() {
|
||||
if (FieldsChanged != null) {
|
||||
FieldsChanged(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <devdoc>
|
||||
/// Called when the Insert() method is complete.
|
||||
/// </devdoc>
|
||||
protected override void OnInsertComplete(int index, object value) {
|
||||
DataPagerField field = value as DataPagerField;
|
||||
if (field != null) {
|
||||
field.FieldChanged += new EventHandler(OnFieldChanged);
|
||||
}
|
||||
field.SetDataPager(_dataPager);
|
||||
OnFieldsChanged();
|
||||
}
|
||||
|
||||
|
||||
/// <devdoc>
|
||||
/// Called when the Remove() method is complete.
|
||||
/// </devdoc>
|
||||
protected override void OnRemoveComplete(int index, object value) {
|
||||
DataPagerField field = value as DataPagerField;
|
||||
if (field != null) {
|
||||
field.FieldChanged -= new EventHandler(OnFieldChanged);
|
||||
}
|
||||
OnFieldsChanged();
|
||||
}
|
||||
|
||||
|
||||
/// <devdoc>
|
||||
/// <para>Validates that an object is a HotSpot.</para>
|
||||
/// </devdoc>
|
||||
protected override void OnValidate(object o) {
|
||||
base.OnValidate(o);
|
||||
if (!(o is DataPagerField))
|
||||
throw new ArgumentException(AtlasWeb.PagerFieldCollection_InvalidType);
|
||||
}
|
||||
|
||||
|
||||
/// <devdoc>
|
||||
/// <para>Removes a <see cref='System.Web.UI.WebControls.DataPagerField'/> from the collection at the specified
|
||||
/// index.</para>
|
||||
/// </devdoc>
|
||||
public void RemoveAt(int index) {
|
||||
((IList)this).RemoveAt(index);
|
||||
}
|
||||
|
||||
|
||||
/// <devdoc>
|
||||
/// <para>Removes the specified <see cref='System.Web.UI.WebControls.DataPagerField'/> from the collection.</para>
|
||||
/// </devdoc>
|
||||
public void Remove(DataPagerField field) {
|
||||
((IList)this).Remove(field);
|
||||
}
|
||||
|
||||
|
||||
/// <devdoc>
|
||||
/// <para>Marks a DataPagerField as dirty so that it will record its entire state into view state.</para>
|
||||
/// </devdoc>
|
||||
protected override void SetDirtyObject(object o) {
|
||||
((DataPagerField)o).SetDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="DataPagerFieldCommandEventArgs.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace System.Web.UI.WebControls {
|
||||
public class DataPagerFieldCommandEventArgs : CommandEventArgs {
|
||||
private DataPagerFieldItem _item;
|
||||
private object _commandSource;
|
||||
|
||||
[SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers", MessageId = "2#")]
|
||||
public DataPagerFieldCommandEventArgs(DataPagerFieldItem item, object commandSource, CommandEventArgs originalArgs) : base(originalArgs) {
|
||||
_item = item;
|
||||
_commandSource = commandSource;
|
||||
}
|
||||
|
||||
public object CommandSource {
|
||||
get {
|
||||
return _commandSource;
|
||||
}
|
||||
}
|
||||
|
||||
public DataPagerFieldItem Item {
|
||||
get {
|
||||
return _item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="DataPagerFieldItem.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
|
||||
namespace System.Web.UI.WebControls {
|
||||
// This class implements INonBindingContainer to allow binding statements on TemplatePagerField
|
||||
// to look like Container.TotalRowCount rather than Container.Pager.TotalRowCount.
|
||||
public class DataPagerFieldItem : Control, INonBindingContainer {
|
||||
private DataPagerField _field;
|
||||
private DataPager _pager;
|
||||
|
||||
public DataPagerFieldItem(DataPagerField field, DataPager pager) {
|
||||
_field = field;
|
||||
_pager = pager;
|
||||
}
|
||||
|
||||
public DataPager Pager {
|
||||
get {
|
||||
return _pager;
|
||||
}
|
||||
}
|
||||
|
||||
public DataPagerField PagerField {
|
||||
get {
|
||||
return _field;
|
||||
}
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers", MessageId = "1#")]
|
||||
protected override bool OnBubbleEvent(object source, EventArgs e) {
|
||||
if (e is CommandEventArgs) {
|
||||
DataPagerFieldCommandEventArgs args = new DataPagerFieldCommandEventArgs(this, source, (CommandEventArgs)e);
|
||||
RaiseBubbleEvent(this, args);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
namespace System.Web.UI.WebControls {
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Web;
|
||||
using System.Linq;
|
||||
using System.Web.Compilation;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.Resources;
|
||||
using System.Globalization;
|
||||
|
||||
internal static class DataSourceHelper {
|
||||
public static object SaveViewState(ParameterCollection parameters) {
|
||||
if (parameters != null) {
|
||||
return ((IStateManager)parameters).SaveViewState();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void TrackViewState(ParameterCollection parameters) {
|
||||
if (parameters != null) {
|
||||
((IStateManager)parameters).TrackViewState();
|
||||
}
|
||||
}
|
||||
|
||||
public static IDictionary<string, object> ToDictionary(this ParameterCollection parameters, HttpContext context, Control control) {
|
||||
return ToDictionary(parameters.GetValues(context, control));
|
||||
}
|
||||
|
||||
internal static IDictionary<string, object> ToDictionary(this IOrderedDictionary parameterValues) {
|
||||
Dictionary<string, object> values = new Dictionary<string, object>(parameterValues.Count, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
foreach (DictionaryEntry entry in parameterValues) {
|
||||
values[(string)entry.Key] = entry.Value;
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
public static IOrderedDictionary ToCaseInsensitiveDictionary(this IDictionary dictionary) {
|
||||
if (dictionary != null) {
|
||||
IOrderedDictionary destination = new OrderedDictionary(dictionary.Count, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
foreach (DictionaryEntry de in dictionary) {
|
||||
destination[de.Key] = de.Value;
|
||||
}
|
||||
|
||||
return destination;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static object CreateObjectInstance(Type type) {
|
||||
// FastCreatePublicInstance is faster than Activator.CreateInstance since it caches the type factories.
|
||||
return HttpRuntime.FastCreatePublicInstance(type);
|
||||
}
|
||||
|
||||
public static bool MergeDictionaries(object dataObjectType, ParameterCollection referenceValues, IDictionary source,
|
||||
IDictionary destination, IDictionary<string, Exception> validationErrors) {
|
||||
return MergeDictionaries(dataObjectType, referenceValues, source, destination, null, validationErrors);
|
||||
}
|
||||
|
||||
public static bool MergeDictionaries(object dataObjectType, ParameterCollection reference, IDictionary source,
|
||||
IDictionary destination, IDictionary destinationCopy, IDictionary<string, Exception> validationErrors) {
|
||||
if (source != null) {
|
||||
foreach (DictionaryEntry de in source) {
|
||||
object value = de.Value;
|
||||
// search for a parameter that corresponds to this dictionary entry.
|
||||
Parameter referenceParameter = null;
|
||||
string parameterName = (string)de.Key;
|
||||
foreach (Parameter p in reference) {
|
||||
if (String.Equals(p.Name, parameterName, StringComparison.OrdinalIgnoreCase)) {
|
||||
referenceParameter = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// use the parameter for type conversion, default value and/or converting empty string to null.
|
||||
if (referenceParameter != null) {
|
||||
try {
|
||||
value = referenceParameter.GetValue(value, true);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// catch conversion exceptions so they can be handled. Note that conversion throws various
|
||||
// types of exceptions like InvalidCastException, FormatException, OverflowException, etc.
|
||||
validationErrors[referenceParameter.Name] = e;
|
||||
}
|
||||
}
|
||||
// save the value to the merged dictionaries.
|
||||
destination[parameterName] = value;
|
||||
if (destinationCopy != null) {
|
||||
destinationCopy[parameterName] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return validationErrors.Count == 0;
|
||||
}
|
||||
|
||||
public static Type GetType(string typeName) {
|
||||
return BuildManager.GetType(typeName, true /* throwOnError */, true /* ignoreCase */);
|
||||
}
|
||||
|
||||
private static object ConvertType(object value, Type type, string paramName) {
|
||||
// NOTE: This method came from ObjectDataSource with no changes made.
|
||||
string s = value as string;
|
||||
if (s != null) {
|
||||
// Get the type converter for the destination type
|
||||
TypeConverter converter = TypeDescriptor.GetConverter(type);
|
||||
if (converter != null) {
|
||||
// Perform the conversion
|
||||
try {
|
||||
value = converter.ConvertFromString(s);
|
||||
}
|
||||
catch (NotSupportedException) {
|
||||
throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture,
|
||||
AtlasWeb.LinqDataSourceView_CannotConvertType, paramName, typeof(string).FullName,
|
||||
type.FullName));
|
||||
}
|
||||
catch (FormatException) {
|
||||
throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture,
|
||||
AtlasWeb.LinqDataSourceView_CannotConvertType, paramName, typeof(string).FullName,
|
||||
type.FullName));
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static object BuildDataObject(Type dataObjectType, IDictionary inputParameters, IDictionary<string, Exception> validationErrors) {
|
||||
object dataObject = CreateObjectInstance(dataObjectType);
|
||||
|
||||
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(dataObject);
|
||||
foreach (DictionaryEntry de in inputParameters) {
|
||||
string propName = (de.Key == null ? String.Empty : de.Key.ToString());
|
||||
PropertyDescriptor property = props.Find(propName, /*ignoreCase*/true);
|
||||
// NOTE: No longer throws when a property is not found or is read only. This makes
|
||||
// Delete, Insert and Update operations more optimistic, allowing scenarios such as:
|
||||
// 1) Deletes and Updates after projecting data in the Selecting event.
|
||||
// 2) Deletes and Updates after selecting children of the data object type in the
|
||||
// Selecting event.
|
||||
if ((property != null) && (!property.IsReadOnly)) {
|
||||
try {
|
||||
object value = BuildObjectValue(de.Value, property.PropertyType, propName);
|
||||
property.SetValue(dataObject, value);
|
||||
}
|
||||
catch (Exception e) {
|
||||
validationErrors[property.Name] = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (validationErrors.Any()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return dataObject;
|
||||
}
|
||||
|
||||
internal static object BuildObjectValue(object value, Type destinationType, string paramName) {
|
||||
// NOTE: This method came from ObjectDataSource with no changes made.
|
||||
// Only consider converting the type if the value is non-null and the types don't match
|
||||
if ((value != null) && (!destinationType.IsInstanceOfType(value))) {
|
||||
Type innerDestinationType = destinationType;
|
||||
bool isNullable = false;
|
||||
if (destinationType.IsGenericType &&
|
||||
(destinationType.GetGenericTypeDefinition() == typeof(Nullable<>))) {
|
||||
innerDestinationType = destinationType.GetGenericArguments()[0];
|
||||
isNullable = true;
|
||||
}
|
||||
else {
|
||||
if (destinationType.IsByRef) {
|
||||
innerDestinationType = destinationType.GetElementType();
|
||||
}
|
||||
}
|
||||
|
||||
// Try to convert from for example string to DateTime, so that
|
||||
// afterwards we can convert DateTime to Nullable<DateTime>
|
||||
|
||||
// If the value is a string, we attempt to use a TypeConverter to convert it
|
||||
value = ConvertType(value, innerDestinationType, paramName);
|
||||
|
||||
// Special-case the value when the destination is Nullable<T>
|
||||
if (isNullable) {
|
||||
Type paramValueType = value.GetType();
|
||||
if (innerDestinationType != paramValueType) {
|
||||
// Throw if for example, we are trying to convert from int to Nullable<bool>
|
||||
throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture,
|
||||
AtlasWeb.LinqDataSourceView_CannotConvertType, paramName, paramValueType.FullName,
|
||||
String.Format(CultureInfo.InvariantCulture, "Nullable<{0}>",
|
||||
destinationType.GetGenericArguments()[0].FullName)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,43 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="DynamicQueryableWrapper.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.UI.WebControls {
|
||||
using System.Web.Query.Dynamic;
|
||||
using System.Linq;
|
||||
|
||||
internal class DynamicQueryableWrapper : IDynamicQueryable {
|
||||
|
||||
public IQueryable Where(IQueryable source, string predicate, params object[] values) {
|
||||
return DynamicQueryable.Where(source, predicate, values);
|
||||
}
|
||||
|
||||
public IQueryable Select(IQueryable source, string selector, params object[] values) {
|
||||
return DynamicQueryable.Select(source, selector, values);
|
||||
}
|
||||
|
||||
public IQueryable OrderBy(IQueryable source, string ordering, params object[] values) {
|
||||
return DynamicQueryable.OrderBy(source, ordering, values);
|
||||
}
|
||||
|
||||
public IQueryable Take(IQueryable source, int count) {
|
||||
return DynamicQueryable.Take(source, count);
|
||||
}
|
||||
|
||||
public IQueryable Skip(IQueryable source, int count) {
|
||||
return DynamicQueryable.Skip(source, count);
|
||||
}
|
||||
|
||||
public IQueryable GroupBy(IQueryable source, string keySelector, string elementSelector, params object[] values) {
|
||||
return DynamicQueryable.GroupBy(source, keySelector, elementSelector, values );
|
||||
}
|
||||
|
||||
public int Count(IQueryable source) {
|
||||
return DynamicQueryable.Count(source);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
namespace System.Web.UI.WebControls.Expressions {
|
||||
using System.Web.Query.Dynamic;
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using System.Security.Permissions;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
[
|
||||
PersistChildren(false),
|
||||
ParseChildren(true, "Parameters")
|
||||
]
|
||||
public class CustomExpression : ParameterDataSourceExpression {
|
||||
private EventHandler<CustomExpressionEventArgs> _querying;
|
||||
|
||||
public event EventHandler<CustomExpressionEventArgs> Querying {
|
||||
add {
|
||||
_querying += value;
|
||||
}
|
||||
remove {
|
||||
_querying -= value;
|
||||
}
|
||||
}
|
||||
|
||||
public override IQueryable GetQueryable(IQueryable source) {
|
||||
CustomExpressionEventArgs e = new CustomExpressionEventArgs(source, GetValues());
|
||||
OnQuerying(e);
|
||||
return e.Query;
|
||||
}
|
||||
|
||||
private void OnQuerying(CustomExpressionEventArgs e) {
|
||||
if (_querying != null) {
|
||||
_querying(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace System.Web.UI.WebControls.Expressions {
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Security.Permissions;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class CustomExpressionEventArgs : EventArgs {
|
||||
public IQueryable Query { get; set; }
|
||||
public IDictionary<string, object> Values { get; private set; }
|
||||
|
||||
public CustomExpressionEventArgs(IQueryable source, IDictionary<string, object> values) {
|
||||
Query = source;
|
||||
Values = values;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
namespace System.Web.UI.WebControls.Expressions {
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
|
||||
public abstract class DataSourceExpression : IStateManager {
|
||||
private bool _tracking;
|
||||
private StateBag _viewState;
|
||||
|
||||
protected HttpContext Context {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
protected Control Owner {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public IQueryableDataSource DataSource {
|
||||
get;
|
||||
// Internal set for unit testing
|
||||
internal set;
|
||||
}
|
||||
|
||||
|
||||
protected bool IsTrackingViewState {
|
||||
get {
|
||||
return _tracking;
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
Browsable(false),
|
||||
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
|
||||
]
|
||||
protected StateBag ViewState {
|
||||
get {
|
||||
if (_viewState == null) {
|
||||
_viewState = new StateBag();
|
||||
if (_tracking)
|
||||
((IStateManager)_viewState).TrackViewState();
|
||||
}
|
||||
return _viewState;
|
||||
}
|
||||
}
|
||||
|
||||
protected DataSourceExpression() {
|
||||
}
|
||||
|
||||
// internal for unit testing
|
||||
internal DataSourceExpression(Control owner) {
|
||||
Owner = owner;
|
||||
}
|
||||
|
||||
public void SetDirty() {
|
||||
ViewState.SetDirty(true);
|
||||
}
|
||||
|
||||
protected virtual void LoadViewState(object savedState) {
|
||||
if (savedState != null) {
|
||||
((IStateManager)ViewState).LoadViewState(savedState);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual object SaveViewState() {
|
||||
return (_viewState != null) ? ((IStateManager)_viewState).SaveViewState() : null;
|
||||
}
|
||||
|
||||
protected virtual void TrackViewState() {
|
||||
_tracking = true;
|
||||
|
||||
if (_viewState != null) {
|
||||
((IStateManager)_viewState).TrackViewState();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract IQueryable GetQueryable(IQueryable source);
|
||||
|
||||
public virtual void SetContext(Control owner, HttpContext context, IQueryableDataSource dataSource) {
|
||||
if (owner == null) {
|
||||
throw new ArgumentNullException("owner");
|
||||
}
|
||||
|
||||
if (context == null) {
|
||||
throw new ArgumentNullException("context");
|
||||
}
|
||||
|
||||
if (dataSource == null) {
|
||||
throw new ArgumentNullException("dataSource");
|
||||
}
|
||||
|
||||
Owner = owner;
|
||||
Context = context;
|
||||
DataSource = dataSource;
|
||||
}
|
||||
|
||||
#region IStateManager Members
|
||||
|
||||
bool IStateManager.IsTrackingViewState {
|
||||
get {
|
||||
return IsTrackingViewState;
|
||||
}
|
||||
}
|
||||
|
||||
void IStateManager.LoadViewState(object state) {
|
||||
LoadViewState(state);
|
||||
}
|
||||
|
||||
object IStateManager.SaveViewState() {
|
||||
return SaveViewState();
|
||||
}
|
||||
|
||||
void IStateManager.TrackViewState() {
|
||||
TrackViewState();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
namespace System.Web.UI.WebControls.Expressions {
|
||||
using System.Collections;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
|
||||
public class DataSourceExpressionCollection : StateManagedCollection {
|
||||
private IQueryableDataSource _dataSource;
|
||||
|
||||
private static readonly Type[] knownTypes = new Type[] {
|
||||
typeof(SearchExpression),
|
||||
typeof(MethodExpression),
|
||||
typeof(OrderByExpression),
|
||||
typeof(RangeExpression),
|
||||
typeof(PropertyExpression),
|
||||
typeof(CustomExpression),
|
||||
};
|
||||
|
||||
public HttpContext Context {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public Control Owner {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public DataSourceExpression this[int index] {
|
||||
get {
|
||||
return (DataSourceExpression)((IList)this)[index];
|
||||
}
|
||||
set {
|
||||
((IList)this)[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Allows for nested expression blocks to be initilaized after the fact
|
||||
internal void SetContext(Control owner, HttpContext context, IQueryableDataSource dataSource) {
|
||||
Owner = owner;
|
||||
Context = context;
|
||||
_dataSource = dataSource;
|
||||
|
||||
foreach (DataSourceExpression expression in this) {
|
||||
expression.SetContext(owner, context, _dataSource);
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(DataSourceExpression expression) {
|
||||
((IList)this).Add(expression);
|
||||
}
|
||||
|
||||
protected override object CreateKnownType(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return new SearchExpression();
|
||||
case 1:
|
||||
return new MethodExpression();
|
||||
case 2:
|
||||
return new OrderByExpression();
|
||||
case 3:
|
||||
return new RangeExpression();
|
||||
case 4:
|
||||
return new PropertyExpression();
|
||||
case 5:
|
||||
return new CustomExpression();
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException("index");
|
||||
}
|
||||
}
|
||||
|
||||
public void CopyTo(DataSourceExpression[] expressionArray, int index) {
|
||||
base.CopyTo(expressionArray, index);
|
||||
}
|
||||
|
||||
public void Contains(DataSourceExpression expression) {
|
||||
((IList)this).Contains(expression);
|
||||
}
|
||||
|
||||
protected override Type[] GetKnownTypes() {
|
||||
return knownTypes;
|
||||
}
|
||||
|
||||
public int IndexOf(DataSourceExpression expression) {
|
||||
return ((IList)this).IndexOf(expression);
|
||||
}
|
||||
|
||||
public void Insert(int index, DataSourceExpression expression) {
|
||||
((IList)this).Insert(index, expression);
|
||||
}
|
||||
|
||||
public void Remove(DataSourceExpression expression) {
|
||||
((IList)this).Remove(expression);
|
||||
}
|
||||
|
||||
public void RemoveAt(int index) {
|
||||
((IList)this).RemoveAt(index);
|
||||
}
|
||||
|
||||
protected override void SetDirtyObject(object o) {
|
||||
((DataSourceExpression)o).SetDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
namespace System.Web.UI.WebControls.Expressions {
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
internal static class ExpressionHelper {
|
||||
public static Expression GetValue(Expression exp) {
|
||||
Type realType = GetUnderlyingType(exp.Type);
|
||||
if (realType == exp.Type) {
|
||||
return exp;
|
||||
}
|
||||
return Expression.Convert(exp, realType);
|
||||
}
|
||||
|
||||
public static Type GetUnderlyingType(Type type) {
|
||||
// Get the type from Nullable types
|
||||
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) {
|
||||
return type.GetGenericArguments()[0];
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public static object BuildObjectValue(object value, Type type) {
|
||||
return System.Web.UI.WebControls.DataSourceHelper.BuildObjectValue(value, type, String.Empty);
|
||||
}
|
||||
|
||||
public static Expression CreatePropertyExpression(Expression parameterExpression, string propertyName) {
|
||||
if (parameterExpression == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(propertyName)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Expression propExpression = null;
|
||||
string[] props = propertyName.Split('.');
|
||||
foreach (var p in props) {
|
||||
if (propExpression == null) {
|
||||
propExpression = Expression.PropertyOrField(parameterExpression, p);
|
||||
}
|
||||
else {
|
||||
propExpression = Expression.PropertyOrField(propExpression, p);
|
||||
}
|
||||
}
|
||||
return propExpression;
|
||||
}
|
||||
|
||||
|
||||
public static IQueryable Where(this IQueryable source, LambdaExpression lambda) {
|
||||
return Call(source, "Where", lambda, source.ElementType);
|
||||
}
|
||||
|
||||
public static IQueryable Call(this IQueryable source, string queryMethod, Type[] genericArgs, params Expression[] arguments) {
|
||||
if (source == null) {
|
||||
throw new ArgumentNullException("source");
|
||||
}
|
||||
return source.Provider.CreateQuery(
|
||||
Expression.Call(
|
||||
typeof(Queryable), queryMethod,
|
||||
genericArgs,
|
||||
arguments));
|
||||
}
|
||||
|
||||
public static IQueryable Call(this IQueryable source, string queryableMethod, LambdaExpression lambda, params Type[] genericArgs) {
|
||||
if (source == null) {
|
||||
throw new ArgumentNullException("source");
|
||||
}
|
||||
return source.Provider.CreateQuery(
|
||||
Expression.Call(
|
||||
typeof(Queryable), queryableMethod,
|
||||
genericArgs,
|
||||
source.Expression, Expression.Quote(lambda)));
|
||||
}
|
||||
|
||||
public static Expression Or(IEnumerable<Expression> expressions) {
|
||||
Expression orExpression = null;
|
||||
foreach (Expression e in expressions) {
|
||||
if (e == null) {
|
||||
continue;
|
||||
}
|
||||
if (orExpression == null) {
|
||||
orExpression = e;
|
||||
}
|
||||
else {
|
||||
orExpression = Expression.OrElse(orExpression, e);
|
||||
}
|
||||
}
|
||||
return orExpression;
|
||||
}
|
||||
|
||||
public static Expression And(IEnumerable<Expression> expressions) {
|
||||
Expression andExpression = null;
|
||||
foreach (Expression e in expressions) {
|
||||
if (e == null) {
|
||||
continue;
|
||||
}
|
||||
if (andExpression == null) {
|
||||
andExpression = e;
|
||||
}
|
||||
else {
|
||||
andExpression = Expression.AndAlso(andExpression, e);
|
||||
}
|
||||
}
|
||||
return andExpression;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
namespace System.Web.UI.WebControls.Expressions {
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Web.Compilation;
|
||||
using System.Web.DynamicData;
|
||||
using System.Web.Resources;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
public class MethodExpression : ParameterDataSourceExpression {
|
||||
private static readonly BindingFlags MethodFlags = BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy;
|
||||
|
||||
// We'll populate a list of ways to get the type
|
||||
private Func<Type>[] typeGetters;
|
||||
|
||||
public string TypeName {
|
||||
get {
|
||||
return (string)ViewState["TypeName"] ?? String.Empty;
|
||||
}
|
||||
set {
|
||||
ViewState["TypeName"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string MethodName {
|
||||
get {
|
||||
return (string)ViewState["MethodName"] ?? String.Empty;
|
||||
}
|
||||
set {
|
||||
ViewState["MethodName"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IgnoreIfNotFound {
|
||||
get {
|
||||
object o = ViewState["IgnoreIfNotFound"];
|
||||
return o != null ? (bool)o : false;
|
||||
}
|
||||
set {
|
||||
ViewState["IgnoreIfNotFound"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public MethodExpression() {
|
||||
// 1. If a TypeName is specified find the method on that type.
|
||||
// 2. Otherwise, if the DataSource is an IDynamicDataSource, then use context type and search for the method.
|
||||
// 3. Otherwise look for the method on the current TemplateControl (Page/UserControl) etc.
|
||||
typeGetters = new Func<Type>[] {
|
||||
() => GetType(TypeName),
|
||||
() => GetType(DataSource),
|
||||
() => (Owner != null && Owner.TemplateControl != null) ? Owner.TemplateControl.GetType() : null
|
||||
};
|
||||
}
|
||||
|
||||
private static Type GetType(string typeName) {
|
||||
if (!String.IsNullOrEmpty(typeName)) {
|
||||
return BuildManager.GetType(typeName, false /* throwOnError */, true /* ignoreCase */);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Type GetType(IQueryableDataSource dataSource) {
|
||||
IDynamicDataSource dynamicDataSource = dataSource as IDynamicDataSource;
|
||||
if (dynamicDataSource != null) {
|
||||
return dynamicDataSource.ContextType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
internal MethodInfo ResolveMethod() {
|
||||
if (String.IsNullOrEmpty(MethodName)) {
|
||||
throw new InvalidOperationException(AtlasWeb.MethodExpression_MethodNameMustBeSpecified);
|
||||
}
|
||||
|
||||
MethodInfo methodInfo = null;
|
||||
// We allow the format string {0} in the method name
|
||||
IDynamicDataSource dataSource = DataSource as IDynamicDataSource;
|
||||
if (dataSource != null) {
|
||||
MethodName = String.Format(CultureInfo.CurrentCulture, MethodName, dataSource.EntitySetName);
|
||||
}
|
||||
else if (MethodName.Contains("{0}")) {
|
||||
// If method has a format string but no IDynamicDataSource then throw an exception
|
||||
throw new InvalidOperationException(AtlasWeb.MethodExpression_DataSourceMustBeIDynamicDataSource);
|
||||
}
|
||||
|
||||
foreach (Func<Type> typeGetter in typeGetters) {
|
||||
Type type = typeGetter();
|
||||
// If the type is null continue to next fall back function
|
||||
if (type == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
methodInfo = type.GetMethod(MethodName, MethodFlags);
|
||||
if (methodInfo != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return methodInfo;
|
||||
}
|
||||
|
||||
public override IQueryable GetQueryable(IQueryable source) {
|
||||
if (source == null) {
|
||||
throw new ArgumentNullException("source");
|
||||
}
|
||||
|
||||
MethodInfo method = ResolveMethod();
|
||||
|
||||
// Get the parameter values
|
||||
IDictionary<string, object> parameterValues = GetValues();
|
||||
|
||||
if (method == null) {
|
||||
if (IgnoreIfNotFound) {
|
||||
// Unchange the IQueryable if the user set IgnoreIfNotFound
|
||||
return source;
|
||||
}
|
||||
throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture,
|
||||
AtlasWeb.MethodExpression_MethodNotFound, MethodName));
|
||||
}
|
||||
|
||||
if(!method.IsStatic) {
|
||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
|
||||
AtlasWeb.MethodExpression_MethodMustBeStatic, MethodName));
|
||||
}
|
||||
|
||||
ParameterInfo[] parameterArray = method.GetParameters();
|
||||
if (parameterArray.Length == 0 || !parameterArray[0].ParameterType.IsAssignableFrom(source.GetType())) {
|
||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, AtlasWeb.MethodExpression_FirstParamterMustBeCorrectType,
|
||||
MethodName, source.GetType()));
|
||||
}
|
||||
|
||||
object[] arguments = new object[parameterArray.Length];
|
||||
// First argument is the IQueryable
|
||||
arguments[0] = source;
|
||||
for (int i = 1; i < parameterArray.Length; ++i) {
|
||||
ParameterInfo param = parameterArray[i];
|
||||
object value;
|
||||
if (!parameterValues.TryGetValue(param.Name, out value)) {
|
||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
|
||||
AtlasWeb.MethodExpression_ParameterNotFound, MethodName, param.Name));
|
||||
}
|
||||
|
||||
arguments[i] = DataSourceHelper.BuildObjectValue(value, param.ParameterType, param.Name);
|
||||
}
|
||||
|
||||
object result = method.Invoke(null, arguments);
|
||||
|
||||
// Require the return type be the same as the parameter type
|
||||
if (result != null) {
|
||||
IQueryable queryable = result as IQueryable;
|
||||
// Check if the user did a projection (changed the T in IQuerable<T>)
|
||||
if (queryable == null || !queryable.ElementType.IsAssignableFrom(source.ElementType)) {
|
||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, AtlasWeb.MethodExpression_ChangingTheReturnTypeIsNotAllowed,
|
||||
source.ElementType.FullName));
|
||||
}
|
||||
}
|
||||
|
||||
return (IQueryable)result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
namespace System.Web.UI.WebControls.Expressions {
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Web.Compilation;
|
||||
using System.Web.Resources;
|
||||
using System;
|
||||
using System.Web.UI;
|
||||
|
||||
public class OfTypeExpression : DataSourceExpression {
|
||||
private MethodInfo _ofTypeMethod;
|
||||
private string _typeName;
|
||||
|
||||
private MethodInfo OfTypeMethod {
|
||||
get {
|
||||
if (_ofTypeMethod == null) {
|
||||
var type = GetType(TypeName);
|
||||
|
||||
_ofTypeMethod = GetOfTypeMethod(type);
|
||||
}
|
||||
return _ofTypeMethod;
|
||||
}
|
||||
}
|
||||
|
||||
[DefaultValue("")]
|
||||
public string TypeName {
|
||||
get {
|
||||
return _typeName ?? String.Empty;
|
||||
}
|
||||
set {
|
||||
if (TypeName != value) {
|
||||
_typeName = value;
|
||||
_ofTypeMethod = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public OfTypeExpression() {
|
||||
}
|
||||
|
||||
public OfTypeExpression(Type type) {
|
||||
if (type == null) {
|
||||
throw new ArgumentNullException("type");
|
||||
}
|
||||
TypeName = type.AssemblyQualifiedName;
|
||||
_ofTypeMethod = GetOfTypeMethod(type);
|
||||
}
|
||||
|
||||
// internal for unit testing
|
||||
internal OfTypeExpression(Control owner)
|
||||
: base(owner) {
|
||||
}
|
||||
|
||||
private Type GetType(string typeName) {
|
||||
if (String.IsNullOrEmpty(typeName)) {
|
||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
|
||||
AtlasWeb.OfTypeExpression_TypeNameNotSpecified,
|
||||
Owner.ID));
|
||||
}
|
||||
try {
|
||||
return BuildManager.GetType(typeName, true /* throwOnError */, true /* ignoreCase */);
|
||||
} catch (Exception e) {
|
||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
|
||||
AtlasWeb.OfTypeExpression_CannotFindType,
|
||||
typeName,
|
||||
Owner.ID), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static MethodInfo GetOfTypeMethod(Type type) {
|
||||
Debug.Assert(type != null);
|
||||
return typeof(Queryable).GetMethod("OfType").MakeGenericMethod(new Type[] { type });
|
||||
}
|
||||
|
||||
public override IQueryable GetQueryable(IQueryable query) {
|
||||
return query.Provider.CreateQuery(Expression.Call(null, OfTypeMethod, query.Expression));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
namespace System.Web.UI.WebControls.Expressions {
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Web.Resources;
|
||||
using System.Web.UI;
|
||||
|
||||
[
|
||||
PersistChildren(false),
|
||||
ParseChildren(true, "ThenByExpressions")
|
||||
]
|
||||
public class OrderByExpression : DataSourceExpression {
|
||||
private const string OrderByMethod = "OrderBy";
|
||||
private const string ThenByMethod = "ThenBy";
|
||||
private const string OrderDescendingByMethod = "OrderByDescending";
|
||||
private const string ThenDescendingByMethod = "ThenByDescending";
|
||||
|
||||
private Collection<ThenBy> _thenByExpressions;
|
||||
|
||||
public string DataField {
|
||||
get {
|
||||
return (string)ViewState["DataField"] ?? String.Empty;
|
||||
}
|
||||
set {
|
||||
ViewState["DataField"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public SortDirection Direction {
|
||||
get {
|
||||
object o = ViewState["Direction"];
|
||||
return o != null ? (SortDirection)o : SortDirection.Ascending;
|
||||
}
|
||||
set {
|
||||
ViewState["Direction"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
|
||||
public Collection<ThenBy> ThenByExpressions {
|
||||
get {
|
||||
if (_thenByExpressions == null) {
|
||||
//
|
||||
_thenByExpressions = new Collection<ThenBy>();
|
||||
}
|
||||
return _thenByExpressions;
|
||||
}
|
||||
}
|
||||
|
||||
public override IQueryable GetQueryable(IQueryable source) {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(DataField)) {
|
||||
throw new InvalidOperationException(AtlasWeb.Expressions_DataFieldRequired);
|
||||
}
|
||||
|
||||
ParameterExpression pe = Expression.Parameter(source.ElementType, String.Empty);
|
||||
source = CreateSortQueryable(source, pe, Direction, DataField, false /* isThenBy */);
|
||||
|
||||
foreach (ThenBy thenBy in ThenByExpressions) {
|
||||
source = CreateSortQueryable(source, pe, thenBy.Direction, thenBy.DataField, true /* isThenBy */);
|
||||
}
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
private static IQueryable CreateSortQueryable(IQueryable source, ParameterExpression parameterExpression, SortDirection direction, string dataField, bool isThenBy) {
|
||||
string methodName = isThenBy ? GetThenBySortMethod(direction) : GetSortMethod(direction);
|
||||
Expression propertyExpression = ExpressionHelper.CreatePropertyExpression(parameterExpression, dataField);
|
||||
|
||||
return source.Call(methodName,
|
||||
Expression.Lambda(propertyExpression, parameterExpression),
|
||||
source.ElementType,
|
||||
propertyExpression.Type);
|
||||
}
|
||||
|
||||
private static string GetSortMethod(SortDirection direction) {
|
||||
switch (direction) {
|
||||
case SortDirection.Ascending:
|
||||
return OrderByMethod;
|
||||
case SortDirection.Descending:
|
||||
return OrderDescendingByMethod;
|
||||
default:
|
||||
Debug.Fail("shouldn't get here!");
|
||||
return OrderByMethod;
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetThenBySortMethod(SortDirection direction) {
|
||||
switch (direction) {
|
||||
case SortDirection.Ascending:
|
||||
return ThenByMethod;
|
||||
case SortDirection.Descending:
|
||||
return ThenDescendingByMethod;
|
||||
default:
|
||||
Debug.Fail("shouldn't get here!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user