示例#1
0
        public static async Task PushNotification(Notification notification)
        {
            await Task.Run
            (
                () =>
            {
                HashSet <string> connectionIds;

                var connectionIsFound = connections.TryGetValue(notification.User.ToString(), out connectionIds);

                if (connectionIsFound)
                {
                    foreach (var connectionId in connectionIds)
                    {
                        logger.Info("Pushed notification to " + notification.User.ToString() + " on connectionId " + connectionId);
                    }

                    var context = GlobalHost.ConnectionManager.GetHubContext <NotificationsHub>();

                    context.Clients.Clients(connectionIds.ToList())
                    .GetNotification(NotificationInfoStringBuilder.GetSnackString(notification));
                }
            }
            );
        }
示例#2
0
        public async Task <HttpResponseMessage> GetUnseenOfType(HttpRequestMessage request, int type, int skip, int amount)
        {
            try
            {
                var userId = ContextParser.GetUserId(request.GetRequestContext());

                var notifications = await notificationService.GetUnseenOfType(userId, type, skip, amount);

                var result = Mapper.Map <ICollection <NotificationDTO> >(notifications);

                for (var i = 0; i < notifications.Count; i++)
                {
                    result.ElementAt(i).Title = NotificationInfoStringBuilder.GetNotificationTitle(notifications.ElementAt(i));
                }

                return(request.CreateResponse(HttpStatusCode.OK, result));
            }
            catch (Exception ex)
            {
                logger.Error(ex, JsonConvert.SerializeObject(new { type, skip, amount }));

                return(request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }