예제 #1
0
        public ControllerClass(Type classType, string name)
        {
            _classType = classType;

            _name = name;

            Type currentClassType = _classType;
            Stack<Type> pageTypeStack = new Stack<Type>();

            while (currentClassType != typeof(Controller) && currentClassType != null)
            {
                pageTypeStack.Push(currentClassType);

                currentClassType = currentClassType.BaseType;
            }

            while (pageTypeStack.Count > 0)
            {
                currentClassType = pageTypeStack.Pop();

                MethodInfo[] methods = currentClassType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

                foreach (MethodInfo methodInfo in methods)
                {
                    if (methodInfo.IsSpecialName)
                        continue;
            #if MEDIUMLEVEL
                    MethodSchema data = new MethodSchema(methodInfo.Name, methodInfo, methodInfo.GetParameters(), methodInfo.IsStatic);
            #else
                    MethodSchema data = new MethodSchema(methodInfo.Name, BaseMethodInvoker.GetMethodInvoker(methodInfo), methodInfo.GetParameters(), methodInfo.IsStatic);
            #endif
                    if (methodInfo.Name.StartsWith("Before"))
                    {
                        _beforeMethods.Add(data);
                    }
                    else if (methodInfo.Name.StartsWith("After"))
                    {
                        _afterMethods.Add(data);
                    }
                    else
                    {
                        if (_publicMethods.ContainsKey(methodInfo.Name))
                        {
                            _publicMethods[methodInfo.Name] = data;
                        }
                        else
                        {
                            _publicMethods.Add(methodInfo.Name, data);
                        }
                    }
                }
            }
        }
예제 #2
0
            } //Disconnect

            protected override object Invoke(MethodInfo targetMethod, object[] args)
            {
                if ((!context.client.Connected) || writer == null || reader == null)
                {
                    if ((!context.client.Connected))
                    {
                        context.client.Connect(context.hostname, context.port);
                    }
                    stream           = context.client.GetStream();
                    reader           = new(stream);
                    writer           = new(stream);
                    writer.AutoFlush = true;
                } //if
                var    methodSchema = new MethodSchema(targetMethod.ToString(), args, dynamicInterfaceImplementationUniqueId);
                string requestLine  = Utility.ObjectToString(context.serializer, methodSchema);

                writer.WriteLine(requestLine);
                string responseLine = reader.ReadLine();

                if (responseLine == DefinitionSet.NullIndicator)
                {
                    return(null);
                }
                else if (responseLine == DefinitionSet.InterfaceMethodNotFoundIndicator)
                {
                    throw new MethodNotFoundException(methodSchema.MethodName);
                }
                if (responseLine != null && responseLine.Length > 0 && char.IsDigit(responseLine[0]))   //IDynamic UniqueID
                {
                    var uniqueId = UniqueId.Parse(responseLine);
                    if (!context.dynamicProxyDictionary.TryGetValue(uniqueId, out object response))
                    {
                        var instantiatedMethod = context.dispathProxyCreator.MakeGenericMethod(new System.Type[] { targetMethod.ReturnType, typeof(ClientProxy) });
                        var dynamicProxy       = instantiatedMethod.Invoke(null, null);
                        ((IClientInfrastructure)dynamicProxy).Context = this.context;
                        ((IClientInfrastructure)dynamicProxy).DynamicInterfaceImplementationUniqueId = uniqueId;
                        context.dynamicProxyDictionary.Add(uniqueId, dynamicProxy);
                        return(dynamicProxy);
                    }
                    else
                    {
                        return(response);
                    }
                } //if IDynamic
                DataContractSerializer returnSerializer = new(targetMethod.ReturnType);

                return(Utility.StringToObject(returnSerializer, responseLine));
            } //Invoke
예제 #3
0
        internal static CheckMethodResult GetEntityMethodName(Type type, string methodName, BeeDataAdapter dataAdapter)
        {
            ThrowExceptionUtil.ArgumentNotNull(type, "type");
            ThrowExceptionUtil.ArgumentNotNullOrEmpty(methodName, "methodName");

            if (dataAdapter == null)
            {
                dataAdapter = new BeeDataAdapter();
            }

            CheckMethodResult result = new CheckMethodResult();

            MethodSchema        methodSchema = null;
            List <MethodSchema> list         = null;

            //lock (lockobject)
            {
                // 保证参数长的先被匹配
                // 该方法本身就排过序了
                list = EntityProxyManager.Instance.GetEntityMethods(type);

                foreach (MethodSchema item in list)
                {
                    // Check the name of the method.
                    if (string.Compare(item.Name, methodName, true) == 0)
                    {
                        if (CheckMethod(item, methodName, dataAdapter, out result.DataAdapter))
                        {
                            methodSchema = item;
                            break;
                        }
                    }
                }
            }

            if (methodSchema != null)
            {
                result.MethodName = methodSchema.MemberInfo.ToString();
            }
            else
            {
                CoreException exception = new CoreException("Can not match a method for {0}.{1}\r\n".FormatWith(type.Name, methodName));
                exception.ErrorCode = ErrorCode.MVCNoAction;
                throw exception;
            }
            return(result);
        }
        /// <summary>
        /// 后台调用业务服务
        /// </summary>
        /// <param name="serviceCode">业务服务编码</param>
        /// <param name="serviceMethod">方法名称</param>
        /// <param name="dicParams">参数字典</param>
        public static Dictionary <string, object> ExecuteBizBus(string serviceCode, string serviceMethod, Dictionary <string, object> dicParams)
        {
            try
            {
                // 获得业务方法
                MethodSchema method = AppUtility.Engine.BizBus.GetMethod(serviceCode, serviceMethod);
                // 获得参数列表
                BizStructure param = null;
                if (dicParams != null)
                {
                    // 填充业务方法需要的参数
                    param = BizStructureUtility.Create(method.ParamSchema);
                    foreach (var item in dicParams)
                    {
                        param[item.Key] = item.Value;
                    }
                }
                // 调用方法返回结果
                BizStructure ret = null;

                // 调用方法,获得返回结果
                ret = AppUtility.Engine.BizBus.Invoke(
                    new BizServiceInvokingContext(
                        OThinker.Organization.User.AdministratorID,
                        serviceCode,
                        method.ServiceVersion,
                        method.MethodName,
                        param));
                Dictionary <string, object> result = new Dictionary <string, object>();
                if (ret != null && ret.Schema != null)
                {
                    foreach (ItemSchema item in ret.Schema.Items)
                    {
                        result.Add(item.Name, ret[item.Name]);
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                // 调用错误日志记录
                AppUtility.Engine.LogWriter.Write("业务服务调用错误:" + ex);
                return(null);
            }
        }
예제 #5
0
        /// <summary>
        /// invoke method
        /// </summary>
        /// <param name="method">request string</param>
        /// <param name="assignMethodsName">assign Methods Name</param>
        /// <returns>method's result</returns>
        public static object Invoke(MethodSchema method, IList <string> assignMethodsName)
        {
            string methodName = method.MethodName;

            MethodContext context;

            if (!assignMethodsName.Contains(methodName) || !methods.TryGetValue(methodName, out context))
            {
                return(null);
            }
            ParameterInfo[] parameters = context.Parameters;

            for (int i = 0; i < parameters.Length; i++)
            {
                if (method.Parameters.ContainsKey(parameters[i].Name))
                {
                    var obj = BuildParameterValue(parameters[i], method.Parameters[parameters[i].Name]);
                    context.SetValue(i, obj);
                }
            }

            return(context.Invoke());
        }
예제 #6
0
        private static bool CheckMethod(MethodSchema methodSchema, string methodName
                                        , BeeDataAdapter dataAdapter, out BeeDataAdapter filteredData)
        {
            bool result = false;

            filteredData = new BeeDataAdapter();

            bool flag = true;
            List <ParameterInfo> customerTypeParaList = new List <ParameterInfo>();
            List <ParameterInfo> simpleTypeParaList   = new List <ParameterInfo>();

            foreach (ParameterInfo parameterInfo in methodSchema.ParameterInfos)
            {
                if (Type.GetTypeCode(parameterInfo.ParameterType) == TypeCode.Object &&
                    parameterInfo.ParameterType != typeof(Guid))
                {
                    customerTypeParaList.Add(parameterInfo);
                }
                else
                {
                    simpleTypeParaList.Add(parameterInfo);
                }
            }
            foreach (ParameterInfo parameterInfo in simpleTypeParaList)
            {
                // check the simple parameters name
                if (!dataAdapter.ContainsKey(parameterInfo.Name))
                {
                    flag = false;
                    break;
                }
            }

            if (flag)
            {
                foreach (ParameterInfo parameterInfo in simpleTypeParaList)
                {
                    filteredData.Add(parameterInfo.Name, dataAdapter[parameterInfo.Name]);
                }

                if (customerTypeParaList.Count == 0)
                {
                    result = true;
                }
                else
                {
                    bool allParameterFlag = true;
                    foreach (ParameterInfo parameterInfo in customerTypeParaList)
                    {
                        object dataValue = dataAdapter[parameterInfo.Name];
                        if (dataValue == null || parameterInfo.ParameterType != dataValue.GetType())
                        {
                            allParameterFlag = false;
                        }
                    }

                    if (allParameterFlag)
                    {
                        result = true;
                    }
                    else if (customerTypeParaList.Count == 1)
                    {
                        // try to match if possible
                        foreach (ParameterInfo parameterInfo in customerTypeParaList)
                        {
                            if (parameterInfo.ParameterType == typeof(BeeDataAdapter))
                            {
                                //dataAdapter.RemoveEmptyOrNull();
                                filteredData.Add(parameterInfo.Name, dataAdapter);
                            }
                            else
                            {
                                filteredData.Add(parameterInfo.Name,
                                                 ConvertUtil.ConvertDataToObject(parameterInfo.ParameterType, dataAdapter));
                                //dataAdapter.RemoveEmptyOrNull();
                            }
                        }

                        result = true;
                    }
                    else
                    {
                        // do nothing here.
                    }
                }
            }

            return(result);
        }
예제 #7
0
        /// <summary>
        /// 执行业务服务方法
        /// </summary>
        protected void ExecuteServiceMethod()
        {
            string serviceCode, methodName;

            serviceCode = Request["ServiceCode"];
            methodName  = Request["MethodName"];
            // 获得方法的定义
            MethodSchema method = AppUtility.Engine.BizBus.GetMethod(serviceCode, methodName);

            if (method == null)
            {
                return;
            }
            // 删除与组织结构对应的系统权限
            OThinker.H3.BizBus.BizService.BizStructure param = null;
            if (method.ParamSchema != null)
            {
                param = H3.BizBus.BizService.BizStructureUtility.Create(method.ParamSchema);
                if (method.ParamSchema.Items != null)
                {
                    foreach (ItemSchema item in method.ParamSchema.Items)
                    {
                        // 转换成相应的类型
                        object obj = null;
                        if (!OThinker.Data.Convertor.Convert(
                                Request[item.Name],
                                item.RealType,
                                ref obj))
                        {
                            Response.Write(string.Format("属性{0}的类型转换错误{1}", item.Name, item.RealType));
                        }
                        param[item.Name] = obj;
                    }
                }
            }

            // 调用方法
            OThinker.H3.BizBus.BizService.BizStructure ret = null;
            try
            {
                ret = AppUtility.Engine.BizBus.Invoke(
                    new BizBus.BizService.BizServiceInvokingContext(
                        UserValidatorFactory.CurrentUser != null ? UserValidatorFactory.CurrentUser.UserID : string.Empty,
                        serviceCode,
                        method.ServiceVersion,
                        method.MethodName,
                        param));
            }
            catch (Exception ex)
            {
                Response.Write(string.Format("系统出现异常->{0}", ex.ToString()));
            }
            if (ret != null && ret.Schema != null)
            {
                Dictionary <string, object> result = new Dictionary <string, object>();
                foreach (OThinker.H3.BizBus.BizService.ItemSchema item in ret.Schema.Items)
                {
                    if (item.LogicType == DataLogicType.BizStructure)
                    {
                        result.Add(item.Name, LoadBizStructure(ret[item.Name] as BizStructure));
                    }
                    else if (item.LogicType == DataLogicType.BizStructureArray)
                    {
                        result.Add(item.Name, LoadBizStructureArray(ret[item.Name]));
                    }
                    else
                    {
                        result.Add(item.Name, ret[item.Name]);
                    }
                }
                Response.Clear();
                Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(result));
                // Response.Write(JSSerializer.Serialize(result));
                Response.Buffer = true;
            }
        }