Пример #1
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;
            }
        }
Пример #2
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);
        }
Пример #3
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);
            }
        }
Пример #4
0
        private static object CreateObject(WboSchema objectSchema, string objectName)
        {
            WboProxy wboProxy = WboProxyFactory.getWboProxy(objectSchema);

            //从持久存档文件中获取对象
            string file = getWboFileName(objectName, objectSchema.Id);

            if (File.Exists(file))
            {
                XmlReader xmlReader = XmlReader.Create(file);

                try
                {
                    if (xmlReader == null)
                    {
                        throw (new EContainerCanNotOpenSchameFile());
                    }
                    XmlSerializer xmls = new XmlSerializer(wboProxy.getWboType());
                    return(xmls.Deserialize(xmlReader));
                }
                catch (Exception e)
                {
                    throw new Exception("打开文件" + file + "时发生错误." + e.Message, e);
                }
                finally
                {
                    xmlReader.Close();
                }
            }


            return(wboProxy.createObject(objectName));
        }
Пример #5
0
        /// <summary>
        /// 根据对象构架创建对象
        /// </summary>
        /// <param name="objectSchema"></param>
        /// <returns></returns>
        public static object CreateObject(WboSchema objectSchema)
        {
            Assembly assembly = Assembly.Load(objectSchema.AssemblyName);
            object   obj      = assembly.CreateInstance(objectSchema.ClassName, true);

            return(obj);
        }
Пример #6
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));
        }
Пример #7
0
        public static object CreateObject(WboSchema objectSchema, string objectName)
        {
            Assembly        assembly = Assembly.Load(objectSchema.AssemblyName);
            Type            t        = assembly.GetType(objectSchema.ClassName, true);
            ConstructorInfo c        = t.GetConstructor(new Type[] { typeof(string) });
            object          obj      = c.Invoke(new object[] { objectName });

            return(obj);
        }
Пример #8
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));
        }
Пример #9
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);
        }
Пример #10
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);
            }
        }
Пример #11
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));
        }
Пример #12
0
 public static Assembly getAssembly(WboSchema wboSchema)
 {
     if (!string.IsNullOrEmpty(wboSchema.AssemblyFile))
     {
         return(getAssembly(wboSchema.AssemblyFile));
     }
     else
     {
         return(getAssembly(wboSchema.AssemblyName));
     }
 }
Пример #13
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));
        }
Пример #14
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));
        }
Пример #15
0
        public static WboProxy getWboProxy(WboSchema wboSchema)
        {
            switch (wboSchema.AssemblyCategory)
            {
            case AssemblyCategory.DotNet:
                return(new DotNetWboProxy(wboSchema));

            case AssemblyCategory.WebService:
                return(new DotNetWboProxy(wboSchema));

            default:
                throw new XException("系统目前不支持,这种程序类型");
            }
        }
Пример #16
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);
        }
Пример #17
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);
 }
Пример #18
0
        private object GetSessionObject(WboSchema objectSchema, string objectName)
        {
            string sesssionId = Session.SessionID;
            string objHashKey = getObjHashKey(objectSchema.Id, objectName);
            object obj        = null;

            if (!SessionObjects.ContainsKey(objHashKey))
            {
                log.Debug("start getObject By Create new,object is" + objectName);
                obj = CreateObject(objectSchema, objectName);
                SessionObjects.Add(objHashKey, obj);
                log.Debug("End getObject By Create new,object is" + objectName);
            }
            obj = SessionObjects[objHashKey];
            return(obj);
        }
Пример #19
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);
            }
        }
Пример #20
0
        private object GetObject(string objectName, WboSchema objectSchema)
        {
            string sessionId = context.Session.SessionID;
            object obj       = null;

            //    log.Debug("\n");

            //    log.Debug("start getObject,object is" + objectName);

            WboProxy wboProxy = WboProxyFactory.getWboProxy(objectSchema);

            if (wboProxy.getWboType().IsSubclassOf(typeof(ISessionWbo)))
            {
                obj = GetSessionObject(objectSchema, objectName);
            }
            else
            {
                switch (objectSchema.LifeCycle)
                {
                case LifeCycle.Global:
                    log.Debug(" start getObject from globle ");
                    obj = GetGlobalObject(objectSchema, objectName);
                    break;

                case LifeCycle.Session:
                    log.Debug("start getObject from session: " + sessionId + ", object:" + objectName);
                    obj = GetSessionObject(objectSchema, objectName);
                    break;

                default:
                    obj = CreateObject(objectSchema, objectName);
                    break;
                }
            }

            if (obj is IHttpHandler)
            {
                (obj as IHttpHandler).ProcessRequest(context);
            }
            if (obj is IHttpWbo)
            {
                (obj as IHttpWbo).setContext(this);
            }
            return(obj);
        }
Пример #21
0
        private static object GetGlobalObject(WboSchema objectSchema, string objectName)
        {
            object obj = null;

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

            if (objects.ContainsKey(objHashKey))
            {
                obj = objects[objHashKey];
            }
            else
            {
                obj = CreateObject(objectSchema, objectName);
                if (obj != null)
                {
                    objects.Add(objHashKey, obj);
                }
            }

            return(obj);
        }
Пример #22
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);
        }
Пример #23
0
 /// <summary>
 /// 通过Wbo对象构架(WboSchema) 加载代理
 /// </summary>
 /// <param name="wboSchema">Wbo对象构架</param>
 public DotNetWboProxy(WboSchema wboSchema) :
     base(wboSchema)
 {
 }
Пример #24
0
 /// <summary>
 /// 通过Wbo对象构架(WboSchema) 加载代理
 /// </summary>
 /// <param name="wboSchema">Wbo对象构架</param>
 public ComWboProxy(WboSchema wboSchema) :
     base(wboSchema)
 {
 }
Пример #25
0
 protected BaseWboProxy(WboSchema wboSchema)
 {
     this.wboSchema = wboSchema;
     loadAssembly();
 }
Пример #26
0
 protected BaseWboProxy(string objectTypeName)
 {
     this.wboSchema = WboSchemaContainer.Instance().GetItem(objectTypeName);
     loadAssembly();
 }
Пример #27
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);
            }
        }