Exemplo n.º 1
0
        public async Task SendSimpleMessageToAll(string groupId, string replyId, dynamic msgObj)
        {
            var id = Context.Request.User.Identity;

            try
            {
                string msgbody = msgObj.body;
                var    msg     = await GroupChatContext.AddUserMessage((new NotificationHub()).HubIdentity, HubIdentity, id.GetUserId(), groupId, replyId, msgbody);

                var cids = (from d in msg.peers select d.ConnectionID).ToArray();
                Clients.Clients(cids).messageReceived(id.Name, msg.msg);
                var nhub = Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext <NotificationHub>();
                if (nhub != null)
                {
                    var ncids = (from d in msg.callbacks where !(from x in msg.peers where x.UserID == d.UserID select x).Any() select d.ConnectionID).ToArray();
                    if (ncids.Length > 0)
                    {
                        nhub.Clients.Clients(ncids).serverNotifications(msg.brief, msg.categ.TypeName);
                    }
                }
            }
            catch (Exception ex)
            {
                Clients.Caller.sendError(ex.Message);
            }
        }