Сообщение форума.
Inheritance: MsgBase
Beispiel #1
0
Datei: Msg.cs Projekt: rsdn/janus
		//private static IQueryable<int> GetKeysetSource(
		//  IDataContext db,
		//  int forumID,
		//  SortType sort)
		//{
		//  if (sort == SortType.ByLastUpdateDateAsc || sort == SortType.ByLastUpdateDateDesc)
		//  {
		//    var topicSrc = db.TopicInfos(ti => ti.ForumID == forumID);
		//    topicSrc =
		//      sort == SortType.ByLastUpdateDateAsc
		//        ? topicSrc.OrderBy(ti => ti.LastUpdateDate)
		//        : topicSrc.OrderByDescending(ti => ti.LastUpdateDate);
		//    return topicSrc.Select(ti => ti.MessageID);
		//  }
		//  var msgSrc = db.Messages(m => m.TopicID == 0 && m.ForumID == forumID);
		//  switch (sort)
		//  {
		//    case SortType.ByDateAsc:
		//      msgSrc = msgSrc.OrderBy(m => m.Date);
		//      break;
		//    case SortType.ByDateDesc:
		//      msgSrc = msgSrc.OrderByDescending(m => m.Date);
		//      break;
		//    case SortType.ByIdAsc:
		//      msgSrc = msgSrc.OrderBy(m => m.ID);
		//      break;
		//    case SortType.ByIdDesc:
		//      msgSrc = msgSrc.OrderByDescending(m => m.ID);
		//      break;
		//    case SortType.BySubjectAsc:
		//      msgSrc = msgSrc.OrderBy(m => m.Subject);
		//      break;
		//    case SortType.BySubjectDesc:
		//      msgSrc = msgSrc.OrderByDescending(m => m.Subject);
		//      break;
		//    case SortType.ByAuthorAsc:
		//      msgSrc = msgSrc.OrderBy(m => m.UserNick);
		//      break;
		//    case SortType.ByAuthorDesc:
		//      msgSrc = msgSrc.OrderByDescending(m => m.UserNick);
		//      break;
		//    case SortType.ByForumAsc:
		//      msgSrc = msgSrc.OrderBy(m => m.ServerForum.Name);
		//      break;
		//    case SortType.ByForumDesc:
		//      msgSrc = msgSrc.OrderByDescending(m => m.ServerForum.Name);
		//      break;
		//    default:
		//      throw new ArgumentOutOfRangeException("sort");
		//  }
		//  return msgSrc.Select(m => m.ID);
		//}

		//public static Msg GetTopicsKeyset(
		//  IServiceProvider provider,
		//  int forumID,
		//  SortType sort,
		//  bool isLoadAll)
		//{
		//  var virtualRoot = new Msg(provider);
		//  using (var db = provider.CreateDBManager())
		//  {
		//    var src = GetKeysetSource(db, forumID, sort);
		//    var displayConfig = Config.Instance.ForumDisplayConfig;
		//    if (!(isLoadAll || displayConfig.MaxTopicsPerForum <= 0))
		//      src = src.Take(displayConfig.MaxTopicsPerForum);
		//    virtualRoot.Children =
		//      src
		//        .Select(
		//          id =>
		//            new Msg(provider)
		//            {
		//              ID = id,
		//              ParentID = 0,
		//              ForumID = forumID,
		//              Parent = virtualRoot,
		//              IsChild = false,
		//              _partiallyLoaded = true
		//            })
		//        .Cast<MsgBase>()
		//        .ToList();
		//    var idx = 0;
		//    foreach (Msg msg in virtualRoot.Children)
		//    {
		//      msg._loadIndex = idx;
		//      idx++;
		//    }
		//  }
		//  return virtualRoot;
		//}

		#endregion


		private static void LoadFrame(Msg msg)
		{
			var children = ((Msg) msg.Parent).Children;
			var frameTop = msg._loadIndex / _frameSize * _frameSize;
			var ids =
				Enumerable
					.Range(frameTop, Math.Min(_frameSize, children.Count - frameTop))
					.Select(i => children[i].ID)
					.ToArray();
			var provider = msg.ServiceProvider;
			using (var db = provider.CreateDBContext())
			{
				var msgs =
					db
						.TopicInfos(ti => ids.Contains(ti.MessageID))
						.Select(
							ti =>
								new
								{
									ti.Message.Name,
									ti.Message.Date,
									ti.Message.Subject,
									ti.Message.UserID,
									UserClass = (short)ti.Message.UserClass,
									ti.Message.UserNick,
									ti.Message.IsRead,
									ti.Message.IsMarked,
									ti.Message.Closed,
									ti.Message.ReadReplies,
									ti.Message.LastModerated,
									ti.Message.ArticleId,
									Rating = ti.SelfRates,
									Smiles = ti.SelfSmiles,
									Agrees = ti.SelfAgrees,
									Disagrees = ti.SelfDisagrees,
									Moderatorials = ti.SelfModeratorials,
									RepliesCount = ti.AnswersCount,
									RepliesUnread = ti.AnswersUnread,
									RepliesRate = ti.AnswersRates,
									RepliesSmiles = ti.AnswersSmiles,
									RepliesAgree = ti.AnswersAgrees,
									RepliesDisagree = ti.AnswersDisagrees,
									RepliesToMeUnread = ti.AnswersToMeUnread,
									RepliesMarked = ti.AnswersMarked,
									RepliesModeratorials = ti.AnswersModeratorials
								});
				var i = frameTop;
				foreach (var tuple in msgs)
				{
					var m = (Msg)children[i];

					m.Name = tuple.Name;
					m.Date = tuple.Date;
					m.Subject = tuple.Subject;
					m.UserID = tuple.UserID;
					m.UserClass = tuple.UserClass;
					m.UserNick = tuple.UserNick;
					m.IsRead = tuple.IsRead;
					m.IsMarked = tuple.IsMarked;
					m.Closed = tuple.Closed;
					m.ReadReplies = tuple.ReadReplies;
					m.LastModerated = tuple.LastModerated;
					m.ArticleId = tuple.ArticleId;
					m.Rating = tuple.Rating;
					m.Smiles = tuple.Smiles;
					m.Agrees = tuple.Agrees;
					m.Disagrees = tuple.Disagrees;
					m.Moderatorials = tuple.Moderatorials;
					m.RepliesCount = tuple.RepliesCount;
					m.RepliesUnread = tuple.RepliesUnread;
					m.RepliesRate = tuple.RepliesRate;
					m.RepliesSmiles = tuple.RepliesSmiles;
					m.RepliesAgree = tuple.RepliesAgree;
					m.RepliesDisagree = tuple.RepliesDisagree;
					m.RepliesToMeUnread = tuple.RepliesToMeUnread;
					m.RepliesMarked = tuple.RepliesMarked;
					m.RepliesModeratorials = tuple.RepliesModeratorials;

					m._partiallyLoaded = false;
					m.EndMapping();
					i++;
				}
			}

		}
Beispiel #2
0
Datei: Msg.cs Projekt: rsdn/janus
		public static Msg GetTopics(
			IServiceProvider provider,
			int forumID,
			SortType sort,
			bool isLoadAll)
		{
			var msg = new Msg(provider);
			msg.Children = GetOldStyleTopicList(provider, forumID, sort, isLoadAll, msg);
			return msg;
		}
Beispiel #3
0
Datei: Msg.cs Projekt: rsdn/janus
		public static IMsg FilterFirstLevel(
			IServiceProvider provider,
			Msg curMsg,
			string text)
		{
			var msg = new Msg(provider);
			var children =
				curMsg
					.Children
					.Where(
						msgBase =>
							msgBase
								.Subject
								.ToLower()
								.IndexOf(text.ToLower()) != -1)
					.ToList();

			msg.Children = children;

			return msg;
		}