public async Task DownloadLatestVersion(ITaskProgress taskProgress) { cachedResponse ??= await InternalCheckForUpdates(); if (cachedResponse != null) { var progress = new Progress <(long downloaded, long?totalBytes)>((v) => { var isDownloaded = (v.totalBytes.HasValue && v.totalBytes.Value == v.downloaded) || v.downloaded == -1; var isStatusKnown = v.totalBytes.HasValue; var currentProgress = v.totalBytes.HasValue ? (int)v.downloaded : (v.downloaded < 0 ? 1 : 0); var maxProgress = v.totalBytes ?? 1; if (taskProgress.State == TaskState.InProgress) { taskProgress.Report(currentProgress, (int)maxProgress, isDownloaded ? "finished" : (isStatusKnown ? $"{v.downloaded / 1_000_000f:0.00}/{maxProgress / 1_000_000f:0.00}MB" : $"{v.downloaded / 1_000_000f:0.00}MB")); } }); var physPath = fileSystem.ResolvePhysicalPath(platformService.UpdateZipFilePath); await UpdateClient.DownloadUpdate(cachedResponse, physPath.FullName, progress); if (cachedResponse.ChangeLog?.Length > 0) { fileSystem.WriteAllText("~/changelog.json", JsonConvert.SerializeObject(cachedResponse.ChangeLog)); } } taskProgress.ReportFinished(); }
public async Task Run(ITaskProgress progress) { int steps = 5; progress.Report(0, steps, "Loading creatures"); cache.creatureTemplateCache = await cache.trinityDatabase.GetCreatureTemplatesAsync(); progress.Report(1, steps, "Loading gameobjects"); cache.gameObjectTemplateCache = await cache.trinityDatabase.GetGameObjectTemplatesAsync(); progress.Report(2, steps, "Loading game events"); cache.gameEventsCache = await cache.trinityDatabase.GetGameEventsAsync(); progress.Report(3, steps, "Loading areatrigger templates"); cache.areaTriggerTemplates = await cache.trinityDatabase.GetAreaTriggerTemplatesAsync(); progress.Report(4, steps, "Loading quests"); cache.questTemplateCache = await cache.trinityDatabase.GetQuestTemplatesAsync(); Dictionary <uint, MySqlCreatureTemplate> creatureTemplateByEntry = new(); Dictionary <uint, MySqlGameObjectTemplate> gameObjectTemplateByEntry = new(); Dictionary <uint, MySqlQuestTemplate> questTemplateByEntry = new(); foreach (var entity in cache.creatureTemplateCache) { creatureTemplateByEntry[entity.Entry] = entity; } foreach (var entity in cache.gameObjectTemplateCache) { gameObjectTemplateByEntry[entity.Entry] = entity; } foreach (var entity in cache.questTemplateCache) { questTemplateByEntry[entity.Entry] = entity; } cache.creatureTemplateByEntry = creatureTemplateByEntry; cache.gameObjectTemplateByEntry = gameObjectTemplateByEntry; cache.questTemplateByEntry = questTemplateByEntry; }
public static Progress <(long, long?)> ToProgress(this ITaskProgress taskProgress) { return(new Progress <(long downloaded, long?totalBytes)>((v) => { var isDownloaded = (v.totalBytes.HasValue && v.totalBytes.Value == v.downloaded) || v.downloaded == -1; var isStatusKnown = v.totalBytes.HasValue; var currentProgress = v.totalBytes.HasValue ? (int)v.downloaded : (v.downloaded < 0 ? 1 : 0); var maxProgress = v.totalBytes ?? 1; if (taskProgress.State == TaskState.InProgress) { taskProgress.Report(currentProgress, (int)maxProgress, isDownloaded ? "finished" : (isStatusKnown ? $"{v.downloaded / 1_000_000f:0.00}/{maxProgress / 1_000_000f:0.00}MB" : $"{v.downloaded / 1_000_000f:0.00}MB")); } })); }
public async Task Run(ITaskProgress progress) { try { int steps = 11; progress.Report(0, steps, "Loading creatures"); cache.creatureTemplateCache = await cache.nonCachedDatabase.GetCreatureTemplatesAsync(); // disabled caching for now, because it may be not needed yet // cache.creatureCache = await cache.nonCachedDatabase.GetCreaturesAsync(); // cache.gameObjectCache = await cache.nonCachedDatabase.GetGameObjectsAsync(); progress.Report(1, steps, "Loading gameobjects"); cache.gameObjectTemplateCache = await cache.nonCachedDatabase.GetGameObjectTemplatesAsync(); progress.Report(2, steps, "Loading game events"); cache.gameEventsCache = await cache.nonCachedDatabase.GetGameEventsAsync(); progress.Report(3, steps, "Loading areatrigger templates"); cache.areaTriggerTemplates = await cache.nonCachedDatabase.GetAreaTriggerTemplatesAsync(); progress.Report(4, steps, "Loading conversation templates"); cache.conversationTemplates = await cache.nonCachedDatabase.GetConversationTemplatesAsync(); progress.Report(5, steps, "Loading gossip menus"); cache.gossipMenusCache = await cache.nonCachedDatabase.GetGossipMenusAsync(); progress.Report(6, steps, "Loading npc texts"); cache.npcTextsCache = await cache.nonCachedDatabase.GetNpcTextsAsync(); cache.npcTextsByIdCache = cache.npcTextsCache.ToDictionary(npcText => npcText.Id); progress.Report(7, steps, "Loading quests"); cache.questTemplateCache = await cache.nonCachedDatabase.GetQuestTemplatesAsync(); progress.Report(8, steps, "Loading creature class level stats"); cache.creatureClassLevelStatsCache = await cache.nonCachedDatabase.GetCreatureClassLevelStatsAsync(); progress.Report(9, steps, "Loading database spell dbc"); cache.databaseSpellDbcCache = await cache.nonCachedDatabase.GetSpellDbcAsync(); progress.Report(10, steps, "Loading broadcast texts"); // todo: is there any benefit of caching this? /*var broadcastTexts = await cache.nonCachedDatabase.GetBroadcastTextsAsync(); * var cachedTrie = new StringTrie<IBroadcastText>(); * await Task.Run(() => * { * foreach (var text in broadcastTexts) * { * if (text.Text != null) * cachedTrie[text.Text] = text; * if (text.Text1 != null) * cachedTrie[text.Text1] = text; * } * }).ConfigureAwait(true); * cache.broadcastTextsCache = cachedTrie;*/ Dictionary <uint, ICreatureTemplate> creatureTemplateByEntry = new(); Dictionary <uint, IGameObjectTemplate> gameObjectTemplateByEntry = new(); Dictionary <uint, IQuestTemplate> questTemplateByEntry = new(); foreach (var entity in cache.creatureTemplateCache) { creatureTemplateByEntry[entity.Entry] = entity; } foreach (var entity in cache.gameObjectTemplateCache) { gameObjectTemplateByEntry[entity.Entry] = entity; } foreach (var entity in cache.questTemplateCache) { questTemplateByEntry[entity.Entry] = entity; } cache.creatureTemplateByEntry = creatureTemplateByEntry; cache.gameObjectTemplateByEntry = gameObjectTemplateByEntry; cache.questTemplateByEntry = questTemplateByEntry; } catch (Exception e) { cache.nonCachedDatabase = new NullWorldDatabaseProvider(); cache.statusBar.PublishNotification(new PlainNotification(NotificationType.Error, $"Error while connecting to the database. Make sure you have correct core version in the settings: {e.Message}")); throw; } finally { cache.loadingEventAggregator.Publish <DatabaseLoadedEvent>(); } }
public async Task Run(ITaskProgress progress) { try { int steps = 9; progress.Report(0, steps, "Loading creatures"); cache.creatureTemplateCache = await cache.nonCachedDatabase.GetCreatureTemplatesAsync(); progress.Report(1, steps, "Loading gameobjects"); cache.gameObjectTemplateCache = await cache.nonCachedDatabase.GetGameObjectTemplatesAsync(); progress.Report(2, steps, "Loading game events"); cache.gameEventsCache = await cache.nonCachedDatabase.GetGameEventsAsync(); progress.Report(3, steps, "Loading areatrigger templates"); cache.areaTriggerTemplates = await cache.nonCachedDatabase.GetAreaTriggerTemplatesAsync(); progress.Report(4, steps, "Loading conversation templates"); cache.conversationTemplates = await cache.nonCachedDatabase.GetConversationTemplatesAsync(); progress.Report(5, steps, "Loading gossip menus"); cache.gossipMenusCache = await cache.nonCachedDatabase.GetGossipMenusAsync(); progress.Report(6, steps, "Loading npc texts"); cache.npcTextsCache = await cache.nonCachedDatabase.GetNpcTextsAsync(); progress.Report(7, steps, "Loading quests"); cache.questTemplateCache = await cache.nonCachedDatabase.GetQuestTemplatesAsync(); progress.Report(8, steps, "Loading creature class level stats"); cache.creatureClassLevelStatsCache = await cache.nonCachedDatabase.GetCreatureClassLevelStatsAsync(); Dictionary <uint, ICreatureTemplate> creatureTemplateByEntry = new(); Dictionary <uint, IGameObjectTemplate> gameObjectTemplateByEntry = new(); Dictionary <uint, IQuestTemplate> questTemplateByEntry = new(); foreach (var entity in cache.creatureTemplateCache) { creatureTemplateByEntry[entity.Entry] = entity; } foreach (var entity in cache.gameObjectTemplateCache) { gameObjectTemplateByEntry[entity.Entry] = entity; } foreach (var entity in cache.questTemplateCache) { questTemplateByEntry[entity.Entry] = entity; } cache.creatureTemplateByEntry = creatureTemplateByEntry; cache.gameObjectTemplateByEntry = gameObjectTemplateByEntry; cache.questTemplateByEntry = questTemplateByEntry; } catch (Exception e) { cache.statusBar.PublishNotification(new PlainNotification(NotificationType.Error, $"Error while connecting to the database. Make sure you have correct core version in the settings: {e.Message}")); throw; } }