コード例 #1
0
ファイル: EntityFactory.cs プロジェクト: wufenglu/BMSNetCore
        /// <summary>
        /// 执行
        /// </summary>
        /// <typeparam name="Tentity"></typeparam>
        /// <returns></returns>
        public static Tentity New <Tentity>() where Tentity : class, new()
        {
            Tentity result     = new Tentity();
            Type    entityType = typeof(Tentity);

            //文件名为源类的命名空间+类名
            string fileName = (entityType.Namespace + "." + entityType.Name).Replace(".", "_");
            //代理类的全称
            string namespaceName     = "Proxy.GenerateClass." + entityType.Namespace.Replace(".", "_");
            string loadClassFullName = namespaceName + "." + entityType.Name;
            object cacheValue        = CachesHelper.Get(loadClassFullName);

            if (cacheValue != null)
            {
                return((Tentity)System.Activator.CreateInstance(cacheValue.GetType()));
            }

            string generateCode = GenerateCode <Tentity>(fileName, namespaceName);

            result = GetTentity <Tentity>(generateCode, loadClassFullName);
            CachesHelper.Set(loadClassFullName, result);

            return((Tentity)System.Activator.CreateInstance(result.GetType()));
        }
コード例 #2
0
        /// <summary>
        /// 租户实体对象
        /// </summary>
        /// <returns></returns>
        internal List <OrganizationEntity> GetOrganizationEntitys()
        {
            List <OrganizationEntity> list = (List <OrganizationEntity>)CachesHelper.Get("OrganizationsEntitys");

            //存在缓存则直接返回,否则实例化对象
            if (list == null)
            {
                list = new List <OrganizationEntity>();
            }
            else
            {
                return(list);
            }

            string      fileUrl = Path.Combine(Directory.GetCurrentDirectory(), "/App_Data/Organization.xml");
            XmlDocument xd      = new XmlDocument();

            xd.Load(fileUrl);
            XmlNodeList xmlNodeList = xd.SelectSingleNode("Organizations").ChildNodes;

            //循环遍历租户
            foreach (XmlNode item in xmlNodeList)
            {
                //如果是注释节点则跳出
                if (item.NodeType == XmlNodeType.Comment)
                {
                    continue;
                }
                OrganizationEntity entity = new OrganizationEntity();

                #region 获取节点实体
                foreach (XmlNode childItem in item.ChildNodes)
                {
                    #region Tenants对象赋值
                    string value = childItem.InnerText;
                    switch (childItem.Name.ToLower())
                    {
                    case "name":
                        entity.Name = value;
                        break;

                    case "code":
                        entity.Code = value;
                        break;

                    case "provider":
                        entity.Provider = value;
                        break;

                    case "connectionstring":
                        entity.Connectionstring = value;
                        break;

                    case "state":
                        entity.State = value.ToInt();
                        break;

                    case "slaves":
                        entity.Slaves = new List <OrganizationSalves>();
                        foreach (XmlNode interfaceItem in childItem.ChildNodes)
                        {
                            #region InterfacePostData实体赋值
                            OrganizationSalves model = new OrganizationSalves();
                            foreach (XmlNode interfaceChildItem in interfaceItem)
                            {
                                switch (interfaceChildItem.Name.ToLower())
                                {
                                case "connectionstring":
                                    model.Connectionstring = interfaceChildItem.ChildNodes[0].InnerText;
                                    break;

                                case "proportion":
                                    model.Proportion = interfaceChildItem.ChildNodes[0].InnerText.ToDecimal();
                                    break;

                                case "state":
                                    model.State = value.ToInt();
                                    break;
                                }
                            }
                            entity.Slaves.Add(model);
                            #endregion
                        }
                        break;
                    }
                    #endregion
                }
                #endregion

                list.Add(entity);
            }
            CachesHelper.Set("OrganizationsEntitys", list);
            return(list);
        }