コード例 #1
0
        /// <summary>
        /// Creates a new database file at the specified path with the specified file name.
        /// The ".sdf" extension will be added to the file. Do not pass it in the file name.
        /// </summary>
        /// <param name="databaseFilePath">The path to the file, excluding the file's name</param>
        /// <param name="databaseFileName">The name of the new database file. Exclude the .sdf extension - it will be added automatically.</param>
        /// <param name="changeApplicationConnection">If true, the application's connection will be changed to this new database.</param>
        /// <returns>Returns the full path to the database file.</returns>
        public string CreateNewDatabase(string databaseFilePath, string databaseFileName, bool changeApplicationConnection)
        {
            string fullPath = databaseFilePath + "\\" + databaseFileName + ".sdf";
            string connectionString;

            // Update connection settings and the active module directory path
            if (changeApplicationConnection)
            {
                ChangeDatabaseConnection(fullPath);
                WinterConnectionInformation.ActiveModuleDirectoryPath = fullPath;
                connectionString = WinterConnectionInformation.ActiveConnectionString;
            }
            // Otherwise we're simply creating a new database file. Build a connection string.
            else
            {
                connectionString = BuildConnectionString(fullPath);
            }

            // Initialize the database - will create the database file at the specified location.
            // Also creates tables based on the code-first model.
            using (ModuleDataContext context = new ModuleDataContext(connectionString))
            {
                DbMigrator migrator = new DbMigrator(new ModuleDataContextMigrationConfiguration());
                migrator.Update();
            }

            return fullPath;
        }
コード例 #2
0
ファイル: RepositoryBase.cs プロジェクト: zunath/WinterEngine
 public RepositoryBase(string connectionString = "", bool autoSaveChanges = true)
 {
     if (String.IsNullOrWhiteSpace(connectionString))
     {
         connectionString = WinterConnectionInformation.ActiveConnectionString;
     }
     ConnectionString = connectionString;
     _context = new ModuleDataContext(ConnectionString);
     _autoSaveChanges = autoSaveChanges;
 }
コード例 #3
0
        public void Initialize()
        {
            Category defaultCategoryArea;
            Category defaultCategoryItem;
            Category defaultCategoryPlaceable;
            Category defaultCategoryCreature;
            Category defaultCategoryConversation;
            Category defaultCategoryScript;
            Category defaultCategoryTileset;
            Category defaultCategoryGameModule;
            Gender defaultGender;
            Race defaultRace;
            Script defaultScript;
            ContentPackageResource defaultContentPackageResourceBGM;
            ContentPackageResource defaultContentPackageResourceCharacter;
            ContentPackageResource defaultContentPackageResourceItem;
            ContentPackageResource defaultContentPackageResourceNone;
            ContentPackageResource defaultContentPackageResourcePlaceable;
            ContentPackageResource defaultContentPackageResourceSoundEffect;
            ContentPackageResource defaultContentPackageResourceTileset;
            Faction defaultFaction;
            Conversation defaultConversation;
            Item defaultItem;
            Tileset defaultTileset;

            using (ModuleDataContext context = new ModuleDataContext())
            {
                #region Category Defaults
                try
                {
                    defaultCategoryArea = context.ResourceCategories.Add(new Category
                    {
                        Name = "*Uncategorized",
                        GameObjectType = GameObjectTypeEnum.Area,
                        ResourceType = ResourceTypeEnum.GameObject,
                        IsSystemResource = true,
                        IsDefault = true,
                    });
                    defaultCategoryConversation = context.ResourceCategories.Add(new Category
                    {
                        Name = "*Uncategorized",
                        GameObjectType = GameObjectTypeEnum.Conversation,
                        ResourceType = ResourceTypeEnum.GameObject,
                        IsSystemResource = true,
                        IsDefault = true,
                    });
                    defaultCategoryCreature = context.ResourceCategories.Add(new Category
                    {
                        Name = "*Uncategorized",
                        GameObjectType = GameObjectTypeEnum.Creature,
                        ResourceType = ResourceTypeEnum.GameObject,
                        IsSystemResource = true,
                        IsDefault = true,
                    });
                    defaultCategoryItem = context.ResourceCategories.Add(new Category
                    {
                        Name = "*Uncategorized",
                        GameObjectType = GameObjectTypeEnum.Item,
                        ResourceType = ResourceTypeEnum.GameObject,
                        IsSystemResource = true,
                        IsDefault = true,
                    });
                    defaultCategoryPlaceable = context.ResourceCategories.Add(new Category
                    {
                        Name = "*Uncategorized",
                        GameObjectType = GameObjectTypeEnum.Placeable,
                        ResourceType = ResourceTypeEnum.GameObject,
                        IsSystemResource = true,
                        IsDefault = true,
                    });
                    defaultCategoryScript = context.ResourceCategories.Add(new Category
                    {
                        Name = "*Uncategorized",
                        GameObjectType = GameObjectTypeEnum.Script,
                        ResourceType = ResourceTypeEnum.GameObject,
                        IsSystemResource = true,
                        IsDefault = true,
                    });
                    defaultCategoryTileset = context.ResourceCategories.Add(new Category
                    {
                        Name = "*Uncategorized",
                        GameObjectType = GameObjectTypeEnum.Tileset,
                        ResourceType = ResourceTypeEnum.GameObject,
                        IsSystemResource = true,
                        IsDefault = true,
                    });
                    defaultCategoryGameModule = context.ResourceCategories.Add(new Category
                    {
                        Name = "*Uncategorized",
                        GameObjectType = GameObjectTypeEnum.GameModule,
                        ResourceType = ResourceTypeEnum.GameObject,
                        IsSystemResource = true,
                        IsDefault = true,
                    });

                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new Exception("Error adding categories.", ex);
                }

                #endregion

                try
                {
                    defaultGender = context.Genders.Add(new Gender
                    {
                        GenderType = GenderTypeEnum.Unknown,
                        IsSystemResource = true,
                        IsDefault = true,
                        Name = "(None)"

                    });

                    context.Genders.Add(new Gender
                    {
                        GenderType = GenderTypeEnum.Male,
                        IsSystemResource = true,
                        Name = "Male"
                    });

                    context.Genders.Add(new Gender
                    {
                        GenderType = GenderTypeEnum.Female,
                        IsSystemResource = true,
                        Name = "Female"
                    });

                    context.SaveChanges();
                }
                catch(Exception ex)
                {
                    throw new Exception("Error adding genders.", ex);
                }

                try
                {
                    defaultRace = context.Races.Add(new Race
                    {
                        IsDefault = true,
                        IsSystemResource = true,
                        Name = "(None)"
                    });

                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new Exception("Error adding races.", ex);
                }
                try
                {
                    defaultContentPackageResourceBGM = context.ContentPackageResources.Add(new ContentPackageResource
                    {
                        IsDefault = true,
                        IsSystemResource = true,
                        Name = "(None)",
                        ContentPackageResourceType = ContentPackageResourceTypeEnum.BGM
                    });
                    defaultContentPackageResourceCharacter = context.ContentPackageResources.Add(new ContentPackageResource
                    {
                        IsDefault = true,
                        IsSystemResource = true,
                        Name = "(None)",
                        ContentPackageResourceType = ContentPackageResourceTypeEnum.Character
                    });
                    defaultContentPackageResourceItem = context.ContentPackageResources.Add(new ContentPackageResource
                    {
                        IsDefault = true,
                        IsSystemResource = true,
                        Name = "(None)",
                        ContentPackageResourceType = ContentPackageResourceTypeEnum.Item
                    });
                    defaultContentPackageResourceNone = context.ContentPackageResources.Add(new ContentPackageResource
                    {
                        IsDefault = true,
                        IsSystemResource = true,
                        Name = "(None)",
                        ContentPackageResourceType = ContentPackageResourceTypeEnum.None
                    });
                    defaultContentPackageResourcePlaceable = context.ContentPackageResources.Add(new ContentPackageResource
                    {
                        IsDefault = true,
                        IsSystemResource = true,
                        Name = "(None)",
                        ContentPackageResourceType = ContentPackageResourceTypeEnum.Placeable
                    });
                    defaultContentPackageResourceSoundEffect = context.ContentPackageResources.Add(new ContentPackageResource
                    {
                        IsDefault = true,
                        IsSystemResource = true,
                        Name = "(None)",
                        ContentPackageResourceType = ContentPackageResourceTypeEnum.SoundEffect
                    });
                    defaultContentPackageResourceTileset = context.ContentPackageResources.Add(new ContentPackageResource
                    {
                        IsDefault = true,
                        IsSystemResource = true,
                        Name = "(None)",
                        ContentPackageResourceType = ContentPackageResourceTypeEnum.Tileset
                    });

                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new Exception("Error adding content package resources.", ex);
                }

                try
                {
                    defaultScript = context.Scripts.Add(new Script
                    {
                        IsDefault = true,
                        IsInTreeView = false,
                        IsSystemResource = true,
                        Name = "(None)",
                        Tag = "",
                        Resref = "",
                        ResourceCategoryID = defaultCategoryScript.ResourceID,
                        GraphicResourceID = defaultContentPackageResourceNone.ResourceID
                    });

                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new Exception("Error adding scripts.", ex);
                }

                try
                {
                    defaultFaction = context.Factions.Add(new Faction
                    {
                        IsDefault = true,
                        IsSystemResource = true,
                        Name = "(None)"
                    });

                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new Exception("Error adding factions.", ex);
                }
                try
                {
                    defaultConversation = context.Conversations.Add(new Conversation
                    {
                        GraphicResourceID = defaultContentPackageResourceNone.ResourceID,
                        IsDefault = true,
                        IsInTreeView = false,
                        IsSystemResource = true,
                        Name = "(None)",
                        Tag = "",
                        Resref = "",
                        ResourceCategoryID = defaultCategoryConversation.ResourceID
                    });

                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new Exception("Error adding conversations.", ex);
                }
                try
                {
                    defaultItem = context.Items.Add(new Item
                    {
                        GraphicResourceID = defaultContentPackageResourceItem.ResourceID,
                        IsDefault = true,
                        IsInTreeView = false,
                        IsSystemResource = true,
                        Name = "(None)",
                        Tag = "",
                        Resref = "",
                        OnSpawnEventScriptID = defaultScript.ResourceID,
                        ResourceCategoryID = defaultCategoryItem.ResourceID
                    });

                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new Exception("Error adding items.", ex);
                }

                try
                {
                    defaultTileset = context.Tilesets.Add(new Tileset
                    {
                        GraphicResourceID = defaultContentPackageResourceTileset.ResourceID,
                        IsDefault = true,
                        IsInTreeView = false,
                        IsSystemResource = true,
                        Name = "(None)",
                        Tag = "",
                        Resref = "",
                        ResourceCategoryID = defaultCategoryTileset.ResourceID
                    });

                    context.SaveChanges();
                }
                catch(Exception ex)
                {
                    throw new Exception("Error adding tilesets.", ex);
                }

                try
                {
                    List<LevelRequirement> levels = new List<LevelRequirement>();

                    for (int current = 1; current <= 99; current++)
                    {
                        levels.Add(new LevelRequirement
                        {
                            NewAbilities = 0,
                            ExperienceRequired = current * 500,
                            IsDefault = false,
                            IsSystemResource = false,
                            Level = current,
                            SkillPoints = 0,
                        });
                    }

                    context.LevelRequirements.AddRange(levels);
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new Exception("Error adding level requirements.", ex);
                }
            }
        }