コード例 #1
0
ファイル: ForumService.cs プロジェクト: andyliyuze/POPForums
		public void Update(Forum forum, int? categoryID, string title, string description, bool isVisible, bool isArchived, string forumAdapterName, bool isQAForum)
		{
			var urlName = forum.UrlName;
			if (forum.Title != title)
				urlName = title.ToUniqueUrlName(_forumRepository.GetUrlNamesThatStartWith(title.ToUrlName()));
			_forumRepository.Update(forum.ForumID, categoryID, title, description, isVisible, isArchived, urlName, forumAdapterName, isQAForum);
		}
コード例 #2
0
ファイル: Broker.cs プロジェクト: andyliyuze/POPForums
		public void NotifyTopicUpdate(Topic topic, Forum forum, string topicLink)
		{
			var isForumViewRestricted = _forumRepo.GetForumViewRoles(forum.ForumID).Count > 0;
			_timeFormattingService.Init(null);
			var recentHubContext = GlobalHost.ConnectionManager.GetHubContext<Recent>();
			var result = new
				{
					Link = topicLink,
					Image = "NewIndicator.png",
					topic.TopicID,
					topic.StartedByName,
					topic.Title,
					ForumTitle = forum.Title,
					topic.ViewCount,
					topic.ReplyCount,
					LastPostTime = _timeFormattingService.GetFormattedTime(topic.LastPostTime),
					Utc = topic.LastPostTime.ToString("o"),
					topic.LastPostName
				};
			var forumHubContext = GlobalHost.ConnectionManager.GetHubContext<Forums>();
			if (isForumViewRestricted)
				recentHubContext.Clients.Group("forum" + forum.ForumID).notifyRecentUpdate(result);
			else
				recentHubContext.Clients.All.notifyRecentUpdate(result);
			forumHubContext.Clients.Group(forum.ForumID.ToString()).notifyUpdatedTopic(result);
		}
コード例 #3
0
ファイル: ForumService.cs プロジェクト: andyliyuze/POPForums
		public void UpdateLast(Forum forum)
		{
			var topic = _topicRepository.GetLastUpdatedTopic(forum.ForumID);
			if (topic != null)
				UpdateLast(forum, topic.LastPostTime, topic.LastPostName);
			else
				UpdateLast(forum, new DateTime(2000, 1, 1), String.Empty);
		}
コード例 #4
0
		public void MarkForumReadSetsReadTime()
		{
			var service = GetService();
			var forum = new Forum(123);
			var user = new User(456, DateTime.MinValue);
			service.MarkForumRead(user, forum);
			_lastReadRepo.Verify(l => l.SetForumRead(user.UserID, forum.ForumID, It.IsAny<DateTime>()), Times.Exactly(1));
		}
コード例 #5
0
		public DateTime? GetForumReadStatus(User user, Forum forum)
		{
			if (user != null)
			{
				return _lastReadRepository.GetLastReadTimesForForum(user.UserID, forum.ForumID);
			}
			return null;
		}
コード例 #6
0
		public void MarkForumReadDeletesOldTopicReadTimes()
		{
			var service = GetService();
			var forum = new Forum(123);
			var user = new User(456, DateTime.MinValue);
			service.MarkForumRead(user, forum);
			_lastReadRepo.Verify(l => l.DeleteTopicReadsInForum(user.UserID, forum.ForumID), Times.Exactly(1));
		}
コード例 #7
0
ファイル: ForumService.cs プロジェクト: andyliyuze/POPForums
		public void UpdateCounts(Forum forum)
		{
			new Thread(() =>
			{
				var topicCount = _topicRepository.GetTopicCount(forum.ForumID, false);
				var postCount = _topicRepository.GetPostCount(forum.ForumID, false);
				_forumRepository.UpdateTopicAndPostCounts(forum.ForumID, topicCount, postCount);
			}).Start();
		}
コード例 #8
0
		public void MarkForumRead(User user, Forum forum)
		{
			if (user == null)
				throw new ArgumentNullException("user");
			if (forum == null)
				throw new ArgumentNullException("forum");
			_lastReadRepository.SetForumRead(user.UserID, forum.ForumID, DateTime.UtcNow);
			_lastReadRepository.DeleteTopicReadsInForum(user.UserID, forum.ForumID);
		}
コード例 #9
0
		public void GetTopicsStartRowCalcd()
		{
			var forum = new Forum(1) { TopicCount = 300 };
			var topicService = GetTopicService();
			var settings = new Settings { TopicsPerPage = 20 };
			_settingsManager.Setup(s => s.Current).Returns(settings);
			PagerContext pagerContext;
			topicService.GetTopics(forum, false, 3, out pagerContext);
			_topicRepo.Verify(t => t.Get(It.IsAny<int>(), It.IsAny<bool>(), 41, It.IsAny<int>()), Times.Once());
		}
コード例 #10
0
		public void UncategorizedInCorrectOrder()
		{
			var f1 = new Forum(1) { SortOrder = 5 };
			var f2 = new Forum(2) { SortOrder = 1 };
			var f3 = new Forum(3) { SortOrder = 3 };
			var forums = new List<Forum> { f1, f2, f3 };
			var container = new CategorizedForumContainer(new List<Category>(), forums);
			Assert.True(container.UncategorizedForums[0] == f2);
			Assert.True(container.UncategorizedForums[1] == f3);
			Assert.True(container.UncategorizedForums[2] == f1);
		}
コード例 #11
0
		public void GetTopicsIncludeDeletedCallsRepoCount()
		{
			var forum = new Forum(1);
			var topicService = GetTopicService();
			_topicRepo.Setup(t => t.Get(It.IsAny<int>(), It.IsAny<bool>(), It.IsAny<int>(), It.IsAny<int>())).Returns(new List<Topic>());
			_topicRepo.Setup(t => t.GetTopicCount(1, true)).Returns(350);
			_settingsManager.Setup(s => s.Current).Returns(new Settings());
			PagerContext pagerContext;
			topicService.GetTopics(forum, true, 3, out pagerContext);
			_topicRepo.Verify(t => t.GetTopicCount(forum.ForumID, true), Times.Once());
		}
コード例 #12
0
		public void GetTopicsFromRepo()
		{
			var forum = new Forum(1) { TopicCount = 3 };
			var topicService = GetTopicService();
			var repoTopics = new List<Topic>();
			var settings = new Settings {TopicsPerPage = 20};
			_topicRepo.Setup(t => t.Get(1, true, 1, settings.TopicsPerPage)).Returns(repoTopics);
			_settingsManager.Setup(s => s.Current).Returns(settings);
			PagerContext pagerContext;
			var topics = topicService.GetTopics(forum, true, 1, out pagerContext);
			Assert.AreSame(repoTopics, topics);
		}
コード例 #13
0
		public ForumAdapterFactory(Forum forum)
		{
			if (!String.IsNullOrWhiteSpace(forum.ForumAdapterName))
			{
				var type = Type.GetType(forum.ForumAdapterName);
				if (type == null)
					throw new Exception(String.Format("Can't find ForumAdapter \"{0}\" (Forum ID: {1}, Title: {2})", forum.ForumAdapterName, forum.ForumID, forum.Title));
				var instance = Activator.CreateInstance(type);
				if (!typeof(IForumAdapter).IsAssignableFrom(instance.GetType()))
					throw new Exception(String.Format("ForumAdapter \"{0}\" does not implement IForumAdapter (Forum ID: {1}, Title: {2})", forum.ForumAdapterName, forum.ForumID, forum.Title));
				ForumAdapter = (IForumAdapter)instance;
			}
		}
コード例 #14
0
		public void AllCollectionsPersist()
		{
			var c1 = new Category(1);
			var c2 = new Category(2);
			var f1 = new Forum(1) { CategoryID = null };
			var f2 = new Forum(2) { CategoryID = 1 };
			var f3 = new Forum(3) { CategoryID = 2 };
			var cats = new List<Category> { c1, c2 };
			var forums = new List<Forum> { f1, f2, f3 };
			var container = new CategorizedForumContainer(cats, forums);
			Assert.AreEqual(cats, container.AllCategories);
			Assert.AreEqual(forums, container.AllForums);
		}
コード例 #15
0
		public void DeleteResetsForumCatIDsToNull()
		{
			var service = GetService();
			var cat = new Category(123);
			var f1 = new Forum(1) { CategoryID = cat.CategoryID };
			var f2 = new Forum(2) { CategoryID = cat.CategoryID };
			var f3 = new Forum(3) { CategoryID = 456 };
			var forums = new List<Forum> {f1, f2, f3};
			_mockForumRepo.Setup(f => f.GetAll()).Returns(forums);
			service.Delete(cat);
			_mockForumRepo.Verify(f => f.UpdateCategoryAssociation(1, null), Times.Once());
			_mockForumRepo.Verify(f => f.UpdateCategoryAssociation(2, null), Times.Once());
			_mockForumRepo.Verify(f => f.UpdateCategoryAssociation(3, null), Times.Never());
		}
コード例 #16
0
ファイル: TopicService.cs プロジェクト: andyliyuze/POPForums
		public List<Topic> GetTopics(Forum forum, bool includeDeleted, int pageIndex, out PagerContext pagerContext)
		{
			var pageSize = _settingsManager.Current.TopicsPerPage;
			var startRow = ((pageIndex - 1) * pageSize) + 1;
			var topics = _topicRepository.Get(forum.ForumID, includeDeleted, startRow, pageSize);
			int topicCount;
			if (includeDeleted)
				topicCount = _topicRepository.GetTopicCount(forum.ForumID, true);
			else
				topicCount = forum.TopicCount;
			var totalPages = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(topicCount) / Convert.ToDouble(pageSize)));
			pagerContext = new PagerContext { PageCount = totalPages, PageIndex = pageIndex, PageSize = pageSize };
			return topics;
		}
コード例 #17
0
		public void CategoriesInCorrectOrder()
		{
			var c1 = new Category(1) { SortOrder = 5 };
			var c2 = new Category(2) { SortOrder = 1 };
			var c3 = new Category(3) { SortOrder = 3 };
			var f1 = new Forum(1) { CategoryID = 1 };
			var f2 = new Forum(2) { CategoryID = 2 };
			var f3 = new Forum(3) { CategoryID = 3 };
			var cats = new List<Category> {c1, c2, c3};
			var forums = new List<Forum> {f1, f2, f3};
			var container = new CategorizedForumContainer(cats, forums);
			Assert.True(container.CategoryDictionary.ToArray()[0].Key == c2);
			Assert.True(container.CategoryDictionary.ToArray()[1].Key == c3);
			Assert.True(container.CategoryDictionary.ToArray()[2].Key == c1);
		}
コード例 #18
0
		public void ForumsAppearInCategories()
		{
			var c1 = new Category(1) { Title = "Cat1" };
			var c2 = new Category(2) { Title = "Cat2" };
			var f1 = new Forum(1) { CategoryID = null };
			var f2 = new Forum(2) { CategoryID = 1 };
			var f3 = new Forum(3) { CategoryID = 2 };
			var cats = new List<Category> { c1, c2 };
			var forums = new List<Forum> { f1, f2, f3 };
			var container = new CategorizedForumContainer(cats, forums);
			Assert.True(container.CategoryDictionary[c1].Contains(f2));
			Assert.True(container.CategoryDictionary[c2].Contains(f3));
			Assert.False(container.CategoryDictionary[c1].Contains(f1));
			Assert.False(container.CategoryDictionary[c1].Contains(f3));
		}
コード例 #19
0
		public void UncategorizedForumsShowUpOnProperty()
		{
			var c1 = new Category(1);
			var c2 = new Category(2);
			var f1 = new Forum(1) {CategoryID = null};
			var f2 = new Forum(2) {CategoryID = 1};
			var f3 = new Forum(3) {CategoryID = 2};
			var f4 = new Forum(4) {CategoryID = 0};
			var cats = new List<Category> {c1, c2};
			var forums = new List<Forum> {f1, f2, f3, f4};
			var container = new CategorizedForumContainer(cats, forums);
			Assert.True(container.UncategorizedForums.Contains(f1));
			Assert.False(container.UncategorizedForums.Contains(f2));
			Assert.False(container.UncategorizedForums.Contains(f3));
			Assert.True(container.UncategorizedForums.Contains(f4));
		}
コード例 #20
0
		private User DoUpNewTopic()
		{
			var forum = new Forum(1);
			var user = GetUser();
			const string ip = "127.0.0.1";
			const string title = "mah title";
			const string text = "mah text";
			var newPost = new NewPost { Title = title, FullText = text, ItemID = 1 };
			var forumService = GetService();
			_mockTopicRepo.Setup(t => t.GetUrlNamesThatStartWith("parsed-title")).Returns(new List<string>());
			_mockTextParser.Setup(t => t.ClientHtmlToHtml("mah text")).Returns("parsed text");
			_mockTextParser.Setup(t => t.EscapeHtmlAndCensor("mah title")).Returns("parsed title");
			_mockPostRepo.Setup(p => p.Create(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<int>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<bool>(), It.IsAny<string>(), null, It.IsAny<bool>(), It.IsAny<int>())).Returns(69);
			_mockForumRepo.Setup(x => x.GetForumViewRoles(forum.ForumID)).Returns(new List<string>());
			forumService.PostNewTopic(forum, user, new ForumPermissionContext { UserCanPost = true, UserCanView = true }, newPost, ip, It.IsAny<string>(), x => "");
			return user;
		}
コード例 #21
0
ファイル: TopicService.cs プロジェクト: andyliyuze/POPForums
		public List<Topic> GetTopics(User viewingUser, Forum forum, bool includeDeleted)
		{
			var nonViewableForumIDs = _forumService.GetNonViewableForumIDs(viewingUser);
			var topics = _topicRepository.Get(forum.ForumID, includeDeleted, nonViewableForumIDs);
			return topics;
		}
コード例 #22
0
ファイル: TopicService.cs プロジェクト: andyliyuze/POPForums
		public void UpdateTitleAndForum(Topic topic, Forum forum, string newTitle, User user)
		{
			if (user.IsInRole(PermanentRoles.Moderator))
			{
				var oldTopic = _topicRepository.Get(topic.TopicID);
				if (oldTopic.ForumID != forum.ForumID)
					_moderationLogService.LogTopic(user, ModerationType.TopicMoved, topic, forum, String.Format("Moved from {0} to {1}", oldTopic.ForumID, forum.ForumID));
				if (oldTopic.Title != newTitle)
					_moderationLogService.LogTopic(user, ModerationType.TopicRenamed, topic, forum, String.Format("Renamed from \"{0}\" to \"{1}\"", oldTopic.Title, newTitle));
				var urlName = newTitle.ToUniqueUrlName(_topicRepository.GetUrlNamesThatStartWith(newTitle.ToUrlName()));
				topic.UrlName = urlName;
				_topicRepository.UpdateTitleAndForum(topic.TopicID, forum.ForumID, newTitle, urlName);
				_topicRepository.MarkTopicForIndexing(topic.TopicID);
				_forumService.UpdateCounts(forum);
				_forumService.UpdateLast(forum);
				var oldForum = _forumService.Get(oldTopic.ForumID);
				_forumService.UpdateCounts(oldForum);
				_forumService.UpdateLast(oldForum);
			}
			else
				throw new InvalidOperationException("User must be Moderator to update topic title or move topic.");
		}
コード例 #23
0
		private static TopicContainer ComposeTopicContainer(Topic topic, Forum forum, ForumPermissionContext permissionContext, bool isSubscribed, List<Post> posts, PagerContext pagerContext, bool isFavorite, Dictionary<int, string> signatures, Dictionary<int, int> avatars, List<int> votedPostIDs, DateTime? lastreadTime)
		{
			return new TopicContainer { Forum = forum, Topic = topic, Posts = posts, PagerContext = pagerContext, PermissionContext = permissionContext, IsSubscribed = isSubscribed, IsFavorite = isFavorite, Signatures = signatures, Avatars = avatars, VotedPostIDs = votedPostIDs, LastReadTime = lastreadTime};
		}
コード例 #24
0
		public void CategoryWithNoForumsDoesNotAppear()
		{
			var c1 = new Category(1) { Title = "Cat1" };
			var c2 = new Category(2) { Title = "Cat2" };
			var c3 = new Category(3) { Title = "Cat3" };
			var f1 = new Forum(1) { CategoryID = null };
			var f2 = new Forum(2) { CategoryID = 1 };
			var f3 = new Forum(3) { CategoryID = 2 };
			var cats = new List<Category> { c1, c2, c3 };
			var forums = new List<Forum> { f1, f2, f3 };
			var container = new CategorizedForumContainer(cats, forums);
			Assert.False(container.CategoryDictionary.ContainsKey(c3));
		}
コード例 #25
0
		public void ForumReadStatusUserNewPostsButNoTopicRecords()
		{
			var service = GetService();
			var forum = new Forum(1) { LastPostTime = new DateTime(2000, 1, 1, 5, 0, 0) };
			var user = new User(2, DateTime.MinValue);
			_lastReadRepo.Setup(l => l.GetLastReadTimesForForums(2)).Returns(new Dictionary<int, DateTime>());
			_lastReadRepo.Setup(l => l.GetLastReadTimesForForum(user.UserID, forum.ForumID)).Returns(new DateTime(2000, 1, 1, 3, 0, 0));
			var container = new CategorizedForumContainer(new List<Category>(), new[] { forum });
			service.GetForumReadStatus(user, container);
			Assert.AreEqual(1, container.ReadStatusLookup.Count);
			Assert.AreEqual(ReadStatus.NewPosts, container.ReadStatusLookup[1]);
		}
コード例 #26
0
		public void ForumReadStatusUserNoNewPostsArchived()
		{
			var service = GetService();
			var forum = new Forum(1) { LastPostTime = new DateTime(2000, 1, 1, 5, 0, 0), IsArchived = true };
			var user = new User(2, DateTime.MinValue);
			_lastReadRepo.Setup(l => l.GetLastReadTimesForForums(2)).Returns(new Dictionary<int, DateTime> { { 1, new DateTime(2000, 1, 1, 7, 0, 0) } });
			var container = new CategorizedForumContainer(new List<Category>(), new[] { forum });
			service.GetForumReadStatus(user, container);
			Assert.AreEqual(1, container.ReadStatusLookup.Count);
			Assert.AreEqual(ReadStatus.NoNewPosts | ReadStatus.Closed, container.ReadStatusLookup[1]);
		}
コード例 #27
0
		public Forum Create(int? categoryID, string title, string description, bool isVisible, bool isArchived, int sortOrder, string urlName, string forumAdapterName, bool isQAForum)
		{
			if (categoryID == 0)
				categoryID = null;
			var forumID = 0;
			var lastPostTime = new DateTime(2000, 1, 1);
			_sqlObjectFactory.GetConnection().Using(connection => forumID = Convert.ToInt32(
				connection.Command("INSERT INTO pf_Forum (CategoryID, Title, Description, IsVisible, IsArchived, SortOrder, TopicCount, PostCount, LastPostTime, LastPostName, UrlName, ForumAdapterName, IsQAForum) VALUES (@CategoryID, @Title, @Description, @IsVisible, @IsArchived, @SortOrder, 0, 0, @LastPostTime, '', @UrlName, @ForumAdapterName, @IsQAForum)")
				.AddParameter("@CategoryID", categoryID.GetObjectOrDbNull())
				.AddParameter("@Title", title)
				.AddParameter("@Description", description)
				.AddParameter("@IsVisible", isVisible)
				.AddParameter("@IsArchived", isArchived)
				.AddParameter("@SortOrder", sortOrder)
				.AddParameter("@LastPostTime", lastPostTime)
				.AddParameter("@UrlName", urlName)
				.AddParameter("@ForumAdapterName", forumAdapterName)
				.AddParameter("@IsQAForum", isQAForum)
				.ExecuteAndReturnIdentity()));
			var forum = new Forum(forumID)
			            	{
			            		CategoryID = categoryID,
			            		Title = title,
			            		Description = description,
			            		IsVisible = isVisible,
			            		IsArchived = isArchived,
			            		SortOrder = sortOrder,
			            		TopicCount = 0,
			            		PostCount = 0,
			            		LastPostTime = lastPostTime,
			            		LastPostName = String.Empty,
			            		UrlName = urlName,
								ForumAdapterName = forumAdapterName,
								IsQAForum = isQAForum
			            	};
			_cacheHelper.RemoveCacheObject(CacheKeys.ForumUrlNames);
			_cacheHelper.RemoveCacheObject(CacheKeys.ForumPostRoleRestrictions);
			_cacheHelper.RemoveCacheObject(CacheKeys.ForumViewRoleRestrictions);
			_cacheHelper.RemoveCacheObject(CacheKeys.ForumTitles);
			return forum;
		}
コード例 #28
0
ファイル: Broker.cs プロジェクト: andyliyuze/POPForums
		public void NotifyForumUpdate(Forum forum)
		{
			_timeFormattingService.Init(null);
			var context = GlobalHost.ConnectionManager.GetHubContext<Forums>();
			context.Clients.All.notifyForumUpdate(new { forum.ForumID, TopicCount = forum.TopicCount.ToString("N0"), PostCount = forum.PostCount.ToString("N0"), LastPostTime = _timeFormattingService.GetFormattedTime(forum.LastPostTime), forum.LastPostName, Utc = forum.LastPostTime.ToString("o"), Image = "NewIndicator.png" });
		}
コード例 #29
0
ファイル: ForumTest.cs プロジェクト: andyliyuze/POPForums
		public void CreateForumObject()
		{
			const int forumID = 123;
			var forum = new Forum(forumID);
			Assert.AreEqual(forumID, forum.ForumID);
		}
コード例 #30
0
		public void ForumReadStatusForNoUser()
		{
			var service = GetService();
			var forum1 = new Forum(1);
			var forum2 = new Forum(2) { IsArchived = true };
			var forum3 = new Forum(3);
			var container = new CategorizedForumContainer(new List<Category>(), new[] { forum1, forum2, forum3 });
			service.GetForumReadStatus(null, container);
			Assert.AreEqual(3, container.ReadStatusLookup.Count);
			Assert.AreEqual(ReadStatus.NoNewPosts, container.ReadStatusLookup[1]);
			Assert.AreEqual(ReadStatus.NoNewPosts | ReadStatus.Closed, container.ReadStatusLookup[2]);
			Assert.AreEqual(ReadStatus.NoNewPosts, container.ReadStatusLookup[3]);
		}