本文整理汇总了C#中INotification.ToMessage方法的典型用法代码示例。如果您正苦于以下问题:C# INotification.ToMessage方法的具体用法?C# INotification.ToMessage怎么用?C# INotification.ToMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类INotification
的用法示例。
在下文中一共展示了INotification.ToMessage方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NotifyAsync
public Task NotifyAsync(IVssRequestContext requestContext, INotification notification, BotElement bot, EventRuleElement matchingRule)
{
if (!notification.TargetUserNames.Any())
return Task.FromResult(0);
var config = TfsNotificationRelaySection.Instance;
string host = bot.GetSetting("host", "127.0.0.1");
int port = bot.GetIntSetting("port", 25);
string fromAddress = bot.GetSetting("fromAddress");
string fromName = bot.GetSetting("fromName");
string subjectTextId = bot.GetSetting("subjectTextId", "plaintext");
bool isHtml = bot.GetSetting("isHtml") == "true";
var subjectTextElement = config.Texts.FirstOrDefault(t => t.Id == subjectTextId) ?? bot.Text;
string subject = notification.ToMessage(bot, subjectTextElement, s => s).First();
var client = new SmtpClient(host, port);
var message = new MailMessage();
message.From = new MailAddress(fromAddress, fromName, Encoding.UTF8);
message.SubjectEncoding = Encoding.UTF8;
message.Subject = subject;
message.IsBodyHtml = isHtml;
message.BodyEncoding = Encoding.UTF8;
message.Body = string.Join(isHtml ? "<br/>": "\n", notification.ToMessage(bot, s => s));
var identityService = requestContext.GetService<ITeamFoundationIdentityService>();
foreach (var username in notification.TargetUserNames)
{
var identity = identityService.ReadIdentity(requestContext, IdentitySearchFactor.AccountName, username);
var email = identityService.GetPreferredEmailAddress(requestContext, identity.TeamFoundationId);
if (string.IsNullOrEmpty(email))
{
string errmsg = $"TfsNotificationRelay.Smtp.SmtpNotifier: User {username} doesn't have an email address.";
TeamFoundationApplicationCore.Log(requestContext, errmsg, 0, EventLogEntryType.Warning);
}
else
{
message.To.Add(email);
}
}
if (message.To.Any())
{
requestContext.Trace(0, TraceLevel.Info, Constants.TraceArea, "SmtpNotifier",
string.Format("Sending {0} email notification to: {1}.", notification.GetType(), string.Join(", ", message.To.Select(m => m.Address))));
return client.SendMailAsync(message);
}
else
{
requestContext.Trace(0, TraceLevel.Warning, Constants.TraceArea, "SmtpNotifier",
string.Format("No recipients to send {0} email notification to.", notification.GetType()));
return Task.FromResult(0);
}
}
示例2: CreateHipChatMessage
private JObject CreateHipChatMessage(INotification notification, BotElement bot, string color)
{
dynamic jobject = new JObject();
if (bot.GetSetting("messageFormat") == "text")
{
var lines = notification.ToMessage(bot, s => s);
if (lines == null || lines.Count() == 0) return null;
jobject.message_format = "text";
jobject.message = String.Join("\n", lines);
} else {
var lines = notification.ToMessage(bot, s => HttpUtility.HtmlEncode(s));
if (lines == null || lines.Count() == 0) return null;
jobject.message_format = "html";
jobject.message = String.Join("<br/>", lines);
}
jobject.color = color;
jobject.notify = bot.GetSetting("notify").Equals("true", StringComparison.OrdinalIgnoreCase);
return jobject;
}
示例3: Notify
public void Notify(INotification notification, BotElement bot)
{
string servicEndpoint = bot.GetSetting("serviceEndpoint", "net.pipe://localhost/BotService");
ChannelFactory<IBotService> factory = new ChannelFactory<IBotService>(new NetNamedPipeBinding(),
new EndpointAddress(servicEndpoint));
IBotService service = factory.CreateChannel();
foreach (string line in notification.ToMessage(bot))
{
service.SendMessage(line);
}
}
示例4: ToSlackMessage
public Message ToSlackMessage(INotification notification, BotElement bot, string channel)
{
var lines = notification.ToMessage(bot, s => s);
return SlackHelper.CreateSlackMessage(lines, bot, channel, bot.GetSetting("standardColor"));
}
示例5: ToSlackMessage
public Message ToSlackMessage(INotification notification, BotElement bot, string channel, bool asUser)
{
var lines = notification.ToMessage(bot, s => s);
return SlackHelper.CreateSlackMessage(lines, bot, channel, asUser);
}