public void UpsertInDatabase(GameObjectBase gameObject, string connectionString = "") { if (gameObject.GameObjectType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository(connectionString)) { repo.Upsert(gameObject as Area); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository(connectionString)) { repo.Upsert(gameObject as Conversation); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository(connectionString)) { repo.Upsert(gameObject as Creature); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository(connectionString)) { repo.Upsert(gameObject as Item); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository(connectionString)) { repo.Upsert(gameObject as Placeable); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository(connectionString)) { repo.Upsert(gameObject as Script); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository(connectionString)) { repo.Upsert(gameObject as Tileset); } } else { throw new NotSupportedException(); } }
private void SavePlaceable(object sender, GameObjectSaveEventArgs e) { using (PlaceableRepository repo = new PlaceableRepository()) { repo.Upsert(e.ActivePlaceable); } }
/// <summary> /// Returns all objects from the database that have a matching resource category. /// </summary> /// <param name="resourceCategory">The resource category all return values must match</param> /// <param name="resourceType">The type of resource to look for.</param> /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param> /// <returns></returns> public List<GameObjectBase> GetAllFromDatabaseByResourceCategory(Category resourceCategory, GameObjectTypeEnum resourceType, string connectionString = "") { List<GameObjectBase> retList = new List<GameObjectBase>(); if (resourceType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository(connectionString)) { return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x); } } else if (resourceType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository(connectionString)) { return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x); } } else if (resourceType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository(connectionString)) { return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x); } } else if (resourceType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository(connectionString)) { return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x); } } else if (resourceType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository(connectionString)) { return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x); } } else if (resourceType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository(connectionString)) { return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x); } } else if (resourceType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository(connectionString)) { return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x); } } else { throw new NotSupportedException(); } }
public GameObjectBase GetFromDatabaseByID(int resourceID, GameObjectTypeEnum gameResourceType) { if (gameResourceType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository()) { return repo.GetByID(resourceID); } } else if (gameResourceType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository()) { return repo.GetByID(resourceID); } } else if (gameResourceType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository()) { return repo.GetByID(resourceID); } } else if (gameResourceType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository()) { return repo.GetByID(resourceID); } } else if (gameResourceType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository()) { return repo.GetByID(resourceID); } } else if (gameResourceType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository()) { return repo.GetByID(resourceID); } } else if (gameResourceType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository()) { return repo.GetByID(resourceID); } } else { throw new NotSupportedException(); } }
/// <summary> /// Returns True if an object exists in the database. /// Returns False if an object does not exist in the database. /// </summary> /// <param name="resref">The resource reference to search for.</param> /// <param name="resourceType">The resource type to look for.</param> /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param> /// <returns></returns> public bool DoesObjectExistInDatabase(string resref, GameObjectTypeEnum resourceType, string connectionString = "") { if (resourceType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository(connectionString)) { return repo.Exists(resref); } } else if (resourceType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository(connectionString)) { return repo.Exists(resref); } } else if (resourceType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository(connectionString)) { return repo.Exists(resref); } } else if (resourceType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository(connectionString)) { return repo.Exists(resref); } } else if (resourceType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository(connectionString)) { return repo.Exists(resref); } } else if (resourceType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository(connectionString)) { return repo.Exists(resref); } } else if (resourceType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository(connectionString)) { return repo.Exists(resref); } } else { throw new NotSupportedException(); } }
/// <summary> /// Delete all objects from database that match a specified resource category. /// </summary> /// <param name="resourceCategory">The resource category to remove all objects from.</param> /// <param name="resourceType">The type of resource to look for.</param> /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param> public void DeleteFromDatabaseByCategory(Category resourceCategory, GameObjectTypeEnum resourceType, string connectionString = "") { if (resourceType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else { throw new NotSupportedException(); } // Now remove the category itself. using (CategoryRepository repo = new CategoryRepository()) { Category dbCategory = repo.GetByID(resourceCategory.ResourceID); repo.Delete(dbCategory); } }
/// <summary> /// Deletes an object with the specified resref from the database. /// </summary> /// <param name="resref">The resource reference to search for.</param> /// <param name="resourceType">The type of resource to remove.</param> /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param> public void DeleteFromDatabase(int resourceID, GameObjectTypeEnum resourceType, string connectionString = "") { if (resourceType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository(connectionString)) { repo.Delete(resourceID); } } else if (resourceType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository(connectionString)) { repo.Delete(resourceID); } } else if (resourceType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository(connectionString)) { repo.Delete(resourceID); } } else if (resourceType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository(connectionString)) { repo.Delete(resourceID); } } else if (resourceType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository(connectionString)) { repo.Delete(resourceID); } } else if (resourceType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository(connectionString)) { repo.Delete(resourceID); } } else if (resourceType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository(connectionString)) { repo.Delete(resourceID); } } else if (resourceType == GameObjectTypeEnum.GameModule) { using (GameModuleRepository repo = new GameModuleRepository()) { repo.Delete(resourceID); } } else { throw new NotSupportedException(); } }
/// <summary> /// Adds a game object to the database. /// </summary> /// <param name="gameObject">The game object to add to the database. This will be type-converted and added to the correct table when run.</param> /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param> public GameObjectBase AddToDatabase(GameObjectBase gameObject, string connectionString = "") { GameObjectBase resultGameObject; try { if (gameObject.GameObjectType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Area); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository()) { resultGameObject = repo.Add(gameObject as Conversation); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Creature); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Item); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Placeable); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Script); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Tileset); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.GameModule) { using (GameModuleRepository repo = new GameModuleRepository()) { resultGameObject = repo.Add(gameObject as GameModule); } } else { throw new NotSupportedException(); } } catch { throw; } return resultGameObject; }
private void LoadTreeViewData(object sender, JavascriptMethodEventArgs e) { try { JSTreeNode areaRootNode; JSTreeNode creatureRootNode; JSTreeNode itemRootNode; JSTreeNode placeableRootNode; JSTreeNode conversationRootNode; JSTreeNode scriptRootNode; JSTreeNode tilesetRootNode; // Get each category's children for each object type using (AreaRepository repo = new AreaRepository()) { areaRootNode = repo.GenerateJSTreeHierarchy(); } using (CreatureRepository repo = new CreatureRepository()) { creatureRootNode = repo.GenerateJSTreeHierarchy(); } using (ItemRepository repo = new ItemRepository()) { itemRootNode = repo.GenerateJSTreeHierarchy(); } using (PlaceableRepository repo = new PlaceableRepository()) { placeableRootNode = repo.GenerateJSTreeHierarchy(); } using (ConversationRepository repo = new ConversationRepository()) { conversationRootNode = repo.GenerateJSTreeHierarchy(); } using (ScriptRepository repo = new ScriptRepository()) { scriptRootNode = repo.GenerateJSTreeHierarchy(); } using (TilesetRepository repo = new TilesetRepository()) { tilesetRootNode = repo.GenerateJSTreeHierarchy(); } AsyncJavascriptCallback("LoadTreeViews_Callback", JsonConvert.SerializeObject(areaRootNode), JsonConvert.SerializeObject(creatureRootNode), JsonConvert.SerializeObject(itemRootNode), JsonConvert.SerializeObject(placeableRootNode), JsonConvert.SerializeObject(conversationRootNode), JsonConvert.SerializeObject(scriptRootNode), JsonConvert.SerializeObject(tilesetRootNode)); } catch { throw; } }