本文整理汇总了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();
//.........这里部分代码省略.........