public Notification(string code, string text, NotificationSeverity severity, object tag) { Text = text; Severity = severity; Tag = tag; Code = code; }
public static Notification Create(string code, string message, NotificationSeverity notificationSeverity) { return(new Notification(message, notificationSeverity) { Code = code }); }
public bool ConfirmMessageBox(string message, string title = null, NotificationSeverity severity = NotificationSeverity.Warning) { _uiShellService.EnableModeless(0); try { var icon = SeverityToIcon(severity); int dialogResult; _uiShellService.ShowMessageBox( dwCompRole: 0, // unused, as per MSDN documentation rclsidComp: Guid.Empty, // unused pszTitle: title, pszText: message, pszHelpFile: null, dwHelpContextID: 0, // required to be 0, as per MSDN documentation msgbtn: OLEMSGBUTTON.OLEMSGBUTTON_YESNO, msgdefbtn: OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, msgicon: icon, fSysAlert: 0, // Not system modal pnResult: out dialogResult); // The dialogResult is 6 when the Yes button is clicked. return(dialogResult == 6); } finally { // if ShowMessageBox() throws we need to ensure that the UI isn't forever stuck in a modal state _uiShellService.EnableModeless(1); } }
/// <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)); }
public async Task ComposesMessage(NotificationSeverity severity) { // Arrange var input = new List <Notification> { new Notification { IsSent = true, DateCreated = DateTime.UtcNow.AddSeconds(-30), Severity = severity, Message = "Hello, world!" } }; var notificationService = new NotificationService( new Mock <ILogger <NotificationService> >().Object, _config, _serviceProvider.GetRequiredService <IDataContext>(), new Mock <IEmailService>().Object, new Mock <ISlackService>().Object ); // Act var actual = await notificationService.ComposeMessageAsync(input); // Assert Assert.Contains($"Severity {severity}", actual); }
public Task SendMessageAsync(UserIdentifier user, LocalizableString localizableMessage, IDictionary <string, object> localizableMessageData = null, NotificationSeverity severity = NotificationSeverity.Info) { return(SendNotificationAsync(AppNotificationNames.SimpleMessage, user, localizableMessage, localizableMessageData, severity)); }
public virtual async Task PublishAsync(string notificationName, NotificationData data = null, EntityIdentifier entityIdentifier = null, NotificationSeverity severity = NotificationSeverity.Info, long[] userIds = null) { if (notificationName.IsNullOrEmpty()) { throw new ArgumentException("NotificationName can not be null or whitespace!", "notificationName"); } var notificationInfo = new NotificationInfo { NotificationName = notificationName, EntityTypeName = entityIdentifier == null ? null : entityIdentifier.Type.FullName, EntityTypeAssemblyQualifiedName = entityIdentifier == null ? null : entityIdentifier.Type.AssemblyQualifiedName, EntityId = entityIdentifier == null ? null : entityIdentifier.Id.ToJsonString(), Severity = severity, UserIds = userIds.IsNullOrEmpty() ? null : userIds.JoinAsString(","), Data = data == null ? null : data.ToJsonString(), DataTypeName = data == null ? null : data.GetType().AssemblyQualifiedName }; await _store.InsertNotificationAsync(notificationInfo); await _backgroundJobManager.EnqueueAsync<NotificationDistributionJob, NotificationDistributionJobArgs>( new NotificationDistributionJobArgs( notificationInfo.Id ) ); }
public virtual async Task PublishAsync( string notificationName, NotificationData data = null, EntityIdentifier entityIdentifier = null, NotificationSeverity severity = NotificationSeverity.Info, long[] userIds = null, long[] excludedUserIds = null, int?[] tenantIds = null) { if (notificationName.IsNullOrEmpty()) { throw new ArgumentException("NotificationName can not be null or whitespace!", "notificationName"); } if (!tenantIds.IsNullOrEmpty() && !userIds.IsNullOrEmpty()) { throw new ArgumentException("tenantIds can be set only userIds is not set!", "tenantIds"); } if (tenantIds.IsNullOrEmpty() && userIds.IsNullOrEmpty()) { tenantIds = new[] {AbpSession.TenantId}; } var notificationInfo = new NotificationInfo { NotificationName = notificationName, EntityTypeName = entityIdentifier == null ? null : entityIdentifier.Type.FullName, EntityTypeAssemblyQualifiedName = entityIdentifier == null ? null : entityIdentifier.Type.AssemblyQualifiedName, EntityId = entityIdentifier == null ? null : entityIdentifier.Id.ToJsonString(), Severity = severity, UserIds = userIds.IsNullOrEmpty() ? null : userIds.JoinAsString(","), ExcludedUserIds = excludedUserIds.IsNullOrEmpty() ? null : excludedUserIds.JoinAsString(","), TenantIds = tenantIds.IsNullOrEmpty() ? null : tenantIds.JoinAsString(","), Data = data == null ? null : data.ToJsonString(), DataTypeName = data == null ? null : data.GetType().AssemblyQualifiedName }; await _store.InsertNotificationAsync(notificationInfo); await CurrentUnitOfWork.SaveChangesAsync(); //To get Id of the notification 获得通知的身份证 if (userIds != null && userIds.Length <= 5) { //We can directly distribute the notification since there are not much receivers //我们可以直接分发通知,因为没有太多的接收器 await _notificationDistributer.DistributeAsync(notificationInfo.Id); } else { //We enqueue a background job since distributing may get a long time //我们将后台工作分配可能会很长一段时间以来 await _backgroundJobManager.EnqueueAsync<NotificationDistributionJob, NotificationDistributionJobArgs>( new NotificationDistributionJobArgs( notificationInfo.Id ) ); } }
public NotificationInfo() { Data = new NotificationData(); NotificationType = NotificationType.Application; NotificationSeverity = NotificationSeverity.Info; CreationTime = DateTime.Now; }
// Roslyn usually does not set a title, only a message. AlertButton ShowAlert(string message, string title, NotificationSeverity severity, params AlertButton[] buttons) { string primary = title ?? message; string secondary = title != null ? message : null; string icon = GetSeverityIcon(severity); return(MessageService.GenericAlert(icon, primary, secondary, buttons)); }
/// <summary> /// Initializes a new instance of the <see cref="Notification"/> class. /// </summary> /// <param name="text">The text.</param> /// <param name="severity">The severity.</param> /// <param name="tag">The Tag.</param> public Notification(string text, NotificationSeverity severity, object tag, string hint) { Guard.ArgumentNotEmpty(text, "text"); Text = text; Severity = severity; Tag = tag; Hint = hint; }
//This is for test purposes public async Task SendMessageAsync(UserIdentifier user, string message, NotificationSeverity severity = NotificationSeverity.Info) { await _notificationPublisher.PublishAsync( "App.SimpleMessage", new MessageNotificationData(message), severity : severity, userIds : new[] { user } ); }
public Notification(long id, string name, string dataType, string data, NotificationSeverity severity = NotificationSeverity.Info) { NotificationId = id; Severity = severity; NotificationName = name; NotificationData = data; NotificationTypeName = dataType; Type = NotificationType.Application; }
//This is for test purposes public async Task SendMessageAsync(UserIdentifier user, string message, NotificationSeverity severity = NotificationSeverity.Info) { await _notificationPublisher.PublishAsync( "App.SimpleMessage", new MessageNotificationData(message), severity: severity, userIds: new[] { user } ); }
public virtual async Task PublishAsync( string notificationName, NotificationData data = null, EntityIdentifier entityIdentifier = null, NotificationSeverity severity = NotificationSeverity.Info, UserIdentifier[] userIds = null, UserIdentifier[] excludedUserIds = null, int?[] tenantIds = null) { if (notificationName.IsNullOrEmpty()) { throw new ArgumentException("NotificationName can not be null or whitespace!", "notificationName"); } if (!tenantIds.IsNullOrEmpty() && !userIds.IsNullOrEmpty()) { throw new ArgumentException("tenantIds can be set only if userIds is not set!", "tenantIds"); } if (tenantIds.IsNullOrEmpty() && userIds.IsNullOrEmpty()) { tenantIds = new[] { CodeZeroSession.TenantId }; } var notificationInfo = new NotificationInfo(_guidGenerator.Create()) { NotificationName = notificationName, EntityTypeName = entityIdentifier == null ? null : entityIdentifier.Type.FullName, EntityTypeAssemblyQualifiedName = entityIdentifier == null ? null : entityIdentifier.Type.AssemblyQualifiedName, EntityId = entityIdentifier == null ? null : entityIdentifier.Id.ToJsonString(), Severity = severity, UserIds = userIds.IsNullOrEmpty() ? null : userIds.Select(uid => uid.ToUserIdentifierString()).JoinAsString(","), ExcludedUserIds = excludedUserIds.IsNullOrEmpty() ? null : excludedUserIds.Select(uid => uid.ToUserIdentifierString()).JoinAsString(","), TenantIds = tenantIds.IsNullOrEmpty() ? null : tenantIds.JoinAsString(","), Data = data == null ? null : data.ToJsonString(), DataTypeName = data == null ? null : data.GetType().AssemblyQualifiedName }; await _store.InsertNotificationAsync(notificationInfo); await CurrentUnitOfWork.SaveChangesAsync(); //To get Id of the notification if (userIds != null && userIds.Length <= MaxUserCountToDirectlyDistributeANotification) { //We can directly distribute the notification since there are not much receivers await _notificationDistributer.DistributeAsync(notificationInfo.Id); } else { //We enqueue a background job since distributing may get a long time await _backgroundJobManager.EnqueueAsync <NotificationDistributionJob, NotificationDistributionJobArgs>( new NotificationDistributionJobArgs( notificationInfo.Id ) ); } }
/// <summary> /// Creates a new <see cref="NotificationPublishOptions"/>. /// </summary> public NotificationPublishOptions(string notificationName, NotificationData data, Type entityType = null, object entityId = null, NotificationSeverity severity = NotificationSeverity.Info, long[] userIds = null) { NotificationName = notificationName; Data = data; EntityType = entityType; EntityId = entityId; Severity = severity; UserIds = userIds; }
public NotificationInfo() { Data = new NotificationData(); Lifetime = NotificationLifetime.Persistent; Type = NotificationType.Application; Severity = NotificationSeverity.Info; CreationTime = DateTime.Now; }
public async Task <string> SendNofitersAsync( string name, NotificationData data, IEnumerable <UserIdentifier> users = null, Guid?tenantId = null, NotificationSeverity severity = NotificationSeverity.Info) { return(await PublishNofiterAsync(name, data, users, tenantId, severity)); }
/// <summary> /// Creates a new <see cref="NotificationPublishOptions"/>. /// </summary> public NotificationPublishOptions(string notificationName, NotificationData data, Type entityType = null, object entityId = null, NotificationSeverity severity = NotificationSeverity.Info) { NotificationName = notificationName; Data = data; EntityType = entityType; EntityId = entityId; Severity = severity; Severity = NotificationSeverity.Info; }
/// <summary> /// 发送其他链接消息 /// </summary> /// <param name="userId"></param> /// <param name="linkUrl"></param> /// <param name="severity"></param> /// <returns></returns> public async Task SendLinkUrlNotification(long userId, string linkUrl, NotificationSeverity severity = NotificationSeverity.Info) { var userIdentifier = new UserIdentifier((await _userManager.GetUserByIdAsync(userId)).TenantId, userId); await _notificationPublisher.PublishAsync( NotificationNames.LinkUrl, new LinkUrlMessageNotificationData("您有新跳转消息,点击跳转相应工作页面", linkUrl), severity : severity, userIds : new[] { userIdentifier } ); }
public Notification CreateNotification(string message, NotificationSeverity severity, DateTime timestamp) { return(new Notification { Id = _notificationId++, Message = message, NotificationSeverity = severity, Timestamp = timestamp }); }
public bool ConfirmMessageBox(string message, string title = null, NotificationSeverity severity = NotificationSeverity.Warning) { if (NotificationCallback != null) { NotificationCallback?.Invoke(message, title, severity); return(true); } return(ShowAlert(message, title, severity, AlertButton.Yes, AlertButton.No) == AlertButton.Yes); }
private static NotificationMessage ConfigurarMensagem(NotificationSeverity notification, string sumario, string detalhe) { return(new NotificationMessage() { Severity = notification, Summary = sumario, Detail = detalhe, Duration = 4000 }); }
private NotificationMessage Message(NotificationSeverity severity, string summary, string message) { return(new NotificationMessage() { Severity = severity, Summary = summary, Detail = message, Duration = 4000 }); }
public TenantNotificationInfo(int?tenantId, NotificationInfo notification) { TenantId = tenantId; NotificationName = notification.NotificationName; Data = notification.Data; DataTypeName = notification.DataTypeName; EntityTypeName = notification.EntityTypeName; EntityTypeAssemblyQualifiedName = notification.EntityTypeAssemblyQualifiedName; EntityId = notification.EntityId; Severity = notification.Severity; }
/// <summary> /// 发送任务分派消息 /// </summary> /// <param name="userId"></param> /// <param name="taskItemId"></param> /// <param name="severity"></param> /// <returns></returns> public async Task SendAssignmentNotification(long userId, Guid taskItemId, NotificationSeverity severity = NotificationSeverity.Info) { var userIdentifier = new UserIdentifier((await _userManager.GetUserByIdAsync(userId)).TenantId, userId); var message = "您被分派了任务:" + _repositoryTaskItem.Get(taskItemId).Name + "。点击打开任务页面"; await _notificationPublisher.PublishAsync( NotificationNames.AssignTaskItem, new LinkUrlMessageNotificationData(message, MessageLinkUrlsInfo.TaskItemAssignmentPrefix + taskItemId), severity : severity, userIds : new[] { userIdentifier } ); }
public void SendNotification(string message, string title = null, NotificationSeverity severity = NotificationSeverity.Warning) { if (NotificationCallback != null) { // invoke the callback and assume 'Yes' was clicked. Since this is a test-only scenario, assuming yes should be fine. NotificationCallback?.Invoke(message, title, severity); return; } ShowAlert(message, title, severity, AlertButton.Ok); }
public NotificationInfo(Guid id, string notificationName, NotificationData data, string entityTypeName, string entityId, NotificationSeverity severity, DateTime creationTime, Guid?tenantId) { Id = id; NotificationName = notificationName; Data = data; EntityTypeName = entityTypeName; EntityId = entityId; Severity = severity; CreationTime = creationTime; TenantId = tenantId; }
public async Task SendMessageAsync(UserIdentifier[] users, string notificationName, string message, object data, NotificationSeverity severity = NotificationSeverity.Info) { await SendMessageAsync(users, notificationName, new MessageNotificationData(message) { Properties = new Dictionary <string, object>() { { "Data", data } } }, severity); }
public Notification(long id, string name, string dataType, string data, NotificationSeverity severity = NotificationSeverity.Info, Guid?tenantId = null) { NotificationId = id; Severity = severity; NotificationName = name; NotificationData = data; NotificationTypeName = dataType; Type = NotificationType.Application; TenantId = tenantId; }
public void OutputValidatorResult(IValidatorRunEntry validatorRunEntry) { NotificationSeverity severity = NotificationSeverity.Unknown; string description = string.Empty; string module = string.Join(".", validatorRunEntry.FilterSequence); string action = string.Join(".", validatorRunEntry.Result.FilterSequence); switch (validatorRunEntry.Result.ResultCode) { case ValidatorResultCode.Warning: { severity = NotificationSeverity.Warn; description = ValidatorDescriptionBuilder.BuildWarningDescription(validatorRunEntry); break; } case ValidatorResultCode.Error: { severity = NotificationSeverity.Error; description = ValidatorDescriptionBuilder.BuildErrorDescription(validatorRunEntry); break; } case ValidatorResultCode.Fatal: { severity = NotificationSeverity.Critical; description = ValidatorDescriptionBuilder.BuildFatalDescription(validatorRunEntry); break; } default: { severity = NotificationSeverity.Info; description = ValidatorDescriptionBuilder.BuildSuccessDescription(validatorRunEntry); break; } } var notification = new NotificationMessage() { ApplicationId = "ValidationServer", NotificationTitle = string.Format("{0} Validation Results", validatorRunEntry.Result.ValidatorId), PhysicalSource = Environment.MachineName, UserId = WindowsIdentity.GetCurrent().Name, Severity = severity, Action = action, Module = module, Description = description } as INotificationMessage; _publishEndpoint.Publish(notification); }
public Notification(Guid id, string notificationName, NotificationData data, string entityTypeName, string entityId, NotificationSeverity severity, DateTime creationTime, Guid?tenantId) { Id = id; NotificationName = notificationName; Data = JsonSerializer.Serialize(data); DataTypeName = data?.GetType().AssemblyQualifiedName; EntityTypeName = entityTypeName; EntityId = entityId; Severity = severity; CreationTime = creationTime; TenantId = tenantId; }
public static AlertRaised Create(string title, string msg, AlertType type, NotificationSeverity severity, string key = null, INotificationDetails details = null) { return(new AlertRaised { IsPersistent = true, Title = title, Message = msg, AlertType = type, Severity = severity, Key = key, Details = details }); }
public async Task <Notification> ScheduleNotificationAsync(string message, NotificationSeverity severity) { var notification = await _context .Notifications .AddAsync(new Notification { Message = message, Severity = severity }); await _context.SaveChangesAsync(); return(notification.Entity); }
public static void Log(NotificationSeverity severity, [NotNull] string text, Exception exception = null) { var textWriter = Console.Out; if (severity == NotificationSeverity.Error) { textWriter = Console.Error; } var description = severity + " on " +Environment.MachineName+": "+ text; if (exception != null) { description += Environment.NewLine + exception; } textWriter.WriteLine(description); }
public virtual async Task PublishAsync( string notificationName, NotificationData data = null, EntityIdentifier entityIdentifier = null, NotificationSeverity severity = NotificationSeverity.Info, long[] userIds = null, long[] excludedUserIds = null, int?[] tenantIds = null) { if (notificationName.IsNullOrEmpty()) { throw new ArgumentException("NotificationName can not be null or whitespace!", "notificationName"); } if (!tenantIds.IsNullOrEmpty() && !userIds.IsNullOrEmpty()) { throw new ArgumentException("tenantIds can be set only userIds is not set!", "tenantIds"); } if (tenantIds.IsNullOrEmpty() && userIds.IsNullOrEmpty()) { tenantIds = new[] {AbpSession.TenantId}; } var notificationInfo = new NotificationInfo { NotificationName = notificationName, EntityTypeName = entityIdentifier == null ? null : entityIdentifier.Type.FullName, EntityTypeAssemblyQualifiedName = entityIdentifier == null ? null : entityIdentifier.Type.AssemblyQualifiedName, EntityId = entityIdentifier == null ? null : entityIdentifier.Id.ToJsonString(), Severity = severity, UserIds = userIds.IsNullOrEmpty() ? null : userIds.JoinAsString(","), ExcludedUserIds = excludedUserIds.IsNullOrEmpty() ? null : excludedUserIds.JoinAsString(","), TenantIds = tenantIds.IsNullOrEmpty() ? null : tenantIds.JoinAsString(","), Data = data == null ? null : data.ToJsonString(), DataTypeName = data == null ? null : data.GetType().AssemblyQualifiedName }; await _store.InsertNotificationAsync(notificationInfo); await CurrentUnitOfWork.SaveChangesAsync(); //To get Id of the notification await _backgroundJobManager.EnqueueAsync<NotificationDistributionJob, NotificationDistributionJobArgs>( new NotificationDistributionJobArgs( notificationInfo.Id ) ); }
public void SendNotification( string message, string title = null, NotificationSeverity severity = NotificationSeverity.Warning) { var callback = NotificationCallback; if (callback != null) { // invoke the callback callback(message, title, severity); } else { var image = SeverityToImage(severity); MessageBox.Show(message, title, MessageBoxButton.OK, image); } }
public bool ConfirmMessageBox( string message, string title = null, NotificationSeverity severity = NotificationSeverity.Warning) { var callback = NotificationCallback; if (callback != null) { // invoke the callback and assume 'Yes' was clicked. Since this is a test-only scenario, assuming yes should be fine. callback(message, title, severity); return true; } else { var image = SeverityToImage(severity); return MessageBox.Show(message, title, MessageBoxButton.YesNo, image) == MessageBoxResult.Yes; } }
private static MessageBoxImage SeverityToImage(NotificationSeverity severity) { MessageBoxImage result; switch (severity) { case NotificationSeverity.Information: result = MessageBoxImage.Information; break; case NotificationSeverity.Warning: result = MessageBoxImage.Warning; break; default: // Error result = MessageBoxImage.Error; break; } return result; }
public void SendNotification( string message, string title = null, NotificationSeverity severity = NotificationSeverity.Warning) { if (NotificationCallback != null) { // invoke the callback NotificationCallback(message, title, severity); } else { _uiShellService.EnableModeless(0); try { var icon = SeverityToIcon(severity); int dialogResult; _uiShellService.ShowMessageBox( dwCompRole: 0, // unused, as per MSDN documentation rclsidComp: Guid.Empty, // unused pszTitle: null, // use a null title since the title just becomes another line in the regular message pszText: message, pszHelpFile: null, dwHelpContextID: 0, // required to be 0, as per MSDN documentation msgbtn: OLEMSGBUTTON.OLEMSGBUTTON_OK, msgdefbtn: OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, msgicon: icon, fSysAlert: 0, // Not system modal pnResult: out dialogResult); } finally { // if ShowMessageBox() throws we need to ensure that the UI isn't forever stuck in a modal state _uiShellService.EnableModeless(1); } } }
/// <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 static OLEMSGICON SeverityToIcon(NotificationSeverity severity) { OLEMSGICON result; switch (severity) { case NotificationSeverity.Information: result = OLEMSGICON.OLEMSGICON_INFO; break; case NotificationSeverity.Warning: result = OLEMSGICON.OLEMSGICON_WARNING; break; default: // Error result = OLEMSGICON.OLEMSGICON_CRITICAL; break; } return result; }
public bool ConfirmMessageBox(string message, string title = null, NotificationSeverity severity = NotificationSeverity.Warning) { _uiShellService.EnableModeless(0); try { var icon = SeverityToIcon(severity); _uiShellService.ShowMessageBox( dwCompRole: 0, // unused, as per MSDN documentation rclsidComp: Guid.Empty, // unused pszTitle: null, // use a null title since the title just becomes another line in the regular message pszText: message, pszHelpFile: null, dwHelpContextID: 0, // required to be 0, as per MSDN documentation msgbtn: OLEMSGBUTTON.OLEMSGBUTTON_YESNO, msgdefbtn: OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, msgicon: icon, fSysAlert: 0, // Not system modal pnResult: out var dialogResult); // The dialogResult is 6 when the Yes button is clicked. return dialogResult == 6; } finally { // if ShowMessageBox() throws we need to ensure that the UI isn't forever stuck in a modal state _uiShellService.EnableModeless(1); } }