private static void BroadcastMessagesFunc(Repositories.IMessangerRepository repository, IDependencyResolver resolver)
        {
            var connectionManager = resolver.Resolve<IConnectionManager>();
            var hubContext = connectionManager.GetHubContext<Hubs.MessangerHub>();

            var allGrpMsgs = (from msg in repository.GetAllNewMessges().ToList()
                              from item in msg.UsersWhoRead.DefaultIfEmpty()
                              let usr = item
                              let grp = msg.Group
                              where usr == null
                              select new { UsersWereRead = usr, Msg = msg, Group = grp } into tuple
                              group tuple by tuple.Group into g
                              select new
                              {
                                  Group = g.Key,
                                  Messages = g.Select(m => new ViewModels.MessageViewModel(m.Msg)),
                                  ExcludeUsers = g.Select(u => u.UsersWereRead)
                              }).ToList();

            if (allGrpMsgs == null)
                return;

            var parallelOpt = new System.Threading.Tasks.ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount };
            var result = System.Threading.Tasks.Parallel.ForEach(allGrpMsgs, parallelOpt, grpMsgs =>
                {
                    if (hubContext != null && grpMsgs.Group != null)
                        hubContext.Clients.Group(grpMsgs.Group.Name).
                        broadcastMessages(grpMsgs.Group.Name, grpMsgs.Messages).Wait();
                });

            //old school sending workflow
            //for (int i = 0; i < allGrpMsgs.Count; i++)
            //{
            //	var groupMessages = allGrpMsgs[i];

            //	if (hubContext != null && groupMessages.Group != null)
            //		hubContext.Clients.Group(groupMessages.Group.Name).
            //		broadcastMessages(groupMessages.Group.Name, groupMessages.Messages).Wait();
            //}
        }