当前位置: 首页>>代码示例>>C#>>正文


C# IServiceProvider.GetFormatter方法代码示例

本文整理汇总了C#中IServiceProvider.GetFormatter方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceProvider.GetFormatter方法的具体用法?C# IServiceProvider.GetFormatter怎么用?C# IServiceProvider.GetFormatter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IServiceProvider的用法示例。


在下文中一共展示了IServiceProvider.GetFormatter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildMessage

		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();

//.........这里部分代码省略.........
开发者ID:rsdn,项目名称:janus,代码行数:101,代码来源:XmlBuilder.cs


注:本文中的IServiceProvider.GetFormatter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。