Пример #1
0
        ///// <summary>
        ///// 执行对象中的一个方法
        ///// </summary>
        ///// <param name="wboSchema"></param>
        ///// <param name="methodId"></param>
        ///// <param name="namedParameters"></param>
        ///// <returns></returns>
        //public static object InvokeMethod(object obj, string methodId, Dictionary<string, object> namedParameters)
        //{
        //    Type t = obj.GetType();
        //    MethodInfo method = t.GetMethod(methodId);
        //    if (method == null)
        //    {
        //        throw new Exception("对象方法没有找到" + t.Name + "." + methodId);
        //    }
        //    ParameterInfo[] pInfos = method.GetParameters();
        //    object[] parameters = GetParameters(pInfos, namedParameters);
        //    return method.Invoke(obj, parameters);
        //}

        //public static MethodInfo GetClassMethodInfo(string objectType, string methodName)
        //{
        //    WboSchema objectSchema = WboSchemaContainer.Instance().GetItem(objectType);

        //    Assembly assembly = Assembly.Load(objectSchema.AssemblyName);
        //    Type t = assembly.GetType(objectSchema.ClassName, true);
        //    MethodInfo method = t.GetMethod(methodName);

        //    if (method == null)
        //    {
        //        throw new Exception("对象方法没有找到" + t.Name + "." + methodName);
        //    }

        //    return method;
        //}

        //public static ParameterInfo GetClassMethodParamInfo(string objectType, string methodName, string paramName)
        //{
        //    MethodInfo m = GetClassMethodInfo(objectType, methodName);
        //    ParameterInfo[] pars = m.GetParameters();
        //    for (int i = 0; i < pars.Length; i++)
        //    {
        //        if (pars[i].Name.Equals(paramName, StringComparison.OrdinalIgnoreCase))
        //            return pars[i];
        //    }
        //    return null;
        //}

        public static PermissionTypes GetObjectPermissionTypes(string objectType, string methodName)
        {
            WboSchema       objectSchema = WboSchemaContainer.Instance().GetItem(objectType);
            WboMethodSchema wms          = objectSchema.Methods.GetItem(methodName);

            return(wms.PermissionTypes);
        }
Пример #2
0
        private void checkPermission(string wboId, string objectName, string memberName, WboSchema wboSchema)
        {
            if (wboId.Equals("Security"))
            {
                return;
            }

            PermissionTypes mPermission = wboSchema.PermissionTypes;


            string objId = wboId;

            if (!string.IsNullOrEmpty(objectName))
            {
                objId += "." + objectName;
            }

            if (!string.IsNullOrEmpty(memberName))
            {
                WboMethodSchema wms = wboSchema.Methods.FindItem(memberName);
                Schema          wmp = wboSchema.Properties.FindItem(memberName);
                if (wms == null && wmp == null)
                {
                    throw new Exception(wboId + "." + memberName + "没有注册不能调用");
                }
                if (wms != null)
                {
                    mPermission = wms.PermissionTypes;
                }
                if (wmp != null)
                {
                    mPermission = PermissionTypes.Read;
                }

                objId += "." + memberName;
            }

            if (wboId.Equals("ds"))
            {
                Security.CheckObjectPermission(null, objectName, mPermission);
            }
            else
            {
                Security.CheckObjectPermission(null, objId, mPermission);
            }
        }
Пример #3
0
        /// <summary>
        /// 生存Wbo对象的架构实体WboSchema
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="type"></param>
        /// <returns></returns>
        public static T BuildObjectSchema <T>(Type type, string comId)
            where T : WboSchema, new()
        {
            T os = null;

            os              = new T();
            os.Src          = type.Assembly.Location;
            os.AssemblyName = type.Assembly.FullName;
            os.ClassName    = type.FullName;
            os.Id           = type.Name.Replace("<>", "");
            if (!string.IsNullOrEmpty(comId))
            {
                os.Id = comId;
            }
            os.Title    = os.Id;
            os.IsVisual = type.GetInterface(typeof(IVisualWbo).FullName) != null;


            Object[] webserviceAttrs = type.GetCustomAttributes(typeof(System.Web.Services.WebServiceBindingAttribute), true);

            if (webserviceAttrs.Length > 0)
            {
                os.Namespace = ((WebServiceBindingAttribute)webserviceAttrs[0]).Namespace;
            }
            else
            {
                os.Namespace = type.Namespace;
            }

            //else
            //    os.Namespace = os.ClassName.Substring(0, os.ClassName.LastIndexOf('.'));
            Object[] objAttrs = type.GetCustomAttributes(typeof(WboAttr), true);
            foreach (Attribute attr in objAttrs)
            {
                WboAttr umcAttr = attr as WboAttr;
                if (umcAttr != null)
                {
                    os.LifeCycle = umcAttr.LifeCycle;
                    if (!String.IsNullOrEmpty(umcAttr.Title))
                    {
                        os.Title = umcAttr.Title;
                    }
                    if (!String.IsNullOrEmpty(umcAttr.Id))
                    {
                        os.Id = umcAttr.Id;
                    }
                    os.Description = umcAttr.Description;

                    if (umcAttr.ContainerType != null)
                    {
                        os.ContainterType = umcAttr.ContainerType.AssemblyQualifiedName;
                    }
                    os.IsPublish = umcAttr.IsPublish;
                }
            }

            MethodInfo[] methods = type.GetMethods();

            for (int i = 0; i < methods.Length; i++)
            {
                MethodInfo mi         = methods[i];
                string     methodName = mi.Name;
                if (methodName.StartsWith("set_") || methodName.StartsWith("get_"))
                {
                    string propHame = methodName.Substring(4);
                    if (type.GetProperty(propHame) != null)
                    {
                        continue;
                    }
                }

                Object[]        methodAttrs = mi.GetCustomAttributes(typeof(WboMethodAttr), true);
                WboMethodSchema wms         = new WboMethodSchema();
                wms.Id    = methodName;
                wms.Title = wms.Id;
                foreach (Attribute attr in methodAttrs)
                {
                    WboMethodAttr wma = attr as WboMethodAttr;
                    wms.Id    = methodName;
                    wms.Title = wms.Id;
                    if (!String.IsNullOrEmpty(wma.Title))
                    {
                        wms.Title = wma.Title;
                    }
                    wms.Description     = wma.Description;
                    wms.PermissionTypes = wma.PermissionTypes;
                    //   os.Methods.Add(wms);
                }

                // string methodName = methods[i].Name;
                wms.ReturnType = methods[i].ReturnType.ToString();
                //FunctionSchema fun = new FunctionSchema();
                //fun.Id = methodName;
                //fun.ObjectId = os.Id;
                //fun.MethodName = methods[i].Name;
                //fun.ReturnValue = methods[i].ReturnType.ToString();

                ParameterInfo[] paramInfos = methods[i].GetParameters();

                for (int j = 0; j < paramInfos.Length; j++)
                {
                    ParameterInfo pi = paramInfos[j];
                    //  ParamDef paramDef = new ParamDef();
                    //  paramDef.ParamName = pi.Name;
                    //  paramDef.DataType = pi.ParameterType.AssemblyQualifiedName;
                    //  fun.ParamDefs.Add(paramDef);
                    WboMethodParamSchema wmps = new WboMethodParamSchema();
                    wmps.DataType = pi.ParameterType.AssemblyQualifiedName;
                    wmps.Title    = pi.Name;
                    wmps.Id       = pi.Name;
                    if (pi.DefaultValue != null)
                    {
                        wmps.DefaultValue = pi.DefaultValue.ToString();
                    }
                    wms.Params.Add(wmps);
                }
                if (!os.Methods.Contains(wms))
                {
                    os.Methods.Add(wms);
                }
            }


            PropertyInfo[] pis = type.GetProperties();
            for (int i = 0; i < pis.Length; i++)
            {
                object[]     pAttrs = pis[i].GetCustomAttributes(typeof(WboPropertyAttr), true);
                PropertyInfo pi     = pis[i];
                Schema       pros   = new Schema();
                pros.Id = pi.Name;

                foreach (WboPropertyAttr prAttr in pAttrs)
                {
                    pros.Description = prAttr.Description;
                    pros.Title       = prAttr.Title;
                }

                os.Properties.Add(pros);
            }

            if (type.IsSubclassOf(typeof(ISessionWbo)))
            {
                os.LifeCycle = LifeCycle.Session;
            }

            return(os);
        }