Exemple #1
0
        protected virtual ActionParameter[] GetActionParameters()
        {
            var actionParams = new ActionParameter[ParamTypes.Length];

            for (var i = 0; i < ParamTypes.Length; i++)
            {
                actionParams[i] = new ActionParameter(ParamNames[i], ParamTypes[i]);
            }

            return(actionParams);
        }
Exemple #2
0
        public override void Initialize(Content context, string backUri, Application application, object parameters)
        {
            var app = application as GenericODataApplication;

            if (app == null)
            {
                throw new InvalidOperationException("Not an OData application: " + application.GetType().Name);
            }

            var type = TypeResolver.GetType(app.ClassName, false);

            if (type == null)
            {
                throw new InvalidOperationException("Unknown type: " + app.ClassName);
            }

            var methodName = app.MethodName;

            string[] paramNames;
            _paramTypes = GetMethodParams(app.Parameters, out paramNames);
            _paramNames = paramNames;

            var prmTypes = new Type[_paramTypes.Length + 1];

            prmTypes[0] = typeof(Content);
            Array.Copy(_paramTypes, 0, prmTypes, 1, _paramTypes.Length);
            _method = type.GetMethod(methodName, prmTypes);
            if (_method == null)
            {
                throw new InvalidOperationException("Unknown method: " + methodName);
            }

            _actionParameters = new ActionParameter[_paramTypes.Length];
            var actualParameters = _method.GetParameters();

            for (int i = 0; i < _paramTypes.Length; i++)
            {
                ActionParameters[i] = new ActionParameter(_paramNames[i], _paramTypes[i], !actualParameters[i + 1].HasDefaultValue);
            }

            var operationAttribute = (ODataOperationAttribute)_method
                                     .GetCustomAttributes(typeof(ODataOperationAttribute), true)
                                     .FirstOrDefault();

            _hasOperationAttribute = operationAttribute != null;
            _causesStateChange     = operationAttribute?.CauseStateChange ?? false;

            base.Initialize(context, backUri, application, parameters);
        }
Exemple #3
0
        public override void Initialize(Content context, string backUri, Application application, object parameters)
        {
            var app        = application as GenericODataApplication;
            var methodName = app.MethodName;

            string[] paramNames;
            _paramTypes = GetMethodParams(app.Parameters, out paramNames);
            _paramNames = paramNames;

            _actionParameters = new ActionParameter[_paramTypes.Length];
            for (int i = 0; i < _paramTypes.Length; i++)
            {
                ActionParameters[i] = new ActionParameter(_paramNames[i], _paramTypes[i], true);
            }

            var type = TypeHandler.GetType(app.ClassName);

            if (type == null)
            {
                throw new InvalidOperationException("Unknown type: " + app.ClassName);
            }

            var prmTypes = new Type[_paramTypes.Length + 1];

            prmTypes[0] = typeof(Content);
            Array.Copy(_paramTypes, 0, prmTypes, 1, _paramTypes.Length);
            _method = type.GetMethod(methodName, prmTypes);
            if (_method == null)
            {
                throw new InvalidOperationException("Unknown method: " + methodName);
            }

            _hasActionAttribute   = _method.GetCustomAttributes(typeof(ODataAction), true).Length != 0;
            _hasFunctionAttribute = _method.GetCustomAttributes(typeof(ODataFunction), true).Length != 0;
            _causesStateChange    = _hasActionAttribute;

            _callingParameters = parameters;

            base.Initialize(context, backUri, application, parameters);
        }