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


C# INotification.GetType方法代码示例

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


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

示例1: SendNotification

        public void SendNotification(INotification notification)
        {
            var notificationType = notification.GetType();

            if (!channels.ContainsKey(notificationType))
            {
                if (notification is AppleNotification)
                {
                    broker.QueueNotification<AppleNotification>(notification as AppleNotification);
                }
                else if (notification is GcmNotification)
                {
                    broker.QueueNotification<GcmNotification>(notification as GcmNotification);
                }
                else
                    throw new NotSupportedException(notification.GetType().ToString());
            }
        }
开发者ID:Elders,项目名称:Pushnotifications,代码行数:18,代码来源:NotificationSender.cs

示例2: 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);
            }
        }
开发者ID:kria,项目名称:TfsNotificationRelay,代码行数:57,代码来源:SmtpNotifier.cs

示例3: ConvertNotificationToString

        /// <summary>
        /// Convert a notification to an xml string
        /// </summary>
        /// <param name="notification">Notification object</param>
        /// <returns>string representation of the notification</returns>
        public string ConvertNotificationToString(INotification notification)
        {
            StringBuilder xmlStringBuilder = new StringBuilder();
            using (StringWriter fs = new StringWriter(xmlStringBuilder))
            {
                fs.WriteLine("LOG AT " + DateTime.Now);

                fs.WriteLine("NOTIFICATION_TYPE: " + notification.NotificationType);
                IpnNotificationMetadata metadata = (IpnNotificationMetadata)notification.NotificationMetadata;
                fs.WriteLine("NOTIFICATION_METADATA_TIMESTAMP: " + metadata.Timestamp);
                fs.WriteLine("NOTIFICATION_METADATA_NotificationReferenceId: " + metadata.NotificationReferenceId);
                fs.WriteLine("NOTIFICATION_METADATA_ReleaseEnvironment: " + metadata.ReleaseEnvironment);
                fs.WriteLine();

                new XmlSerializer(notification.GetType()).Serialize(fs, notification);
                return xmlStringBuilder.ToString();
            }
        }
开发者ID:Georotzen,项目名称:login-and-pay-with-amazon-sdk-csharp,代码行数:23,代码来源:IpnHandler.aspx.cs


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