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,10 @@
2009-07-03 Marek Habersack <mhabersack@novell.com>
* IDynamicDataContainer.cs: became a generic interface.
* DynamicDataSource.cs; some reformatting.
DynamicDataSourceView is a generic class now.
* DynamicDataContainer.cs: IDynamicDataContainer is a generic
interface now.

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.DynamicData.ModelProviders;
namespace MonoTests.DataSource
{
public abstract class DynamicDataColumn
{
public Type DataType { get; protected set; }
public string Name { get; protected set; }
public bool PrimaryKey { get; protected set; }
public string AssociatedTo { get; protected set; }
public AssociationDirection AssociationDirection { get; protected set; }
public bool CustomProperty { get; protected set; }
public bool Generated { get; protected set; }
public bool Sortable { get; protected set; }
}
}

View File

@@ -0,0 +1,52 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MonoTests.DataSource
{
public abstract class DynamicDataContainer<T> : IDynamicDataContainer<T>
{
T containedTypeInstance;
public string TableName {
get;
set;
}
public T ContainedTypeInstance {
get { return containedTypeInstance; }
set {
if (value == null)
throw new InvalidOperationException ("Null type instance is not allowed.");
containedTypeInstance = value;
}
}
public DynamicDataContainer ()
: this (null)
{ }
public DynamicDataContainer (string tableName)
{
TableName = tableName;
ContainedTypeInstance = Activator.CreateInstance<T> ();
}
public virtual Type ContainedType
{
get { return typeof (T); }
}
#region IDynamicDataContainer Members
public abstract int Update (IDictionary keys, IDictionary values, IDictionary oldValues);
public abstract int Insert (IDictionary values);
public abstract int Delete (IDictionary keys, IDictionary oldValues);
public abstract IEnumerable Select (DataSourceSelectArguments args, string where, ParameterCollection whereParams);
public abstract List<DynamicDataTable> GetTables ();
#endregion
}
}

View File

@@ -0,0 +1,150 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.DynamicData;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MonoTests.DataSource
{
[PersistChildren (false)]
[ParseChildren (true)]
public class DynamicDataSource : DataSourceControl, IDynamicDataSource
{
const string DEFAULT_VIEW_NAME = "DefaultView";
static readonly string[] emptyNames = new string[] { "DefaultView" };
DataSourceView defaultView;
ParameterCollection whereCollection;
Type dataContainerType;
public DynamicDataSource ()
: this (null)
{
}
public DynamicDataSource (string dataContainerTypeName)
{
this.DataContainerTypeName = dataContainerTypeName;
}
public DataSourceView DefaultView {
get {
if (defaultView == null)
defaultView = CreateView (DEFAULT_VIEW_NAME);
return defaultView;
}
}
public Type DataContainerType {
get {
if (dataContainerType == null)
dataContainerType = Type.GetType (DataContainerTypeName, true);
return dataContainerType;
}
}
public string DataContainerTypeName {
get;
set;
}
public object DataContainerInstance
{
get;
set;
}
DataSourceView CreateView (string viewName)
{
Type genType = typeof (DynamicDataSourceView<>).GetGenericTypeDefinition ();
return Activator.CreateInstance (genType.MakeGenericType (new Type[] { ContextType }), this, viewName) as DataSourceView;
}
#region DataSourceControl Members
protected override DataSourceView GetView (string viewName)
{
if (String.IsNullOrEmpty (viewName))
return DefaultView;
return CreateView (viewName);
}
#endregion
#region IDynamicDataSource Members
public bool AutoGenerateWhereClause
{
get;
set;
}
public Type ContextType
{
get;
set;
}
public bool EnableDelete
{
get;
set;
}
public bool EnableInsert
{
get;
set;
}
public bool EnableUpdate
{
get;
set;
}
public string EntitySetName
{
get;
set;
}
public event EventHandler<DynamicValidatorEventArgs> Exception;
public string Where
{
get;
set;
}
[PersistenceMode (PersistenceMode.InnerProperty)]
public ParameterCollection WhereParameters
{
get
{
if (whereCollection == null)
whereCollection = new ParameterCollection ();
return whereCollection;
}
}
#endregion
#region IDataSource Members
DataSourceView IDataSource.GetView (string viewName)
{
return GetView (viewName);
}
ICollection IDataSource.GetViewNames ()
{
return emptyNames;
}
#endregion
}
}

View File

@@ -0,0 +1,114 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MonoTests.DataSource
{
public class DynamicDataSourceView<T> : DataSourceView
{
#region Private fields
DynamicDataSource owner;
IDynamicDataContainer<T> dataContainer;
#endregion
#region Can* overrides
public override bool CanDelete
{
get { return true; }
}
public override bool CanInsert
{
get { return true; }
}
public override bool CanPage
{
get { return true; }
}
public override bool CanRetrieveTotalRowCount
{
get { return true; }
}
public override bool CanSort
{
get { return true; }
}
public override bool CanUpdate
{
get { return true; }
}
#endregion
public IDynamicDataContainer<T> DataContainerInstance
{
get
{
if (dataContainer != null)
return dataContainer;
object inst = owner.DataContainerInstance;
if (inst != null) {
dataContainer = inst as IDynamicDataContainer<T>;
if (dataContainer == null)
throw new InvalidOperationException (
"DynamicDataSource.DataContainerInstance must be set to an instance of '" + typeof (IDynamicDataContainer <T>) + "'.");
if (String.IsNullOrEmpty (dataContainer.TableName))
dataContainer.TableName = owner.EntitySetName;
return dataContainer;
}
string typeName = owner.DataContainerTypeName;
if (String.IsNullOrEmpty (typeName))
throw new InvalidOperationException ("DynamicDataSource '" + owner.ID + "' does not specify either data container instance or its type name.");
Type type = Type.GetType (typeName, true);
if (!typeof (IDynamicDataContainer<T>).IsAssignableFrom (type))
throw new InvalidOperationException ("Data container type '" + typeName + "' specified by DynamicDataSource '" + owner.ID + "' does not implement the IDynamicDataContainer interface.");
dataContainer = Activator.CreateInstance (type, owner.EntitySetName) as IDynamicDataContainer<T>;
if (dataContainer == null)
throw new InvalidOperationException ("Failed to create instance of data container type '" + typeName + "'.");
return dataContainer;
}
}
#region Constructors
public DynamicDataSourceView (DynamicDataSource owner, string viewName)
: base (owner, viewName)
{
this.owner = owner;
}
#endregion
#region DataSourceView methods
protected override int ExecuteDelete (IDictionary keys, IDictionary oldValues)
{
return DataContainerInstance.Delete (keys, oldValues);
}
protected override int ExecuteInsert (IDictionary values)
{
return DataContainerInstance.Insert (values);
}
protected override int ExecuteUpdate (IDictionary keys, IDictionary values, IDictionary oldValues)
{
return DataContainerInstance.Update (keys, values, oldValues);
}
protected override IEnumerable ExecuteSelect (DataSourceSelectArguments arguments)
{
return DataContainerInstance.Select (arguments, owner.Where, owner.WhereParameters);
}
#endregion
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MonoTests.DataSource
{
public abstract class DynamicDataTable
{
public string Name
{
get;
set;
}
public Type DataType
{
get;
set;
}
public abstract List<DynamicDataColumn> GetColumns ();
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MonoTests.DataSource
{
public interface IDynamicDataContainer <T>
{
T ContainedTypeInstance { get; set; }
Type ContainedType { get; }
string TableName { get; set; }
int Update (IDictionary keys, IDictionary values, IDictionary oldValues);
int Insert (IDictionary values);
int Delete (IDictionary keys, IDictionary oldValues);
IEnumerable Select (DataSourceSelectArguments args, string where, ParameterCollection whereParams);
List<DynamicDataTable> GetTables ();
}
}