示例#1
0
        internal static async Task SendMessagesAsync1()
        {
            var notifications = new DataAccess(Startup.ConnectionString).getNotifications();

            if (notifications != null)
            {
                var messages = from m in notifications orderby m.MessageId descending select m;
                var messagesForNotification = messages.Take(10);
                List <MichaeNotificationPayload> michaeNotifications = new List <MichaeNotificationPayload>();
                foreach (var item in messagesForNotification)
                {
                    var notification = new MichaeNotificationPayload()
                    {
                        MessageId    = item.MessageId,
                        UserId       = (int)item.UserId,
                        EmptyMessage = item.EmptyMessage,
                        Message      = item.Message,
                        Target       = item.Target,
                        Processed    = (int)item.Processed,
                        DateAdded    = item.Date.Value.ToLocalTime().TimeAgo()
                    };
                    michaeNotifications.Add(notification);
                    //michaeNotifications.Add(new MichaeNotification()
                    //{
                    //    Channel = item.UserId.ToString(),
                    //    michaeNotificationPayload = new MichaeNotificationPayload()
                    //    {
                    //        MessageId = item.MessageId,
                    //        UserId = (int)item.UserId,
                    //        EmptyMessage = item.EmptyMessage,
                    //        Message = item.Message,
                    //        Target = item.Target,
                    //        Processed = (int)item.Processed,
                    //        DateAdded = item.Date.Value.ToLocalTime().TimeAgo()
                    //    }
                    //});
                }

                int totalUnreadNotification = messages.Count();
                MichaeNotificationBase michaeNotificationBase = new MichaeNotificationBase()
                {
                    Count = totalUnreadNotification, MichaeNotificationPayloads = michaeNotifications
                };

                if (totalUnreadNotification > 0)
                {
                    //await publishNotificationsAsync(michaeNotificationBase);
                }
            }
        }
示例#2
0
        internal static async Task SendMessagesAsync()
        {
            var notifications = new DataAccess(Startup.ConnectionString).getNotifications();

            if (notifications != null)
            {
                Dictionary <string, List <MichaeNotificationPayload> > userNotification = new Dictionary <string, List <MichaeNotificationPayload> >();


                var messages = from m in notifications orderby m.MessageId descending select m;
                //var messagesForNotification = messages.Take(10);
                List <MichaeNotificationPayload> michaeNotifications = new List <MichaeNotificationPayload>();
                foreach (var item in messages)
                {
                    var notification = new MichaeNotificationPayload()
                    {
                        MessageId    = item.MessageId,
                        UserId       = (int)item.UserId,
                        EmptyMessage = item.EmptyMessage,
                        Message      = item.Message,
                        Target       = item.Target,
                        Processed    = (int)item.Processed,
                        DateAdded    = item.Date.Value.ToLocalTime().TimeAgo()
                    };
                    //michaeNotifications.Add(notification);
                    if (userNotification.Keys.Where(x => x == notification.UserId.ToString()).Count() <= 0)
                    {
                        userNotification.Add(notification.UserId.ToString(), new List <MichaeNotificationPayload>()
                        {
                            notification
                        });
                    }
                    else
                    {
                        userNotification[notification.UserId.ToString()].Add(notification);
                    }
                }

                int totalUnreadNotification = messages.Count();
                //MichaeNotificationBase michaeNotificationBase = new MichaeNotificationBase() { Count = totalUnreadNotification, MichaeNotificationPayloads = michaeNotifications };

                if (userNotification.Count > 0)
                {
                    await publishNotificationsAsync(userNotification);
                }
            }
        }