示例#1
0
        /// <summary>
        /// Updates a gameObject's entry in the database.
        /// An exception will be thrown if an object with a matching resref is not found.
        /// </summary>
        /// <param name="gameObjectBase">The game object to update. Its resref will be searched for in the database.</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 UpdateInDatabase(GameObjectBase gameObject, string connectionString = "")
        {
            if (gameObject.GameObjectType == GameObjectTypeEnum.Area)
            {
                using (AreaRepository repo = new AreaRepository(connectionString))
                {
                    repo.Update(gameObject as Area);

                }
            }
            else if (gameObject.GameObjectType == GameObjectTypeEnum.Conversation)
            {
                using (ConversationRepository repo = new ConversationRepository(connectionString))
                {
                    repo.Update(gameObject as Conversation);
                }
            }
            else if (gameObject.GameObjectType == GameObjectTypeEnum.Creature)
            {
                using (CreatureRepository repo = new CreatureRepository(connectionString))
                {
                    repo.Update(gameObject as Creature);
                }
            }
            else if (gameObject.GameObjectType == GameObjectTypeEnum.Item)
            {
                using (ItemRepository repo = new ItemRepository(connectionString))
                {
                    repo.Update(gameObject as Item);
                }
            }
            else if (gameObject.GameObjectType == GameObjectTypeEnum.Placeable)
            {
                using (PlaceableRepository repo = new PlaceableRepository(connectionString))
                {
                    repo.Update(gameObject as Placeable);
                }
            }
            else if (gameObject.GameObjectType == GameObjectTypeEnum.Script)
            {
                using (ScriptRepository repo = new ScriptRepository(connectionString))
                {
                    repo.Update(gameObject as Script);
                }
            }
            else if (gameObject.GameObjectType == GameObjectTypeEnum.Tileset)
            {
                using (TilesetRepository repo = new TilesetRepository(connectionString))
                {
                    repo.Update(gameObject as Tileset);
                }
            }
            else if (gameObject.GameObjectType == GameObjectTypeEnum.GameModule)
            {
                using (GameModuleRepository repo = new GameModuleRepository())
                {
                    repo.Update(gameObject as GameModule);
                }
            }
            else
            {
                throw new NotSupportedException();
            }
        }
示例#2
0
        private async void SaveModulePropertiesAsync(object sender, JavascriptMethodEventArgs e)
        {
            try
            {
                await TaskEx.Run(() =>
                {
                    GameModule updatedModule = JsonConvert.DeserializeObject<GameModule>(e.Arguments[0]);
                    List<LevelRequirement> levelRequirements = JsonConvert.DeserializeObject<List<LevelRequirement>>(e.Arguments[1]);

                    using (GameModuleRepository repo = new GameModuleRepository())
                    {
                        repo.Update(updatedModule);
                    }

                    using (LevelRequirementRepository repo = new LevelRequirementRepository())
                    {
                        levelRequirements.ForEach(x => repo.Update(x));
                    }

                    PopulateToolsetViewModel();
                });

                AsyncJavascriptCallback("SaveModuleProperties_Callback");
            }
            catch (Exception ex)
            {
                throw new Exception("Error saving module properties", ex);
            }
        }