Преглед на файлове

2008-05-18 Marek Habersack <[email protected]>

	* HierarchicalDataBoundControl.cs: Modified GetData method to check if
	DataSource implements IHierarchicalEnumerable and if so constructs and
	returns a new instance of ReadOnlyDataSourceView. This provides functional
	compatibility with the Microsoft.NET framework. Fixes bug
	#395209. Patch contributed by James Fitzsimons
	<[email protected]>, thanks!

2008-05-18  Marek Habersack  <[email protected]>

	* HierarchicalDataBoundControlTest.cs: Added 
	TestIHierarchicalEnumerableDataSource to test change made to
	GetData method to make functionally compatibile with Microsoft.NET
	framework. Patch contributed by James Fitzsimons
	<[email protected]>, thanks!

2008-05-28  Marek Habersack  <[email protected]>

	* ReadOnlyDataSourceView.cs: added. Patch contributed by James
	Fitzsimons <[email protected]>, thanks!

svn path=/trunk/mcs/; revision=104329
Marek Habersack преди 17 години
родител
ревизия
abb3087f1e

+ 9 - 0
mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog

@@ -1,3 +1,12 @@
+2008-05-18  Marek Habersack  <[email protected]>
+
+	* HierarchicalDataBoundControl.cs: Modified GetData method to check if
+	DataSource implements IHierarchicalEnumerable and if so constructs and
+	returns a new instance of ReadOnlyDataSourceView. This provides functional
+	compatibility with the Microsoft.NET framework. Fixes bug
+	#395209. Patch contributed by James Fitzsimons
+	<[email protected]>, thanks!
+
 2008-05-06  Marek Habersack  <[email protected]>
 
 	* Calendar.cs: do not create dateInfo in the constructor - culture

+ 7 - 5
mcs/class/System.Web/System.Web.UI.WebControls/HierarchicalDataBoundControl.cs

@@ -31,6 +31,7 @@
 #if NET_2_0
 using System.Collections;
 using System.ComponentModel;
+using System.Web.UI;
 using System.Web.UI.WebControls.Adapters;
 
 namespace System.Web.UI.WebControls
@@ -58,19 +59,20 @@ namespace System.Web.UI.WebControls
 		protected virtual HierarchicalDataSourceView GetData (string viewPath)
 		{
 			if (DataSource != null && DataSourceID != "")
-				throw new HttpException ();
-			
+				throw new HttpException ();	
 			IHierarchicalDataSource ds = GetDataSource ();
 			if (ds != null)
 				return ds.GetHierarchicalView (viewPath);
-			else
-				return null; 
+			
+			if (DataSource is IHierarchicalEnumerable)
+				return new ReadOnlyDataSourceView ((IHierarchicalEnumerable) DataSource);
+			
+			return null;
 		}
 		
 		protected virtual IHierarchicalDataSource GetDataSource ()
 		{
 			if (IsBoundUsingDataSourceID) {
-				
 				Control ctrl = FindDataSource ();
 
 				if (ctrl == null)

+ 3 - 0
mcs/class/System.Web/System.Web.UI/ChangeLog

@@ -1,5 +1,8 @@
 2008-05-28  Marek Habersack  <[email protected]>
 
+	* ReadOnlyDataSourceView.cs: added. Patch contributed by James
+	Fitzsimons <[email protected]>, thanks!
+
 	* TemplateParser.cs: added support for #pragma checksum
 
 2008-05-19  Juraj Skripsky  <[email protected]>

+ 51 - 0
mcs/class/System.Web/System.Web.UI/ReadOnlyDataSourceView.cs

@@ -0,0 +1,51 @@
+//
+// System.Web.UI.ReadOnlyDataSourceView.cs
+//
+// Authors:
+//	James Fitzsimons ([email protected])
+//
+// (C) 2008 James Fitzsimons
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+using System;
+
+namespace System.Web.UI
+{
+    internal class ReadOnlyDataSourceView : HierarchicalDataSourceView
+    {
+        IHierarchicalEnumerable datasource;
+
+        public ReadOnlyDataSourceView (IHierarchicalEnumerable datasource)
+        {
+            this.datasource = datasource;
+        }
+
+        public override IHierarchicalEnumerable Select ()
+        {
+            return datasource;
+        }
+    }
+}
+#endif

+ 1 - 0
mcs/class/System.Web/System.Web.dll.sources

@@ -666,6 +666,7 @@ System.Web.UI/PersistenceMode.cs
 System.Web.UI/PostBackOptions.cs
 System.Web.UI/PropertyConverter.cs
 System.Web.UI/PropertyEntry.cs
+System.Web.UI/ReadOnlyDataSourceView.cs
 System.Web.UI/RenderMethod.cs
 System.Web.UI/RootBuilder.cs
 System.Web.UI/SimpleHandlerFactory.cs

+ 8 - 0
mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog

@@ -1,3 +1,11 @@
+2008-05-18  Marek Habersack  <[email protected]>
+
+	* HierarchicalDataBoundControlTest.cs: Added 
+	TestIHierarchicalEnumerableDataSource to test change made to
+	GetData method to make functionally compatibile with Microsoft.NET
+	framework. Patch contributed by James Fitzsimons
+	<[email protected]>, thanks!
+	
 2008-05-04 Igor Zelmanovich <[email protected]>
 
 	* WebControlTest.cs: make tests compatible with Windows

+ 100 - 1
mcs/class/System.Web/Test/System.Web.UI.WebControls/HierarchicalDataBoundControlTest.cs

@@ -79,6 +79,11 @@ namespace MonoTests.System.Web.UI.WebControls
 				dataBindTrace.Append ("[Start PerformDataBinding]");
 				base.PerformDataBinding ();
 				dataBindTrace.Append ("[End PerformDataBinding]");
+			}
+
+			public HierarchicalDataSourceView GetData (string path) {
+				dataBindTrace.Append ("[Start GetData]");
+				return base.GetData (path);
 			}
 
 			protected override void OnDataBinding (EventArgs e) {
@@ -149,11 +154,105 @@ namespace MonoTests.System.Web.UI.WebControls
 		public void PerformDataBinding_WorksWithControlAdapter ()
 		{
 			MyHierarchicalDataBoundControl c = new MyHierarchicalDataBoundControl ();
-			MyControlAdapter a = new MyControlAdapter();;
+			MyControlAdapter a = new MyControlAdapter();
 			c.controlAdapter = a;
 			c.DataBind ();
 		}
+
+		public class TestHierarchy : IHierarchicalEnumerable
+		{
+			List<TestNode> list;
+			
+			public TestHierarchy (List<TestNode> source)
+			{
+			    list = source;
+			}
+
+			public IHierarchyData GetHierarchyData (object enumeratedItem)
+			{
+			    return enumeratedItem as TestNode;
+			}
+
+			public IEnumerator GetEnumerator ()
+			{
+				return list.GetEnumerator ();
+			}
+		}
+
+		public class TestNode : IHierarchyData
+		{
+			string name;
+			TestNode parent;
+			List<TestNode> childNodes;
+
+			public TestNode (string name, TestNode parent, List<TestNode> children)
+			{
+				this.name = name;
+				this.parent = parent;
+				this.childNodes = children;
+			}
+
+			public string Name
+			{
+				get { return name; }
+			}
+
+			public IHierarchicalEnumerable GetChildren ()
+			{
+			    return new TestHierarchy (childNodes);
+			}
+
+			public IHierarchyData GetParent ()
+			{
+			    return parent;
+			}
+
+			public bool HasChildren
+			{
+			    get 
+			    {
+				if (childNodes == null)
+				    return false;
 
+				return childNodes.Count > 0; 
+			    }
+			}
+
+			public object Item
+			{
+			    get { return this; }
+			}
+
+			public string Path
+			{
+			    get
+			    {
+				TestNode node = this;
+				string s = name;
+				while ((node = (TestNode)node.GetParent ()) != null)
+				    s = node.Name + ": " + s;
+				return s.Trim ();
+			    }
+			}
+
+			public string Type
+			{
+			    get { return this.ToString (); }
+			}
+		}
+		
+		[Test]
+		public void TestIHierarchicalEnumerableDataSource ()
+		{
+			List<TestNode> list = new List<TestNode> ();
+			list.Add (new TestNode ("test", null, null));
+                        TestHierarchy hierarchy = new TestHierarchy (list);
+			MyHierarchicalDataBoundControl c = new MyHierarchicalDataBoundControl ();
+			c.DataSource = hierarchy;
+			c.DataBind ();
+			HierarchicalDataSourceView view = c.GetData ("");
+		        Assert.IsNotNull (view);
+		}
 	}
 }