Exemple #1
0
		internal ServerMethodArgs(string query, int top, Hashtable clientState, Cambro.Web.DbCombo.SecureHashtable serverState, bool upLevel, FieldSecurityClass fieldSecurity, ArrayList fieldSubset, DataMemberSecurityClass dataMamberSecurity, ArrayList dataMemberSubset )
		{
			this.query = query;
			this.top = top;
			this.clientState = clientState; 
			this.serverState = serverState;
			this.upLevel = upLevel;
			this.fieldSecurity = fieldSecurity;
			this.fieldSubset = fieldSubset;
			this.dataMemberSecurity = dataMemberSecurity;
			this.dataMemberSubset = dataMemberSubset;
		}
Exemple #2
0
		internal static bool StoreResults(
			int rows, 
			string query, 
			int skip, 
			string serverAssembly, 
			string serverType, 
			string serverMethod,
			string dataMember,

			string dataValueField,
			string dataTextField,

			string parentAssembly,
			string parentType,
			string parentBaseAssembly,
			string parentBaseType,

			string pageAssembly,
			string pageType,
			string pageBaseAssembly,
			string pageBaseType,

			StoreResult StoreResultDel, 
			XmlDocument xmlDoc, 
			XmlNode responseTag,
			Hashtable clientState,
			Hashtable serverState,
			string serverStateString,
			string serverStateHash,
			bool upLevel)
		{
			bool foundMethod = false;
			bool attributeMissingException=false;
			MethodInfo methodInfo = null;

			#region Find the method - bit messy, could be improved?
			if (serverAssembly!="")//assembly specified
			{
				if (serverType!="")//type specified
				{
					foundMethod = GetMethod(serverAssembly, serverType, serverMethod, ref attributeMissingException, ref methodInfo); //try with specified assembly and specified type
				}
			}
			if (serverType!="" &! foundMethod)//type specified
			{
				foundMethod = GetMethod(pageAssembly, serverType, serverMethod, ref attributeMissingException, ref methodInfo); //try with page assembly and specified type
				if(!foundMethod)
					foundMethod = GetMethod(pageBaseAssembly, serverType, serverMethod, ref attributeMissingException, ref methodInfo); //try with page codebehind assembly and specified type
				if(!foundMethod)
					foundMethod = GetMethod(parentAssembly, serverType, serverMethod, ref attributeMissingException, ref methodInfo); //try with parent assembly and specified type
				if(!foundMethod)
					foundMethod = GetMethod(parentBaseAssembly, serverType, serverMethod, ref attributeMissingException, ref methodInfo); //try with parent codebehind assembly and specified type
			}
			if(!foundMethod)
				foundMethod = GetMethod(pageAssembly, pageType, serverMethod, ref attributeMissingException, ref methodInfo); //try with page assembly and page type
			if(!foundMethod)
				foundMethod = GetMethod(pageBaseAssembly, pageBaseType, serverMethod, ref attributeMissingException, ref methodInfo); //try with page codebehind assembly and page codebehind type
			if(!foundMethod)
				foundMethod = GetMethod(parentAssembly, parentType, serverMethod, ref attributeMissingException, ref methodInfo); //try with parent assembly and parent type
			if(!foundMethod)
				foundMethod = GetMethod(parentBaseAssembly, parentBaseType, serverMethod, ref attributeMissingException, ref methodInfo); //try with parent codebehind assembly and parent codebehind type

			if(!foundMethod && attributeMissingException)
				throw new Exception("ServerMethod is not tagged with '[Cambro.Web.DbCombo.ResultsMethodAttribute(true)]' attribute.");

			if(!foundMethod)
				throw new Exception("Can't find ServerMethod.");
			#endregion

			#region Convert the method to a GetResults delegate, and throw a nice exception if it doesn't convert
			DbCombo.GetResults mydel;
			try
			{
				mydel = (DbCombo.GetResults) Delegate.CreateDelegate(typeof(DbCombo.GetResults),methodInfo);
			}
			catch(Exception ex)
			{
				throw new Exception("Error while getting results - I've found your ServerMethod, but an exception was thrown while converting it to a DbCombo.GetResults delegate. Are you sure your ServerMethod has the signature: public static object YourServerMethodName(Cambro.Web.DbCombo.ServerMethodArgs args)? ",ex);
			}
			#endregion

			#region Populate our Secure Server State hashtable
			SecureHashtable serverStateSecure = new SecureHashtable();
			serverStateSecure.HashHash=serverStateHash;
			serverStateSecure.Downlevel=!upLevel;
			serverStateSecure.HashSerial=serverStateString;
			if (serverState != null)
			{
				foreach(object c in serverState.Keys)
				{
					serverStateSecure.Add(c,serverState[c]);
				}
			}
			#endregion
			
			FieldSecurityClass fieldSecurity = new FieldSecurityClass();
			ArrayList fieldSubset = new ArrayList();

			DataMemberSecurityClass dataMemberSecurity = new DataMemberSecurityClass();
			ArrayList dataMemberSubset = new ArrayList();

			#region Build our ServerMethodArgs and execute our delegate
			ServerMethodArgs a = new ServerMethodArgs(
				query,
				skip+rows+2,
				clientState,
				serverStateSecure,
				upLevel,
				fieldSecurity,
				fieldSubset,
				dataMemberSecurity,
				dataMemberSubset);
			object result1 = mydel(a);
			#endregion

			object result = new object();
			object iListObj = new object();

			#region Throw an exception if we are trying to use a field that is not alowed by the fieldsecurity.
			if ( fieldSecurity.Value.Equals(FieldSecurity.Default) )
			{
				if ( dataValueField!="" || dataTextField!="" )
					throw new Exception("You have specified either DataValueField or DataTextField, but have not specified FieldSecurity in the ServerMethod. Add 'args.FieldSecurity.Value = FieldSecurity.xxx' to your ServerMethod, where xxx is either 'AllFields' or 'fieldSubset'");
			}
			else if ( fieldSecurity.Value.Equals(FieldSecurity.IncludeFieldSubset) )
			{
				string valueField="DbComboValue";
				string textField="DbComboText";
				if (dataValueField!="")
					valueField = dataValueField;
				if (dataTextField!="")
					textField = dataTextField;
				if ( ! fieldSubset.Contains(valueField) )
					throw new Exception("You have specified FieldSecurity=IncludeFieldSubset in the ServerMethod, but your DataValueField ('"+valueField+"') does not occur in the ArrayList FieldSubset.");
				if ( ! fieldSubset.Contains(textField) )
					throw new Exception("You have specified FieldSecurity=IncludeFieldSubset in the ServerMethod, but your DataTextField ('"+textField+"') does not occur in the ArrayList FieldSubset.");
			}
			else if ( fieldSecurity.Value.Equals(FieldSecurity.ExcludeFieldSubset) )
			{
				string valueField="DbComboValue";
				string textField="DbComboText";
				if (dataValueField!="")
					valueField = dataValueField;
				if (dataTextField!="")
					textField = dataTextField;
				if ( fieldSubset.Contains(valueField) )
					throw new Exception("You have specified FieldSecurity=ExcludeFieldSubset in the ServerMethod, and your DataValueField ('"+valueField+"') occurs in the ArrayList FieldSubset.");
				if ( fieldSubset.Contains(textField) )
					throw new Exception("You have specified FieldSecurity=ExcludeFieldSubset in the ServerMethod, and your DataTextField ('"+textField+"') occurs in the ArrayList FieldSubset.");
			}	
			if (dataValueField=="")
				dataValueField = "DbComboValue";
			if (dataTextField=="")
				dataTextField = "DbComboText";
			#endregion
			#region Throw an exception if we are trying to use a DataMember that is not alowed by the DataMemberSecurity.
			if (dataMemberSecurity.Equals(DataMemberSecurity.Default))
			{
				if (dataMember!="")
					throw new Exception("You have specified a DataMember, but DataMemberSecurity is still set on Default. In your ServerMethod, please choose a diferent value for DataMemberSecurity.");
			}
			else if (dataMemberSecurity.Equals(DataMemberSecurity.IncludeDataMemberSubset))
			{
				if (!dataMemberSubset.Contains(dataMember))
					throw new Exception("You have specified a DataMember, and you have chosed DataMemberSecurity.IncludeDataMemberSubset. Your chosen DataMember does not occur in the ArrayList DataMemberSubset.");
			}
			else if (dataMemberSecurity.Equals(DataMemberSecurity.ExcludeDataMemberSubset))
			{
				if (dataMemberSubset.Contains(dataMember))
					throw new Exception("You have specified a DataMember, and you have chosed DataMemberSecurity.ExcludeDataMemberSubset. Your chosen DataMember occurs in the ArrayList DataMemberSubset.");
			}
			#endregion

			bool moreRowsAvailable=false;
			int counter=0;

			#region Extract an IList (if we can)
			bool useIList = true;
			if (result1 is DataSet)
			{
				if (dataMember.Length>0)
					iListObj = ((IListSource)(object)((DataSet)result1).Tables[dataMember]).GetList();
				else
					iListObj = ((IListSource)(object)((DataSet)result1).Tables[0]).GetList();
			}
			else if (result1 is IListSource)
				iListObj = ((IListSource)result1).GetList();
			else if (result1 is IList)
				iListObj = (IList)result1;
			else
				useIList = false;
			#endregion

			if (useIList)
			{
				#region This is the new DataBinding code (>=v4.1) - it handles custom objects, but not DataReaders.
				IList iList = (IList)iListObj;
				int maxVar = rows+skip;
				if (rows+skip>iList.Count)
					maxVar = iList.Count;
				for(int i=skip;i<maxVar;i++)
				{
					string thisValue = GetField(iList[i],dataValueField);
					string thisText  = GetField(iList[i],dataTextField);
					StoreResultDel(xmlDoc,responseTag,thisValue,thisText);
				}
				if (iList.Count>rows+skip)
					return true;
				else
					return false;
				#endregion
			}
			else
			{
				#region This is the old DataDinding code (<v4.1) - it handles DataReaders.
				if (result1 is DataSet)
				{
					result = (object)((DataSet)result1).Tables[0].DefaultView;
				}
				else
				{
					result = result1;
				}
				if (result is IEnumerable)
				{
					IEnumerator iEnumerator = ((IEnumerable)result).GetEnumerator();
					while (counter<skip && iEnumerator.MoveNext())
					{
						counter++;
					}
					while (counter<(rows+skip) && iEnumerator.MoveNext())
					{
						string val = GetField(iEnumerator.Current,dataValueField);
						string text = GetField(iEnumerator.Current,dataTextField);
						StoreResultDel(xmlDoc,responseTag,val,text);
						counter++;
					}
					try
					{
						moreRowsAvailable=iEnumerator.MoveNext();
					}
					catch
					{
						moreRowsAvailable=false;
					}
				
				}
				else 
				{
					throw new Exception("Returned object is not DataSet or IListSource or IList or IEnumerable");
				}
				if (result is IDisposable)
				{
					IDisposable dis = (IDisposable)result;
					dis.Dispose();
				}
				#endregion
			}
		
			#region Old DataBinding code (removed)
			/*
			if (result1 is DataSet)
			{
				result = (object)((DataSet)result1).Tables[0].DefaultView;
			}
			else
			{
				result = result1;
			}
			if (result is IEnumerable)
			{
				IEnumerator iEnumerator = ((IEnumerable)result).GetEnumerator();
				while (counter<skip && iEnumerator.MoveNext())
				{
					counter++;
				}
				while (counter<(rows+skip) && iEnumerator.MoveNext())
				{
					string val;
					string text;
					#region extract the data record
					if (iEnumerator.Current is IDataRecord)
					{
						IDataRecord current = (IDataRecord)iEnumerator.Current;
						val = current[dataValueField].ToString();
						text = current[dataTextField].ToString();
					}
					else if (iEnumerator.Current is DataRowView)
					{
						DataRowView current = (DataRowView)iEnumerator.Current;
						val = current[dataValueField].ToString();
						text = current[dataTextField].ToString();
					}
					else if (iEnumerator.Current is IDictionary)
					{
						IDictionary current = (IDictionary)iEnumerator.Current;
						val = current[dataValueField].ToString();
						text = current[dataTextField].ToString();
					}
					else if (iEnumerator.Current is IEnumerable)
					{
						IEnumerator ie = ((IEnumerable)iEnumerator.Current).GetEnumerator();
						ie.MoveNext();
						val = ie.Current.ToString();
						ie.MoveNext();
						text = ie.Current.ToString();
					}
					else
					{
						throw new Exception("Returned Object's IEnumerator.Current is not IDataRecord, DataRowView, IDictionary or IEnumerable");
					}
					#endregion
					StoreResultDel(xmlDoc,responseTag,val,text);
					counter++;
				}
				try
				{
					moreRowsAvailable=iEnumerator.MoveNext();
				}
				catch
				{
					moreRowsAvailable=false;
				}
				
			}
			else 
			{
				throw new Exception("returned object is not IEnumerable");
			}

			if (result is IDisposable)
			{
				IDisposable dis = (IDisposable)result;
				dis.Dispose();
			}
			*/
			#endregion

			return moreRowsAvailable;
		}