コード例 #1
0
    // Use this for initialization
    void Start()
    {
        EntityRegister register = GetComponent <EntityRegister>();

        if (register == null)
        {
            register = gameObject.AddComponent <EntityRegister>();
        }

        id = IDCaculater.TransformIdInSceneHierachy(transform);
        //register to aoi
        register.Regist(id);
        register.RegistAOI(id, gameObject);

        fightAgent = gameObject.GetComponent <DefenseTowerAgent>();
        if (fightAgent != null)
        {
            //Data Model setting
            fightAgent.Id       = id;
            fightAgent.AtkRange = 20f;
            fightAgent.AtkSpeed = 2f;
            //start ai
            fightAgent.Initial();
            fightAgent.StartAI();
        }

        //Invoke("MakeDeath", 15f);
    }
コード例 #2
0
        public EdmModel Build(StoreSchemaDetails storeSchemaDetails)
        {
            Debug.Assert(storeSchemaDetails != null, "storeSchemaDetails != null");

            var entityRegister = new EntityRegister();
            CreateEntitySets(
                storeSchemaDetails.TableDetails,
                storeSchemaDetails.ViewDetails,
                entityRegister);

            var associationTypes = new List<AssociationType>();
            var associationSets =
                CreateAssociationSets(
                    storeSchemaDetails.RelationshipDetails,
                    entityRegister,
                    associationTypes);

            var entityContainer =
                EntityContainer.Create(
                    _namespaceName.Replace(".", string.Empty) + "Container",
                    DataSpace.SSpace,
                    entityRegister.EntitySets.Union<EntitySetBase>(associationSets),
                    null,
                    null);

            var storeModel =
                EdmModel.CreateStoreModel(
                    entityContainer,
                    new DbProviderInfo(_providerInvariantName, _providerManifestToken),
                    null,
                    EntityFrameworkVersion.VersionToDouble(_targetEntityFrameworkVersion));

            foreach (var entityType in entityRegister.EntityTypes)
            {
                storeModel.AddItem(entityType);
            }

            foreach (var associationType in associationTypes)
            {
                storeModel.AddItem(associationType);
            }

            var functions = CreateFunctions(storeSchemaDetails.FunctionDetails, storeSchemaDetails.TVFReturnTypeDetails);
            foreach (var function in functions)
            {
                storeModel.AddItem(function);
            }

            return storeModel;
        }
コード例 #3
0
        internal List<AssociationSet> CreateAssociationSets(
            IEnumerable<RelationshipDetailsRow> relationshipDetailsRows,
            EntityRegister entityRegister,
            List<AssociationType> associationTypes)
        {
            Debug.Assert(relationshipDetailsRows != null, "relationshipDetailsRows != null");
            Debug.Assert(entityRegister != null, "entityRegister != null");
            Debug.Assert(associationTypes != null, "associationTypes != null");

            var associationSets = new List<AssociationSet>();
            var rowGroups =
                relationshipDetailsRows
                    .GroupBy(row => row.RelationshipId)
                    .Select(g => g.ToList());

            foreach (var group in rowGroups)
            {
                var set = TryCreateAssociationSet(group, entityRegister, associationTypes);
                if (set != null)
                {
                    associationSets.Add(set);
                }
            }

            return associationSets;
        }
コード例 #4
0
        // internal for testing
        internal void CreateEntitySets(
            IEnumerable<TableDetailsRow> tableDetailsRows,
            EntityRegister entityRegister,
            IList<EntitySet> entitySetsForReadOnlyEntityTypes,
            DbObjectType objectType)
        {
            Debug.Assert(tableDetailsRows != null, "tableDetailsRows != null");
            Debug.Assert(entityRegister != null, "entityRegister != null");
            Debug.Assert(entitySetsForReadOnlyEntityTypes != null, "entitySetsForReadOnlyEntityTypes != null");
            Debug.Assert(
                objectType == DbObjectType.Table || objectType == DbObjectType.View,
                "Unexpected object type - only tables and views are supported");

            foreach (var tableDetailsRowsForTable in SplitRows(tableDetailsRows))
            {
                var firstRow = tableDetailsRowsForTable[0];

                bool needsDefiningQuery;
                var entityType = CreateEntityType(tableDetailsRowsForTable, out needsDefiningQuery);
                entityRegister.AddEntityType(firstRow.GetMostQualifiedTableName(), entityType);

                // skip EntitySet creation for invalid entity types. We still need the types themselves - they
                // will be written to the ssdl in comments for informational and debugging purposes.
                if (!MetadataItemHelper.IsInvalid(entityType))
                {
                    var entitySet =
                        EntitySet.Create(
                            entityType.Name,
                            !firstRow.IsSchemaNull() ? firstRow.Schema : null,
                            firstRow.TableName != entityType.Name ? firstRow.TableName : null,
                            null,
                            entityType,
                            new[]
                                {
                                    CreateStoreModelBuilderMetadataProperty(
                                        TypeAttributeName,
                                        objectType == DbObjectType.Table
                                            ? TablesTypeAttributeValue
                                            : ViewsTypeAttributeValue)
                                });

                    if (needsDefiningQuery)
                    {
                        entitySetsForReadOnlyEntityTypes.Add(entitySet);
                    }
                    else
                    {
                        entityRegister.AddEntitySet(entitySet);
                    }
                }
            }
        }
コード例 #5
0
        // internal for testing
        internal void CreateEntitySets(
            IEnumerable<TableDetailsRow> tableDetailsRowsForTables,
            IEnumerable<TableDetailsRow> tableDetailsRowsForViews,
            EntityRegister entityRegister)
        {
            Debug.Assert(tableDetailsRowsForTables != null, "tableDetailsRowsForTables != null");
            Debug.Assert(tableDetailsRowsForViews != null, "tableDetailsRowsForViews != null");
            Debug.Assert(entityRegister != null, "entityRegister != null");

            var entitySetsForReadOnlyEntityTypes = new List<EntitySet>();

            CreateEntitySets(tableDetailsRowsForTables, entityRegister, entitySetsForReadOnlyEntityTypes, DbObjectType.Table);

            CreateEntitySets(tableDetailsRowsForViews, entityRegister, entitySetsForReadOnlyEntityTypes, DbObjectType.View);

            if (entitySetsForReadOnlyEntityTypes.Any())
            {
                // readonly entity sets need to be rewritten so that they 
                // contain provider specific SQL query to retrieve the data
                entityRegister.AddEntitySets(
                    EntitySetDefiningQueryConverter.Convert(
                        entitySetsForReadOnlyEntityTypes,
                        _targetEntityFrameworkVersion,
                        _providerInvariantName,
                        _providerManifestToken,
                        _dependencyResolver));
            }
        }
コード例 #6
0
        private static EntityType TryGetEndEntity(EntityRegister entityRegister, string key, List<EdmSchemaError> errors)
        {
            EntityType type;
            if (entityRegister.EntityLookup.TryGetValue(key, out type)
                && !MetadataItemHelper.IsInvalid(type))
            {
                return type;
            }

            errors.Add(
                new EdmSchemaError(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources_VersioningFacade.TableReferencedByAssociationWasNotFound,
                        key),
                    (int)ModelBuilderErrorCode.MissingEntity,
                    EdmSchemaErrorSeverity.Error));

            return null;
        }
コード例 #7
0
        private static AssociationSet CreateAssociationSet(AssociationType associationType, EntityRegister entityRegister)
        {
            Debug.Assert(associationType.AssociationEndMembers.Count == 2);

            var sourceEnd = associationType.AssociationEndMembers[0];
            var targetEnd = associationType.AssociationEndMembers[1];

            EntitySet sourceSet, targetSet;
            if (!entityRegister.EntityTypeToSet.TryGetValue(sourceEnd.GetEntityType(), out sourceSet)
                || !entityRegister.EntityTypeToSet.TryGetValue(targetEnd.GetEntityType(), out targetSet))
            {
                return null;
            }

            return AssociationSet.Create(associationType.Name, associationType, sourceSet, targetSet, null);
        }
コード例 #8
0
        internal AssociationSet TryCreateAssociationSet(
            List<RelationshipDetailsRow> relationshipDetailsRows,
            EntityRegister entityRegister,
            List<AssociationType> associationTypes)
        {
            Debug.Assert(relationshipDetailsRows.Count > 0, "relationshipDetailsRows.Count > 0");

            var firstRow = relationshipDetailsRows.First();
            var errors = new List<EdmSchemaError>();

            AssociationType associationType;
            var isValidAssociationType = false;
            var typeName = _usedTypeNames.AdjustIdentifier(firstRow.RelationshipName);
            AssociationEndMember pkEnd = null;
            AssociationEndMember fkEnd = null;
            ReferentialConstraint constraint = null;

            var pkEntityType = TryGetEndEntity(entityRegister, firstRow.GetMostQualifiedPrimaryKey(), errors);
            var fkEntityType = TryGetEndEntity(entityRegister, firstRow.GetMostQualifiedForeignKey(), errors);

            if (ValidateEndEntities(relationshipDetailsRows, pkEntityType, fkEntityType, errors))
            {
                var someFKColumnsAreNullable =
                    _targetEntityFrameworkVersion == EntityFrameworkVersion.Version1
                        ? AreAllFKColumnsNullable(relationshipDetailsRows, fkEntityType)
                        : AreAnyFKColumnsNullable(relationshipDetailsRows, fkEntityType);

                var usedEndNames = new UniqueIdentifierService(StringComparer.OrdinalIgnoreCase);

                pkEnd = AssociationEndMember.Create(
                    usedEndNames.AdjustIdentifier(pkEntityType.Name),
                    pkEntityType.GetReferenceType(),
                    someFKColumnsAreNullable
                        ? RelationshipMultiplicity.ZeroOrOne
                        : RelationshipMultiplicity.One,
                    firstRow.RelationshipIsCascadeDelete
                        ? OperationAction.Cascade
                        : OperationAction.None,
                    null);

                fkEnd = AssociationEndMember.Create(
                    usedEndNames.AdjustIdentifier(fkEntityType.Name),
                    fkEntityType.GetReferenceType(),
                    !someFKColumnsAreNullable && AreRelationshipColumnsTheFullKey(relationshipDetailsRows, fkEntityType, r => r.FKColumn)
                        ? RelationshipMultiplicity.ZeroOrOne
                        : RelationshipMultiplicity.Many,
                    OperationAction.None,
                    null);

                constraint = TryCreateReferentialConstraint(relationshipDetailsRows, pkEnd, fkEnd, errors);
                if (constraint != null
                    && ValidateReferentialConstraint(constraint, _generateForeignKeyProperties, typeName, associationTypes, errors))
                {
                    isValidAssociationType = true;
                }
            }

            associationType = AssociationType.Create(
                typeName,
                _namespaceName,
                false,
                DataSpace.SSpace,
                pkEnd,
                fkEnd,
                constraint,
                CreateMetadataProperties(!isValidAssociationType, errors));

            associationTypes.Add(associationType);

            return isValidAssociationType
                       ? CreateAssociationSet(associationType, entityRegister)
                       : null;
        }