public static CfgCardWeb Create(ToH_Database_WebContext context, string Name)
        {
            CfgCardWeb ret   = new CfgCardWeb();
            var        cards = from c in context.CfgCard select c;

            ret.Card = cards.Where(c => c.Name == Name && c.In_book && c.Id == c.Root_card_id).FirstOrDefault();
            if (ret.Card != null)
            {
                List <CfgCard> cardList = cards.Where(c => c.Id != ret.Card.Id && c.Root_card_id == ret.Card.Root_card_id).OrderBy(c => c.Star).ThenBy(c => c.Id).ToList();
                for (int i = 0; i < cardList.Count; i++)
                {
                    CfgCardWeb c = new CfgCardWeb();
                    c.Card = cardList[i];
                    ret.Cards.Add(c);
                }

                ret.Skills.Add(CfgSkillWeb.Create(context, ret.Card.Skill1));
                ret.Skills.Add(CfgSkillWeb.Create(context, ret.Card.Skill2));
                ret.Skills.Add(CfgSkillWeb.Create(context, ret.Card.Skill3));
                ret.Skills.Add(CfgSkillWeb.Create(context, ret.Card.Skill4));
                ret.Gift = CfgSkillWeb.Create(context, ret.Card.Skill_gift);
            }

            return(ret);
        }
Exemple #2
0
        public static CfgSkillWeb Create(ToH_Database_WebContext context, long ID)
        {
            CfgSkillWeb ret   = new CfgSkillWeb();
            CfgSkill    skill = (from c in context.CfgSkill select c).Where(c => c.Id == ID).FirstOrDefault();

            ret.Skill = skill;
            if (skill != null)
            {
                string[] effects = skill.Skill_effects.Split(";");
                ret.Effects = (from c in context.CfgSkillEffect select c).Where(c => effects.Contains(c.Id.ToString())).ToList();
            }

            return(ret);
        }
Exemple #3
0
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;

            // Ensure that the mainthread is actually blocked otherweise our Seeding-Algorithm will kick in before the DB is fully created.

            try
            {
                using (var db = new ToH_Database_WebContext())
                {
                    db.Database.EnsureCreated();
                    db.Database.Migrate();
                }
            }
            catch { }
        }
Exemple #4
0
            public MetaData(Type baseType, ToH_Database_WebContext context)
            {
                JsonModel           = (string)baseType.GetMethod("getCfgJsonPath").Invoke(null, null);
                DBModel             = (IEnumerable <I_CfgModel>)baseType.GetMethod("getDBSet").Invoke(null, new object[] { context });
                DeserializingMethod = typeof(JsonSerializer).GetMethods().Single(m =>
                                                                                 m.Name == "Deserialize" &&
                                                                                 m.GetGenericArguments().Length == 1 &&
                                                                                 m.GetParameters().Length == 1 &&
                                                                                 m.GetParameters()[0].ParameterType == typeof(JsonReader)).MakeGenericMethod(baseType);

                object db = baseType.GetMethod("getDBSet").Invoke(null, new object[] { context });

                AddObject    = db.GetType().GetMethod("Add");
                UpdateObject = db.GetType().GetMethod("Attach");
                Type         = baseType;
            }
 public static DbSet <CfgActivityHeroCall> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgActivityHeroCall>)ctx.GetType().GetProperty("CfgActivityHeroCall")?.GetValue(ctx, null));
 }
Exemple #6
0
 public static DbSet <CfgHorseMission> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgHorseMission>)ctx.GetType().GetProperty("CfgHorseMission")?.GetValue(ctx, null));
 }
Exemple #7
0
 public static DbSet<CfgBattlePass> getDBSet(ToH_Database_WebContext ctx)
 {
     return (DbSet<CfgBattlePass>)ctx.GetType().GetProperty("CfgBattlePass")?.GetValue(ctx, null);
 }
Exemple #8
0
 public static DbSet <CfgCardRandType> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgCardRandType>)ctx.GetType().GetProperty("CfgCardRandType")?.GetValue(ctx, null));
 }
Exemple #9
0
 public static DbSet <CfgDecayBigGrid> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgDecayBigGrid>)ctx.GetType().GetProperty("CfgDecayBigGrid")?.GetValue(ctx, null));
 }
Exemple #10
0
 public static DbSet <CfgArenaRewardUser> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgArenaRewardUser>)ctx.GetType().GetProperty("CfgArenaRewardUser")?.GetValue(ctx, null));
 }
 public static DbSet <CfgUnionFortNormalMissionRewardLv> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgUnionFortNormalMissionRewardLv>)ctx.GetType().GetProperty("CfgUnionFortNormalMissionRewardLv")?.GetValue(ctx, null));
 }
Exemple #12
0
 public static DbSet <CfgAchieveText> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgAchieveText>)ctx.GetType().GetProperty("CfgAchieveText")?.GetValue(ctx, null));
 }
 public static DbSet <CfgArtifactPieceCombine> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgArtifactPieceCombine>)ctx.GetType().GetProperty("CfgArtifactPieceCombine")?.GetValue(ctx, null));
 }
 public static DbSet <CfgHollowMineLv> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgHollowMineLv>)ctx.GetType().GetProperty("CfgHollowMineLv")?.GetValue(ctx, null));
 }
 public static DbSet <CfgNoticeEvents> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgNoticeEvents>)ctx.GetType().GetProperty("CfgNoticeEvents")?.GetValue(ctx, null));
 }
Exemple #16
0
        private void SeedData()
        {
            try
            {
                // To make the seeding WAY faster we can "cheat" our way to it by using only changed data in the json.
                // The Data-Fetcher-Service is now outputting a json file with the correct format to get all changed data.
                // Seeding the data.json only if the data_web.json is not existent.

                // My Service is acutally now outputting a correct diff of the new and old Json files. If we delete the json File after seeding, everything will be fine and way faster than before.
#if BETA
                string SeedingFile = "D:/ToH/Data/data_web_dev.json";
#else
                string SeedingFile = "D:/ToH/Data/data_web.json";
#endif
                if (!File.Exists(SeedingFile))
                {
                    return;
                }

                /*
                 * if (File.Exists("D:/ToH/Data/data_web.json"))
                 * {
                 *  // Get differences with the current file and the backuped file.
                 *  SeedingFile = "D:/ToH/Data/data_web.json";
                 * }
                 */

                using (var context = new ToH_Database_WebContext(
                           _serviceProvider.GetRequiredService <
                               DbContextOptions <ToH_Database_WebContext> >()))
                {
                    // TODO: Deserialize ToH-Json File here.
                    string FilePath = SeedingFile;
                    if (File.Exists(FilePath))
                    {
                        JsonSerializer serializer = new JsonSerializer();
                        serializer.Converters.Add(new BooleanJsonConverter());

                        // Get all Meta-Data of all models available.
                        var types = AppDomain.CurrentDomain.GetAssemblies()
                                    .SelectMany(s => s.GetTypes())
                                    .Where(p => typeof(I_CfgModel).IsAssignableFrom(p) && p.IsClass && !p.IsAbstract);

                        List <MetaData> metaModels = new List <MetaData>();

                        foreach (Type t in types)
                        {
                            metaModels.Add(new MetaData(t, context));
                        }


                        for (int i = 0; i < metaModels.Count; i++)
                        {
                            using (FileStream s = File.Open(FilePath, FileMode.Open))
                                using (StreamReader sr = new StreamReader(s))
                                    using (JsonTextReader reader = new JsonTextReader(sr))
                                    {
                                        MetaData md = metaModels[i];
                                        if (md.DBModel == null || md.DeserializingMethod == null || md.AddObject == null || md.UpdateObject == null)
                                        {
                                            continue;
                                        }

                                        var tbl = new DefaultJsonNameTable();
                                        tbl.Add(md.JsonModel);
                                        reader.PropertyNameTable = tbl;

                                        bool UsedToHaveData = false;

                                        // Seems like formatted json code is actually slower to read as unformatted json code.

                                        while (reader.Read())
                                        {
                                            if (reader.TokenType != JsonToken.StartObject)
                                            {
                                                continue;
                                            }

                                            if (i == 41)
                                            {
                                                int aasd = 0;
                                            }

                                            if (!reader.Path.Contains(md.JsonModel.Replace("data.", "") + "."))
                                            {
                                                if (UsedToHaveData)
                                                {
                                                    break;
                                                }
                                                continue;
                                            }

                                            UsedToHaveData = true;

                                            // Insert new Object or update existing ones.
                                            I_CfgModel c = (I_CfgModel)md.DeserializingMethod.Invoke(serializer, new object[] { reader });

                                            if (c == null)
                                            {
                                                continue;
                                            }

                                            var a = context.Find(md.Type, new object[] { c.getID() });
                                            if (a != null)
                                            {
                                                context.Entry(a).CurrentValues.SetValues(c);
                                            }
                                            else
                                            {
                                                md.AddObject.Invoke(md.DBModel, new object[] { c });
                                            }
                                        }
                                    }
                        }
                    }
                    context.SaveChanges();
                }

                File.Delete(SeedingFile);
            }
            catch (Exception ex)
            {
                // TODO: Log ex.
            }
        }
 public static DbSet <CfgMagicArtifactExchange> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgMagicArtifactExchange>)ctx.GetType().GetProperty("CfgMagicArtifactExchange")?.GetValue(ctx, null));
 }
 public static DbSet <CfgProductItem> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgProductItem>)ctx.GetType().GetProperty("CfgProductItem")?.GetValue(ctx, null));
 }
 public static DbSet <CfgLostcityDrug> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgLostcityDrug>)ctx.GetType().GetProperty("CfgLostcityDrug")?.GetValue(ctx, null));
 }
Exemple #20
0
 public static DbSet <CfgWheelHighWish> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgWheelHighWish>)ctx.GetType().GetProperty("CfgWheelHighWish")?.GetValue(ctx, null));
 }
 public static DbSet <CfgRuneBook> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgRuneBook>)ctx.GetType().GetProperty("CfgRuneBook")?.GetValue(ctx, null));
 }
 public static DbSet <CfgBholeDebuff> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgBholeDebuff>)ctx.GetType().GetProperty("CfgBholeDebuff")?.GetValue(ctx, null));
 }
Exemple #23
0
 public static DbSet <CfgBholeTitleRewardFirst> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgBholeTitleRewardFirst>)ctx.GetType().GetProperty("CfgBholeTitleRewardFirst")?.GetValue(ctx, null));
 }
Exemple #24
0
 public static DbSet <CfgHappiestBuildingUpgrade> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgHappiestBuildingUpgrade>)ctx.GetType().GetProperty("CfgHappiestBuildingUpgrade")?.GetValue(ctx, null));
 }
Exemple #25
0
 public static DbSet <CfgChallengeFinalSp> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgChallengeFinalSp>)ctx.GetType().GetProperty("CfgChallengeFinalSp")?.GetValue(ctx, null));
 }
 public static DbSet <CfgLongBattleBoost> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgLongBattleBoost>)ctx.GetType().GetProperty("CfgLongBattleBoost")?.GetValue(ctx, null));
 }
Exemple #27
0
 public static DbSet <CfgUnionBossReward> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgUnionBossReward>)ctx.GetType().GetProperty("CfgUnionBossReward")?.GetValue(ctx, null));
 }
Exemple #28
0
 public static DbSet <CfgDecaySmallMapConsist> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgDecaySmallMapConsist>)ctx.GetType().GetProperty("CfgDecaySmallMapConsist")?.GetValue(ctx, null));
 }
 public static DbSet <CfgEquipmentGroup> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgEquipmentGroup>)ctx.GetType().GetProperty("CfgEquipmentGroup")?.GetValue(ctx, null));
 }
 public static DbSet <CfgGalaxyChooseLvUp> getDBSet(ToH_Database_WebContext ctx)
 {
     return((DbSet <CfgGalaxyChooseLvUp>)ctx.GetType().GetProperty("CfgGalaxyChooseLvUp")?.GetValue(ctx, null));
 }