private void ShowNotifications(NotificationInfo appNotifications) { var numNotifications = appNotifications.notifications.Count; notificationGroup.alpha = numNotifications > 0 ? 1 : 0; var rectTransform = notificationGroup.GetComponent<RectTransform>(); if (numNotifications < 10) { rectTransform.sizeDelta = new Vector2(16, 16); } else if (numNotifications < 100) { rectTransform.sizeDelta = new Vector2(24, 24); } else if (numNotifications < 1000) { rectTransform.sizeDelta = new Vector2(32, 32); } else { rectTransform.sizeDelta = new Vector2(48, 48); } rectTransform.sizeDelta *= 2; notificationText.text = numNotifications + ""; }
private void FinishNotificationInfo(NotificationInfo info) { lock (this) { try { _notificationStack.Remove(info); if(_notificationStack.Count == 0) ProgressActive = false; } catch { } } }
/// <summary> /// Send a email. /// </summary> /// <remarks></remarks> public static void SendMessage(string viewMessageUrl, DateTime expDate, int portalId, string messsageTo = null, string messageCo = null, string messsageCco = null) { try { var subject = App_GlobalResources.Errors.NotificationSubject; var body = $"{App_GlobalResources.Errors.NotificationBody} {viewMessageUrl} {App_GlobalResources.Errors.NotificationBody2} {expDate.ToLongDateString()}, {expDate.ToShortTimeString()}"; var notificacionInfoAdmins = new NotificationInfo(messsageTo,messageCo, messsageCco, subject, body, portalId); ThreadPool.QueueUserWorkItem(o => SendMail(notificacionInfoAdmins)); } catch (Exception ex) { Exceptions.LogException(ex); } }
private void AddNotificationInfo(NotificationInfo info) { if (!ViewModelBase.IsInDesignModeStatic) { lock (this) { _notificationStack.Add(info); ProgressActive = true; } if (!_isProcessing) { _isProcessing = true; Task.Run(() => ProcessProgress()); } } }
public static void SetSmsData(this NotificationInfo notificationInfo, [NotNull] string text, [NotNull] IDictionary <string, object> properties) { notificationInfo.SetDataValue(NotificationProviderSmsConsts.NotificationInfoTextPropertyName, text); notificationInfo.SetDataValue(NotificationProviderSmsConsts.NotificationInfoPropertiesPropertyName, properties); }
public async Task Add(NotificationInfo notification) { _dbCollection.Add(notification.Id, notification); }
public async Task Update(NotificationInfo notification) { _dbCollection[notification.Id] = notification; }
public virtual Task DeleteNotificationAsync(NotificationInfo notification) { return(_notificationRepository.DeleteAsync(notification)); }
private void WaitForNotifications() { var handles = new WaitHandle[] { notificationHandle, stopEvent.WaitHandle }; while (WaitHandle.WaitAny(handles) == 0) { if (WinSpool.FindNextPrinterChangeNotification(notificationHandle, out var change, IntPtr.Zero, out SafePrinterNotifyInfo pNotifyInfo)) { PrinterNotifyInfo printerNotifyInfo = pNotifyInfo; while ((printerNotifyInfo.Flags & PRINTER_NOTIFY_INFO_DISCARDED) == PRINTER_NOTIFY_INFO_DISCARDED) { pNotifyInfo.Close(); var notifyOptions = new PrinterNotifyOptions { Flags = PRINTER_NOTIFY_OPTIONS_REFRESH }; var nextRet = WinSpool.FindNextPrinterChangeNotification(notificationHandle, out change, notifyOptions, out pNotifyInfo); printerNotifyInfo = pNotifyInfo; if (!nextRet) { break; } } if (SpoolerNotificationReached != null) { var datas = new List <NotificationInfo>(); for (uint i = 0; i < printerNotifyInfo.Count; i++) { var notificationInfo = new NotificationInfo(); notificationInfo.Id = printerNotifyInfo.aData[i].Id; switch (printerNotifyInfo.aData[i].Type) { case NotifyType.Job: notificationInfo.Type = NotifyType.Job; notificationInfo.InfoData = DataFieldParser.GetJobTypeData(printerNotifyInfo.aData[i]); break; case NotifyType.Printer: notificationInfo.Type = NotifyType.Printer; notificationInfo.InfoData = DataFieldParser.GetPrinterTypeData(printerNotifyInfo.aData[i]); break; default: break; } datas.Add(notificationInfo); } var evArgs = new SpoolNotificationEventArgs { PrinterChange = change, NotificationInfos = datas.ToArray() }; SpoolerNotificationReached(this, evArgs); } pNotifyInfo.Close(); } } }
public async Task ModalReportWithCancelation(string message, Func<CancellationToken, Task> operation) { var notificationInfo = new NotificationInfo { Text = message, Progress = -1 }; try { AddNotificationInfo(notificationInfo); CancellationTokenSource cancelationTokenSource = new CancellationTokenSource(); var opTask = operation(cancelationTokenSource.Token); if (await Task.WhenAny(opTask, Task.Delay(2500, cancelationTokenSource.Token)) == opTask) { // task completed within timeout cancelationTokenSource.Cancel(); } else { // timeout logic //show cancel dialog await Task.WhenAny(SnooStreamViewModel.NavigationService.ShowPopup(new OperationCancellationViewModel(message, cancelationTokenSource), null, cancelationTokenSource.Token), opTask); cancelationTokenSource.Cancel(); } } catch (TaskCanceledException) { //_logger.Info("Task Canceled: " + message); } catch (Exception ex) { ProcessFailure(ex, message); } finally { FinishNotificationInfo(notificationInfo); } }
private static void OnScene(SceneView sceneview) { Styles.Init(); if (!texturePlaceholder) { texturePlaceholder = new Texture2D(1, 1); } if (!hasLoadedWebpage) { _notificationInfo = new NotificationInfo(); new Thread(GetNotifications).Start(); hasLoadedWebpage = true; } #if SKS_VR SKSGlobalRenderSettings.SinglePassStereo = PlayerSettings.stereoRenderingPath == StereoRenderingPath.SinglePass; #endif if (Camera.current.name.Equals("SceneCamera")) { sceneCamera = Camera.current; UIBlurController.AddBlurToCamera(sceneCamera); } Handles.BeginGUI(); GUI.skin = skin; //windowRect = new Rect (Screen.width - size.x - 100, Screen.height - size.y - 190, 200, 200); if (SetupUtility.projectInitialized) { if (SKSGlobalRenderSettings.MenuClosed) { Handles.EndGUI(); return; } //Blur Graphics.DrawTexture(new Rect(windowRect.x, windowRect.y - 16, windowRect.width, windowRect.height), texturePlaceholder, Styles.blurMat); //Window Border //Graphics.DrawTexture(new Rect(windowRect.x, windowRect.y - 16, windowRect.width, windowRect.height), // Styles.borderTex, Styles.borderMat); GUI.Window(0, windowRect, DoWindow, "<color=#2599f5>[PKPRO]</color> Notifications:"); GUI.skin = null; Handles.EndGUI(); } else { Graphics.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), texturePlaceholder, Styles.blurMat); if (GUILayout.Button("Click here to re-open the import dialog")) { SettingsWindow.Show(); } #if SKS_DEV if (GUILayout.Button( "(Intended for the devs of the asset) Click here to reset the ScriptableObjects for deployment")) { SKSGlobalRenderSettings.RecursionNumber = 0; SKSGlobalRenderSettings.AggressiveRecursionOptimization = true; SKSGlobalRenderSettings.AdaptiveQuality = true; SKSGlobalRenderSettings.CustomSkybox = true; SKSGlobalRenderSettings.Preview = false; SKSGlobalRenderSettings.PhysicsPassthrough = false; SKSGlobalRenderSettings.PhysStyleB = true; SKSGlobalRenderSettings.Gizmos = true; SKSGlobalRenderSettings.IgnoredNotifications = new List <int>(); SKSGlobalRenderSettings.MenuClosed = false; SKSGlobalRenderSettings.Minimized = false; GlobalPortalSettings.Nagged = false; } #endif } }
protected virtual async Task <List <NotificationMessageDto> > SaveUserNotificationMessagesAsync(NotificationInfo notificationInfo) { var notificationMessages = new List <NotificationMessageDto>(); var tenantIds = GetTenantIds(notificationInfo); foreach (var tenantId in tenantIds) { using (_unitOfWorkManager.Current.SetTenantId(tenantId)) { var tenantNotificationInfo = new TenantNotificationInfo(_guidGenerator.Create(), tenantId, notificationInfo); await _notificationStore.InsertTenantNotificationAsync(tenantNotificationInfo); await _unitOfWorkManager.Current.SaveChangesAsync(); //To get tenantNotification.Id. var tenantNotification = tenantNotificationInfo.ToTenantNotification(); if (tenantNotification.Data is ShaNotificationData shaData) { await _notificationStore.InsertTenantNotificationAsync(tenantNotificationInfo); await _unitOfWorkManager.Current.SaveChangesAsync(); //To get tenantNotification.Id. var notificationMessage = new NotificationMessage { TenantNotification = tenantNotificationInfo, SendType = shaData.SendType, RecipientText = shaData.RecipientText, Status = RefListNotificationStatus.Preparing }; await _messageRepository.InsertAsync(notificationMessage); var notificationMessageDto = ObjectMapper.Map <NotificationMessageDto>(notificationMessage); // save attachments if specified if (shaData.Attachments != null) { foreach (var attachmentDto in shaData.Attachments) { var file = await _storedFileRepository.GetAsync(attachmentDto.StoredFileId); var attachment = new NotificationMessageAttachment { Message = notificationMessage, File = file, FileName = attachmentDto.FileName }; await _attachmentRepository.InsertAsync(attachment); notificationMessageDto.Attachments.Add(ObjectMapper.Map <NotificationAttachmentDto>(attachment)); } } notificationMessages.Add(notificationMessageDto); await CurrentUnitOfWork.SaveChangesAsync(); //To get Ids of the notifications } } } return(notificationMessages); }
public async Task Report(string message, Func<Task> operation) { var notificationInfo = new NotificationInfo { Text = message, Progress = -1 }; try { AddNotificationInfo(notificationInfo); await operation(); } catch (Exception ex) { ProcessFailure(ex, message); } finally { FinishNotificationInfo(notificationInfo); } }
protected virtual async Task <List <UserNotification> > SaveUserNotificationsAsync(UserIdentifier[] users, NotificationInfo notificationInfo) { var userNotifications = new List <UserNotification>(); var tenantGroups = users.GroupBy(user => user.TenantId); foreach (var tenantGroup in tenantGroups) { using (_unitOfWorkManager.Current.SetTenantId(tenantGroup.Key)) { var tenantNotificationInfo = new TenantNotificationInfo(_guidGenerator.Create(), tenantGroup.Key, notificationInfo); await _notificationStore.InsertTenantNotificationAsync(tenantNotificationInfo); await _unitOfWorkManager.Current.SaveChangesAsync(); //To get tenantNotification.Id. var tenantNotification = tenantNotificationInfo.ToTenantNotification(); foreach (var user in tenantGroup) { var userNotification = new UserNotificationInfo(_guidGenerator.Create()) { TenantId = tenantGroup.Key, UserId = user.UserId, TenantNotificationId = tenantNotificationInfo.Id }; await _notificationStore.InsertUserNotificationAsync(userNotification); userNotifications.Add(userNotification.ToUserNotification(tenantNotification)); } await CurrentUnitOfWork.SaveChangesAsync(); //To get Ids of the notifications } } return(userNotifications); }
protected virtual async Task <UserIdentifier[]> GetUsersAsync(NotificationInfo notificationInfo) { List <UserIdentifier> userIds; if (!notificationInfo.UserIds.IsNullOrEmpty()) { //Directly get from UserIds userIds = notificationInfo .UserIds .Split(",") .Select(uidAsStr => UserIdentifier.Parse(uidAsStr)) .Where(uid => SettingManager.GetSettingValueForUser <bool>(NotificationSettingNames.ReceiveNotifications, uid.TenantId, uid.UserId)) .ToList(); } else { //Get subscribed users var tenantIds = GetTenantIds(notificationInfo); List <NotificationSubscriptionInfo> subscriptions; if (tenantIds.IsNullOrEmpty() || (tenantIds.Length == 1 && tenantIds[0] == NotificationInfo.AllTenantIds.To <int>())) { //Get all subscribed users of all tenants subscriptions = await _notificationStore.GetSubscriptionsAsync( notificationInfo.NotificationName, notificationInfo.EntityTypeName, notificationInfo.EntityId ); } else { //Get all subscribed users of specified tenant(s) subscriptions = await _notificationStore.GetSubscriptionsAsync( tenantIds, notificationInfo.NotificationName, notificationInfo.EntityTypeName, notificationInfo.EntityId ); } //Remove invalid subscriptions var invalidSubscriptions = new Dictionary <Guid, NotificationSubscriptionInfo>(); //TODO: Group subscriptions per tenant for potential performance improvement foreach (var subscription in subscriptions) { using (CurrentUnitOfWork.SetTenantId(subscription.TenantId)) { if (!await _notificationDefinitionManager.IsAvailableAsync(notificationInfo.NotificationName, new UserIdentifier(subscription.TenantId, subscription.UserId)) || !SettingManager.GetSettingValueForUser <bool>(NotificationSettingNames.ReceiveNotifications, subscription.TenantId, subscription.UserId)) { invalidSubscriptions[subscription.Id] = subscription; } } } subscriptions.RemoveAll(s => invalidSubscriptions.ContainsKey(s.Id)); //Get user ids userIds = subscriptions .Select(s => new UserIdentifier(s.TenantId, s.UserId)) .ToList(); } if (!notificationInfo.ExcludedUserIds.IsNullOrEmpty()) { //Exclude specified users. var excludedUserIds = notificationInfo .ExcludedUserIds .Split(",") .Select(uidAsStr => UserIdentifier.Parse(uidAsStr)) .ToList(); userIds.RemoveAll(uid => excludedUserIds.Any(euid => euid.Equals(uid))); } return(userIds.ToArray()); }
public async Task <NotificationInfo> GetNotification(int id, SportsType sportsType, NotificationType notificationType) { return(await _sqliteService.SelectAsync <NotificationInfo>( NotificationInfo.BuildPrimaryKey(id, sportsType, notificationType))); }
/// <summary> /// Blocks calling thread and collects notifications. Notifications collecting will continue until /// - count of messages achieves <paramref name="limit"/>. If <paramref name="messageCheck"/> parameter /// is specified, messages will be checked before adding to the list. /// </summary> /// <param name="action">Action which should trigger notification sending</param> /// <param name="timeout">Timeout for waiting</param> /// <param name="limit">Limit of message to receive</param> /// <param name="messageCheck">Filter procedure</param> /// <param name="stop">Semaphore object</param> /// <returns></returns> public Dictionary <Notify, byte[]> CollectNotifications(Action action, int timeout, /* Milliseconds! */ int limit, Func <NotificationMessageHolderType, bool> messageCheck, WaitHandle startProcessing, WaitHandle stop) { Dictionary <Notify, byte[]> notifications = new Dictionary <Notify, byte[]>(); _notifications = new Queue <NotificationInfo>(); Events.NotificationConsumer consumer = new Events.NotificationConsumer(GetNotificationUri()); Action <Exception> errorHandling = new Action <Exception>( (err) => { RaiseDataReceived(consumer.RawData); OnNotifyError(err); } ); consumer.OnError += errorHandling; consumer.OnNotify += OnNotify; NotifyReceived.Reset(); ErrorReceived.Reset(); bool exitByStop = false; try { consumer.Start(); if (action != null) { action(); } RaiseWaitStarted(); int hndl = WaitHandle.WaitAny(new WaitHandle[] { startProcessing }, timeout); if (hndl == WaitHandle.WaitTimeout) { return(notifications); } int total = 0; while (true) { int res = WaitHandle.WaitAny(new WaitHandle[] { NotifyReceived, ErrorReceived, stop }, timeout); if (res == 0) { while (_notifications.Count > 0) { NotificationInfo info = _notifications.Dequeue(); Notify notify = info.Notify; System.Diagnostics.Debug.WriteLine("Process Notify: " + notify.GetHashCode()); RaiseDataReceived(info.RawData); bool add = false; if (notify.NotificationMessage != null) { if (messageCheck == null) { add = true; total += notify.NotificationMessage.Length; } else { foreach (NotificationMessageHolderType message in notify.NotificationMessage) { System.Diagnostics.Debug.WriteLine("Check if message passes the test"); if (messageCheck(message)) { System.Diagnostics.Debug.WriteLine("PASSED!"); add = true; total += 1; } else { System.Diagnostics.Debug.WriteLine("Message filtered out!"); } } } } if (add) { try { System.Diagnostics.Debug.WriteLine("Add Notify object: " + notify.GetHashCode()); notifications.Add(notify, info.RawData); } catch (Exception exc) { System.Diagnostics.Debug.WriteLine("Error when adding notify [" + notify.GetHashCode() + "]"); throw exc; } } if (total >= limit) { System.Diagnostics.Debug.WriteLine(string.Format("All {0} messages received", limit)); break; } } // while notifications.Count > 0 if (total >= limit) { break; // exit from the second cycle } } else if (res == 1) { // error - stop consumer.Stop(); break; } else if (res == 2) { // stop event exitByStop = true; break; } else { break; } } } finally { consumer.OnError -= errorHandling; consumer.OnNotify -= OnNotify; consumer.Stop(); } if (exitByStop) { throw new TestTool.Tests.Definitions.Exceptions.StopEventException(); } return(notifications); }
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) { Guid?notificationId = null; using (var uow = UnitOfWorkManager.Begin(TransactionScopeOption.RequiresNew)) { 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[] { AbpSession.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 uow.CompleteAsync(); //To get Id of the notification notificationId = notificationInfo.Id; } if (notificationId == null) { throw new ShaNotificationSaveFailedException(notificationName, data); } var isShaNotification = data != null && data is ShaNotificationData; if (isShaNotification || userIds != null && userIds.Length <= MaxUserCountToDirectlyDistributeANotification) { await _notificationDistributer.DistributeAsync(notificationId.Value); } else { //We enqueue a background job since distributing may get a long time await _backgroundJobManager.EnqueueAsync <NotificationDistributionJob, NotificationDistributionJobArgs>( new NotificationDistributionJobArgs( notificationId.Value ) ); } }
public async Task ReportWithProgress(string message, Func<Action<int>, Task> operation) { var notificationInfo = new NotificationInfo { Text = message, Progress = 0 }; try { AddNotificationInfo(notificationInfo); await operation((progress) => { notificationInfo.Progress = progress; ReprocessForProgress(); }); } catch (Exception ex) { ProcessFailure(ex, message); } finally { FinishNotificationInfo(notificationInfo); } }
/// <summary> /// Initializes a new instance of the <see cref="UserNotificationInfoWithNotificationInfo"/> class. /// </summary> public UserNotificationInfoWithNotificationInfo(UserNotificationInfo userNotification, NotificationInfo notification) { UserNotification = userNotification; Notification = notification; }
public static async Task MarkNotificationAsRead(this ICommandDispatcher dispatcher, NotificationInfo notification) { await dispatcher.ExecuteAsync(new MarkAsRead { Notification = notification }); }
/// <summary> /// 알림 서버 - 알림 추가 /// </summary> /// <param name="notificationInfo">추가할 알림 정보</param> /// <returns></returns> public Task <string> AddNotification(NotificationInfo notificationInfo) { return(restService.AddNotification(notificationInfo)); }
public NotificationCreatedEvent(NotificationInfo info) { Info = info; }