public string Handling(IProtocol protocol, IChatClient client)
        {
            var ptc    = protocol as DeleteFriendRequestProtocol;
            var toView = new ToViewStringFormat(DateTime.Now, client.GetEndPoint().ToString(), ptc.UserRequest, "request delete friend reationship with [user:"******"]");

            int delete = 0;

            try
            {
                delete = Delete(ptc.UserRequest, ptc.UserDelete);
            }
            catch (Exception ex)
            {
                toView.Message += "error to delete relationship \n detail : " + ex.Message;
                return(toView.ToString());
            }

            IChatClient _client = null;

            if (Instance.OnlineUser.TryGetValue(ptc.UserDelete, out _client))
            {
                var accounts = new List <Account>();
                try
                {
                    accounts = NewListFriend(ptc.UserDelete);
                }
                catch (Exception ex)
                {
                    toView.Message += "error get list friend from db \n deltail : " + ex.Message;
                }
                _client.ResponseGetListFriends(accounts);
            }

            return(toView.ToString());
        }
Ejemplo n.º 2
0
        public string Handling(IProtocol protocol, IChatClient client)
        {
            var ptc    = protocol as GetFriendStreamingRequestProtocol;
            var toView = new ToViewStringFormat(DateTime.Now, client.GetEndPoint().ToString(), ptc.Email, "get list friends are streaming");

            var listFriend = new List <ChatDataModel.Account>();

            try
            {
                listFriend = GetListFriend(ptc.Email);
            }
            catch (Exception ex)
            {
                toView.Message += "error to use db\n detail : " + ex.Message;
            }

            var listFriendStreaming = new List <ChatDataModel.AccountStream>();

            foreach (var item in listFriend)
            {
                lock (this)
                {
                    string value = "";
                    if (Instance.Streaming.TryGetValue(item.Email, out value))
                    {
                        Console.WriteLine(value);
                        listFriendStreaming.Add(new ChatDataModel.AccountStream(item.Name, item.AvatarDriveID, value));
                    }
                }
            }

            client.ResponseListUserStreaming(listFriendStreaming);
            return(toView.ToString());
        }
        public string Handling(IProtocol protocol, IChatClient client)
        {
            var ptc    = protocol as AskBeFriendRequestProtocol;
            var toView = new ToViewStringFormat(DateTime.Now, client.GetEndPoint().ToString(), ptc.SenderEmail, "Send a friend requset to user[" + ptc.ReceiverEmail + "]");


            try
            {
                var request = new FriendResquestNotExcept(ptc.SenderEmail, ptc.ReceiverEmail, DateTime.Now);
                Insert(request);
                toView.Message += "\n insert request successful";
            }
            catch (Exception ex)
            {
                toView.Message += "\n insert request to db Failed \n detail : " + ex.Message;;
                return(toView.ToString());
            }

            IChatClient _client = null;

            if (Instance.OnlineUser.TryGetValue(ptc.ReceiverEmail, out _client))
            {
                _client.ResponseGetListUserRequestAddFriend(ListRequestOfUser(ptc.ReceiverEmail));
                toView.Message += " send friend request successful!";
            }

            var accounts = new List <Account>();

            try
            {
                accounts = GetRequestIAsk(ptc.SenderEmail);
            }
            catch (Exception ex)
            {
                toView.Message += "error get list user from db \n detail : " + ex.Message;
                return(toView.ToString());
            }

            client.ResponseGetListUserIRequestAddFriend(accounts);

            return(toView.ToString());
        }
Ejemplo n.º 4
0
        public string Handling(IProtocol protocol, IChatClient client)
        {
            var ptc      = protocol as LiveStreamRequestProtocol;
            var toView   = new ToViewStringFormat(DateTime.Now, client.GetEndPoint().ToString(), ptc.Email, "request create a stream video");
            var streamID = Guid.NewGuid().ToString();

            client.ResponseStreamID(streamID);
            lock (synclock)
            {
                Instance.Streaming.Add(ptc.Email, streamID);
            }
            return(toView.ToString());
        }
        public string Handling(IProtocol protocol, IChatClient client)
        {
            var ptc    = protocol as AddUsersToGroupRequestProtocol;
            var toView = new ToViewStringFormat(DateTime.Now, client.GetEndPoint().ToString(), "null", "Add user to group " + ptc.GroupId);


            int isSuccess = 0;

            try
            {
                isSuccess      = Insert(ptc.Email, ptc.GroupId);
                toView.Message = "Insert Successful";
            }
            catch (Exception ex)
            {
                toView.Message = "Insert failed \n detail : " + ex.Message;
            }

            client.ResponseAddFriendToGroup(isSuccess, ptc.GroupId);

            if (isSuccess == 1)
            {
                var accounts = GetUserInGroup(ptc.GroupId);
                foreach (var item in accounts)
                {
                    IChatClient _client = null;
                    if (item.Email != ptc.EmailRequest && !Instance.OnlineUser.TryGetValue(item.Email, out client))
                    {
                        _client.ResponseGetUserInGroup(ptc.GroupId, accounts);
                    }
                }
            }
            List <Group> listGroup = new List <Group>();

            try
            {
                listGroup = GetListGroup(ptc.Email);
            }
            catch (Exception)
            {
            }
            IChatClient cl;

            if (Instance.OnlineUser.TryGetValue(ptc.Email, out cl) && listGroup.Count > 0)
            {
                cl.ResponseGetGroups(listGroup);
            }

            return(toView.ToString());
        }