Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
2009-07-03 Marek Habersack <mhabersack@novell.com>
* DynamicDataContainerModelProvider.cs,
DynamicDataContainerTableProvider.cs: are generic classes now.
2009-06-18 Marek Habersack <mhabersack@novell.com>
* DynamicDataContainerColumnProvider.cs: added setting of
IsSortable
2009-06-17 Marek Habersack <mhabersack@novell.com>
* DynamicDataStringLengthAttribute.cs: added
* DynamicDataContainerColumnProvider.cs: implemented
EntityTypeProperty, IsCustomProperty, IsGenerated, MaxLength.
2009-06-12 Marek Habersack <mhabersack@novell.com>
* DynamicDataContainerColumnProvider.cs: implemented table
association support.
* DynamicDataAssociationProvider.cs,
DynamicDataAssociationAttribute.cs: added

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.DynamicData.ModelProviders;
namespace MonoTests.ModelProviders
{
[AttributeUsage (AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
class DynamicDataAssociationAttribute : Attribute
{
public string ColumnName { get; private set; }
public AssociationDirection Direction { get; private set; }
public DynamicDataAssociationAttribute (string columnName, AssociationDirection direction)
{
this.ColumnName = columnName;
this.Direction = direction;
}
}
}

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.DynamicData;
using System.Web.DynamicData.ModelProviders;
using MonoTests.DataSource;
namespace MonoTests.ModelProviders
{
class DynamicDataAssociationProvider : AssociationProvider
{
public DynamicDataAssociationProvider (AssociationDirection direction, ColumnProvider owner, ColumnProvider to)
{
this.Direction = direction;
this.IsPrimaryKeyInThisTable = owner.IsPrimaryKey;
this.FromColumn = owner;
this.ToTable = to.Table;
}
}
}

View File

@@ -0,0 +1,133 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.DynamicData;
using System.Web.DynamicData.ModelProviders;
using MonoTests.DataSource;
namespace MonoTests.ModelProviders
{
public class DynamicDataContainerColumnProvider <T> : ColumnProvider
{
DynamicDataColumn column;
bool associationResolved;
public override AssociationProvider Association {
get {
ResolveAssociations ();
return base.Association;
}
protected set {
base.Association = value;
}
}
public DynamicDataContainerColumnProvider (DynamicDataContainerTableProvider <T> owner, DynamicDataColumn column)
: base (owner)
{
if (column == null)
throw new ArgumentNullException ("column");
this.column = column;
Type columnType = column.DataType;
if (columnType == null)
throw new InvalidOperationException ("column.TContext must not be null for column '" + column.Name + "'");
Name = column.Name;
ColumnType = columnType;
Nullable = columnType.IsGenericType && typeof (Nullable<>).IsAssignableFrom (columnType.GetGenericTypeDefinition ());
IsPrimaryKey = column.PrimaryKey;
EntityTypeProperty = GetPropertyInfo (owner.EntityType, Name);
IsCustomProperty = column.CustomProperty;
IsGenerated = column.Generated;
MaxLength = GetMaxLength (EntityTypeProperty);
IsSortable = column.Sortable;
}
public void ResolveAssociations ()
{
if (associationResolved)
return;
associationResolved = true;
string associated = column.AssociatedTo;
if (String.IsNullOrEmpty (associated))
return;
string[] names = associated.Split (new char[] { '.' });
if (names.Length != 2)
throw new ApplicationException ("Only associations of type Table.Column are supported");
string tableName = names[0];
string columnName = names[1];
TableProvider tableProvider = null;
try {
tableProvider = Table.DataModel.Tables.First<TableProvider> ((TableProvider tp) => {
if (tp.Name == tableName)
return true;
return false;
});
} catch {
return;
}
if (tableProvider == null)
return;
ColumnProvider toColumn = null;
try {
toColumn = tableProvider.Columns.First<ColumnProvider> ((ColumnProvider cp) => {
if (cp.Name == columnName)
return true;
return false;
});
} catch {
return;
}
if (toColumn == null)
return;
IsForeignKeyComponent = true;
Association = new DynamicDataAssociationProvider (column.AssociationDirection, this, toColumn);
}
int GetMaxLength (PropertyInfo pi)
{
if (pi == null)
return 0;
object[] attrs = pi.GetCustomAttributes (typeof (DynamicDataStringLengthAttribute), true);
if (attrs == null || attrs.Length == 0)
return 0;
var attr = attrs[0] as DynamicDataStringLengthAttribute;
if (attr == null)
return 0;
return attr.MaxLength;
}
PropertyInfo GetPropertyInfo (Type type, string name)
{
try {
PropertyInfo ret = type.GetProperties (BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy).
First<PropertyInfo> ((pi) => {
if (String.Compare (pi.Name, name, StringComparison.Ordinal) == 0)
return true;
return false;
}
);
return ret;
} catch (InvalidOperationException ex) {
return null;
}
}
}
}

View File

@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Web;
using System.Web.DynamicData;
using System.Web.DynamicData.ModelProviders;
using MonoTests.DataSource;
using MonoTests.Common;
namespace MonoTests.ModelProviders
{
public class DynamicDataContainerModelProvider <TContext> : DataModelProvider
{
IDynamicDataContainer <TContext> container;
Type containerType;
ReadOnlyCollection<TableProvider> tables;
public IDynamicDataContainer <TContext> Container
{
get
{
if (container != null)
return container;
container = Activator.CreateInstance (containerType) as IDynamicDataContainer <TContext>;
if (container == null)
throw new InvalidOperationException ("Failed to create an instance of container type '" + ContextType + "'.");
return container;
}
}
public override Type ContextType
{
get
{
return typeof (TContext);
}
protected set
{
throw new InvalidOperationException ("Setting the context type on this provider is not supported.");
}
}
public DynamicDataContainerModelProvider ()
{
Type genType = typeof (TestDataContainer<>).GetGenericTypeDefinition ();
this.containerType = genType.MakeGenericType (new Type[] { ContextType });
}
public DynamicDataContainerModelProvider (IDynamicDataContainer <TContext> container)
{
if (container == null)
throw new ArgumentNullException ("container");
this.container = container;
}
public override object CreateContext ()
{
return Activator.CreateInstance (ContextType);
}
public override ReadOnlyCollection<TableProvider> Tables
{
get
{
if (tables != null)
return tables;
tables = LoadTables ();
return tables;
}
}
public void ResolveAssociations ()
{
foreach (var t in Tables) {
var table = t as DynamicDataContainerTableProvider <TContext>;
if (t == null)
continue;
table.ResolveAssociations ();
}
}
ReadOnlyCollection<TableProvider> LoadTables ()
{
List<DynamicDataTable> containerTables = Container.GetTables ();
if (containerTables == null || containerTables.Count == 0)
return new ReadOnlyCollection<TableProvider> (new List<TableProvider> ());
var tables = new List<TableProvider> ();
foreach (var table in containerTables)
tables.Add (new DynamicDataContainerTableProvider <TContext>(this, table));
return new ReadOnlyCollection<TableProvider> (tables);
}
}
}

View File

@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Web;
using System.Web.DynamicData;
using System.Web.DynamicData.ModelProviders;
using MonoTests.DataSource;
namespace MonoTests.ModelProviders
{
public class DynamicDataContainerTableProvider <T> : TableProvider
{
ReadOnlyCollection<ColumnProvider> columns;
DynamicDataTable table;
public DynamicDataContainerTableProvider (DynamicDataContainerModelProvider <T> owner, DynamicDataTable table)
: base (owner)
{
if (table == null)
throw new ArgumentNullException ("table");
this.EntityType = table.DataType;
this.Name = table.Name;
this.table = table;
}
public override ReadOnlyCollection<ColumnProvider> Columns
{
get
{
if (columns != null)
return columns;
columns = LoadColumns ();
return columns;
}
}
public override IQueryable GetQuery (object context)
{
throw new NotImplementedException ();
}
ReadOnlyCollection<ColumnProvider> LoadColumns ()
{
List<DynamicDataColumn> containerColumns = table.GetColumns ();
if (containerColumns == null || containerColumns.Count == 0)
return new ReadOnlyCollection<ColumnProvider> (new List<ColumnProvider> ());
var columns = new List<ColumnProvider> ();
foreach (var column in containerColumns)
columns.Add (new DynamicDataContainerColumnProvider <T> (this, column));
return new ReadOnlyCollection<ColumnProvider> (columns);
}
public void ResolveAssociations ()
{
DynamicDataContainerColumnProvider <T> column;
foreach (var cp in Columns) {
column = cp as DynamicDataContainerColumnProvider <T>;
if (column == null)
continue;
column.ResolveAssociations ();
}
}
}
}

View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.DynamicData.ModelProviders;
namespace MonoTests.ModelProviders
{
[AttributeUsage (AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
class DynamicDataSortableAttribute : Attribute
{
public bool Sortable { get; private set; }
public DynamicDataSortableAttribute (bool sortable)
{
Sortable = sortable;
}
}
}

View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.DynamicData.ModelProviders;
namespace MonoTests.ModelProviders
{
[AttributeUsage (AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
class DynamicDataStringLengthAttribute : Attribute
{
public int MaxLength { get; private set; }
public DynamicDataStringLengthAttribute (int maxLength)
{
MaxLength = maxLength;
}
}
}