예제 #1
0
        public static MethodDescription FromMethodInfo(MethodInfo methodInfo, bool isQuery)
        {
            Type returnType           = methodInfo.ReturnType;
            bool isVoid               = returnType == typeof(void);
            MethodDescription invInfo = new MethodDescription();

            invInfo.methodInfo = methodInfo;
            invInfo.methodName = methodInfo.Name;
            invInfo.isQuery    = isQuery;

            if (!isVoid)
            {
                invInfo.methodResult = true;
            }
            //else Result is Converted to JSON
            ParameterInfo[] paramsInfo = methodInfo.GetParameters();
            for (var i = 0; i < paramsInfo.Length; ++i)
            {
                if (isQuery && paramsInfo[i].ParameterType == typeof(GetDataInfo))
                {
                    continue;
                }
                ParamMetadataInfo param = ParamMetadataInfo.FromParamInfo(paramsInfo[i]);
                param.ordinal = i;
                invInfo.parameters.Add(param);
            }
            return(invInfo);
        }
예제 #2
0
        protected InvokeResult InvokeMethod(InvokeInfo invokeInfo)
        {
            List <MethodDescription> methodList = this.EnsureMetadataInitialized().methodDescriptions;
            MethodDescription        method     = methodList.Where((m) => m.methodName == invokeInfo.methodName && m.isQuery == false).FirstOrDefault();

            if (method == null)
            {
                throw new DomainServiceException(string.Format(ErrorStrings.ERR_METH_NAME_INVALID, invokeInfo.methodName));
            }
            this.Authorizer.CheckUserRightsToExecute(method.methodInfo);
            List <object> methParams = new List <object>();

            for (var i = 0; i < method.parameters.Count; ++i)
            {
                methParams.Add(invokeInfo.paramInfo.GetValue(method.parameters[i].name, method, this.DataHelper));
            }
            object       meth_result = method.methodInfo.Invoke(this, methParams.ToArray());
            InvokeResult res         = new InvokeResult();

            if (method.methodResult)
            {
                res.result = meth_result;
            }
            return(res);
        }
예제 #3
0
        protected GetDataResult GetData(GetDataInfo getInfo)
        {
            var metadata = this.EnsureMetadataInitialized();
            List <MethodDescription> methodList = metadata.methodDescriptions;
            MethodDescription        method     = methodList.Where((m) => m.methodName == getInfo.queryName && m.isQuery == true).FirstOrDefault();

            if (method == null)
            {
                throw new DomainServiceException(string.Format(ErrorStrings.ERR_QUERY_NAME_INVALID, getInfo.queryName));
            }

            this.Authorizer.CheckUserRightsToExecute(method.methodInfo);
            getInfo.dbSetInfo = metadata.dbSets[getInfo.dbSetName];
            bool isMultyPageRequest = getInfo.dbSetInfo.enablePaging && getInfo.pageCount > 1;

            QueryResult   queryResult = null;
            int?          totalCount  = null;
            List <object> methParams  = new List <object>();

            methParams.Add(getInfo);
            for (var i = 0; i < method.parameters.Count; ++i)
            {
                methParams.Add(getInfo.paramInfo.GetValue(method.parameters[i].name, method, this.DataHelper));
            }
            queryResult = (QueryResult)method.methodInfo.Invoke(this, methParams.ToArray());

            IEnumerable entities = (IEnumerable)queryResult.Result;

            totalCount = queryResult.TotalCount;
            int rowCnt = 0;
            LinkedList <object> entityList = new LinkedList <object>();

            foreach (object entity in entities)
            {
                entityList.AddLast(entity);
                ++rowCnt;
            }
            var rows = this.CreateRows(getInfo.dbSetInfo, entityList, rowCnt);
            IEnumerable <IncludedResult> subResults = this.CreateIncludedResults(getInfo.dbSetInfo, entityList, queryResult.includeNavigations);

            GetDataResult res = new GetDataResult()
            {
                pageIndex  = getInfo.pageIndex,
                pageCount  = getInfo.pageCount,
                dbSetName  = getInfo.dbSetName,
                names      = getInfo.dbSetInfo.fieldInfos.Where(f => f.isIncludeInResult()).OrderBy(f => f._ordinal).Select(fi => fi.fieldName),
                totalCount = totalCount,
                extraInfo  = queryResult.extraInfo,
                rows       = rows,
                rowCount   = rowCnt,
                fetchSize  = getInfo.dbSetInfo.FetchSize,
                included   = subResults,
                error      = null
            };

            return((GetDataResult)res);
        }
예제 #4
0
 public object GetValue(string name, MethodDescription methodDescription)
 {
     var par = this.parameters.Where(p => p.name == name).FirstOrDefault();
     if (par == null)
         return null;
     var paraminfo = methodDescription.parameters.Where(p => p.name == name).FirstOrDefault();
     if (paraminfo == null)
     {
         throw new DomainServiceException(string.Format("Method: {0} has no parameter with the name: {1}",methodDescription.methodName, name));
     }
     return DataHelper.ParseParameter(paraminfo.ParameterType, paraminfo, paraminfo.isArray, par.value);
 }
예제 #5
0
        public object GetValue(string name, MethodDescription methodDescription, IDataHelper dataHelper)
        {
            var par = this.parameters.Where(p => p.name == name).FirstOrDefault();

            if (par == null)
            {
                return(null);
            }
            var paraminfo = methodDescription.parameters.Where(p => p.name == name).FirstOrDefault();

            if (paraminfo == null)
            {
                throw new DomainServiceException(string.Format("Method: {0} has no parameter with the name: {1}", methodDescription.methodName, name));
            }
            return(dataHelper.ParseParameter(paraminfo.ParameterType, paraminfo, paraminfo.isArray, par.value));
        }
예제 #6
0
        /// <summary>
        /// Test if public methods on the service has Invoke or Query Attribute
        /// and generates from this methods their invocation method descriptions
        /// </summary>
        /// <returns></returns>
        private MethodsList GetMethodDescriptions(Type thisType)
        {
            MethodsList res = null;

            if (BaseDomainService._tInvokesInfo.TryGetValue(thisType, out res))
            {
                return(res);
            }
            res = new MethodsList();
            var methList = thisType.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public).Select(m => new { method = m, isQuery = m.IsDefined(typeof(QueryAttribute), false), isInvoke = m.IsDefined(typeof(InvokeAttribute), false) }).Where(m => (m.isInvoke || m.isQuery)).ToArray();

            Array.ForEach(methList, (info) => {
                res.Add(MethodDescription.FromMethodInfo(info.method, info.isQuery, this.DataHelper));
            });
            BaseDomainService._tInvokesInfo.TryAdd(thisType, res);
            return(res);
        }
예제 #7
0
        public static MethodDescription FromMethodInfo(MethodInfo methodInfo, bool isQuery)
        {
            Type returnType = methodInfo.ReturnType;
            bool isVoid = returnType == typeof(void);
            MethodDescription invInfo = new MethodDescription();
            invInfo.methodInfo = methodInfo;
            invInfo.methodName = methodInfo.Name;
            invInfo.isQuery = isQuery;

            if (!isVoid)
                invInfo.methodResult = true;
            //else Result is Converted to JSON
            ParameterInfo[] paramsInfo = methodInfo.GetParameters();
            for (var i = 0; i < paramsInfo.Length; ++i) {
                if (isQuery && paramsInfo[i].ParameterType == typeof(GetDataInfo))
                    continue;
                ParamMetadataInfo param = ParamMetadataInfo.FromParamInfo(paramsInfo[i]);
                param.ordinal = i;
                invInfo.parameters.Add(param);
            }
            return invInfo;
        }