Exemplo n.º 1
0
        private void ParseEntity(CodeClass codeClass)
        {
            _currentType             = new EntityType();
            _currentType.Name        = codeClass.Name;
            _currentType.FullName    = codeClass.FullName;
            _currentType.CodeElement = codeClass;
            var baseType = Helper.GetBaseClass(codeClass);

            if (baseType != null)
            {
                _currentType[BaseTypeFullNameProperty] = baseType.FullName;
            }
            //使用 Attribute 来进行检测是否为聚合根。
            foreach (CodeAttribute attri in codeClass.Attributes)
            {
                if (attri.FullName == Consts.RootEntityAttributeClassFullName)
                {
                    _currentType.IsAggtRoot = true;
                    break;
                }
            }

            //获取模型的注释。
            TryParseDomainName(_currentType, codeClass.DocComment);

            base.VisitClass(codeClass);

            _entityTypes.Add(_currentType);
            _currentType = null;
        }
Exemplo n.º 2
0
        public static EntityTypeCollection GetCollection(EntityEnum entityName)
        {
            EntityTypeCollection tempList = null;
           
            using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("usp_GetEntityType", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;
                    myCommand.Parameters.AddWithValue("@QueryId", SelectTypeEnum.GetCollectionByName);
                    myCommand.Parameters.AddWithValue("@EntityName", entityName.ToString());
                    myConnection.Open();
                    using (SqlDataReader myReader = myCommand.ExecuteReader())
                    {
                        if (myReader.HasRows)
                        {
                            tempList = new EntityTypeCollection();
                            while (myReader.Read())
                            {
                                tempList.Add(FillDataRecord(myReader));
                            }

                        }
                        myReader.Close();
                    }
                }
            }

            return tempList;
        }
Exemplo n.º 3
0
        public static EntityTypeCollection GetCollection(EntityEnum entityName)
        {
            EntityTypeCollection tempList = null;

            using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("usp_GetEntityType", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    myCommand.Parameters.AddWithValue("@QueryId", SelectTypeEnum.GetCollectionByName);
                    myCommand.Parameters.AddWithValue("@EntityName", entityName.ToString());

                    myConnection.Open();
                    using (SqlDataReader myReader = myCommand.ExecuteReader())
                    {
                        if (myReader.HasRows)
                        {
                            tempList = new EntityTypeCollection();
                            while (myReader.Read())
                            {
                                tempList.Add(FillDataRecord(myReader));
                            }
                        }
                        myReader.Close();
                    }
                }
            }
            return(tempList);
        }
Exemplo n.º 4
0
        public void ApplyAttributesPatch(EntityTypeCollection entityTypeCollection, AttributesPatch attributesPatch)
        {
            logger.Log("[ APPLYING ENTITY TYPE ATTRIBUTES ]");

            foreach (var kvp in attributesPatch.Entities)
            {
                string          entityTypeName  = kvp.Key;
                EntityTypePatch entityTypePatch = kvp.Value;

                EntityTypeAttributes entityType;
                if (!entityTypePatch.CloneFrom.IsNullOrEmpty())
                {
                    EntityTypeAttributes toClone = entityTypeCollection.GetEntityType(entityTypePatch.CloneFrom);
                    if (toClone == null)
                    {
                        logger.Log($"ERROR: CloneFrom {entityTypePatch.CloneFrom} attributes not found");
                        continue;
                    }

                    entityType = new EntityTypeAttributes(entityTypeName)
                    {
                        Flags = toClone.Flags
                    };

                    var attributes = toClone.GetAll <object>();
                    foreach (var w in attributes)
                    {
                        entityType.Add(w);
                    }

                    entityTypeCollection.Add(entityType);

                    logger.BeginScope($"Cloned {entityTypeName} from {entityTypePatch.CloneFrom}").Dispose();
                }
                else
                {
                    entityType = entityTypeCollection.GetEntityType(entityTypeName);
                }

                using (logger.BeginScope($"EntityType: {entityTypeName}"))
                {
                    if (entityType == null)
                    {
                        if (entityTypePatch.CloneFrom.IsNullOrEmpty())
                        {
                            logger.Log("NOTICE: EntityType not found");
                        }
                        else
                        {
                            logger.Log("ERROR: Entity cloning failed");
                        }
                        continue;
                    }

                    ApplyEntityTypePatch(entityType, entityTypePatch);
                }
            }

            if (attributesPatch.Global != null)
            {
                logger.Log("[ APPLYING GLOBAL TYPE ATTRIBUTES ]");
                //logger.enable = false;
                notFoundErrors = false;
                foreach (var kvp in entityTypeCollection.GetAllEntityTypeNames())
                {
                    using (logger.BeginScope($"{kvp}:"))
                    {
                        ApplyEntityTypePatch(entityTypeCollection.GetEntityType(kvp), attributesPatch.Global);
                    }
                }
                //logger.enable = true;
                notFoundErrors = true;
            }

            Debug.Log($"[SUBSYSTEM] Applied attributes patch. See Subsystem.log for details.");
        }