Example #1
0
        private Forums(IServiceProvider provider)
            : base(provider)
        {
            if (provider == null)
                throw new ArgumentNullException("provider");

            _serviceProvider = provider;
            _dbManager = _serviceProvider.GetRequiredService<IJanusDatabaseManager>();
            _forumsAggregatesService = new Lazy<IForumsAggregatesService>(
                () => _serviceProvider.GetRequiredService<IForumsAggregatesService>());

            _unsubscribedFolder = new ForumFolder(_serviceProvider, this, SR.Forum.Unsubscribed.DisplayName);
            _folders.Add(_unsubscribedFolder);
            _flags = NodeFlags.AutoExpand;
            _description = SR.Forum.Incoming.DisplayName;

            LoadData();
        }
Example #2
0
        private Forums(IServiceProvider provider)
            : base(provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            _serviceProvider         = provider;
            _dbManager               = _serviceProvider.GetRequiredService <IJanusDatabaseManager>();
            _forumsAggregatesService = new Lazy <IForumsAggregatesService>(
                () => _serviceProvider.GetRequiredService <IForumsAggregatesService>());

            _unsubscribedFolder = new ForumFolder(_serviceProvider, this, SR.Forum.Unsubscribed.DisplayName);
            _folders.Add(_unsubscribedFolder);
            _flags       = NodeFlags.AutoExpand;
            _description = SR.Forum.Incoming.DisplayName;

            LoadData();
        }
Example #3
0
		public static XmlMessage BuildMessage(
			IServiceProvider provider,
			IJanusDatabaseManager dbMgr,
			int mid,
			[CanBeNull] Func<string, string> sourceFormatter)
		{
			using (var db = dbMgr.CreateDBContext())
			{
				var msg =
					db
						.Message(
							mid,
							m =>
								new
								{
									m.UserID,
									m.UserClass,
									UserNick = m.UserNick.ToUserDisplayName(m.UserClass),
									m.Date,
									m.IsRead,
									m.IsMarked,
									m.ArticleId,
									m.Name,
									m.Subject,
									m.Message,
									m.User.Origin,
									Rating = m.Rating(),
									Smiles = m.SmileCount(),
									Agrees = m.AgreeCount(),
									Disagrees = m.DisagreeCount(),
									PenaltyType = m.Violation != null ? m.Violation.PenaltyType : 0,
									Reason = m.Violation != null ? m.Violation.Reason : null,
									ViolationDate = m.Violation != null ? (DateTime?)m.Violation.Create : null
								});
				var body = sourceFormatter != null ? sourceFormatter(msg.Message) : msg.Message;
				var formatter = provider.GetFormatter();
				var dateFormat = Config.Instance.ForumDisplayConfig.DateFormat;
				var xmlMessage =
					new XmlMessage
					{
						FormattingOptions =
							{
								ShowHeader = Config.Instance.ForumDisplayConfig.Envelope.ShowHeader,
								ShowRateFrame = Config.Instance.ForumDisplayConfig.Envelope.ShowRateFrame
							},
						ID = mid,
						Author =
							{
								ID = msg.UserID,
								UserClass = (int)msg.UserClass,
								DisplayName = msg.UserNick
							},
						Date =
							{
								Value = msg.Date.ToString(dateFormat),
								IsOutdate =
									DateTime.Now.AddDays(-Config.Instance.ForumDisplayConfig.DaysToOutdate) > msg.Date
									&& Config.Instance.ForumDisplayConfig.DaysToOutdate != 0,
								DayOfWeek = Convert.ToInt32(msg.Date.DayOfWeek)
							},
						IsUnread = !msg.IsRead,
						IsMarked = msg.IsMarked,
						ArticleID = msg.ArticleId.GetValueOrDefault(),
						Name = msg.Name,
						Subject = msg.Subject,
						Content = formatter.Format(body, true),
						Origin = formatter.Format(msg.Origin, true),
						Rate = {Summary = JanusFormatMessage.FormatRates(msg.Rating, msg.Smiles, msg.Agrees, msg.Disagrees)},
						ViolationPenaltyType = (int) msg.PenaltyType,
						ViolationReason =
							msg.Reason.IsNullOrEmpty()
								? null
								: msg.ViolationDate.GetValueOrDefault().ToString(dateFormat) + " " + msg.Reason
					};

				if (Config.Instance.ForumDisplayConfig.Envelope.ShowRateFrame)
				{
					var rateList =
						db
							.Rates(r => r.MessageID == mid)
							.OrderByDescending(r => r.Date)
							.Select(
								r =>
									new
										{
											r.RateType,
											r.Multiplier,
											r.Message.ServerForum.InTop,
											r.UserID,
											r.User.UserClass,
											DisplayName = r.User.DisplayName()
										});
					foreach (var rate in rateList)
					{
						var rateItem = new XmlMessage.MessageRateItem();
						var rateString = string.Empty;
						var intType = (int)rate.RateType;
						if (intType > 0)
							rateString = (rate.Multiplier*intType).ToString();

						rateItem.Value = rateString;
						rateItem.ForumInTop = rate.InTop;
						rateItem.Type = (int)rate.RateType;

						rateItem.Author.ID = rate.UserID;
						rateItem.Author.UserClass = (int)rate.UserClass;
						rateItem.Author.DisplayName = rate.DisplayName;

						xmlMessage.Rate.List.Add(rateItem);
					}
				}
				return xmlMessage;
			}
		}
Example #4
0
        public static XmlMessage BuildMessage(
            IServiceProvider provider,
            IJanusDatabaseManager dbMgr,
            int mid,
            [CanBeNull] Func <string, string> sourceFormatter)
        {
            using (var db = dbMgr.CreateDBContext())
            {
                var msg =
                    db
                    .Message(
                        mid,
                        m =>
                        new
                {
                    m.UserID,
                    m.UserClass,
                    UserNick = m.UserNick.ToUserDisplayName(m.UserClass),
                    m.Date,
                    m.IsRead,
                    m.IsMarked,
                    m.ArticleId,
                    m.Name,
                    m.Subject,
                    m.Message,
                    m.User.Origin,
                    Rating        = m.Rating(),
                    Smiles        = m.SmileCount(),
                    Agrees        = m.AgreeCount(),
                    Disagrees     = m.DisagreeCount(),
                    PenaltyType   = m.Violation != null ? m.Violation.PenaltyType : 0,
                    Reason        = m.Violation != null ? m.Violation.Reason : null,
                    ViolationDate = m.Violation != null ? (DateTime?)m.Violation.Create : null
                });
                var body = sourceFormatter != null?sourceFormatter(msg.Message) : msg.Message;

                var formatter  = provider.GetFormatter();
                var dateFormat = Config.Instance.ForumDisplayConfig.DateFormat;
                var xmlMessage =
                    new XmlMessage
                {
                    FormattingOptions =
                    {
                        ShowHeader    = Config.Instance.ForumDisplayConfig.Envelope.ShowHeader,
                        ShowRateFrame = Config.Instance.ForumDisplayConfig.Envelope.ShowRateFrame
                    },
                    ID     = mid,
                    Author =
                    {
                        ID          = msg.UserID,
                        UserClass   = (int)msg.UserClass,
                        DisplayName = msg.UserNick
                    },
                    Date =
                    {
                        Value     = msg.Date.ToString(dateFormat),
                        IsOutdate =
                            DateTime.Now.AddDays(-Config.Instance.ForumDisplayConfig.DaysToOutdate) > msg.Date &&
                            Config.Instance.ForumDisplayConfig.DaysToOutdate != 0,
                        DayOfWeek = Convert.ToInt32(msg.Date.DayOfWeek)
                    },
                    IsUnread             = !msg.IsRead,
                    IsMarked             = msg.IsMarked,
                    ArticleID            = msg.ArticleId.GetValueOrDefault(),
                    Name                 = msg.Name,
                    Subject              = msg.Subject,
                    Content              = formatter.Format(body, true),
                    Origin               = formatter.Format(msg.Origin, true),
                    Rate                 = { Summary = JanusFormatMessage.FormatRates(msg.Rating, msg.Smiles, msg.Agrees, msg.Disagrees) },
                    ViolationPenaltyType = (int)msg.PenaltyType,
                    ViolationReason      =
                        msg.Reason.IsNullOrEmpty()
                                                                ? null
                                                                : msg.ViolationDate.GetValueOrDefault().ToString(dateFormat) + " " + msg.Reason
                };

                if (Config.Instance.ForumDisplayConfig.Envelope.ShowRateFrame)
                {
                    var rateList =
                        db
                        .Rates(r => r.MessageID == mid)
                        .OrderByDescending(r => r.Date)
                        .Select(
                            r =>
                            new
                    {
                        r.RateType,
                        r.Multiplier,
                        r.Message.ServerForum.InTop,
                        r.UserID,
                        r.User.UserClass,
                        DisplayName = r.User.DisplayName()
                    });
                    foreach (var rate in rateList)
                    {
                        var rateItem   = new XmlMessage.MessageRateItem();
                        var rateString = string.Empty;
                        var intType    = (int)rate.RateType;
                        if (intType > 0)
                        {
                            rateString = (rate.Multiplier * intType).ToString();
                        }

                        rateItem.Value      = rateString;
                        rateItem.ForumInTop = rate.InTop;
                        rateItem.Type       = (int)rate.RateType;

                        rateItem.Author.ID          = rate.UserID;
                        rateItem.Author.UserClass   = (int)rate.UserClass;
                        rateItem.Author.DisplayName = rate.DisplayName;

                        xmlMessage.Rate.List.Add(rateItem);
                    }
                }
                return(xmlMessage);
            }
        }