Exemplo n.º 1
0
        public static void SendStatusNotification(string userId, string title, string message, NotificationType notifyType)
        {
            //
            // TODO
            //

            var context        = GlobalHost.ConnectionManager.GetHubContext <NotifyHub>();
            var connectionRepo = new ConnectionsRepository();

            string json = System.Web.Helpers.Json.Encode(new
            {
                title   = title,
                message = message,
                type    = notifyType,
            });


            // Calls method on client side to show notification
            //context.Clients.All.addNotification(json);

            var userConnections = connectionRepo.GetConnectionsByUserId(userId);

            foreach (var connId in userConnections)
            {
                // Calls method on client side to show notification
                context.Clients.Client(connId.RowKey).addNotification(json);
            }
        }
Exemplo n.º 2
0
        public void SendNotification()
        {
            var name = Context.User.Identity.Name;

            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            //
            // Azure table storage repositories
            //
            var connRepository = new ConnectionsRepository();
            var notifyRepo     = new NotificationsRepository();

            if (!notifyRepo.Init())
            {
                return;
            }
            if (!connRepository.Init())
            {
                return;
            }

            var connections   = connRepository.GetConnectionsByUserId(name).ToList();
            var notifications = notifyRepo.GetNotificationsByUserId(name).ToList();

            notifications.Sort();

            if (connections.Count > 0 && notifications.Count > 0)
            {
                // Send notification(s) to each user connection.
                foreach (var connection in connections)
                {
                    foreach (var notification in notifications)
                    {
                        string json = System.Web.Helpers.Json.Encode(new
                        {
                            title          = notification.Title,
                            message        = notification.Message,
                            url            = string.IsNullOrEmpty(notification.Url) ? string.Empty : notification.Url,
                            linkText       = string.IsNullOrEmpty(notification.LinkText) ? string.Empty : notification.LinkText,
                            type           = (int)notification.NotifyTypeInt,
                            notificationId = notification.RowKey
                        });

                        // Calls method on client side to show notification
                        Clients.Client(connection.RowKey).addNotification(json);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void RemoveOldUserConnections(string who, int daysOld, ConnectionsRepository repo)
        {
            if (!repo.Init())
            {
                return;
            }

            var connections = repo.GetConnectionsByUserId(who).ToList();

            var timeSpan = TimeSpan.FromDays(daysOld);

            var dateTimeOffset = DateTime.Now.Subtract(timeSpan);

            foreach (var connection in connections)
            {
                // Remove connection if older that 'daysOld'
                if (connection.ConnectionTimeStamp <= dateTimeOffset)
                {
                    RemoveConnection(connection.PartitionKey, connection.RowKey, repo);
                }
            }
        }