private IAssetType GetAssetType(DatabaseConnection conn, Guid databaseId, int assetTypeId)
        {
            // First, find the type of asset.
            AssetType assetType     = this.GetAssetType(conn, assetTypeId);
            string    assetTypeName = assetType.Name;

            IEnumerable <AssetTypeAttributesMap> maps = conn.AssetTypeAttributesMaps
                                                        .Include(nameof(AssetTypeAttributesMap.AttributeKey))
                                                        .Include(nameof(AssetTypeAttributesMap.AttributeProperties))
                                                        .Where(m => m.AssetType.Id == assetType.Id);

            AssetTypeBuilder assetTypeBuilder = new AssetTypeBuilder(assetTypeName, databaseId);

            foreach (AssetTypeAttributesMap map in maps)
            {
                IAttributeType attributeType = AttributeTypeFactory.CreateAttributeType(map.AttributeKey.AttributeType);
                attributeType.DeserializeDefaultValue(map.AttributeProperties.DefaultValue);
                attributeType.DeserializePossibleValues(map.AttributeProperties.PossibleValues);
                attributeType.Key      = map.AttributeKey.Name;
                attributeType.Required = map.AttributeProperties.Required;

                assetTypeBuilder.AttributeTypes.Add(attributeType);
            }

            return(assetTypeBuilder);
        }
        // ---------------- Functions ----------------

        public int AddAssetType(AssetTypeBuilder builder)
        {
            ArgumentChecker.IsNotNull(builder, nameof(builder));
            builder.Validate();

            Guid databaseId = builder.DatabaseId;

            this.GuidCheck(databaseId);

            using (DatabaseConnection conn = new DatabaseConnection(this.databaseConfigs[databaseId]))
            {
                DateTime  timestamp = DateTime.UtcNow;
                AssetType assetType = new AssetType
                {
                    Name         = builder.Name,
                    CreationDate = timestamp,
                    ModifiedDate = timestamp
                };

                conn.AssetTypes.Add(assetType);

                foreach (IAttributeType key in builder.AttributeTypes)
                {
                    AttributeKeys attributeKey = new AttributeKeys
                    {
                        Name          = key.Key,
                        AttributeType = key.AttributeType
                    };

                    conn.AttributeKeys.Add(attributeKey);

                    AttributeProperties properties = new AttributeProperties
                    {
                        DefaultValue   = key.SerializeDefaultValue(),
                        PossibleValues = key.SerializePossibleValues(),
                        Required       = key.Required
                    };
                    conn.AttributeProperties.Add(properties);

                    AssetTypeAttributesMap map = new AssetTypeAttributesMap
                    {
                        AssetType           = assetType,
                        AttributeKey        = attributeKey,
                        AttributeProperties = properties
                    };

                    conn.AssetTypeAttributesMaps.Add(map);
                }

                conn.SaveChanges();

                return(assetType.Id); // Must come after SaveChanges() so the ID gets updated.
            }
        }
        /// <summary>
        /// Adds the color attribute type.
        /// </summary>
        /// <returns>The type ID.</returns>
        private int AddColorAttributeType(IDatabaseApi uut, Guid databaseId)
        {
            AssetTypeBuilder       typeBuilder   = new AssetTypeBuilder(colorTypeName, databaseId);
            AssetNameAttributeType assetNameType = new AssetNameAttributeType
            {
                Key      = nameKey,
                Required = true
            };

            typeBuilder.AttributeTypes.Add(assetNameType);

            IntegerAttributeType redValue = new IntegerAttributeType
            {
                Key          = redKey,
                Required     = true,
                MinValue     = 0,
                MaxValue     = 255,
                DefaultValue = 0
            };

            typeBuilder.AttributeTypes.Add(redValue);

            IntegerAttributeType greenValue = new IntegerAttributeType
            {
                Key          = greenKey,
                Required     = true,
                MinValue     = 0,
                MaxValue     = 255,
                DefaultValue = 0
            };

            typeBuilder.AttributeTypes.Add(greenValue);

            IntegerAttributeType blueValue = new IntegerAttributeType
            {
                Key          = blueKey,
                Required     = true,
                MinValue     = 0,
                MaxValue     = 255,
                DefaultValue = 0
            };

            typeBuilder.AttributeTypes.Add(blueValue);

            int colorAssetTypeID = uut.AddAssetType(typeBuilder);

            return(colorAssetTypeID);
        }
Exemple #4
0
        private static void AddVideoGames(IAssetManagerApi api)
        {
            if (File.Exists(@"C:\Users\xfore\Downloads\VideoGames.db"))
            {
                File.Delete(@"C:\Users\xfore\Downloads\VideoGames.db");
            }

            Guid databaseId = api.DataBase.DatabaseNames.First(n => n.Value == "VideoGames").Key;

            AssetTypeBuilder builder = new AssetTypeBuilder("PC Games", databaseId);

            AssetNameAttributeType assetNameType = new AssetNameAttributeType
            {
                Key      = "Title",
                Required = true
            };

            builder.AttributeTypes.Add(assetNameType);

            IntegerAttributeType releaseYear = new IntegerAttributeType
            {
                Key      = "Release Year",
                Required = true
            };

            builder.AttributeTypes.Add(releaseYear);

            int pcGameId = api.DataBase.AddAssetType(builder);

            {
                Asset asset = api.DataBase.GenerateEmptyAsset(databaseId, pcGameId);
                asset.SetAttribute("Title", new AssetNameAttribute("Command and Conquer"));
                asset.SetAttribute("Release Year", new IntegerAttribute {
                    Value = 1995
                });
                api.DataBase.AddAsset(asset);
            }
        }
        // ---------------- Functions ----------------

        public Task <int> AsyncAddAssetType(AssetTypeBuilder builder)
        {
            return(Task.Factory.StartNew(() => this.databaseApi.AddAssetType(builder)));
        }
Exemple #6
0
        private static void AddTradingCards(IAssetManagerApi api)
        {
            if (File.Exists(@"C:\Users\xfore\Downloads\TradingCards.db"))
            {
                File.Delete(@"C:\Users\xfore\Downloads\TradingCards.db");
            }

            Guid databaseId = api.DataBase.DatabaseNames.First(n => n.Value == "TradingCards").Key;

            int pokemonCardTypeId = -1;
            {
                AssetTypeBuilder builder = new AssetTypeBuilder("Pokemon Card", databaseId);

                AssetNameAttributeType assetNameType = new AssetNameAttributeType
                {
                    Key      = "Card Name",
                    Required = true
                };
                builder.AttributeTypes.Add(assetNameType);

                IntegerAttributeType hpAttribute = new IntegerAttributeType
                {
                    Key          = "HP",
                    MinValue     = 10,
                    Required     = false,
                    DefaultValue = 50
                };

                builder.AttributeTypes.Add(hpAttribute);

                IntegerAttributeType retreatCostAttribute = new IntegerAttributeType
                {
                    Key      = "Retreat Cost",
                    MinValue = 0,
                    MaxValue = 4,
                    Required = false
                };
                builder.AttributeTypes.Add(retreatCostAttribute);

                StringAttributeType flavorText = new StringAttributeType
                {
                    Key      = "Flavor Text",
                    Required = true
                };
                builder.AttributeTypes.Add(flavorText);

                pokemonCardTypeId = api.DataBase.AddAssetType(builder);
            }

            int yugiohCardTypeId = -1;
            {
                AssetTypeBuilder builder = new AssetTypeBuilder("Yugioh! Card", databaseId);

                AssetNameAttributeType assetNameType = new AssetNameAttributeType
                {
                    Key      = "Card Name",
                    Required = true
                };
                builder.AttributeTypes.Add(assetNameType);

                IntegerAttributeType attackAttribute = new IntegerAttributeType
                {
                    Key      = "Attack",
                    MinValue = 0,
                    Required = true
                };
                builder.AttributeTypes.Add(attackAttribute);

                IntegerAttributeType defenseAttribute = new IntegerAttributeType
                {
                    Key      = "Defense",
                    MinValue = 0,
                    Required = true
                };
                builder.AttributeTypes.Add(defenseAttribute);

                yugiohCardTypeId = api.DataBase.AddAssetType(builder);
            }

            {
                Asset asset = api.DataBase.GenerateEmptyAsset(databaseId, pokemonCardTypeId);
                asset.SetAttribute("Card Name", new AssetNameAttribute("Politoed"));
                asset.SetAttribute("HP", new IntegerAttribute()
                {
                    Value = 100
                });
                asset.SetAttribute("Retreat Cost", new IntegerAttribute()
                {
                    Value = 3
                });
                asset.SetAttribute(
                    "Flavor Text",
                    new StringAttribute
                {
                    Value =
                        @"Whenever 3 or more of these get together,
they sing in an lound voice that sounds like bellowing."
                }
                    );

                api.DataBase.AddAsset(asset);
            }

            {
                Asset asset = api.DataBase.GenerateEmptyAsset(databaseId, yugiohCardTypeId);
                asset.SetAttribute("Card Name", new AssetNameAttribute("The 13th Grave"));

                IntegerAttribute attackAttr = asset.CloneAttributeAsType <IntegerAttribute>("Attack");
                attackAttr.Value = 1200;
                asset.SetAttribute("Attack", attackAttr);

                IntegerAttribute defenseAttr = asset.CloneAttributeAsType <IntegerAttribute>("Defense");
                defenseAttr.Value = 900;
                asset.SetAttribute("Defense", attackAttr);

                api.DataBase.AddAsset(asset);
            }

            {
                Asset asset = api.DataBase.GenerateEmptyAsset(databaseId, yugiohCardTypeId);
                asset.SetAttribute("Card Name", new AssetNameAttribute("Overdrive"));
                asset.SetAttribute("Attack", new IntegerAttribute(1600));
                asset.SetAttribute("Defense", new IntegerAttribute(1500));

                api.DataBase.AddAsset(asset);
            }
        }