/// <summary> /// This is a demo code to demonstrate sending notification to default tenant admin and host admin uers. /// Don't use this code in production !!! /// </summary> /// <param name="message"></param> /// <returns></returns> public async Task <ActionResult> TestNotification(string message = "") { if (message.IsNullOrEmpty()) { message = "This is a test notification, created at " + Clock.Now; } var defaultTenantAdmin = new UserIdentifier(1, 2); var hostAdmin = new UserIdentifier(null, 1); await _notificationPublisher.PublishAsync( "App.SimpleMessage", new MessageNotificationData(message), severity : NotificationSeverity.Info, userIds : new[] { defaultTenantAdmin, hostAdmin } ); return(Content("Sent notification: " + message)); }
/// <summary> /// 这是一个演示代码,演示向默认租户管理员和主机管理员发送通知 /// This is a demo code to demonstrate sending notification to default tenant admin and host admin uers. /// 不要在生产中使用此代码 !!! /// </summary> /// <param name="message"></param> /// <returns></returns> public async Task <ActionResult> TestNotification(string message = "") { if (message.IsNullOrEmpty()) { message = "这是一个测速通知, 创建时间 " + Clock.Now; } //根据租户Id和用户Id得到标识用户 var defaultTenantAdmin = new UserIdentifier(1, 2); var hostAdmin = new UserIdentifier(null, 1); //发布异步消息 await _notificationPublisher.PublishAsync( "App.SimpleMessage", new MessageNotificationData(message), severity : NotificationSeverity.Info, userIds : new[] { defaultTenantAdmin, hostAdmin } ); return(Content("Sent notification: " + message)); }
public async Task Handle([NotNull] LogbookEntryPublishedEvent notification, CancellationToken cancellationToken) { if (notification == null) { throw new ArgumentNullException(nameof(notification)); } var recipients = await diverRepository.GetAllTauchboldeUsersAsync(); var logbookEntry = await logbookEntryRepository.FindByIdAsync(notification.LogbookEntryId); var author = await diverRepository.FindByIdAsync(logbookEntry.OriginalAuthorId); var message = $"Neuer Logbucheintrag '{logbookEntry.Title}' von {author.Realname}."; await notificationPublisher.PublishAsync( NotificationType.NewLogbookEntry, message, recipients, relatedLogbookEntryId : notification.LogbookEntryId); }
public async Task PublishMessage(ChatData data) { var conversationId = "ChatMessage"; var userIndentifierFrom = new UserIdentifier(data.From.TenantId, data.From.Id); var userIndentifierTo = new UserIdentifier(data.To.TenantId, data.To.Id); UserIdentifier[] userIds = { userIndentifierTo, userIndentifierFrom }; await SubscribeFromToUsers(conversationId, userIndentifierFrom, userIndentifierTo); try { await _notificationPublisher.PublishAsync(conversationId, data, userIds : userIds); } catch (Exception ex) { throw ex; } }
public async Task Handle(CommentEditedEvent notification, CancellationToken cancellationToken) { var comment = await commentRepository.FindByIdAsync(notification.CommentId); var author = await diverRepository.FindByIdAsync(notification.AuthorId); var evt = await eventRepository.FindByIdAsync(notification.EventId); var recipients = await recipientsBuilder.GetAllTauchboldeButDeclinedParticipantsAsync( author.Id, notification.EventId); var startEndTimeAsString = evt.StartTime.FormatTimeRange(evt.EndTime); var message = $"Neuer Kommentar von '{author.Realname}' für Event '{evt.Name}' ({startEndTimeAsString}): {comment?.Text}"; await notificationPublisher.PublishAsync( NotificationType.Commented, message, recipients, relatedEventId : notification.EventId); }
public async Task Should_Notify_Using_Custom_Notifiers() { //Arrange var notificationData = new NotificationData(); //Act var before = Clock.Now; await _publisher.PublishAsync("TestNotification", notificationData, severity : NotificationSeverity.Success, userIds : new[] { AbpSession.ToUserIdentifier() }); var after = Clock.Now; //Assert Predicate <UserNotification[]> predicate = userNotifications => { userNotifications.Length.ShouldBe(1); var userNotification = userNotifications[0]; userNotification.State.ShouldBe(UserNotificationState.Unread); userNotification.TenantId.ShouldBe(AbpSession.TenantId); userNotification.UserId.ShouldBe(AbpSession.UserId.Value); var notification = userNotification.Notification; notification.CreationTime.ShouldBeInRange(before, after); notification.Data.ToString().ShouldBe(notificationData.ToString()); notification.EntityId.ShouldBe(null); notification.EntityType.ShouldBe(null); notification.EntityTypeName.ShouldBe(null); notification.NotificationName.ShouldBe("TestNotification"); notification.Severity.ShouldBe(NotificationSeverity.Success); notification.TenantId.ShouldBe(AbpSession.TenantId); return(true); }; await _realTimeNotifier1.Received().SendNotificationsAsync(Arg.Is <UserNotification[]>(uns => predicate(uns))); await _realTimeNotifier2.Received().SendNotificationsAsync(Arg.Is <UserNotification[]>(uns => predicate(uns))); }
public async Task SetNotificationAsRead(EntityDto <Guid> input) { var _user = await UserManager.FindByIdAsync("2"); if (AbpSession.UserId.HasValue) { _user = await UserManager.FindByIdAsync(AbpSession.UserId.ToString()); } await _notificationPublisher.PublishAsync( "Ali Essa", new MessageNotificationData("Has registered on site test"), userIds : new[] { _user.ToUserIdentifier() } ); var userNotification = await _userNotificationManager.GetUserNotificationAsync(AbpSession.TenantId, input.Id); if (userNotification.UserId != AbpSession.GetUserId()) { throw new Exception(string.Format("Given user notification id ({0}) is not belong to the current user ({1})", input.Id, AbpSession.GetUserId())); } await _userNotificationManager.UpdateUserNotificationStateAsync(AbpSession.TenantId, input.Id, UserNotificationState.Read); }
public async Task Handle([NotNull] CommentCreatedEvent notification, CancellationToken cancellationToken) { if (notification == null) { throw new ArgumentNullException(nameof(notification)); } var author = await diverRepository.FindByIdAsync(notification.AuthorId); var evt = await eventRepository.FindByIdAsync(notification.EventId); var recipients = await recipientsBuilder.GetAllTauchboldeButDeclinedParticipantsAsync( author.Id, notification.EventId); var startEndTimeString = evt.StartTime.FormatTimeRange(evt.EndTime); var message = $"Neuer Kommentar von '{author.Realname}' für Event '{evt.Name}' ({startEndTimeString}): {notification.Text}"; await notificationPublisher.PublishAsync( NotificationType.Commented, message, recipients, relatedEventId : notification.EventId); }
/// <summary> /// Publishes a new notification. /// </summary> /// <param name="notificationPublisher">Notification publisher</param> /// <param name="notificationName">Unique notification name</param> /// <param name="data">Notification data (optional)</param> /// <param name="entityIdentifier">The entity identifier if this notification is related to an entity</param> /// <param name="severity">Notification severity</param> /// <param name="userIds">Target user id(s). Used to send notification to specific user(s). If this is null/empty, the notification is sent to all subscribed users</param> public static void Publish(this INotificationPublisher notificationPublisher, string notificationName, NotificationData data = null, EntityIdentifier entityIdentifier = null, NotificationSeverity severity = NotificationSeverity.Info, UserIdentifier[] userIds = null) { AsyncHelper.RunSync(() => notificationPublisher.PublishAsync(notificationName, data, entityIdentifier, severity, userIds)); }
//private readonly INotificationPublisher _notificationPublisher; /// <summary> /// Calculate Depreciation /// </summary> /// <param name="startDate">Start Date</param> /// <param name="endDate">End Start</param> /// <param name="originalPrice">Original Price</param> /// <returns>Depreciation</returns> /// public async Task Execute(IJobExecutionContext context) { //_notificationPublisher = notificationPublisher; Console.WriteLine("KH"); //this.WelcomeToTheApplicationAsync() //try // { INotificationPublisher notificationPublisher = IocManager.Instance.IocContainer.Resolve <INotificationPublisher>(); IRepository <User, long> userRepository = IocManager.Instance.IocContainer.Resolve <IRepository <User, long> >(); var admin = (await userRepository.GetAllListAsync()).Where(x => x.Name == "admin").FirstOrDefault(); //IRepository<User, long> userRepository = IocManager.Instance.IocContainer.Resolve<IRepository<User, long>>(); var user = admin.ToUserIdentifier(); SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder { DataSource = "DESKTOP-OAVL1J3", InitialCatalog = "gwebsite", IntegratedSecurity = true }; string connString = "Data Source=DESKTOP-OAVL1J3;Initial Catalog=gwebsite;Integrated Security=True"; //Be sure to replace <YourTable> with the actual name of the Table string queryString = "select * from Assets"; Dictionary <string, int> map = new Dictionary <string, int>(); Dictionary <string, int> mapprice = new Dictionary <string, int>(); Dictionary <string, string> name = new Dictionary <string, string>(); Dictionary <string, int> month = new Dictionary <string, int>(); using (SqlConnection connection = new SqlConnection(connString)) using (SqlCommand command = connection.CreateCommand()) { command.CommandText = queryString; connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { string id = reader["AssetCode"].ToString(); //int month = int.Parse(reader["MonthDepreciation"].ToString()); int originalprice = int.Parse(reader["OriginalPrice"].ToString()); string assetname = reader["AssetName"].ToString(); // map.Add(id, month); mapprice.Add(id, originalprice); name.Add(id, assetname); } } } string queryString1 = "Select * From Depreciations Where DAY(DayBeginCalculateDepreciation) = " + DateTime.Now.Day.ToString(); using (SqlConnection connection = new SqlConnection(connString)) using (SqlCommand command = connection.CreateCommand()) { command.CommandText = queryString1; connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { string id = reader["AssetCode"].ToString(); int depreciatedvalue = int.Parse(reader["DepreciatedValue"].ToString()); int depreciationmonth = int.Parse(reader["DepreciationMonths"].ToString()); //int originalprice = int.Parse(reader["OriginalPrice"].ToString()); //map.Add(id, month); map.Add(id, depreciatedvalue); month.Add(id, depreciationmonth); } } } foreach (KeyValuePair <string, int> asset in map) { try { AssetDto assets = new AssetDto(); using (SqlConnection connection = new SqlConnection(connString)) using (SqlCommand command = connection.CreateCommand()) { foreach (KeyValuePair <string, int> assetprice in mapprice) { if (asset.Key == assetprice.Key) { assets.OriginalPrice = assetprice.Value; break; } } foreach (KeyValuePair <string, int> assetmonth in month) { if (asset.Key == assetmonth.Key) { assets.DepreciationMonths = assetmonth.Value; break; } } foreach (KeyValuePair <string, string> assetname in name) { if (asset.Key == assetname.Key) { assets.AssetName = assetname.Value; break; } } //assets.MonthDepreciation = asset.Value; int depreciatedvalue = asset.Value + (int)CalculateDepreciation(assets.OriginalPrice, assets.DepreciationMonths); depreciatedvalue = depreciatedvalue > assets.OriginalPrice ? assets.OriginalPrice : depreciatedvalue; float remainingvalue = (assets.OriginalPrice - depreciatedvalue) >= 0 ? (assets.OriginalPrice - depreciatedvalue) : 0; command.CommandText = "UPDATE Depreciations SET DepreciatedValue = " + depreciatedvalue.ToString() + ", RemainingValue = " + remainingvalue.ToString() + " WHERE AssetCode = '" + asset.Key.ToString() + "'"; //command.CommandText = "Select * From Depreciations Where DAY(DayBeginCalculateDepreciation) = " + DateTime.Now.Day.ToString(); Console.WriteLine(command.CommandText); connection.Open(); await notificationPublisher.PublishAsync( AppNotificationNames.WelcomeToTheApplication, new MessageNotificationData("Da Khau Hao Tai San " + assets.AssetName), severity : NotificationSeverity.Success, userIds : new[] { user } ); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { } } } } catch (Exception ex) { Console.WriteLine(ex); } } }
public async Task Publish_Message(string senderName, string Message, long targetUserId) { UserIdentifier targetUserIdentifier = new UserIdentifier(null, targetUserId); await _notiticationPublisher.PublishAsync("Message", new AppMessageNotificationData(senderName, Message), userIds : new[] { targetUserIdentifier }); }
//Send a general notification to a specific user public async Task Publish_SentFrendshipRequest(string senderUserName, string friendshipMessage, UserIdentifier targetUserId) { await _notiticationPublisher.PublishAsync("SentFrendshipRequest", new SentFrendshipRequestNotificationData(senderUserName, friendshipMessage), userIds : new[] { targetUserId }); }