/// <summary> /// Get the forum adapter for the provided quest. /// </summary> /// <param name="quest">The quest to get a forum adapter for.</param> /// <param name="token">The cancellation token.</param> /// <returns>Returns the forum adapter that knows how to read the forum of the quest thread.</returns> private async Task <IForumAdapter> GetForumAdapterAsync(IQuest quest, CancellationToken token) { if (quest.ForumType == ForumType.Unknown) { quest.ForumType = await ForumIdentifier.IdentifyForumTypeAsync(quest.ThreadUri, token).ConfigureAwait(false); } var adapter = ForumAdapterSelector.GetForumAdapter(quest.ForumType, quest.ThreadUri); quest.ForumAdapter = adapter; return(adapter); }
/// <summary> /// Gets a forum adapter to match the provided forum type and Uri. /// </summary> /// <param name="forumType">The type of forum being requested.</param> /// <param name="site">The Uri of the site the adapter is for.</param> /// <returns>Returns a forum adapter matching the forum type, initialized to the provided Uri.</returns> //public static IForumAdapter GetForumAdapter(ForumType forumType, Uri site) public static async Task <IForumAdapter> GetForumAdapterAsync(Uri site, CancellationToken token) { if (site == null) { throw new ArgumentNullException(nameof(site)); } ForumType forumType = await ForumIdentifier.IdentifyForumTypeAsync(site, token); if (!cachedAdapters.TryGetValue(forumType, out IForumAdapter adapter)) { switch (forumType) { case ForumType.XenForo1: adapter = new XenForo1Adapter(site); break; case ForumType.vBulletin3: adapter = new vBulletin3Adapter(site); break; case ForumType.vBulletin4: adapter = new vBulletin4Adapter(site); break; case ForumType.vBulletin5: adapter = new vBulletin5Adapter(site); break; default: throw new ArgumentException($"Unknown forum type: {forumType} for site {site.Host}", nameof(forumType)); } cachedAdapters[forumType] = adapter; } else { adapter.Site = site; } return(adapter); }
/// <summary> /// Create a new forum adapter appropriate to the provided quest. /// </summary> /// <param name="quest">The quest that we need a forum adapter for.</param> /// <param name="pageProvider">A page provider for requesting a page from the web site, if needed.</param> /// <param name="token">A cancellation token for if we need to make a web request.</param> /// <returns>Returns a forum adapter for the quest.</returns> public async Task <IForumAdapter2> CreateForumAdapterAsync(IQuest quest, IPageProvider pageProvider, CancellationToken token) { if (quest.ThreadUri == Quest.InvalidThreadUri) { throw new InvalidOperationException("Quest does not have a valid thread specified."); } if (quest.ForumType == ForumType.Unknown) { await ss.WaitAsync(token).ConfigureAwait(false); try { quest.ForumType = await ForumIdentifier.IdentifyForumTypeAsync(quest.ThreadUri, pageProvider, token); } finally { ss.Release(); } } return(CreateForumAdapter(quest.ForumType, quest.ThreadUri)); }