public static IList <Topic> GetSideBarWtfs() { try { return(DiscourseCache.GetOrAdd( "SideBarWtfs", () => { Logger.Debug("Getting Side Bar WTFs."); var api = DiscourseHelper.CreateApi(); return api.GetTopicsByCategory(new Category(Config.Discourse.SideBarWtfCategory)) .Where(topic => !topic.Pinned && topic.Visible) .Take(5) .ToList() .AsReadOnly(); } )); } catch (Exception ex) { Logger.Error("Error getting Side Bar WTFs, error: {0}", ex); return(new Topic[0]); } }
public static IList <Post> GetFeaturedCommentsForArticle(int articleId) { try { return(DiscourseCache.GetOrAdd( "FeaturedCommentsForArticle_" + articleId, () => { Logger.Debug("Getting and caching featured comments for article (ID={0}).", articleId); var api = DiscourseHelper.CreateApi(); return StoredProcs.Articles_GetFeaturedComments(articleId) .Execute() .Select(c => api.GetReplyPost(c.Discourse_Post_Id)) .Where(p => !p.Hidden) .ToList() .AsReadOnly(); } )); } catch (Exception ex) { Logger.Error("Error getting featured comments for article (ID={0}), error: {1}", articleId, ex); return(new Post[0]); } }
public static Topic GetDiscussionTopic(int topicId) { try { return(DiscourseCache.GetOrAdd( "Topic_" + topicId, () => { var api = DiscourseHelper.CreateApi(); return api.GetTopic(topicId); } )); } catch (Exception ex) { throw new InvalidOperationException( string.Format("An unknown error occurred when attempting to get the Discourse topic #{0}. " + "Verify that this Discourse topic ID actually exists (e.g. /t/{0} relative to forum)", topicId), ex); } }
public static IList <Topic> GetSideBarWtfs() { try { return(DiscourseCache.GetOrAdd( "SideBarWtfs", () => { var api = DiscourseHelper.CreateApi(); return api.GetTopicsByCategory(new Category(Config.Discourse.SideBarWtfCategory)) .Where(topic => !topic.Pinned && topic.Visible) .Take(5) .ToList() .AsReadOnly(); } )); } catch { return(new Topic[0]); } }
public static IList <Post> GetFeaturedCommentsForArticle(int articleId) { try { return(DiscourseCache.GetOrAdd( "FeaturedCommentsForArticle_" + articleId, () => { var api = DiscourseHelper.CreateApi(); return StoredProcs.Articles_GetFeaturedComments(articleId) .Execute() .Select(c => api.GetReplyPost(c.Discourse_Post_Id)) .Where(p => !p.Hidden) .ToList() .AsReadOnly(); } )); } catch { return(new Post[0]); } }