Beispiel #1
0
        public void JoinChat(int chatId, int profileId, string clientId)
        {
            object           callbackObj = OperationContext.Current.GetCallbackChannel <IMessageCallBack>();
            IMessageCallBack callback    = (IMessageCallBack)callbackObj;

            if (chatController.JoinChat(chatId, profileId, callbackObj, clientId))
            {
                Chat chat = chatController.FindChat(chatId);
                List <Tuple <object, int, string> > callbacks = new List <Tuple <object, int, string> >();
                List <Profile> profiles = new List <Profile>();
                foreach (var tuple in chat.Users)
                {
                    profiles.Add(tuple.Item1);
                    if (tuple.Item2 != null)
                    {
                        callbacks.Add(new Tuple <object, int, string>(tuple.Item2, tuple.Item1.ProfileID, tuple.Item3));
                    }
                }
                callback.GetChat(chat, clientId);
                callback.GetMessages(messageController.GetMessages(chatId), clientId);
                callback.GetOnlineProfiles(profiles, clientId);
                callback.Show(true, clientId);

                foreach (Tuple <object, int, string> messageCallBack in callbacks)
                {
                    try
                    {
                        callback = (IMessageCallBack)messageCallBack.Item1;
                        callback.GetOnlineProfiles(profiles, clientId);
                    }
                    catch (Exception)
                    {
                        chatController.LeaveChat(chatId, messageCallBack.Item2);
                    }
                }
            }
            else
            {
                callback.Show(false, clientId);
            }
        }