Example #1
0
        protected virtual void OnCallingDataMethods(CallingDataMethodsEventArgs e)
        {
            CallingDataMethodsEventHandler handler = Events[EventCallingDataMethods] as CallingDataMethodsEventHandler;

            if (handler != null)
            {
                handler(_owner.DataControl, e);
            }
        }
Example #2
0
        /// <summary>
        /// Finds the method to be executed. Raises the CallingDataMethods event to see if developer opted in for custom model method look-up instead of page/usercontrol code behind.
        /// Uses the TemplateControl type as a fallback.
        /// </summary>
        /// <param name="methodName">Name of the data method.</param>
        /// <returns>
        /// A ModelDataSourceMethod with the Instance and MethodInfo set.
        /// The Parameters collection on ModelDataSourceMethod is still empty after this method.
        /// </returns>
        protected virtual ModelDataSourceMethod FindMethod(string methodName)
        {
            CallingDataMethodsEventArgs e = new CallingDataMethodsEventArgs();

            OnCallingDataMethods(e);
            Type         type;
            BindingFlags flags;
            object       instance;

            if (e.DataMethodsType != null)
            {
                if (e.DataMethodsObject != null)
                {
                    throw new InvalidOperationException(SR.GetString(SR.ModelDataSourceView_MultipleModelMethodSources, methodName));
                }
                flags    = BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy;
                instance = null;
                type     = e.DataMethodsType;
            }
            else if (e.DataMethodsObject != null)
            {
                flags    = BindingFlags.Public | BindingFlags.Instance;
                instance = e.DataMethodsObject;
                type     = instance.GetType();
            }
            else
            {
                //The compiled page code is a child class of code behind class where usually static methods are defined.
                //We will not get those methods unless we use FlattenHierarchy.
                flags    = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy;
                instance = _owner.DataControl.TemplateControl;
                type     = instance.GetType();
            }

            MethodInfo[] allMethods    = type.GetMethods(flags);
            MethodInfo[] actionMethods = Array.FindAll(allMethods, methodInfo => methodInfo.Name.Equals(methodName, StringComparison.OrdinalIgnoreCase));

            if (actionMethods.Length != 1)
            {
                throw new InvalidOperationException(SR.GetString(SR.ModelDataSourceView_DataMethodNotFound, methodName, type));
            }

            ValidateMethodIsCallable(actionMethods[0]);

            return(new ModelDataSourceMethod(instance: instance, methodInfo: actionMethods[0]));
        }
 protected void GetAccountController(object sender, CallingDataMethodsEventArgs e)
 {
     e.DataMethodsObject = new AccountController();
 }
 protected void Page_CallingDataMethods(object sender, CallingDataMethodsEventArgs e)
 {
     e.DataMethodsObject = Page.Items["controller"];
 }
 protected void DataBoundControl_CallingDataMethods(object sender, CallingDataMethodsEventArgs e)
 {
     HttpContext.Current.Items["_GlimpseWebFormModelBinding"] = new DataBindParameterModel(Offset);
 }
Example #6
0
		protected void FormView1_CallingDataMethods(object sender, CallingDataMethodsEventArgs e)
		{
			e.DataMethodsObject = new PersonSearch();
		}
 protected virtual void OnCallingDataMethods(CallingDataMethodsEventArgs e) {
     CallingDataMethodsEventHandler handler = Events[EventCallingDataMethods] as CallingDataMethodsEventHandler;
     if (handler != null) {
         handler(_owner.DataControl, e);
     }
 }
        /// <summary>
        /// Finds the method to be executed. Raises the CallingDataMethods event to see if developer opted in for custom model method look-up instead of page/usercontrol code behind.
        /// Uses the TemplateControl type as a fallback.
        /// </summary>
        /// <param name="methodName">Name of the data method.</param>
        /// <returns>
        /// A ModelDataSourceMethod with the Instance and MethodInfo set. 
        /// The Parameters collection on ModelDataSourceMethod is still empty after this method.
        /// </returns>
        protected virtual ModelDataSourceMethod FindMethod(string methodName) {
            CallingDataMethodsEventArgs e = new CallingDataMethodsEventArgs();
            OnCallingDataMethods(e);
            Type type;
            BindingFlags flags;
            object instance;

            if (e.DataMethodsType != null) {
                if (e.DataMethodsObject != null) {
                    throw new InvalidOperationException(SR.GetString(SR.ModelDataSourceView_MultipleModelMethodSources, methodName));
                }
                flags = BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy;
                instance = null;
                type = e.DataMethodsType;
            } 
            else if (e.DataMethodsObject != null) {
                flags = BindingFlags.Public | BindingFlags.Instance;
                instance = e.DataMethodsObject;
                type = instance.GetType();
            } 
            else {
                //The compiled page code is a child class of code behind class where usually static methods are defined.
                //We will not get those methods unless we use FlattenHierarchy.
                flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy;
                instance = _owner.DataControl.TemplateControl;
                type = instance.GetType();
            }
            
            MethodInfo[] allMethods = type.GetMethods(flags);
            MethodInfo[] actionMethods = Array.FindAll(allMethods, methodInfo => methodInfo.Name.Equals(methodName, StringComparison.OrdinalIgnoreCase));

            if (actionMethods.Length != 1) {
                throw new InvalidOperationException(SR.GetString(SR.ModelDataSourceView_DataMethodNotFound, methodName, type));
            }

            ValidateMethodIsCallable(actionMethods[0]);

            return new ModelDataSourceMethod(instance: instance, methodInfo: actionMethods[0]);
        }