public MysqlDatabaseProvider() { try { string Database = MySqlDatabaseModule.DbAccess.DB; string User = MySqlDatabaseModule.DbAccess.User; string Password = MySqlDatabaseModule.DbAccess.Password; string Host = MySqlDatabaseModule.DbAccess.Host; var config = MySqlConfiguration.Create(Database, Host, User, Password); model = DataAccessModel.BuildDataAccessModel <TrinityDatabase>(config); try { model.Create(DatabaseCreationOptions.IfDatabaseNotExist); } catch (Exception e) { // already exists, its ok } var temp = GetCreatureTemplates(); } catch (Exception e) { Console.WriteLine("Cannot connect to MySql database. Check your settings."); model = null; } }
public IQuestTemplate?GetQuestTemplate(uint entry) { using var model = new TrinityDatabase(); MySqlQuestTemplateAddon?addon = model.QuestTemplateAddon.FirstOrDefault(addon => addon.Entry == entry); return(model.QuestTemplate.FirstOrDefault(q => q.Entry == entry)?.SetAddon(addon)); }
public TrinityMysqlDatabaseProvider() { string Database = TrinityMySqlDatabaseModule.DbAccess.DB; string User = TrinityMySqlDatabaseModule.DbAccess.User; string Password = TrinityMySqlDatabaseModule.DbAccess.Password; string Host = TrinityMySqlDatabaseModule.DbAccess.Host; try { var config = MySqlConfiguration.Create(Database, Host, User, Password); model = DataAccessModel.BuildDataAccessModel <TrinityDatabase>(config); try { model.Create(DatabaseCreationOptions.IfDatabaseNotExist); } catch (Exception) { // already exists, its ok } var temp = GetCreatureTemplates(); } catch (Exception e) { if (!string.IsNullOrEmpty(Host)) { MessageBox.Show($"Cannot connect to MySql database: {e.Message} Check your settings."); } model = null; } }
private IQueryable <MySqlQuestTemplate> GetQuestsQuery(TrinityDatabase model) { return(from t in model.QuestTemplate join addon in model.QuestTemplateAddon on t.Entry equals addon.Entry into adn from subaddon in adn.DefaultIfEmpty() orderby t.Entry select t.SetAddon(subaddon)); }
public async Task InstallScriptFor(int entryOrGuid, SmartScriptType type, IEnumerable <ISmartScriptLine> script) { using var writeLock = await MySqlSingleWriteLock.WriteLock(); await using var model = new TrinityDatabase(); await model.BeginTransactionAsync(IsolationLevel.ReadCommitted); await model.SmartScript.Where(x => x.EntryOrGuid == entryOrGuid && x.ScriptSourceType == (int)type).DeleteAsync(); switch (type) { case SmartScriptType.Creature: await model.CreatureTemplate.Where(p => p.Entry == (uint)entryOrGuid) .Set(p => p.AIName, "SmartAI") .Set(p => p.ScriptName, "") .UpdateAsync(); break; case SmartScriptType.GameObject: await model.GameObjectTemplate.Where(p => p.Entry == (uint)entryOrGuid) .Set(p => p.AIName, "SmartAI") .Set(p => p.ScriptName, "") .UpdateAsync(); break; case SmartScriptType.AreaTrigger: await model.AreaTriggerScript.Where(p => p.Id == entryOrGuid).DeleteAsync(); await model.AreaTriggerScript.InsertAsync(() => new MySqlAreaTriggerScript() { Id = entryOrGuid, ScriptName = "SmartTrigger" }); break; case SmartScriptType.AreaTriggerEntity: await model.AreaTriggerTemplate.Where(p => p.Id == (uint)entryOrGuid && p.IsServerSide == false) .Set(p => p.ScriptName, "SmartAreaTriggerAI") .UpdateAsync(); break; case SmartScriptType.AreaTriggerEntityServerSide: await model.AreaTriggerTemplate.Where(p => p.Id == (uint)entryOrGuid && p.IsServerSide == true) .Set(p => p.ScriptName, "SmartAreaTriggerAI") .UpdateAsync(); break; } await model.SmartScript.BulkCopyAsync(script.Select(l => new MySqlSmartScriptLine(l))); await model.CommitTransactionAsync(); }
public IEnumerable <ICreatureClassLevelStat> GetCreatureClassLevelStats() { if (currentCoreVersion.Current.DatabaseFeatures.UnsupportedTables.Contains(typeof(ICreatureClassLevelStat))) { return(Enumerable.Empty <ICreatureClassLevelStat>()); } using var model = new TrinityDatabase(); return((from t in model.CreatureClassLevelStats select t).ToList <ICreatureClassLevelStat>()); }
public async Task <List <IConversationTemplate> > GetConversationTemplatesAsync() { if (currentCoreVersion.Current.DatabaseFeatures.UnsupportedTables.Contains(typeof(IConversationTemplate))) { return(new List <IConversationTemplate>()); } await using var model = new TrinityDatabase(); return(await(from t in model.ConversationTemplate orderby t.Id select t).ToListAsync <IConversationTemplate>()); }
public async Task <List <INpcText> > GetNpcTextsAsync() { if (currentCoreVersion.Current.DatabaseFeatures.UnsupportedTables.Contains(typeof(INpcText))) { return(new List <INpcText>()); } await using var model = new TrinityDatabase(); return(await(from t in model.NpcTexts orderby t.Id select t).ToListAsync <INpcText>()); }
public IEnumerable <IConversationTemplate> GetConversationTemplates() { if (currentCoreVersion.Current.DatabaseFeatures.UnsupportedTables.Contains(typeof(IConversationTemplate))) { return(new List <IConversationTemplate>()); } using var model = new TrinityDatabase(); return((from t in model.ConversationTemplate orderby t.Id select t).ToList <IConversationTemplate>()); }
public async Task <List <ICreatureClassLevelStat> > GetCreatureClassLevelStatsAsync() { if (currentCoreVersion.Current.DatabaseFeatures.UnsupportedTables.Contains(typeof(ICreatureClassLevelStat))) { return(new List <ICreatureClassLevelStat>()); } await using var model = new TrinityDatabase(); return(await(from t in model.CreatureClassLevelStats select t).ToListAsync <ICreatureClassLevelStat>()); }
public async Task <List <IQuestTemplate> > GetQuestTemplatesAsync() { using var model = new TrinityDatabase(); return(await(from t in model.QuestTemplate join addon in model.QuestTemplateAddon on t.Entry equals addon.Entry into adn from subaddon in adn.DefaultIfEmpty() orderby t.Entry select t.SetAddon(subaddon)).ToListAsync <IQuestTemplate>()); }
public IEnumerable <INpcText> GetNpcTexts() { if (currentCoreVersion.Current.DatabaseFeatures.UnsupportedTables.Contains(typeof(INpcText))) { return(new List <INpcText>()); } using var model = new TrinityDatabase(); return((from t in model.NpcTexts orderby t.Id select t).ToList <INpcText>()); }
public async Task InstallConditions(IEnumerable <IConditionLine> conditionLines, IDatabaseProvider.ConditionKeyMask keyMask, IDatabaseProvider.ConditionKey?manualKey = null) { using var writeLock = await DatabaseLock.WriteLock(); await using var model = new TrinityDatabase(); var conditions = conditionLines?.ToList() ?? new List <IConditionLine>(); List <(int SourceType, int?SourceGroup, int?SourceEntry, int?SourceId)> keys = conditions.Select(c => (c.SourceType, keyMask.HasFlag(IDatabaseProvider.ConditionKeyMask.SourceGroup) ? (int?)c.SourceGroup : null, keyMask.HasFlag(IDatabaseProvider.ConditionKeyMask.SourceEntry) ? (int?)c.SourceEntry : null, keyMask.HasFlag(IDatabaseProvider.ConditionKeyMask.SourceId) ? (int?)c.SourceId : null)) .Union(manualKey.HasValue ? new[]
public IEnumerable <IGossipMenu> GetGossipMenus() { using var model = new TrinityDatabase(); List <MySqlGossipMenuLine> gossips; if (currentCoreVersion.Current.DatabaseFeatures.UnsupportedTables.Contains(typeof(INpcText))) { gossips = model.GossipMenus.ToList(); } else { gossips = (from gossip in model.GossipMenus join p in model.NpcTexts on gossip.TextId equals p.Id into lj from lp in lj.DefaultIfEmpty() select gossip.SetText(lp)).ToList(); } return(gossips.GroupBy(g => g.MenuId) .Select(t => new MySqlGossipMenu(t.Key, t.Where(t => t.Text != null).Select(t => t.Text !).ToList())) .ToList <IGossipMenu>()); }
public async Task <List <IGameEvent> > GetGameEventsAsync() { await using var model = new TrinityDatabase(); return(await(from t in model.GameEvents orderby t.Entry select t).ToListAsync <IGameEvent>()); }
public IEnumerable <IGameEvent> GetGameEvents() { using var model = new TrinityDatabase(); return((from t in model.GameEvents orderby t.Entry select t).ToList <IGameEvent>()); }
public IEnumerable <ISmartScriptLine> GetScriptFor(int entryOrGuid, SmartScriptType type) { using var model = new TrinityDatabase(); return(model.SmartScript.Where(line => line.EntryOrGuid == entryOrGuid && line.ScriptSourceType == (int)type).ToList()); }
public async Task <List <ICreatureTemplate> > GetCreatureTemplatesAsync() { await using var model = new TrinityDatabase(); return(await model.CreatureTemplate.OrderBy(t => t.Entry).ToListAsync <ICreatureTemplate>()); }
public IEnumerable <ICreatureTemplate> GetCreatureTemplates() { using var model = new TrinityDatabase(); return(model.CreatureTemplate.OrderBy(t => t.Entry).ToList <ICreatureTemplate>()); }
public async Task <List <IGameObjectTemplate> > GetGameObjectTemplatesAsync() { using var model = new TrinityDatabase(); return(await(from t in model.GameObjectTemplate orderby t.Entry select t).ToListAsync <IGameObjectTemplate>()); }
public async Task <List <IQuestTemplate> > GetQuestTemplatesAsync() { await using var model = new TrinityDatabase(); return(await GetQuestsQuery(model).ToListAsync <IQuestTemplate>()); }
public IEnumerable <IQuestTemplate> GetQuestTemplates() { using var model = new TrinityDatabase(); return(GetQuestsQuery(model).ToList <IQuestTemplate>()); }
public IEnumerable <IGameObjectTemplate> GetGameObjectTemplates() { using var model = new TrinityDatabase(); return((from t in model.GameObjectTemplate orderby t.Entry select t).ToList <IGameObjectTemplate>()); }
public IGameObjectTemplate?GetGameObjectTemplate(uint entry) { using var model = new TrinityDatabase(); return(model.GameObjectTemplate.FirstOrDefault(g => g.Entry == entry)); }
public ICreatureTemplate?GetCreatureTemplate(uint entry) { using var model = new TrinityDatabase(); return(model.CreatureTemplate.FirstOrDefault(ct => ct.Entry == entry)); }