Пример #1
0
        public void Test_entity_conversion_to_generated_class_output_model()
        {
            var ns             = new Namespace("MyApp.MyTest", null);
            var entity         = new Entity("MyClass", ns);
            var targetPlatform = new TargetPlatform("test");

            targetPlatform.RegisterNamingConvention(BasePluginConstants.Language_CSharp, new CSharpClassNamingConvention());

            entity.AddAttribute(new EntityAttribute("Id", TestDataTypes.Int, null, null));
            entity.AddAttribute(new EntityAttribute("Name", TestDataTypes.String, null, null));
            entity.OutputConfiguration.RegisterOutputFolder(new Filter(NHibernatePluginConstants.OutputModelType_Entity_GeneratedClass), new ProjectFolder(""));
            entity.OutputConfiguration.RegisterTargetPlatformForDesignModelType(entity.DesignModelType, targetPlatform);

            var templateCollection = new TemplateCollection();

            templateCollection.LoadTemplates(typeof(NHibernatePluginConstants).Assembly, NHibernatePluginConstants.TemplateResourcePrefix, NHibernatePluginConstants.TemplateNamePrefix);

            var template = templateCollection.GetTemplate(NHibernatePluginConstants.OutputTemplateName_Entity_GeneratedClass);

            targetPlatform.RegisterOutputTemplate(NHibernatePluginConstants.OutputTemplateName_Entity_GeneratedClass, template);

            var converter      = new EntityConverter(templateCollection);
            var generatedClass = converter.CreateEntityGeneratedClass(entity, BasePluginConstants.Language_CSharp);

            generatedClass.Should().NotBeNull();
            generatedClass.ClassName.Should().Be("MyClass");
            generatedClass.ClassNamespace.Should().Be("MyApp.MyTest");

            var properties = generatedClass
                             .Properties
                             .Select(x => (name: x.Name, type: x.Type.TypeName));

            properties.Should().BeEquivalentTo(new[]
        /// <summary>
        /// Generates required data for a OneToMany relationship without embedded documents
        /// </summary>
        /// <returns></returns>
        public static RequiredDataContainer OneToManyNotEmbedded()
        {
            // Create ER Stuff
            Entity Person = new Entity("Person");

            Person.AddAttribute("personId");
            Person.AddAttribute("name");

            Entity Car = new Entity("Car");

            Car.AddAttribute("carId");
            Car.AddAttribute("name");
            Car.AddAttribute("year");
            Car.AddAttribute("personId");

            Relationship Drives = new Relationship("Drives");

            Drives.AddRelationshipEnd(new RelationshipEnd(Person));
            Drives.AddRelationshipEnd(new RelationshipEnd(Car));

            ERModel Model = new ERModel("PersonCarModel", new List <BaseERElement> {
                Person, Car, Drives
            });

            // Create MongoDB schema
            MongoDBCollection PersonCollection = new MongoDBCollection("Person");

            PersonCollection.DocumentSchema.AddAttribute("_id");
            PersonCollection.DocumentSchema.AddAttribute("name");

            MongoDBCollection CarCollection = new MongoDBCollection("Car");

            CarCollection.DocumentSchema.AddAttribute("_id");
            CarCollection.DocumentSchema.AddAttribute("name");
            CarCollection.DocumentSchema.AddAttribute("year");
            CarCollection.DocumentSchema.AddAttribute("personId");

            MongoSchema Schema = new MongoSchema("PersonCarSchema", new List <MongoDBCollection> {
                PersonCollection, CarCollection
            });

            // Create Map
            MapRule PersonRule = new MapRule(Model.FindByName("Person"), Schema.FindByName("Person"));

            PersonRule.AddRule("personId", "_id");
            PersonRule.AddRule("name", "name");

            MapRule CarRule = new MapRule(Model.FindByName("Car"), Schema.FindByName("Car"));

            CarRule.AddRule("carId", "_id");
            CarRule.AddRule("name", "name");
            CarRule.AddRule("year", "year");
            CarRule.AddRule("personId", "personId");

            ModelMapping Map = new ModelMapping("PersonCarMap", new List <MapRule> {
                PersonRule, CarRule
            });

            return(new RequiredDataContainer(Model, Schema, Map));
        }
        public CombatBehavior(Entity entity)
            : base(entity)
        {
            entity.AddAttribute(Key_FiringSpeed, 0);
            entity.AddAttribute(Key_ProjectileType, string.Empty);

            initializeHandledEventTypes();
        }
Пример #4
0
        public CollisionBehavior(Entity entity)
            : base(entity)
        {
            entity.AddAttribute(Key_CollisionDamage, 1);
            entity.AddAttribute(Key_Faction, string.Empty);

            initializeHandledEventTypes();
        }
        /// <summary>
        /// Generates required data to test a One To Many relationship
        /// joining one entity while the left side entity is embedded into another
        /// </summary>
        /// <returns></returns>
        public static RequiredDataContainer OneToManyLeftSideEmbedded()
        {
            Entity Car = new Entity("Car");

            Car.AddAttribute("carId");
            Car.AddAttribute("model");

            Entity Insurance = new Entity("Insurance");

            Insurance.AddAttribute("insuranceId");
            Insurance.AddAttribute("name");
            Insurance.AddAttribute("value");
            Insurance.AddAttribute("carId");

            Relationship HasInsurance = new Relationship("HasInsurance");

            HasInsurance.AddRelationshipEnd(new RelationshipEnd(Car));
            HasInsurance.AddRelationshipEnd(new RelationshipEnd(Insurance));

            ERModel Model = new ERModel("CarInsuranceModel", new List <BaseERElement> {
                Car, Insurance, HasInsurance
            });

            MongoDBCollection CarCol = new MongoDBCollection("Car");

            CarCol.DocumentSchema.AddAttribute("carId");
            CarCol.DocumentSchema.AddAttribute("model");

            MongoDBCollection InsCol = new MongoDBCollection("Insurance");

            InsCol.DocumentSchema.AddAttribute("_id");
            InsCol.DocumentSchema.AddAttribute("name");
            InsCol.DocumentSchema.AddAttribute("value");
            InsCol.DocumentSchema.AddAttribute("carId");

            MongoSchema Schema = new MongoSchema("CarInsuranceSchema", new List <MongoDBCollection> {
                CarCol, InsCol
            });

            MapRule CarRule = new MapRule(Car, CarCol);

            CarRule.AddRule("carId", "car.carId");
            CarRule.AddRule("model", "car.model");

            MapRule InsRule = new MapRule(Insurance, InsCol);

            InsRule.AddRule("insuranceId", "_id");
            InsRule.AddRule("name", "name");
            InsRule.AddRule("value", "value");
            InsRule.AddRule("carId", "carId");

            ModelMapping Map = new ModelMapping("CarInsuranceMap", new List <MapRule> {
                CarRule, InsRule
            });

            return(new RequiredDataContainer(Model, Schema, Map));
        }
Пример #6
0
        public AnimationBehavior(Entity entity)
            : base(entity)
        {
            //entity.AddAttribute(Key_Frame, new Attribute<float>(0.0f)); // this variable is owned by render behaviour
            entity.AddAttribute(Key_FrameCount, 1.0f);
            entity.AddAttribute(Key_FrameRate, 30.0f);

            initializeHandledEventTypes();
        }
        public HealthBehavior(Entity entity)
            : base(entity)
        {
            entity.AddAttribute(Key_Health, 1);
            entity.AddAttribute(Key_Lifes, 1);
            entity.AddAttribute(Key_RespawnTime, 1.5f);
            entity.AddAttribute(Key_IsInvulnerable, false);

            initializeHandledEventTypes();
        }
        public RenderBehavior(Entity entity)
            : base(entity)
        {
            entity.AddAttribute(Key_Material, (ResourceHandle)null);
            entity.AddAttribute(Key_Mesh, (ResourceHandle)null);
            entity.AddAttribute(Key_IsRenderable, true);
            entity.AddAttribute(Key_Frame, 0.0f);

            initializeHandledEventTypes();
        }
Пример #9
0
        public void Fall()
        {
            ResizeForm();
            pet.AddAttribute(Entity.CoreAttributes.WalkOnWindows);
            pet.AddAttribute(Entity.CoreAttributes.ClimbOnWindows);
            int x = 10;//currentScreen.Bounds.Width / 2 - this.Width / 2;
            int y = 0;

            pet.Position     = this.PointToScreen(new Point(x, y));
            petPanel.Visible = true;
            pet.AllowedArea  = this.Bounds;
            animTimer.Start();
        }
        public ProjectileBehavior(Entity entity)
            : base(entity)
        {
            entity.AddAttribute(Key_ProjectileOwner, -1);

            initializeHandledEventTypes();
        }
Пример #11
0
        public CollectsPointsBehavior(Entity entity)
            : base(entity)
        {
            entity.AddAttribute(Key_PointsCollected, 0);

            initializeHandledEventTypes();
        }
Пример #12
0
        public AwardsPointsBehavior(Entity entity)
            : base(entity)
        {
            entity.AddAttribute(Key_PointsAwarded, 0);

            initializeHandledEventTypes();
        }
Пример #13
0
        public AudioEmitterBehavior(Entity entity)
            : base(entity)
        {
            entity.AddAttribute(Key_SoundEffects, (AudioInfo)null);

            initializeHandledEventTypes();
        }
Пример #14
0
        public DyingBehavior(Entity entity)
            : base(entity)
        {
            entity.AddAttribute(Key_DeathAnimation, (ResourceHandle)null);

            initializeHandledEventTypes();
        }
Пример #15
0
        public void AddLocalAttribute()
        {
            Entity entity = new Entity();

            Attribute attribute = new Attribute("test");
            entity.AddAttribute(attribute);

            Assert.AreEqual(1, entity.Attributes.Where(x => x.Name == "test").Count());
        }
Пример #16
0
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            for (int i = 0; i < MaxPlayers; i++)
            {
                bool      active = playerActive[i];
                Texture2D sprite = playerBackgroundInactive;
                float     scale  = 200f / sprite.Width;
                Vector2   pos    = Position - new Vector2(210, 0) + new Vector2((i & 1) * 210, ((i & 2) >> 1) * (sprite.Height * scale + 10));

                Color backgroundColor = Color.White;

                // load templates
                LevelData            levelData  = Game.Instance.ContentManager.Load <LevelData>("Level/Common/RobotTemplates");
                EntityData           entityData = levelData.entities[Game.Instance.Robots[robotSelected[i]].Entity];
                List <AttributeData> attributes = entityData.CollectAttributes(levelData);
                List <PropertyData>  properties = entityData.CollectProperties(levelData);

                // create a dummy entity
                Entity entity = new Entity(entityData.name);
                foreach (AttributeData attributeData in attributes)
                {
                    entity.AddAttribute(attributeData.name, attributeData.template, attributeData.value);
                }

                Vector3 color1 = entity.GetVector3(CommonNames.Color1);
                Vector3 color2 = entity.GetVector3(CommonNames.Color2);

                if (active)
                {
                    backgroundColor = new Color(color2 * 0.8f);
                }

                Vector2 halfSpriteDim = new Vector2(sprite.Width, sprite.Height) / 4;
                spriteBatch.Draw(sprite, pos - halfSpriteDim * (playerBoxSize.Value - 1f),
                                 null, backgroundColor, 0, Vector2.Zero, scale * playerBoxSize.Value, SpriteEffects.None, 0);

                if (active)
                {
                    Texture2D robot  = playerPreview[i];
                    float     width  = PlayerIconRect.Width * scale;
                    float     rscale = width / robot.Width;
                    //spriteBatch.Draw(robot, pos + new Vector2(PlayerIconRect.Left, PlayerIconRect.Top) * scale,
                    //    null, Color.White, 0, Vector2.Zero, ((float)sprite.Width )/ robot.Width*scale, SpriteEffects.None, 0);
                    spriteBatch.Draw(robot, pos,
                                     null, Color.White, 0, Vector2.Zero, ((float)sprite.Width) / robot.Width * scale, SpriteEffects.None, 0);
                }
                else
                {
                    DrawTools.DrawCenteredShadowString(spriteBatch, menu.StaticStringFont, "HIT START", pos + halfSpriteDim - Vector2.UnitY * 27 * scale, menu.StaticStringColor, 1.2f * scale);
                    DrawTools.DrawCenteredShadowString(spriteBatch, menu.StaticStringFont, "TO JOIN", pos + halfSpriteDim + Vector2.UnitY * 27 * scale, menu.StaticStringColor, 1.2f * scale);
                }
            }
        }
Пример #17
0
        public Entity Entity()
        {
            var ent = new Entity(tbxEntityName.Text);

            for (int i = 0; i < clbAttributes.Items.Count; i++)
            {
                var name = clbAttributes.Items[i].ToString();
                var key  = clbAttributes.CheckedIndices.Contains(i);
                ent.AddAttribute(new Attribute(name, key));
            }
            return(ent);
        }
Пример #18
0
 override public bool VisitEntity(QueryBuilderMappingParser.EntityContext context)
 {
     if (Pass == 1)
     {
         Entity entity = new Entity(context.name.Text);
         foreach (QueryBuilderMappingParser.AttributeContext ac in context.attribute())
         {
             entity.AddAttribute(ac.name.Text, ac.type.Text, ac.multivalued != null, ac.primarykey != null);
         }
         EntityRelationshipModel.Elements.Add(entity);
     }
     return(true);
 }
Пример #19
0
        public void CombinedImage_Uses_Target_Over_Post_Over_Pre()
        {
            var targetImage = new Entity(EntityName);

            targetImage.AddAttribute("target", null);

            var postImage = new Entity(EntityName);

            postImage.AddAttribute("target", "post");
            postImage.AddAttribute("post", "post");

            var preImage = new Entity(EntityName);

            preImage.AddAttribute("target", "pre");
            preImage.AddAttribute("post", "pre");
            preImage.AddAttribute("pre", "pre");

            var em = new ImageManager <Entity>(preImage, targetImage, postImage);

            Assert.Equal(em.CombinedImageEntity["target"], targetImage["target"]);
            Assert.Equal(em.CombinedImageEntity["post"], postImage["post"]);
            Assert.Equal(em.CombinedImageEntity["pre"], preImage["pre"]);
        }
Пример #20
0
        public SpatialBehavior(Entity entity)
            : base(entity)
        {
            entity.AddAttribute(Key_Position, new Vector2D(0, 0));
            entity.AddAttribute(Key_Dimensions, new Vector2D(0, 0));
            entity.AddAttribute(Key_MoveDirection, new Vector2D(0, 0));
            entity.AddAttribute(Key_MovementSpeed, 0);
            entity.AddAttribute(Key_AtBoundary, new Vector2D(0, 0));
            entity.AddAttribute(Key_RespectsBoundary, true);

            initializeHandledEventTypes();
        }
        /// <summary>
        /// Create ER Model
        /// </summary>
        /// <returns></returns>
        public static ERModel CreateERModel()
        {
            Entity User = new Entity("User");

            User.AddAttribute("user_id", true);
            User.AddAttributes("user_name", "user_email", "user_access", "user_newsletter");

            Entity Store = new Entity("Store");

            Store.AddAttribute("store_id", true);
            Store.AddAttributes("store_name", "store_logo");

            Entity Category = new Entity("Category");

            Category.AddAttribute("category_id", true);
            Category.AddAttributes("category_name");

            Entity Product = new Entity("Product");

            Product.AddAttribute("product_id", true);
            Product.AddAttributes("product_title", "product_description", "product_short_description", "product_url",
                                  "product_category_id", "product_store_id", "product_user_id", "product_published", "product_image");

            Relationship UserProducts = new Relationship("UserProducts");

            UserProducts.AddRelationshipEnd(new RelationshipEnd(User));
            UserProducts.AddRelationshipEnd(new RelationshipEnd(Product));

            Relationship StoreProducts = new Relationship("StoreProducts");

            StoreProducts.AddRelationshipEnd(new RelationshipEnd(Store));
            StoreProducts.AddRelationshipEnd(new RelationshipEnd(Product));

            Relationship CategoryProducts = new Relationship("CategoryProducts");

            CategoryProducts.AddRelationshipEnd(new RelationshipEnd(Category));
            CategoryProducts.AddRelationshipEnd(new RelationshipEnd(Product));

            return(new ERModel("CMSModel", new List <BaseERElement>()
            {
                User, Store, Category, Product, UserProducts, StoreProducts, CategoryProducts
            }));
        }
Пример #22
0
        internal Entity CreateEntity(string name, ScalarType primaryIdType)
        {
            Entity entity = new Entity(Model, Schema, name);

            if (PersistentSchemaDefined)
            {
                entity.Persistence.Schema        = PersistentSchema;
                entity.Persistence.SchemaDefined = true;
            }

            Metamodel.Attribute a = entity.AddAttribute("Id", primaryIdType);
            a.TypeDefinition.Required = true;
            if (PrimaryIdType.IsIntegerValueType)
            {
                a.IsAutoincrement = true;
            }
            entity.Constraints.PrimaryId = new PrimaryId(entity, a);
            return(entity);
        }
Пример #23
0
        public void AttributeBecomesInheritableAfterAddToParent()
        {
            Entity parent = new Entity() { Name = "parent" };

            Entity child = new Entity();
            child.AddPrototype(parent);

            Attribute attribute = new Attribute("test") { Value = new Value("value") };
            child.AddAttribute(attribute);

            //Assert.IsFalse(attribute.CanInherit);

            Attribute parentAttribute = new Attribute("test") { Value = new Value("new value") };
            parent.AddAttribute(parentAttribute);

            //Assert.IsTrue(attribute.CanInherit);
            Assert.AreEqual(1, parent.Attributes.Count);
            Assert.AreEqual(1, child.Attributes.Count);
        }
        /// <summary>
        /// Create ER Model
        /// </summary>
        /// <returns></returns>
        public static ERModel CreateERModel()
        {
            Entity User = new Entity("User");

            User.AddAttribute("UserID", true);
            User.AddAttributes("UserName", "UserEmail");

            Entity Store = new Entity("Store");

            Store.AddAttribute("StoreID", true);
            Store.AddAttributes("StoreName");

            Entity Category = new Entity("Category");

            Category.AddAttribute("CategoryID", true);
            Category.AddAttributes("CategoryName");

            Entity Product = new Entity("Product");

            Product.AddAttribute("ProductID", true);
            Product.AddAttributes("Title", "Description");

            Relationship UserProducts = new Relationship("UserProducts");

            UserProducts.AddRelationshipEnd(new RelationshipEnd(User));
            UserProducts.AddRelationshipEnd(new RelationshipEnd(Product));

            Relationship StoreProducts = new Relationship("StoreProducts");

            StoreProducts.AddRelationshipEnd(new RelationshipEnd(Store));
            StoreProducts.AddRelationshipEnd(new RelationshipEnd(Product));

            Relationship CategoryProducts = new Relationship("CategoryProducts");

            CategoryProducts.AddRelationshipEnd(new RelationshipEnd(Category));
            CategoryProducts.AddRelationshipEnd(new RelationshipEnd(Product));

            return(new ERModel("CMSModel", new List <BaseERElement>()
            {
                User, Store, Category, Product, UserProducts, StoreProducts, CategoryProducts
            }));
        }
Пример #25
0
        public void EntityInheritsAttributeFromPrototype()
        {
            Entity parent = new Entity() { Name = "parent" };
            parent.AddAttribute(new Attribute("test"));

            Entity child = new Entity();
            child.AddPrototype(parent);

            Assert.AreEqual(1, parent.Attributes.Where(x => x.Name == "test").Count());
            Assert.AreEqual(1, child.Attributes.Where(x => x.Name == "test").Count());
        }
        private void addAttributeEditContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            auxAttribute.Name        = AttributeName.Text;
            auxAttribute.Description = Description.Text;
            if (!String.IsNullOrWhiteSpace(AttributeName.Text) && DataType.SelectedValue != null && IndexType.SelectedValue != null)
            {
                // An attribute is being added, not edited, "attribute" is passed in the constructor
                // When its meant to be edited.
                if (attribute == null)
                {
                    // Entity doesn't contain an attribute with this name
                    if (!entity.Attributes.Any(x => x.Name == auxAttribute.Name))
                    {
                        // If already contains a primary key
                        if (entity.Key != null && auxAttribute.KeyType == KeyTypes.Primary) //Attributes.Any(x => x.KeyType == KeyTypes.Primary)
                        {
                            args.Cancel  = true;
                            Warning.Text = "Error: This entity already contains a primary key.";
                        }
                        else if (auxAttribute.KeyType == KeyTypes.Foreign && AsociatedEntity.SelectedItem == null)
                        {
                            Warning.Text = "Please select a valid entity as Foreign Key";
                            args.Cancel  = true;
                        }
                        else if (auxAttribute.KeyType == KeyTypes.Foreign && entity.Attributes.Any(x => x.KeyType == KeyTypes.Foreign && x.AssociatedEntity == auxAttribute.AssociatedEntity))
                        {
                            Warning.Text = "This entity already contains Foreign Key from the selected Entity";
                            args.Cancel  = true;
                        }
                        else
                        {
                            auxAttribute.Name        = AttributeName.Text;
                            auxAttribute.Description = Description.Text;
                            entity.AddAttribute(auxAttribute);
                        }
                    }
                    else
                    {
                        args.Cancel  = true;
                        Warning.Text = "Error: Already exists an attribute with ths name.";
                    }
                }
                else
                {
                    //if (auxAttribute.Name == attribute.Name && auxAttribute.KeyType == attribute.KeyType)
                    //{

                    //}
                    if (auxAttribute.KeyType != attribute.KeyType && auxAttribute.KeyType == KeyTypes.Primary && entity.Key != null)//Attributes.Any(x => x.KeyType == KeyTypes.Primary)
                    {
                        args.Cancel  = true;
                        Warning.Text = "Error: This entity already contains a primary key.";
                        return;
                    }


                    if (auxAttribute.Name != attribute.Name && entity.Attributes.Any(x => x.Name == auxAttribute.Name))
                    {
                        args.Cancel  = true;
                        Warning.Text = "Error: Already exists an attribute with ths name.";
                        return;
                    }



                    else if (auxAttribute.KeyType == KeyTypes.Foreign && AsociatedEntity.SelectedItem == null)
                    {
                        Warning.Text = "Please select a valid entity as Foreign Key";
                        args.Cancel  = true;
                        return;
                    }
                    else if (auxAttribute.KeyType == KeyTypes.Foreign && entity.Attributes.Any(x => x.KeyType == KeyTypes.Foreign && x.AssociatedEntity == auxAttribute.AssociatedEntity))
                    {
                        Warning.Text = "This entity already contains Foreign Key from the selected Entity";
                        args.Cancel  = true;
                        return;
                    }


                    auxAttribute.CopyTo(attribute);
                }
            }
            else
            {
                args.Cancel  = true;
                Warning.Text = "Error: Complete all the fields correctly";
            }
        }
Пример #27
0
        public void CannotSetExistingAttributeKeyToDuplicate()
        {
            Entity entity = new Entity();
            entity.AddAttribute(new Attribute("test1"));

            Attribute attribute = new Attribute("test2");
            entity.AddAttribute(attribute);

            attribute.Name = "test1";

            Assert.AreEqual("test2", attribute.Name);
            Assert.AreEqual(2, entity.Attributes.Count);
        }
Пример #28
0
        public override void Update(GameTime gameTime)
        {
            double at = gameTime.TotalGameTime.TotalMilliseconds;

            playerBoxSize.Update(at);

            if (at > menu.buttonPressedAt + Menu.ButtonRepeatTimeout &&
                ((GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed &&
                  menu.lastGPState.Buttons.A == ButtonState.Released) ||
                 GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed ||
                 (Keyboard.GetState().IsKeyDown(Keys.Enter) &&
                  menu.lastKBState.IsKeyUp(Keys.Enter))))
            {
                List <Entity> players = new List <Entity>(MaxPlayers);
                for (int i = 0; i < MaxPlayers; i++)
                {
                    if (playerActive[i])
                    {
                        Entity player = new Entity("player" + (players.Count + 1));
                        player.AddIntAttribute(CommonNames.GamePadIndex, i);
                        player.AddStringAttribute("robot_entity", Game.Instance.Robots[robotSelected[i]].Entity);
                        player.AddStringAttribute(CommonNames.PlayerName, Game.Instance.Robots[robotSelected[i]].Name);
                        players.Add(player);
                    }
                }

                Game.Instance.AddPlayers(players.ToArray <Entity>());

                menu.Close();
                return;
            }

            for (int i = 0; i < MaxPlayers; i++)
            {
                GamePadState gamePadState = GamePad.GetState((PlayerIndex)i);

                if (i > 0 && // don't allow player1 do deactivate
                    gamePadState.Buttons.Start == ButtonState.Pressed &&
                    previousState[i].Buttons.Start == ButtonState.Released &&
                    at > playerButtonPressedAt[i] + Menu.ButtonRepeatTimeout)
                {
                    playerActive[i]          = !playerActive[i];
                    playerButtonPressedAt[i] = at;
                }

                if (at > menu.elementSelectedAt + Menu.StickRepeatTimeout)
                {
                    int oldRobotSelected = robotSelected[i];
                    if (Vector2.Dot(gamePadState.ThumbSticks.Left, Vector2.UnitY) > Menu.StickDirectionSelectionMin ||
                        gamePadState.DPad.Up == ButtonState.Pressed)
                    {
                        // select prev robot
                        robotSelected[i]--;
                        if (robotSelected[i] < 0)
                        {
                            robotSelected[i] = Game.Instance.Robots.Count - 1;
                        }
                        menu.elementSelectedAt = at;
                    }
                    else
                    if (Vector2.Dot(gamePadState.ThumbSticks.Left, Vector2.UnitY) < -Menu.StickDirectionSelectionMin ||
                        gamePadState.DPad.Down == ButtonState.Pressed)
                    {
                        // select next robot
                        robotSelected[i]++;
                        if (robotSelected[i] == Game.Instance.Robots.Count)
                        {
                            robotSelected[i] = 0;
                        }
                        menu.elementSelectedAt = at;
                    }
                    for (int j = 0; j < MaxPlayers; ++j)
                    {
                        if (robotSelected[j] == robotSelected[i] && i != j)
                        {
                            if (playerActive[j])
                            {
                                robotSelected[i] = oldRobotSelected;
                            }
                            else
                            {
                                robotSelected[j] = oldRobotSelected;
                            }
                        }
                    }
                }

                previousState[i] = gamePadState;
            }

            for (int i = 0; i < MaxPlayers; ++i)
            {
                // load templates
                LevelData            levelData  = Game.Instance.ContentManager.Load <LevelData>("Level/Common/RobotTemplates");
                EntityData           entityData = levelData.entities[Game.Instance.Robots[robotSelected[i]].Entity];
                List <AttributeData> attributes = entityData.CollectAttributes(levelData);
                List <PropertyData>  properties = entityData.CollectProperties(levelData);

                // create a dummy entity
                Entity entity = new Entity(entityData.name);
                foreach (AttributeData attributeData in attributes)
                {
                    entity.AddAttribute(attributeData.name, attributeData.template, attributeData.value);
                }

                Vector3 color1 = entity.GetVector3(CommonNames.Color1);
                Vector3 color2 = entity.GetVector3(CommonNames.Color2);

                RenderTargetBinding[] oldRenderTarget = Game.Instance.GraphicsDevice.GetRenderTargets();
                Game.Instance.GraphicsDevice.SetRenderTargets(playerPreview[i]);
                Game.Instance.GraphicsDevice.Clear(new Color(0, 0, 0, 0));

                ////////playerModel.Meshes[0].Draw();
                playerMesh.Effects[0].CurrentTechnique = playerMesh.Effects[0].Techniques["AnimatedPlayer"];
                playerMesh.Effects[0].Parameters["Local"].SetValue(Matrix.Identity);
                playerMesh.Effects[0].Parameters["World"].SetValue(Matrix.Identity * 0.8f);
                playerMesh.Effects[0].Parameters["View"].SetValue(Matrix.CreateLookAt(new Vector3(3, 3, 3), new Vector3(0, 2.0f, -3), Vector3.Up));
                ////////playerMesh.Effects[0].Parameters["View"].SetValue(Matrix.CreateLookAt(new);
                playerMesh.Effects[0].Parameters["Projection"].SetValue(Matrix.CreateOrthographic(8.5f, 8.5f, 0.001f, 1000) * Matrix.CreateTranslation(Vector3.UnitX * 0.36f));
                playerMesh.Effects[0].Parameters["DiffuseTexture"].SetValue(playerTexture);
                playerMesh.Effects[0].Parameters["SpecularTexture"].SetValue(specularTexture);
                playerMesh.Effects[0].Parameters["DiffuseColor"].SetValue(Vector3.One * 1.0f);
                playerMesh.Effects[0].Parameters["SpecularColor"].SetValue(Vector3.One);
                playerMesh.Effects[0].Parameters["SpecularPower"].SetValue(16f);
                playerMesh.Effects[0].Parameters["EmissiveColor"].SetValue(Vector3.One * 0.2f);
                playerMesh.Effects[0].Parameters["ToneColor"].SetValue(entity.GetVector3(CommonNames.Color1));
                playerMesh.Effects[0].Parameters["DirLight0Direction"].SetValue(-Vector3.One);
                playerMesh.Effects[0].Parameters["DirLight0DiffuseColor"].SetValue(entity.GetVector3(CommonNames.Color1) * 0.5f);
                playerMesh.Effects[0].Parameters["DirLight0SpecularColor"].SetValue(Vector3.One / 3);
                playerMesh.Effects[0].Parameters["DirLight1Direction"].SetValue(new Vector3(-1, 1, -1));
                playerMesh.Effects[0].Parameters["DirLight1DiffuseColor"].SetValue(new Vector3(1, 1, 1) * 0.75f);
                playerMesh.Effects[0].Parameters["DirLight1SpecularColor"].SetValue(Vector3.One / 3);
                playerMesh.Effects[0].Parameters["DirLight2Direction"].SetValue(new Vector3(-1, -1, 1));
                playerMesh.Effects[0].Parameters["DirLight2DiffuseColor"].SetValue(entity.GetVector3(CommonNames.Color2) * 0.75f);
                playerMesh.Effects[0].Parameters["DirLight2SpecularColor"].SetValue(Vector3.One / 3);

                Viewport oldViewport = Game.Instance.GraphicsDevice.Viewport;

                double now = Game.Instance.GlobalClock.ContinuousMilliseconds;

                GameTime myGameTime = new GameTime(
                    new TimeSpan((long)(now * 10000d)),
                    new TimeSpan((long)((now - last) * 10000d)) /*,
                                                                 * new TimeSpan((long)(now * 10000d)),
                                                                 * new TimeSpan((long)((now - last) * 10000d))*/);
                last = now;

                animator.World = Matrix.Identity;
                walkController.Update(myGameTime);
                animator.Update();
                animator.Draw();

                playerMesh.Draw();

                Game.Instance.GraphicsDevice.SetRenderTargets(oldRenderTarget);
            }
        }
Пример #29
0
        public void CannotChangeKeyForInheritedAttribute()
        {
            Entity parent = new Entity() { Name = "parent" };

            Attribute attribute = new Attribute("test") { Value = new Value("value") };
            parent.AddAttribute(attribute);

            Entity child = new Entity();
            child.AddPrototype(parent);

            Attribute childAttribute = child.GetAttribute("test");
            childAttribute.Value = new Value("new value");

            Assert.IsTrue(childAttribute.IsInherited);
            Assert.IsTrue(childAttribute.Name == "test");

            childAttribute.Name = "test2";

            Assert.IsTrue(childAttribute.IsInherited);
            Assert.IsTrue(childAttribute.Name == "test");
            Assert.AreEqual(1, parent.Attributes.Count);
            Assert.AreEqual(1, child.Attributes.Count);
        }
Пример #30
0
        public void AttributesBecomesNonInheritableAfterParentKeyChange()
        {
            Entity parent = new Entity() { Name = "parent" };

            Attribute attribute = new Attribute("test") { Value = new Value("value") };
            parent.AddAttribute(attribute);

            Entity child = new Entity();
            child.AddPrototype(parent);

            Attribute childAttribute = child.GetAttribute("test");
            //childAttribute.IsInherited = false;
            childAttribute.Value = new Value("new value");

            attribute.Name = "test2";

            Assert.AreEqual(childAttribute.Name, "test");
            //Assert.IsFalse(childAttribute.CanInherit);
            Assert.AreEqual(1, parent.Attributes.Count);
            Assert.AreEqual(2, child.Attributes.Count);
        }
        /// <summary>
        /// Generates required data to test a One to One relationship
        /// joining multiple entities with relationship attribute and multiple root attributes
        /// </summary>
        /// <returns></returns>
        public static RequiredDataContainer OneToOneRelationshipMultipleRootAttributes()
        {
            // Create ER Stuff
            Entity Person = new Entity("Person");

            Person.AddAttribute("personId", true);
            Person.AddAttribute("name");
            Person.AddAttribute("insuranceId");

            Entity Car = new Entity("Car");

            Car.AddAttribute("name");
            Car.AddAttribute("year");
            Car.AddAttribute("engine");
            Car.AddAttribute("fuel");

            Entity Insurance = new Entity("Insurance");

            Insurance.AddAttribute("insuranceId", true);
            Insurance.AddAttribute("name");

            Relationship HasInsurance = new Relationship("HasInsurance");

            HasInsurance.AddAttribute("insuranceValue");
            HasInsurance.AddRelationshipEnd(new RelationshipEnd(Person));
            HasInsurance.AddRelationshipEnd(new RelationshipEnd(Car));
            HasInsurance.AddRelationshipEnd(new RelationshipEnd(Insurance));

            ERModel Model = new ERModel("PersonCarModel", new List <BaseERElement> {
                Person, Car, HasInsurance, Insurance
            });

            // Create MongoDB schema
            MongoDBCollection PersonCollection = new MongoDBCollection("Person");

            PersonCollection.DocumentSchema.AddAttribute("_id");
            PersonCollection.DocumentSchema.AddAttribute("name");
            PersonCollection.DocumentSchema.AddAttribute("car.name");
            PersonCollection.DocumentSchema.AddAttribute("car.year");
            PersonCollection.DocumentSchema.AddAttribute("carDetails.engine");
            PersonCollection.DocumentSchema.AddAttribute("CarDetails.fuel");
            PersonCollection.DocumentSchema.AddAttribute("insuranceId");
            PersonCollection.DocumentSchema.AddAttribute("insuranceValue");

            MongoDBCollection InsuranceCollection = new MongoDBCollection("Insurance");

            InsuranceCollection.DocumentSchema.AddAttribute("_id");
            InsuranceCollection.DocumentSchema.AddAttribute("name");

            MongoSchema Schema = new MongoSchema("PersonCarSchema", new List <MongoDBCollection> {
                PersonCollection, InsuranceCollection
            });

            // Create Map
            MapRule PersonRule = new MapRule(Model.FindByName("Person"), Schema.FindByName("Person"));

            PersonRule.AddRule("personId", "_id");
            PersonRule.AddRule("name", "name");
            PersonRule.AddRule("carId", "carId");
            PersonRule.AddRule("insuranceId", "insuranceId");

            MapRule CarRule = new MapRule(Model.FindByName("Car"), Schema.FindByName("Person"), false);

            CarRule.AddRule("name", "car.name");
            CarRule.AddRule("year", "car.year");
            CarRule.AddRule("engine", "carDetails.engine");
            CarRule.AddRule("fuel", "carDetails.fuel");

            MapRule InsuranceRule = new MapRule(Model.FindByName("Insurance"), Schema.FindByName("Insurance"));

            InsuranceRule.AddRule("insuranceId", "_id");
            InsuranceRule.AddRule("name", "name");

            MapRule InsurancePersonRule = new MapRule(Model.FindByName("Insurance"), Schema.FindByName("Person"), false);

            InsurancePersonRule.AddRule("insuranceId", "insuranceId");

            MapRule RelationshipRule = new MapRule(Model.FindByName("HasInsurance"), Schema.FindByName("Person"), false);

            RelationshipRule.AddRule("insuranceValue", "insuranceValue");

            ModelMapping Map = new ModelMapping("PersonCarMap", new List <MapRule> {
                PersonRule, CarRule, InsuranceRule, RelationshipRule, InsurancePersonRule
            });

            return(new RequiredDataContainer(Model, Schema, Map));
        }
Пример #32
0
        public void KeyFollowsInheritedAttribute()
        {
            Entity parent = new Entity() { Name = "parent" };

            Attribute parentAttribute = new Attribute("test");
            parent.AddAttribute(parentAttribute);

            Entity child = new Entity();
            child.AddPrototype(parent);

            Attribute childAttribute = child.GetAttribute("test");

            parentAttribute.Name = "test2";

            Assert.IsFalse(childAttribute.HasOwnValue);
            Assert.AreEqual(0, child.Attributes.Count(x => x.Name == "test"));
            Assert.AreEqual(1, child.Attributes.Count(x => x.Name == "test2"));
        }
Пример #33
0
        /// <summary>
        /// Generates data to test a many to many relationship join with multiple entities
        /// and relationship attributes
        /// </summary>
        /// <returns></returns>
        public static RequiredDataContainer ManyToManyRelationshipAttributeMultipleEntities()
        {
            Entity Person = new Entity("Person");

            Person.AddAttribute("personId", true);
            Person.AddAttribute("name");

            Entity Car = new Entity("Car");

            Car.AddAttribute("carId", true);
            Car.AddAttribute("name");
            Car.AddAttribute("year");

            Entity InsCompany = new Entity("InsCompany");

            InsCompany.AddAttribute("companyId", true);
            InsCompany.AddAttribute("name");

            Relationship Insurance = new Relationship("Insurance");

            Insurance.AddAttribute("insuranceId");
            Insurance.AddAttribute("insuranceValue");
            Insurance.AddAttribute("aRandomValue");
            Insurance.AddRelationshipEnd(new RelationshipEnd(Person));
            Insurance.AddRelationshipEnd(new RelationshipEnd(Car));
            Insurance.AddRelationshipEnd(new RelationshipEnd(InsCompany));

            ERModel Model = new ERModel("PersonCar", new List <BaseERElement> {
                Person, Car, Insurance, InsCompany
            });

            // MongoDB Schema
            MongoDBCollection PersonCol = new MongoDBCollection("Person");

            PersonCol.DocumentSchema.AddAttribute("_id");
            PersonCol.DocumentSchema.AddAttribute("name");

            MongoDBCollection CarCol = new MongoDBCollection("Car");

            CarCol.DocumentSchema.AddAttribute("_id");
            CarCol.DocumentSchema.AddAttribute("name");
            CarCol.DocumentSchema.AddAttribute("year");

            MongoDBCollection InsuranceCol = new MongoDBCollection("Insurance");

            InsuranceCol.DocumentSchema.AddAttribute("_id");
            InsuranceCol.DocumentSchema.AddAttribute("personId");
            InsuranceCol.DocumentSchema.AddAttribute("carId");
            InsuranceCol.DocumentSchema.AddAttribute("companyId");
            InsuranceCol.DocumentSchema.AddAttribute("insuranceValue");
            InsuranceCol.DocumentSchema.AddAttribute("aRandomValue");

            MongoDBCollection InsCompanyCol = new MongoDBCollection("InsCompany");

            InsCompanyCol.DocumentSchema.AddAttribute("_id");
            InsCompanyCol.DocumentSchema.AddAttribute("name");

            MongoSchema DBSchema = new MongoSchema("PersonCarSchema",
                                                   new List <MongoDBCollection> {
                PersonCol, CarCol, InsuranceCol, InsCompanyCol
            });

            // Map
            MapRule PersonRule = new MapRule(Person, PersonCol);

            PersonRule.AddRule("personId", "_id");
            PersonRule.AddRule("name", "name");

            MapRule CarRule = new MapRule(Car, CarCol);

            CarRule.AddRule("carId", "_id");
            CarRule.AddRule("name", "name");
            CarRule.AddRule("year", "year");

            MapRule InsuranceRule = new MapRule(Insurance, InsuranceCol);

            InsuranceRule.AddRule("insuranceId", "_id");
            InsuranceRule.AddRule("insuranceValue", "insuranceValue");
            InsuranceRule.AddRule("aRandomValue", "aRandomValue");

            MapRule InsCompanyRule = new MapRule(InsCompany, InsCompanyCol);

            InsCompanyRule.AddRule("companyId", "_id");
            InsCompanyRule.AddRule("name", "name");

            MapRule PersonInsuranceRule = new MapRule(Person, InsuranceCol, false);

            PersonInsuranceRule.AddRule("personId", "personId");

            MapRule CarInsuranceRule = new MapRule(Car, InsuranceCol, false);

            CarInsuranceRule.AddRule("carId", "carId");

            MapRule InsCompanyInsuranceRule = new MapRule(InsCompany, InsuranceCol, false);

            InsCompanyInsuranceRule.AddRule("companyId", "companyId");

            ModelMapping Map = new ModelMapping("PersonCarMap", new List <MapRule> {
                PersonRule,
                CarRule, InsuranceRule, InsCompanyRule, PersonInsuranceRule, CarInsuranceRule, InsCompanyInsuranceRule
            });

            return(new RequiredDataContainer(Model, DBSchema, Map));
        }
Пример #34
0
        /// <summary>
        /// Generates data to test a query in which the target entity is embedded in the middle collection
        /// </summary>
        /// <returns></returns>
        public static RequiredDataContainer ManyToManyEmbeddedTarget()
        {
            // ER Model
            Entity Person = new Entity("Person");

            Person.AddAttribute("personId", true);
            Person.AddAttributes("name", "age");

            Entity Car = new Entity("Car");

            Car.AddAttribute("carId", true);
            Car.AddAttributes("model", "year");

            Relationship Drives = new Relationship("Drives");

            Drives.AddAttribute("something");

            Drives.AddRelationshipEnd(new RelationshipEnd(Person));
            Drives.AddRelationshipEnd(new RelationshipEnd(Car));

            ERModel Model = new ERModel("Model", new List <BaseERElement>()
            {
                Person, Car, Drives
            });

            // Mongo Schema
            MongoDBCollection PersonCol = new MongoDBCollection("Person");

            PersonCol.AddAttributes("_id", "name", "age");

            MongoDBCollection DrivesCol = new MongoDBCollection("Drives");

            DrivesCol.AddAttributes("_id", "something", "car.carId", "car.model", "car.year");

            MongoSchema Schema = new MongoSchema("Schema", new List <MongoDBCollection>()
            {
                PersonCol, DrivesCol
            });

            // Map
            MapRule PersonRule = new MapRule(Person, PersonCol);

            PersonRule.AddRule("personId", "_id");
            PersonRule.AddRule("name", "name");
            PersonRule.AddRule("age", "age");

            MapRule CarRule = new MapRule(Car, DrivesCol, false);

            CarRule.AddRule("carId", "car.carId");
            CarRule.AddRule("model", "car.model");
            CarRule.AddRule("year", "car.year");

            MapRule DrivesRule = new MapRule(Drives, DrivesCol);

            DrivesRule.AddRule("something", "something");

            MapRule PersonDrivesRule = new MapRule(Person, DrivesCol, false);

            PersonDrivesRule.AddRule("personId", "personId");

            ModelMapping Map = new ModelMapping("Map", new List <MapRule>()
            {
                PersonRule, CarRule, DrivesRule, PersonDrivesRule
            });

            return(new RequiredDataContainer(Model, Schema, Map));
        }
Пример #35
0
        public void CannotRemoveInheritedAttribute()
        {
            Entity parent = new Entity() { Name = "parent" };
            parent.AddAttribute(new Attribute("test"));

            Entity child = new Entity();
            child.AddPrototype(parent);

            Attribute childAttribute = child.GetAttribute("test");
            child.RemoveAttribute(childAttribute);

            Assert.AreEqual(1, child.Attributes.Where(x => x.Name == "test").Count());
        }
        public static DataContainer CreateDataContainer()
        {
            Entity Person = new Entity("Person");

            Person.AddAttribute("personId", true);
            Person.AddAttribute("name");

            Entity Car = new Entity("Car");

            Car.AddAttribute("carId", true);
            Car.AddAttributes("plate", "color");

            Relationship Drives = new Relationship("Drives");

            Drives.AddAttribute("note");
            Drives.AddRelationshipEnd(new RelationshipEnd(Person));
            Drives.AddRelationshipEnd(new RelationshipEnd(Car));

            ERModel Model = new ERModel("Model", new List <BaseERElement>()
            {
                Person, Car, Drives
            });

            MongoDBCollection PersonCol = new MongoDBCollection("Person");

            PersonCol.AddAttributes("_id", "name", "cars_multivalued_.id", "cars_multivalued_.note");

            MongoDBCollection CarCol = new MongoDBCollection("Car");

            CarCol.AddAttributes("_id", "plate", "color");

            MongoSchema Schema = new MongoSchema("Schema", new List <MongoDBCollection>()
            {
                PersonCol, CarCol
            });

            MapRule PersonRule = new MapRule(Person, PersonCol);

            PersonRule.AddRule("personId", "_id");
            PersonRule.AddRule("name", "name");

            MapRule CarRule = new MapRule(Car, CarCol);

            CarRule.AddRule("carId", "_id");
            CarRule.AddRule("plate", "plate");
            CarRule.AddRule("color", "color");

            MapRule CarPersonRule = new MapRule(Car, PersonCol, false);

            CarPersonRule.AddRule("carId", "cars_multivalued_.id");

            MapRule DrivesPersonRule = new MapRule(Drives, PersonCol, false);

            DrivesPersonRule.AddRule("note", "cars_multivalued_.note");

            ModelMapping Map = new ModelMapping("Map", new List <MapRule>()
            {
                PersonRule, CarRule, CarPersonRule, DrivesPersonRule
            });

            return(new DataContainer(Model, Schema, Map));
        }
Пример #37
0
        public void AttributeBecomesNonInheritableAfterRemoveFromParent()
        {
            Entity parent = new Entity() { Name = "parent" };

            Attribute attribute = new Attribute("test") { Value = new Value("value") };
            parent.AddAttribute(attribute);

            Entity child = new Entity();
            child.AddPrototype(parent);

            Attribute childAttribute = child.GetAttribute("test");
            //childAttribute.IsInherited = false;
            childAttribute.Value = new Value("new value");

            //Assert.IsTrue(childAttribute.CanInherit);

            parent.RemoveAttribute(attribute);

            //Assert.IsFalse(childAttribute.CanInherit);
            Assert.AreEqual(0, parent.Attributes.Count);
            Assert.AreEqual(1, child.Attributes.Count);
        }
Пример #38
0
        public void ClearAttributeValue()
        {
            Entity parent = new Entity() { Name = "parent" };

            Attribute parentAttribute = new Attribute("test") { Value = new Value("originalValue") };
            parent.AddAttribute(parentAttribute);

            Entity child = new Entity();
            child.AddPrototype(parent);

            Attribute childAttribute = child.GetAttribute("test");

            childAttribute.Value = new Value("value");

            Assert.AreEqual(childAttribute.Value.Initializer, "value");
            Assert.AreEqual(1, child.Attributes.Count(x => x.HasOwnValue));

            childAttribute.Value = null;

            Assert.AreEqual(childAttribute.Value.Initializer, "originalValue");
            Assert.AreEqual(0, child.Attributes.Count(x => x.HasOwnValue));
        }
Пример #39
0
        public void CannotAddDuplicateAttributeKey()
        {
            Entity entity = new Entity();

            entity.AddAttribute(new Attribute("test"));
            entity.AddAttribute(new Attribute("test"));

            Assert.AreEqual(1, entity.Attributes.Where(x => x.Name == "test").Count());
        }
Пример #40
0
        public void GiveInheritedAttributeLocalValue()
        {
            bool propertyChanged = false;

            Entity parent = new Entity() { Name = "parent" };

            Attribute parentAttribute = new Attribute("test");
            parent.AddAttribute(parentAttribute);

            Entity child = new Entity();
            child.AddPrototype(parent);

            Assert.AreEqual(1, child.Attributes.Count(x => x.IsInherited && !x.HasOwnValue));

            Attribute childAttribute = child.GetAttribute("test");
            childAttribute.PropertyChanged += (o, e) => propertyChanged |= (e.PropertyName == "HasOwnValue");

            childAttribute.Value = new Value("value");

            Assert.IsTrue(propertyChanged);
            Assert.AreEqual(1, child.Attributes.Count(x => x.HasOwnValue));
        }
Пример #41
0
        //protected EntityDescriptor<TRelatedEntity> Get<TRelatedEntity>(Func<EntityDescriptor<TRelatedEntity>> getRelatedEntity, [CallerMemberName]string name = "") where TRelatedEntity: EntityDescriptor<TRelatedEntity>
        //{
        //    if (_relations.TryGetValue(name, out RelationDescriptor relation))
        //    {
        //        return relation as EntityDescriptor<TRelatedEntity>;
        //    }

        //    var relationDescriptor = getRelatedEntity.Invoke() as RelationDescriptor;
        //    var metadata = relationDescriptor.Metadata;
        //    FillMetadataName(metadata, name);
        //    Entity.AddRelation(metadata);
        //    _relations.Add(name, relationDescriptor);

        //    return relationDescriptor as TMetadata;
        //}

        /// <summary>
        /// Has to be called only from descriptor because of caller member name
        /// </summary>
        /// <typeparam name="TMetadata"></typeparam>
        /// <param name="getMetadata"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        protected virtual TMetadata Get <TMetadata>(Func <TMetadata> getMetadata, [CallerMemberName] string name = "") where TMetadata : class
        {
            if (getMetadata is Func <AttributeMetadata> )
            {
                if (Entity.TryGetAttribute(name, out AttributeMetadata metadata))
                {
                    return(metadata as TMetadata);
                }

                metadata = getMetadata.Invoke() as AttributeMetadata;
                FillMetadataName(metadata, name);
                Entity.AddAttribute(metadata);
                return(metadata as TMetadata);
            }
            else if (getMetadata is Func <RelationMetadata> )
            {
                if (Entity.TryGetRelation(name, out RelationMetadata metadata))
                {
                    return(metadata as TMetadata);
                }

                metadata = getMetadata.Invoke() as RelationMetadata;
                FillMetadataName(metadata, name);
                Entity.AddRelation(metadata);
                return(metadata as TMetadata);
            }
            else if (getMetadata is Func <RelationDescriptor> )
            {
                if (_relationDescriptors.TryGetValue(name, out RelationDescriptor relation))
                {
                    return(relation as TMetadata);
                }

                var relationDescriptor = getMetadata.Invoke() as RelationDescriptor;

                var metadata = relationDescriptor.Metadata;

                FillMetadataName(metadata, name);

                Entity.AddRelation(metadata);


                _relationDescriptors.Add(name, relationDescriptor);

                return(relationDescriptor as TMetadata);
                //if (Entity.TryGetRelation(name, out RelationMetadata metadata))
                //{
                //    //TODO resolve retun descriptor instead of Metadata
                //    return _relationDescriptorDictionary[metadata] as TMetadata;
                //    return metadata as TMetadata;
                //}

                //var relationDescriptor = getMetadata.Invoke() as RelationDescriptor;
                //metadata = relationDescriptor.Metadata;
                //FillMetadataName(metadata, name);
                //Entity.AddRelation(metadata);

                //_relationDescriptorDictionary.Add(metadata, relationDescriptor);

                //return relationDescriptor as TMetadata;
            }

            //TODO Improve exception
            throw new EafException("Cannot create Attribute");
        }
Пример #42
0
        public void ValueFollowsInheritedAttribute()
        {
            //bool propertyChanged = false;

            Entity parent = new Entity() { Name = "parent" };

            Attribute parentAttribute = new Attribute("test");
            parent.AddAttribute(parentAttribute);

            Entity child = new Entity();
            child.AddPrototype(parent);

            Attribute childAttribute = child.GetAttribute("test");
            //childAttribute.PropertyChanged += (o, e) => propertyChanged = (e.PropertyName == "Value");

            parentAttribute.Value = new Value("value");

            //Assert.IsTrue(propertyChanged);
            Assert.AreEqual("value", childAttribute.Value.Initializer);
        }
        /// <summary>
        /// Generate data to test a computed entity from a many to many relationship
        /// </summary>
        /// <returns></returns>
        public static RequiredDataContainer ManyToManyComputedEntity()
        {
            Entity Person = new Entity("Person");

            Person.AddAttributes("personId", "name");
            Person.SetIdentifier("personId");

            Entity Car = new Entity("Car");

            Car.AddAttributes("carId", "model", "year");
            Car.SetIdentifier("carId");

            Entity Garage = new Entity("Garage");

            Garage.AddAttributes("garageId", "name");
            Garage.SetIdentifier("garageId");

            Entity Supplier = new Entity("Supplier");

            Supplier.AddAttributes("supplierId", "name");
            Supplier.SetIdentifier("supplierId");

            Entity Insurance = new Entity("Insurance");

            Insurance.AddAttributes("insuranceId", "name", "value");
            Insurance.AddAttribute("insuranceId");

            Relationship Owns = new Relationship("Owns");

            Owns.AddRelationshipEnd(new RelationshipEnd(Person));
            Owns.AddRelationshipEnd(new RelationshipEnd(Car));
            Owns.AddRelationshipEnd(new RelationshipEnd(Insurance));
            Owns.AddAttributes("ownsId", "personId", "carId", "insuranceId");

            Relationship Repaired = new Relationship("Repaired");

            Repaired.AddAttributes("repairedId", "carId", "garageId", "supplierId", "repaired");
            Repaired.AddRelationshipEnd(new RelationshipEnd(Car));
            Repaired.AddRelationshipEnd(new RelationshipEnd(Garage));
            Repaired.AddRelationshipEnd(new RelationshipEnd(Supplier));;

            ERModel Model = new ERModel("ERModel", new List <BaseERElement> {
                Person, Car, Garage, Repaired, Supplier, Insurance, Owns
            });

            // Mongo Schema
            MongoDBCollection PersonCol = new MongoDBCollection("Person");

            PersonCol.AddAttributes("_id", "name", "insuranceId");

            MongoDBCollection CarCol = new MongoDBCollection("Car");

            CarCol.AddAttributes("_id", "model", "year", "driverId");

            MongoDBCollection GarageCol = new MongoDBCollection("Garage");

            GarageCol.AddAttributes("_id", "name");

            MongoDBCollection SupplierCol = new MongoDBCollection("Supplier");

            SupplierCol.AddAttributes("_id", "name");

            MongoDBCollection RepairedCol = new MongoDBCollection("Repaired");

            RepairedCol.AddAttributes("_id", "carId", "garageId", "supplierId", "repaired");

            MongoDBCollection InsuranceCol = new MongoDBCollection("Insurance");

            InsuranceCol.AddAttributes("_id", "name", "value");

            MongoDBCollection OwnsCol = new MongoDBCollection("Owns");

            OwnsCol.AddAttributes("_id", "personId", "carId", "insuranceId");

            MongoSchema Schema = new MongoSchema("Schema", new List <MongoDBCollection> {
                PersonCol, CarCol, GarageCol, RepairedCol, SupplierCol, InsuranceCol, OwnsCol
            });

            // Map Rules
            MapRule PersonRule = new MapRule(Person, PersonCol);

            PersonRule.AddRule("personId", "_id");
            PersonRule.AddRule("name", "name");

            MapRule CarRule = new MapRule(Car, CarCol);

            CarRule.AddRule("carId", "_id");
            CarRule.AddRule("model", "model");
            CarRule.AddRule("year", "year");

            MapRule GarageRule = new MapRule(Garage, GarageCol);

            GarageRule.AddRule("garageId", "_id");
            GarageRule.AddRule("name", "name");

            MapRule SupplierRule = new MapRule(Supplier, SupplierCol);

            SupplierRule.AddRule("supplierId", "_id");
            SupplierRule.AddRule("name", "name");

            MapRule RepairedRule = new MapRule(Repaired, RepairedCol);

            RepairedRule.AddRule("repairedId", "_id");
            RepairedRule.AddRule("carId", "carId");
            RepairedRule.AddRule("garageId", "garageId");
            RepairedRule.AddRule("supplierId", "supplierId");
            RepairedRule.AddRule("repaired", "repaired");

            MapRule InsuranceRule = new MapRule(Insurance, InsuranceCol);

            InsuranceRule.AddRule("insuranceId", "_id");
            InsuranceRule.AddRule("name", "name");
            InsuranceRule.AddRule("value", "value");

            MapRule OwnsRule = new MapRule(Owns, OwnsCol);

            OwnsRule.AddRule("ownsId", "_id");
            OwnsRule.AddRule("personId", "personId");
            OwnsRule.AddRule("carId", "carId");
            OwnsRule.AddRule("insuranceId", "insuranceId");

            ModelMapping Map = new ModelMapping("Map", new List <MapRule> {
                PersonRule, CarRule, GarageRule, RepairedRule, SupplierRule, InsuranceRule, OwnsRule
            });

            return(new RequiredDataContainer(Model, Schema, Map));
        }