public async Task NotifyAsync(NotifierData data) { var identity = GetSettingsIdentity(data); var settings = _notificationSettingsService.Get <EmailNotifierTemplate>(identity); if (settings != null && settings.IsEnabled) { var receivers = (await _intranetMemberService.GetManyAsync(data.ReceiverIds)).ToList(); foreach (var receiverId in data.ReceiverIds) { var user = receivers.Find(receiver => receiver.Id == receiverId); var message = _notificationModelMapper.Map(data.Value, settings.Template, user); _mailService.SendAsync(message); _notificationRepository.AddAsync(new Sql.Notification { Id = Guid.NewGuid(), Date = DateTime.UtcNow, IsNotified = true, IsViewed = false, Type = data.NotificationType.ToInt(), NotifierType = NotifierTypeEnum.EmailNotifier.ToInt(), Value = new { message }.ToJson(), ReceiverId = receiverId }); } } }
public string Send(NotifierData msg, string userId) { DAL.EmpModels.EmpContext emp = new DAL.EmpModels.EmpContext(); try { var u = emp.Users.FirstOrDefault(x => x.Id == userId); if (u.Email == null) { return(null); } if (u == null) { return(null); } if (msg.Msg.Body == null) { msg.Msg.Body = msg.Msg.Subject; } EmailHelper e = new EmailHelper(u.Email, msg.Msg.Subject, msg.Msg.Body); e.Send(); return(userId); //} } catch (Exception ex) { MyConsole.log(ex, "邮件发送异常"); //throw (ex); } return(null); }
public void Notify(NotifierData data) { var identity = GetSettingsIdentity(data); var settings = _notificationSettingsService.Get <EmailNotifierTemplate>(identity); if (!settings.IsEnabled) { return; } var receivers = _intranetUserService.GetMany(data.ReceiverIds).ToList(); foreach (var receiverId in data.ReceiverIds) { var user = receivers.Find(receiver => receiver.Id == receiverId); var message = _notificationModelMapper.Map(data.Value, settings.Template, user); _mailService.Send(message); _notificationRepository.Add(new global::Uintra.Notification.Notification() { Id = Guid.NewGuid(), Date = DateTime.UtcNow, IsNotified = true, IsViewed = false, Type = data.NotificationType.ToInt(), NotifierType = NotifierTypeEnum.EmailNotifier.ToInt(), Value = new { message }.ToJson(), ReceiverId = receiverId }); } }
private async Task StartNotifier(NotifierData data) { try { _logger.LogDebug($"Starting Notifier {data.Name}"); var notifier = _neonManager.Resolve(data.NotifierType) as INotifier; if (data.NotifierConfigType != null) { _logger.LogDebug($"Loading config for notifier {data.Name}"); var cfg = _fileSystemManager.ReadFromFile(GetNotifierConfigFileName(data.Name), data.NotifierConfigType); if (cfg == null) { cfg = notifier.GetDefaultConfig(); _fileSystemManager.WriteToFile(GetNotifierConfigFileName(data.Name), cfg); } await notifier.Init(cfg); _fileSystemManager.WriteToFile(GetNotifierConfigFileName(data.Name), cfg); } await notifier.Start(); _runningNotifiers.Add(data.Name, notifier); } catch (Exception ex) { _logger.LogError($"Error during starting notifier {data.Name} - {ex.Message}"); } }
private NotifierData GetNotifierData(Guid entityId, Enum notificationType) { var currentUser = _userService.GetCurrentUser(); var data = new NotifierData() { NotificationType = notificationType, ActivityType = Type, }; switch (notificationType) { case NotificationTypeEnum.CommentLikeAdded: case NotificationTypeEnum.CommentReplied: { var comment = _commentsService.Get(entityId); data.ReceiverIds = comment.UserId.ToEnumerable(); var currentContentPage = _umbracoHelper.TypedContent(comment.ActivityId); data.Value = _notifierDataHelper.GetCommentNotifierDataModel(currentContentPage, comment, notificationType, currentUser.Id); } break; default: return(null); } return(data); }
public void Notify(NotifierData data) { var isCommunicationSettings = data.NotificationType.In( NotificationTypeEnum.CommentLikeAdded, NotificationTypeEnum.MonthlyMail) || //TODO: temporary for communication settings data.ActivityType.In( IntranetActivityTypeEnum.ContentPage, IntranetActivityTypeEnum.PagePromotion); var identity = new ActivityEventIdentity(isCommunicationSettings ? CommunicationTypeEnum.CommunicationSettings : data.ActivityType, data.NotificationType) .AddNotifierIdentity(Type); var settings = _notificationSettingsService.Get <UiNotifierTemplate>(identity); if (settings == null || !settings.IsEnabled) { return; } var receivers = _intranetUserService.GetMany(data.ReceiverIds); var messages = receivers.Select(r => _notificationModelMapper.Map(data.Value, settings.Template, r)); _notificationsService.Notify(messages); }
public async Task <NotifierData> GetNotifierDataAsync <TEntity>(TEntity activity, Enum notificationType) where TEntity : IIntranetActivity, IHaveOwner { var currentMemberId = _intranetMemberService.GetCurrentMemberId(); var data = new NotifierData { NotificationType = notificationType, ActivityType = activity.Type, ReceiverIds = ReceiverIds(activity, notificationType).Except(new [] { currentMemberId }) }; switch (notificationType) { case ActivityLikeAdded: data.Value = await _notifierDataHelper.GetLikesNotifierDataModelAsync(activity, notificationType, currentMemberId); break; case BeforeStart: data.Value = await _notifierDataHelper.GetActivityReminderDataModelAsync(activity, notificationType); break; case EventHidden: case EventUpdated: data.Value = await _notifierDataHelper.GetActivityNotifierDataModelAsync(activity, notificationType, currentMemberId); break; default: throw new InvalidOperationException(); } return(data); }
public NotifierData GetNotifierData <TActivity>(TActivity activity, Enum notificationType) where TActivity : IIntranetActivity, IHaveOwner { var currentMemberId = new Lazy <Guid>(() => _intranetMemberService.GetCurrentMemberId()); var data = new NotifierData { NotificationType = notificationType, ActivityType = activity.Type, }; switch (notificationType) { case ActivityLikeAdded: data.Value = _notifierDataHelper.GetLikesNotifierDataModel(activity, notificationType, currentMemberId.Value); data.ReceiverIds = ReceiverIds(activity, notificationType).Except(new[] { currentMemberId.Value }); break; case BeforeStart: data.Value = _notifierDataHelper.GetActivityReminderDataModel(activity, notificationType); data.ReceiverIds = ReceiverIds(activity, notificationType); break; case EventHidden: case EventUpdated: data.Value = _notifierDataHelper.GetActivityNotifierDataModel(activity, notificationType, currentMemberId.Value); data.ReceiverIds = ReceiverIds(activity, notificationType).Except(new[] { currentMemberId.Value }); break; default: throw new InvalidOperationException(); } return(data); }
private NotifierData GetNotifierData(Guid entityId, Enum notificationType) { var currentMember = _memberService.GetCurrentMember(); var data = new NotifierData { NotificationType = notificationType, ActivityType = Type, }; switch (notificationType) { case NotificationTypeEnum.CommentLikeAdded: case NotificationTypeEnum.CommentReplied: { var comment = _commentsService.Get(entityId); data.ReceiverIds = comment.UserId.ToEnumerableOfOne(); var currentContentPage = _nodeModelService.Get(_requestContext.Node.Id); data.Value = _notifierDataHelper.GetCommentNotifierDataModel(currentContentPage, comment, notificationType, currentMember.Id); } break; default: throw new InvalidOperationException(); } return(data); }
public void Notify(NotifierData data) { var isCommunicationSettings = data.NotificationType.In( NotificationTypeEnum.CommentLikeAdded, NotificationTypeEnum.MonthlyMail); //TODO: temporary for communication settings var identity = new ActivityEventIdentity(isCommunicationSettings ? CommunicationTypeEnum.CommunicationSettings : data.ActivityType, data.NotificationType) .AddNotifierIdentity(Type); var settings = _notificationSettingsService.Get <EmailNotifierTemplate>(identity); if (settings == null || !settings.IsEnabled) { return; } var receivers = _intranetUserService.GetMany(data.ReceiverIds).ToList(); foreach (var receiverId in data.ReceiverIds) { var user = receivers.Find(receiver => receiver.Id == receiverId); var message = _notificationModelMapper.Map(data.Value, settings.Template, user); _mailService.Send(message); } }
public List <string> Send(NotifierData msg, List <string> userIds) { DAL.EmpModels.EmpContext emp = new DAL.EmpModels.EmpContext(); List <string> successes = new List <string>(); ITopClient client = new DefaultTopClient("http://gw.api.taobao.com/router/rest", appkey, secret); var users = emp.Users.Where(x => userIds.Contains(x.Id)).ToList(); if (users.Count() == 0) { return(successes); } foreach (var u in users) { try { AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest(); req.SmsType = "normal"; req.SmsFreeSignName = msg.SignName; req.SmsParam = "{\"source\":\"\",\"reason\":\"" + msg.Msg.Subject + "\",\"alert\":\"\"}"; req.RecNum = "" + u.PhoneNumber; req.SmsTemplateCode = msg.TemplateCode; AlibabaAliqinFcSmsNumSendResponse rsp = client.Execute(req); successes.Add(u.Id); } catch (Exception ex) { MyConsole.log(ex, "短信发送异常"); } } return(successes); }
private async Task <NotifierData> GetNotifierDataAsync(Guid entityId, Enum notificationType) { var currentMember = await _memberService.GetCurrentMemberAsync(); var data = new NotifierData { NotificationType = notificationType, ActivityType = Type, }; switch (notificationType) { case NotificationTypeEnum.CommentLikeAdded: case NotificationTypeEnum.CommentReplied: { var comment = await _commentsService.GetAsync(entityId); data.ReceiverIds = comment.UserId.ToEnumerableOfOne(); var currentContentPage = _nodeModelService.AsEnumerable().FirstOrDefault(x => x.Key == entityId); data.Value = _notifierDataHelper.GetCommentNotifierDataModel(currentContentPage, comment, notificationType, currentMember.Id); } break; default: throw new InvalidOperationException(); } return(data); }
public string Send(NotifierData msg, string userId) { DAL.EmpModels.EmpContext emp = new DAL.EmpModels.EmpContext(); ITopClient client = new DefaultTopClient("http://gw.api.taobao.com/router/rest", appkey, secret); try { var u = emp.Users.FirstOrDefault(x => x.Id == userId); if (u == null) { return(null); } AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest(); req.SmsType = "normal"; req.SmsFreeSignName = msg.SignName; req.SmsParam = "{\"source\":\"\",\"reason\":\"" + msg.Msg.Subject + "\",\"alert\":\"\"}"; req.RecNum = "" + u.PhoneNumber; req.SmsTemplateCode = msg.TemplateCode; AlibabaAliqinFcSmsNumSendResponse rsp = client.Execute(req); return(rsp.Body); } catch (Exception ex) { MyConsole.log(ex, "短信发送异常"); } return(null); }
public List <string> Send(NotifierData msg, List <string> userIds) { List <string> successes = new List <string>(); foreach (var userId in userIds) { try { var notifier = GlobalHost.ConnectionManager.GetHubContext <MyHub>(); var isonline = MyHub.IsOnline(userId); if (!isonline) { return(null); } var cids = MyHub.CurrClients.Where(x => x.Value.ClientName == userId).Select(x => x.Key).ToList(); foreach (var item in cids) { notifier.Clients.Client(item).broadcast(msg.Msg); } successes.Add(userId); } catch (Exception ex) { MyConsole.log(ex, "Web消息发送异常"); } } return(successes); }
public void SendNotification(UserMentionNotificationModel model) { const NotificationTypeEnum notificationType = NotificationTypeEnum.UserMention; foreach (var receivedId in model.ReceivedIds) { if (SkipNotification(receivedId, model.MentionedSourceId)) { continue; } var notifierData = new NotifierData { NotificationType = notificationType, ActivityType = model.ActivityType, ReceiverIds = receivedId.ToEnumerable(), Value = new UserMentionNotifierDataModel { MentionedSourceId = model.MentionedSourceId, Title = model.Title, Url = model.Url.ToLinkModel(), NotifierId = model.CreatorId, ReceiverId = receivedId, NotificationType = notificationType } }; _notificationService.ProcessNotification(notifierData); } }
public List <string> Send(NotifierData msg, List <string> userIds) { List <string> successes = new List <string>(); DAL.EmpModels.EmpContext emp = new DAL.EmpModels.EmpContext(); var users = emp.Users.Where(x => userIds.Contains(x.Id)).ToList(); if (users.Count() == 0) { return(successes); } foreach (var u in users) { try { EmailHelper e = new EmailHelper(u.Email, msg.Msg.Subject, msg.Msg.Body); e.Send(); successes.Add(u.Id); } catch (Exception ex) { MyConsole.log(ex, "邮件发送异常"); } } return(successes); }
private NotifierData GetNotifierData(Guid entityId, Enum notificationType) { var data = new NotifierData { NotificationType = notificationType, ActivityType = Type }; var currentUser = _intranetUserService.GetCurrentUser(); switch (notificationType) { case NotificationTypeEnum.ActivityLikeAdded: { var bulletinsEntity = Get(entityId); data.ReceiverIds = bulletinsEntity.OwnerId.ToEnumerable(); data.Value = _notifierDataHelper.GetLikesNotifierDataModel(bulletinsEntity, notificationType, currentUser.Id); } break; case NotificationTypeEnum.CommentAdded: case NotificationTypeEnum.CommentEdited: { var comment = _commentsService.Get(entityId); var bulletinsEntity = Get(comment.ActivityId); data.ReceiverIds = bulletinsEntity.OwnerId.ToEnumerable(); data.Value = _notifierDataHelper.GetCommentNotifierDataModel(bulletinsEntity, comment, notificationType, comment.UserId); } break; case NotificationTypeEnum.CommentReplied: { var comment = _commentsService.Get(entityId); var bulletinsEntity = Get(comment.ActivityId); data.ReceiverIds = comment.UserId.ToEnumerable(); data.Value = _notifierDataHelper.GetCommentNotifierDataModel(bulletinsEntity, comment, notificationType, currentUser.Id); } break; case NotificationTypeEnum.CommentLikeAdded: { var comment = _commentsService.Get(entityId); var bulletinsEntity = Get(comment.ActivityId); data.ReceiverIds = currentUser.Id == comment.UserId ? Enumerable.Empty <Guid>() : comment.UserId.ToEnumerable(); data.Value = _notifierDataHelper.GetCommentNotifierDataModel(bulletinsEntity, comment, notificationType, currentUser.Id); } break; default: return(null); } return(data); }
public WorkerService(IOptions <ReviewGrabberOptions> options, ILogger <WorkerService> logger, Context context, TelegramBotClient client) { _notifierData = options.Value.NotifierData; _scriptRunnerData = options.Value.ScriptRunnerData; _logger = logger; _context = context; _client = client; }
protected async Task NotifyAsync(INotifierService service, NotifierData data) { try { await service.NotifyAsync(data); } catch (Exception ex) { _logger.Error <NotificationsService>(ex); } }
protected void Notify(INotifierService service, NotifierData data) { try { service.Notify(data); } catch (Exception ex) { _logger.Error <NotificationsService>(ex); } }
protected void Notify(INotifierService service, NotifierData data) { try { service.Notify(data); } catch (Exception ex) { _exceptionLogger.Log(ex); } }
public async Task NotifyAsync(NotifierData data) { var identity = new ActivityEventIdentity(CommunicationTypeEnum.Member, data.NotificationType).AddNotifierIdentity(Type); var settings = await _notificationSettingsService.GetAsync <PopupNotifierTemplate>(identity); if (settings != null && settings.IsEnabled) { var receivers = await _intranetMemberService.GetManyAsync(data.ReceiverIds); var messages = receivers.Select(r => _notificationModelMapper.Map(data.Value, settings.Template, r)); await _notificationsService.NotifyAsync(messages); } }
public NotifierData GetNotifierData <TActivity>(CommentModel comment, TActivity activity, Enum notificationType) where TActivity : IIntranetActivity, IHaveOwner { var currentMember = _intranetMemberService.GetCurrentMember(); var data = new NotifierData { NotificationType = notificationType, ActivityType = activity.Type, ReceiverIds = ReceiverIds(comment, activity, notificationType, currentMember).Except(currentMember.Id.ToEnumerableOfOne()), Value = _notifierDataHelper.GetCommentNotifierDataModel(activity, comment, notificationType, currentMember.Id) }; return(data); }
public async Task <NotifierData> GetNotifierDataAsync <TEntity>(CommentModel comment, TEntity activity, Enum notificationType) where TEntity : IIntranetActivity, IHaveOwner { //var currentMember = await _intranetMemberService.GetCurrentMemberAsync(); var currentMember = _intranetMemberService.GetCurrentMember(); var data = new NotifierData { NotificationType = notificationType, ActivityType = activity.Type, ReceiverIds = ReceiverIds(comment, activity, notificationType, currentMember).Except(new [] { currentMember.Id } /*.ToEnumerableOfOne()*/), Value = await _notifierDataHelper.GetCommentNotifierDataModelAsync(activity, comment, notificationType, currentMember.Id) }; return(data); }
public void Notify(NotifierData data) { var identity = new ActivityEventIdentity(CommunicationTypeEnum.Member, data.NotificationType).AddNotifierIdentity(Type); var settings = _notificationSettingsService.Get <PopupNotifierTemplate>(identity); if (settings == null || !settings.IsEnabled) { return; } var receivers = _intranetUserService.GetMany(data.ReceiverIds); var messages = receivers.Select(r => _notificationModelMapper.Map(data.Value, settings.Template, r)); _notificationsService.Notify(messages); }
public void Notify(NotifierData data) { var isCommunicationSettings = data.NotificationType.In( NotificationTypeEnum.CommentLikeAdded, NotificationTypeEnum.MonthlyMail, IntranetActivityTypeEnum.ContentPage); var identity = new ActivityEventIdentity(isCommunicationSettings ? CommunicationTypeEnum.CommunicationSettings : data.ActivityType, data.NotificationType) .AddNotifierIdentity(Type); var settings = _notificationSettingsService.Get <UiNotifierTemplate>(identity); var desktopSettingsIdentity = new ActivityEventIdentity(settings.ActivityType, settings.NotificationType) .AddNotifierIdentity(NotifierTypeEnum.DesktopNotifier); var desktopSettings = _notificationSettingsService.Get <DesktopNotifierTemplate>(desktopSettingsIdentity); if (!settings.IsEnabled && !desktopSettings.IsEnabled) { return; } var receivers = _intranetMemberService.GetMany(data.ReceiverIds).ToList(); var messages = receivers.Select(receiver => { var uiMsg = _notificationModelMapper.Map(data.Value, settings.Template, receiver); if (desktopSettings.IsEnabled) { var desktopMsg = _desktopNotificationModelMapper.Map(data.Value, desktopSettings.Template, receiver); uiMsg.DesktopTitle = desktopMsg.Title; uiMsg.DesktopMessage = desktopMsg.Message; uiMsg.IsDesktopNotificationEnabled = true; if (uiMsg.NotifierId.HasValue) { uiMsg.NotifierPhotoUrl = _intranetMemberService.Get(uiMsg.NotifierId.Value)?.Photo; } } return(uiMsg); }); _notificationsService.Notify(messages); }
public string Send(NotifierData msg, string userId) { DAL.EmpModels.EmpContext emp = new DAL.EmpModels.EmpContext(); JPushClient client = new JPushClient(app_key, master_secret); PushPayload pushPayload = new PushPayload(); pushPayload.platform = Platform.android(); pushPayload.audience = Audience.s_tag(userId); pushPayload.notification = Notification.android(msg.Msg.Body, msg.Msg.Subject); try { var result = client.SendPush(pushPayload); return(userId); } catch { return(null); } return(null); }
private ActivityEventNotifierIdentity GetSettingsIdentity(NotifierData data) { Enum activityType; switch (data.NotificationType.ToInt()) { case (int)NotificationTypeEnum.CommentLikeAdded: case (int)NotificationTypeEnum.MonthlyMail: case (int)IntranetActivityTypeEnum.ContentPage: activityType = CommunicationTypeEnum.CommunicationSettings; break; default: activityType = data.ActivityType; break; } return(new ActivityEventIdentity(activityType, data.NotificationType) .AddNotifierIdentity(Type)); }
public void ProcessNotification(NotifierData data) { var allReceiversIds = data.ReceiverIds.ToList(); var allReceiversNotifiersSettings = _memberNotifiersSettingsService.GetForMembers(allReceiversIds); (IEnumerable <Guid> receiverIds, bool isNotEmpty) GetReceiverIdsForNotifier(Enum notifierType) { var ids = allReceiversIds .Where(receiverId => allReceiversNotifiersSettings[receiverId].Contains(notifierType)) .ToList(); return(ids, ids.Any()); } foreach (var notifier in _notifiers) { var filterResult = GetReceiverIdsForNotifier(notifier.Type); if (filterResult.isNotEmpty) { Notify(notifier, data); } } }
public List <string> Send(NotifierData msg, List <string> userIds) { DAL.EmpModels.EmpContext emp = new DAL.EmpModels.EmpContext(); List <string> successes = new List <string>(); JPushClient client = new JPushClient(app_key, master_secret); foreach (var userId in userIds) { PushPayload pushPayload = new PushPayload(); pushPayload.platform = Platform.android(); pushPayload.audience = Audience.s_tag(userId); pushPayload.notification = Notification.android(msg.Msg.Body, msg.Msg.Subject); try { var result = client.SendPush(pushPayload); successes.Add(userId); } catch { } } return(successes); }