Example #1
0
        public static void InitialSeed()
        {
            // check whether initial seed needs to continue
            bool doSeed = false;

            using (var db = new MyDbContext())
            {
                var se = db.GlobalSettings.FirstOrDefault();
                if (se == null || se.databaseGenerated == false)
                {
                    doSeed = true;
                }
            }

            if (doSeed == true)
            {
                // populate Versions table
                Versions version = Versions.GetVersionDefaults();
                using (var context = new MyDbContext())
                {
                    context.Versions.Add(version);
                    context.SaveChanges();
                }


                // default netplay settings
                ConfigNetplaySettings npSettings = ConfigNetplaySettings.GetNetplayDefaults();
                using (var context = new MyDbContext())
                {
                    context.ConfigNetplaySettings.Add(npSettings);
                    context.SaveChanges();
                }

                // default ConfigBaseSettings population
                ConfigBaseSettings cfbs = ConfigBaseSettings.GetConfigDefaults();

                cfbs.ConfigId = 2000000000; // base configuration

                using (var context = new MyDbContext())
                {
                    context.ConfigBaseSettings.Add(cfbs);
                    context.SaveChanges();
                }

                // create system specific configs (set to disabled by default)
                List <GSystem> gamesystems = GSystem.GetSystems();
                using (var gsContext = new MyDbContext())
                {
                    // iterate through each system and create a default config for them - setting them to disabled, setting their ID to 2000000000 + SystemID
                    // and setting their systemident to systemid
                    foreach (GSystem System in gamesystems)
                    {
                        int def = 2000000000;
                        ConfigBaseSettings c = ConfigBaseSettings.GetConfigDefaults();
                        c.ConfigId    = def + System.systemId;
                        c.systemIdent = System.systemId;
                        c.isEnabled   = false;

                        // add to databsae
                        gsContext.ConfigBaseSettings.Add(c);
                        gsContext.SaveChanges();
                    }
                }

                // Populate Servers
                List <ConfigServerSettings> servers = ConfigServerSettings.GetServerDefaults();
                using (var context = new MyDbContext())
                {
                    context.ConfigServerSettings.AddRange(servers);
                    context.SaveChanges();
                }

                // Create General Settings Entry
                GlobalSettings gs = GlobalSettings.GetGlobalDefaults();
                using (var context = new MyDbContext())
                {
                    context.GlobalSettings.Add(gs);
                    context.SaveChanges();
                }

                // create mednanet general entry
                MednaNetSettings ms = MednaNetSettings.GetMednaNetDefaults();
                using (var context = new MyDbContext())
                {
                    context.MednaNetSettings.Add(ms);
                    context.SaveChanges();
                }

                // create Paths entry
                Paths paths = new Paths
                {
                    pathId = 1
                };
                using (var context = new MyDbContext())
                {
                    context.Paths.Add(paths);
                    context.SaveChanges();
                }

                // initial seeding complete. mark GeneralSettings table so that regeneration does not occur
                GlobalSettings set;
                using (var context = new MyDbContext())
                {
                    set = (from a in context.GlobalSettings
                           where a.settingsId == 1
                           select a).FirstOrDefault <GlobalSettings>();
                }

                if (set != null)
                {
                    set.databaseGenerated = true;
                }

                using (var dbCtx = new MyDbContext())
                {
                    dbCtx.Entry(set).State = EntityState.Modified;
                    dbCtx.SaveChanges();
                }
            }
        }
Example #2
0
        public static void InitialSeed()
        {
            // check whether initial seed needs to continue
            bool doSeed = false;

            using (var db = new MyDbContext())
            {
                var se = db.GlobalSettings.FirstOrDefault();
                if (se == null || se.databaseGenerated == false)
                {
                    doSeed = true;
                }
            }

            if (doSeed == true)
            {
                /*
                 * // Create systems
                 * List<GameSystem> gSystems = GameSystem.GetGameSystemDefaults();
                 * using (var context = new MyDbContext())
                 * {
                 *  var gameData = context.GameSystem.AsNoTracking().ToList();
                 *  foreach (var newEntry in gSystems)
                 *  {
                 *      var idLookup = (from e in gameData
                 *                      where e.systemId == newEntry.systemId
                 *                      select e).FirstOrDefault();
                 *
                 *      if (idLookup == null)
                 *      {
                 *          // entry doesnt exist - insert
                 *          context.GameSystem.Add(newEntry);
                 *      }
                 *      else
                 *      {
                 *          // entry exists - update
                 *          context.GameSystem.Update(newEntry);
                 *      }
                 *  }
                 *  context.SaveChanges();
                 * }
                 */

                // populate Versions table
                Versions version = Versions.GetVersionDefaults();
                using (var context = new MyDbContext())
                {
                    context.Versions.Add(version);
                    context.SaveChanges();
                }


                // default netplay settings
                ConfigNetplaySettings npSettings = ConfigNetplaySettings.GetNetplayDefaults();
                using (var context = new MyDbContext())
                {
                    context.ConfigNetplaySettings.Add(npSettings);
                    context.SaveChanges();
                }

                // default ConfigBaseSettings population
                ConfigBaseSettings cfbs = ConfigBaseSettings.GetConfigDefaults();

                cfbs.ConfigId = 2000000000; // base configuration

                using (var context = new MyDbContext())
                {
                    context.ConfigBaseSettings.Add(cfbs);
                    context.SaveChanges();
                }

                // create system specific configs (set to disabled by default)
                List <GSystem> gamesystems = GSystem.GetSystems();
                using (var gsContext = new MyDbContext())
                {
                    // iterate through each system and create a default config for them - setting them to disabled, setting their ID to 2000000000 + SystemID
                    // and setting their systemident to systemid
                    foreach (GSystem System in gamesystems)
                    {
                        int def = 2000000000;
                        ConfigBaseSettings c = ConfigBaseSettings.GetConfigDefaults();
                        c.ConfigId    = def + System.systemId;
                        c.systemIdent = System.systemId;
                        c.isEnabled   = false;

                        // add to databsae
                        gsContext.ConfigBaseSettings.Add(c);
                        gsContext.SaveChanges();
                    }
                }

                // Populate Servers
                List <ConfigServerSettings> servers = ConfigServerSettings.GetServerDefaults();
                using (var context = new MyDbContext())
                {
                    context.ConfigServerSettings.AddRange(servers);
                    context.SaveChanges();
                }

                // Create General Settings Entry
                GlobalSettings gs = GlobalSettings.GetGlobalDefaults();
                using (var context = new MyDbContext())
                {
                    context.GlobalSettings.Add(gs);
                    context.SaveChanges();
                }

                // create Paths entry
                Paths paths = new Paths
                {
                    pathId = 1
                };
                using (var context = new MyDbContext())
                {
                    context.Paths.Add(paths);
                    context.SaveChanges();
                }


                //add test rom data

                /*
                 * List<Game> roms = new List<Game>
                 * {
                 * new Game { gameName = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 8), gamePath = ".\\", systemId = 3, hidden = false, isFavorite = true },
                 * new Game { gameName = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 8), gamePath = ".\\", systemId = 10, hidden = false, isFavorite = false }
                 * };
                 * using (var context = new MyDbContext())
                 * {
                 *
                 *  context.Game.AddRange(roms);
                 *  context.SaveChanges();
                 * }
                 */

                // initial seeding complete. mark GeneralSettings table so that regeneration does not occur
                GlobalSettings set;
                using (var context = new MyDbContext())
                {
                    set = (from a in context.GlobalSettings
                           where a.settingsId == 1
                           select a).FirstOrDefault <GlobalSettings>();
                }

                if (set != null)
                {
                    set.databaseGenerated = true;
                }

                using (var dbCtx = new MyDbContext())
                {
                    dbCtx.Entry(set).State = EntityState.Modified;
                    dbCtx.SaveChanges();
                }
            }
        }