Пример #1
0
        public override void regAssembly()
        {
            Type[] types = this.assembly.GetTypes();
            if (types.Length < 1)
            {
                throw new Exception("在程序集" + assembly.FullName + "中,没有发现任何类");
            }

            Type type = types[0];

            WboSchema os = WboSchemaRegisterUtils.BuildObjectSchema <WboSchema>(type);

            os.Src = src;
            os.AssemblyCategory = AssemblyCategory.DotNet;
            os.AssemblyFile     = assemblyFile;
            os.Id = Path.GetFileNameWithoutExtension(assemblyFile) + "." + type.FullName;
            if (!WboSchemaContainer.Instance().Contains(os.Id))
            {
                WboSchemaContainer.Instance().AddItem(os.Id, os);
            }
            else
            {
                WboSchemaContainer.Instance().UpdateItem(os.Id, os);
            }
        }
Пример #2
0
        private static object InvokeMethod(object o, string wboId, string methodName, Dictionary <string, string> jsonNamedParams)
        {
            WboSchema wboSchema = WboSchemaContainer.Instance().GetItem(wboId);
            WboProxy  wbop      = WboProxyFactory.getWboProxy(wboSchema);

            return(wbop.invokeMethd(o, methodName, jsonNamedParams));
        }
Пример #3
0
        public void freeWbo(string wboName, string wboTypeId)
        {
            WboSchema objectSchema = WboSchemaContainer.Instance().GetItem(wboTypeId);

            WboProxy wboProxy = WboProxyFactory.getWboProxy(objectSchema);

            if (wboProxy.getWboType().IsSubclassOf(typeof(ISessionWbo)))
            {
                objectSchema.LifeCycle = LifeCycle.Session;
            }

            string objHashKey = getObjHashKey(objectSchema.Id, wboName);

            switch (objectSchema.LifeCycle)
            {
            case LifeCycle.Global:

                if (objects.ContainsKey(objHashKey))
                {
                    objects.Remove(objHashKey);
                }
                break;

            case LifeCycle.Session:
                string sesssionId = Session.SessionID;
                if (SessionObjects.ContainsKey(objHashKey))
                {
                    SessionObjects.Remove(objHashKey);
                }
                break;
            }
        }
Пример #4
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);
        }
Пример #5
0
        public object invoke(string req, Dictionary <string, string> jsonNamedParams)
        {
            if (string.IsNullOrEmpty(req))
            {
                throw new Exception(string.Format(Lang.RequestNameIsNull, req));
            }
            string memberName = null;
            string objName    = null;

            string[] names = req.Split('.');
            string   comId = names[0];
            object   obj;

            if (USER_COMID.Equals(comId, StringComparison.OrdinalIgnoreCase))
            {
                obj = security.user;
                if (names.Length == 1)
                {
                    return(obj);
                }
                PropertyInfo pi = obj.GetType().GetProperty(names[1]);
                return(pi.GetValue(obj, null));
            }

            WboSchema wboSchema = WboSchemaContainer.Instance().GetItem(comId);
            WboProxy  wbop      = WboProxyFactory.getWboProxy(wboSchema);

            if (names.Length > 1)
            {
                memberName = names[names.Length - 1];
                if (wbop.hasMember(memberName))
                {
                    objName = UmcTools.getObjName(names, 1, names.Length - 2);
                }
                else
                {
                    // memberName = null;
                    objName = UmcTools.getObjName(names, 1);
                    if (!string.IsNullOrEmpty(objName))
                    {
                        memberName = null;
                    }
                }
            }

            checkPermission(comId, objName, memberName, wboSchema);

            obj = GetObject(objName, comId);

            if (string.IsNullOrEmpty(memberName))
            {
                return(obj);
            }

            return(invoke(obj, comId, objName, memberName, jsonNamedParams));
        }
Пример #6
0
        /// <summary>
        /// 注册系统内置组件,组件Id默认为组件类名
        /// </summary>
        /// <param name="type"></param>
        public static void RegisterClass(Type type)
        {
            WboSchema os = WboSchemaRegisterUtils.BuildObjectSchema <WboSchema>(type);

            os.AssemblyCategory = AssemblyCategory.DotNet;
            if (!WboSchemaContainer.Instance().Contains(os.Id))
            {
                WboSchemaContainer.Instance().AddItem(os.Id, os);
            }
        }
Пример #7
0
        /// <summary>
        /// 通过传入wboSchema对象构架,和wbo对象的方法名及命名参数列表,调用methodName指定的方法
        /// </summary>
        /// <param name="wboSchema">要调用的对象的对象架构</param>
        /// <param name="memberName">要调用的方法名称</param>
        /// <param name="jsonNamedParams">json命名参数列表规范的参数</param>
        /// <returns>methodName指定的方法的返回结果</returns>
        public object Invoke(string wboId, string objectName, string memberName, Dictionary <string, string> jsonNamedParams)
        {
            WboSchema wboSchema = WboSchemaContainer.Instance().GetItem(wboId);
            object    obj       = GetObject(objectName, wboId);
            WboProxy  wbop      = WboProxyFactory.getWboProxy(wboSchema);

            checkPermission(wboId, objectName, memberName, wboSchema);

            return(wbop.invoke(obj, memberName, jsonNamedParams));
        }
Пример #8
0
        public object GetObject(string objectName, string comId)
        {
            //            log.Debug("WboSchemaContainer.Instance().GetItem(objectType)");
            WboSchema objectSchema = WboSchemaContainer.Instance().GetItem(comId);

            //            log.Debug("end WboSchemaContainer.Instance().GetItem(objectType)");
            object obj = GetObject(objectName, objectSchema);

            return(obj);
        }
Пример #9
0
        public static object invoke(object o, string comId, string objName, string memberName, Dictionary <string, string> jsonNamedParams)
        {
            //WboProxy wp = WboProxyFactory.getWboProxy(objectSchema);
            if (string.IsNullOrEmpty(memberName))
            {
                return(o);
            }

            WboSchema objectSchema = WboSchemaContainer.Instance().GetItem(comId);
            WboProxy  wp           = WboProxyFactory.getWboProxy(objectSchema);

            return(wp.invoke(o, memberName, jsonNamedParams));
        }
Пример #10
0
        private object invoke(string comId, string memberName, Dictionary <string, string> jsonNamedParams)
        {
            WboSchema objectSchema = WboSchemaContainer.Instance().GetItem(comId);
            object    obj          = GetObject(null, objectSchema);

            if (string.IsNullOrEmpty(memberName))
            {
                return(obj);
            }
            WboProxy wp = WboProxyFactory.getWboProxy(objectSchema);

            return(wp.invoke(obj, memberName, jsonNamedParams));
        }
Пример #11
0
 public static string getComId(Type type)
 {
     string[] typeIds = WboSchemaContainer.Instance().GetSchemaIds();
     foreach (string comId in typeIds)
     {
         WboSchema schema  = WboSchemaContainer.Instance().GetItem(comId);
         Type      regType = WboProxyFactory.getWboProxy(schema).getWboType();
         if (regType.Equals(type))
         {
             return(comId);
         }
     }
     return(type.Name);
 }
Пример #12
0
        public object setWbo(string comId, string wboName, string wboJSON)
        {
            WboSchema objectSchema = WboSchemaContainer.Instance().GetItem(comId);
            WboProxy  wboProxy     = WboProxyFactory.getWboProxy(objectSchema);

            object wbo;

            try
            {
                wbo = JsonConvert.DeserializeObject(wboJSON, wboProxy.getWboType());
            }
            catch
            {
                throw new XException(string.Format(Lang.WboTypeNotMatchComId, comId));
            }

            if (wboProxy.getWboType().IsSubclassOf(typeof(ISessionWbo)))
            {
                objectSchema.LifeCycle = LifeCycle.Session;
            }

            string objHashKey = getObjHashKey(objectSchema.Id, wboName);

            switch (objectSchema.LifeCycle)
            {
            case LifeCycle.Global:
                if (objects.ContainsKey(objHashKey))
                {
                    objects[objHashKey] = wbo;
                }
                else
                {
                    objects.Add(objHashKey, wbo);
                }
                break;

            case LifeCycle.Session:
                string sesssionId = Session.SessionID;
                if (SessionObjects.ContainsKey(objHashKey))
                {
                    SessionObjects[objHashKey] = wbo;
                }
                else
                {
                    SessionObjects.Add(objHashKey, wbo);
                }
                break;
            }
            return(wbo);
        }
Пример #13
0
        public static void regType(Type type, string src, AssemblyCategory srcType, string filePath)
        {
            WboSchema os = WboSchemaRegisterUtils.BuildObjectSchema <WboSchema>(type);

            os.Src = src;
            os.AssemblyCategory = AssemblyCategory.DotNet;
            os.AssemblyFile     = filePath;

            if (!WboSchemaContainer.Instance().Contains(os.Id))
            {
                WboSchemaContainer.Instance().AddItem(os.Id, os);
            }
            else
            {
                WboSchemaContainer.Instance().UpdateItem(os.Id, os);
            }
        }
Пример #14
0
        public T GetObject <T>(string objectName)
        {
            string comId = WboSchemaRegisterUtils.getTypeRegId(typeof(T));

            if (!WboSchemaContainer.Instance().Contains(comId))
            {
                throw new E_UmcNotFindRegObjcect(comId);
            }
            WboSchema objectSchema = WboSchemaContainer.Instance().GetItem(comId);

            object obj = GetObject(objectName, objectSchema);

            if (obj == null)
            {
                throw new E_UmcNotFindRegObjcect(objectName);
            }

            if (!(obj is T))
            {
                throw new E_UmcNoMatchObjectType(obj.GetType().ToString() + ":" + typeof(T).ToString());
            }

            return((T)obj);
        }
Пример #15
0
 protected BaseWboProxy(string objectTypeName)
 {
     this.wboSchema = WboSchemaContainer.Instance().GetItem(objectTypeName);
     loadAssembly();
 }