public void SendDataToClients()
 {
     foreach (var client in subscriptionService.GetClients())
     {
         subscriptionService.GetClients()[client.Key].TestCallback(new List <string>()
         {
             "List1", "List2", "List3"
         });
     }
 }
Beispiel #2
0
        internal string JoinRoom(Connection initiator, Connection joined, bool withoutAllowanceCheck, bool broadCast)
        {
            if (initiator != null && joined != null)
            {
                bool f;
                lock (_room.AllowedUsers)
                    f = !withoutAllowanceCheck && _room.Moderator != initiator.User &&
                        !_room.AllowedUsers.Contains(joined.User);
                if (f)
                {
                    lock (_room.DeniedUsers)
                    {
                        if (_room.DeniedUsers.Contains(joined.User))
                        {
                            return(Resources.AccessDenied);
                        }
                    }
                    if (!_room.IsPublic)
                    {
                        return(Resources.PrivateRoomAllowedUsersOnly);
                    }

                    if (!_room.IsAutoAccepted)
                    {
                        lock (_userStatuses)
                            if (_userStatuses.ContainsKey(joined.User) &&
                                _userStatuses[joined.User] == ChatUser4RoomStatus.WaitingModeratorApproveToJoin)
                            {
                                return(WcfDomain.Contracts.Chats.Resources.ApprovalNeeded);
                            }

                        if (_room.Moderator == null)
                        {
                            return(Resources.ModeratorNull);
                        }

                        List <Connection> moderatorClients = _mainService.Broadcast(_room.Moderator);
                        bool moderatorNotified             = false;
                        moderatorClients.ForEach(a =>
                        {
                            try
                            {
                                a.BroadcastChannel <T>()
                                .ChatJoinReceived(Initiator.User,
                                                  JoinType.ApproveNeeded,
                                                  _room.Name);
                                moderatorNotified = true;
                            }
                            catch (SystemException)
                            {
                                _mainService.PuntUser(a, "bad connection");
                            }
                        });
                        if (!moderatorNotified)
                        {
                            return(Resources.UserNotConnected);
                        }

                        lock (_userStatuses)
                            _userStatuses[joined.User] = ChatUser4RoomStatus.WaitingModeratorApproveToJoin;
                        return(WcfDomain.Contracts.Chats.Resources.ApprovalNeeded);
                    }
                }

                lock (_room.ActiveClients)
                {
                    if (_room.ActiveClients.Contains(joined))
                    {
                        return(string.Format(Resources.ChatUserAlreadyJoined, joined, _room));
                    }
                    _room.ActiveClients.Add(joined);
                }

                if (broadCast)
                {
                    _mainService.GetClients(_room.ActiveUsersWithModerator, false)
                    .ForEach(a =>
                    {
                        try
                        {
                            a.BroadcastChannel <T>().ChatUserJoined(joined,
                                                                    (ChatRoom)
                                                                    ComplexMonitor.CopyFrom(_room));
                        }
                        catch (SystemException)
                        {
                            _mainService.PuntUser(a, "bad connection");
                        }
                    });
                }
            }
            else
            {
                return(string.Format("Initiator or joiner to room {0} was not determined", _room));
            }

            return(null);
        }