/* The GetFriendList MessageHandler
         * It handles messages of UPDATE_FRIENDSHIP_REQ type.
         */
        private static void UpdateFriendship(RMessage message, TcpClient connection)
        {
            Console.WriteLine("UpdateFriendship");
            FriendshipData friendship = (FriendshipData)message.Data;
            RMessage       replyMessageFormer, replyMessageLatter;

            if (friendship.Status)
            {
                FriendshipConnector.ConfirmFriendship(friendship);
                replyMessageFormer = new RMessage(MessageType.CONFIRM_FRIENDSHIP_REPLY, friendship.Latter);
                replyMessageLatter = new RMessage(MessageType.CONFIRM_FRIENDSHIP_REPLY, friendship.Former);
                UserConnector.UpdateUserRank(friendship.Latter, Ranking.ADD_FRIEND);
                UserConnector.UpdateUserRank(friendship.Former, Ranking.ADD_FRIEND);
            }
            else
            {
                FriendshipConnector.DeleteFriendship(friendship);
                replyMessageFormer = new RMessage(MessageType.DENY_FRIENDSHIP_REPLY, friendship.Latter);
                replyMessageLatter = new RMessage(MessageType.DENY_FRIENDSHIP_REPLY, friendship.Former);
            }
            ClientWorker formerWorker = ServerCore.GetWorkerById(friendship.Former);

            if (formerWorker != null)
            {
                formerWorker.SendMessage(replyMessageFormer);
            }
            ClientWorker latterWorker = ServerCore.GetWorkerById(friendship.Latter);

            if (latterWorker != null)
            {
                latterWorker.SendMessage(replyMessageLatter);
            }
        }
Exemple #2
0
        /// <summary>
        /// 保存friendshipdata数据集数据
        /// </summary>
        /// <param name="friendshipdata">数据集对象</param>
        /// <returns>返回保存后的响应信息</returns>
        public String SaveFriendship(FriendshipData friendshipdata)
        {
            #region
            return(base.Save(friendshipdata, this._friendshipclass));

            #endregion
        }
Exemple #3
0
        /// <summary>
        /// 获取Friendship数据表的全部数据
        /// </summary>
        /// <returns>Json字符串</returns>
        public string GetJsonByAll()
        {
            #region
            int            totalCount     = 0;
            FriendshipData friendshipdata = this.getData(null);
            totalCount = friendshipdata.Tables[0].Rows.Count;
            return(base.GetJson(friendshipdata, totalCount));

            #endregion
        }
Exemple #4
0
        /// <summary>
        /// 根据主键值检索符合该条件的记录,用于编辑和删除记录时。
        /// </summary>
        /// <param name="fid">主键-朋友关系序号</param>
        /// <returns></returns>
        private FriendshipData getData(string fid)
        {
            #region
            FriendshipData friendshipdata      = new FriendshipData();
            DBConditions   querybusinessparams = new DBConditions();
            querybusinessparams.Add(FriendshipData.fid, EnumSqlType.sqlint, EnumCondition.Equal, fid);
            this._friendshipclass.GetSingleTAllWithoutCount(friendshipdata, querybusinessparams);
            return(friendshipdata);

            #endregion
        }
Exemple #5
0
 /// <summary>
 /// 添加Friendship表行数据(如主键为非自增型字段,则自行修改代码)
 /// </summary>
 /// <param name="friendshipdata">数据集对象</param>
 /// <param name="friendship">实体对象</param>
 public void AddRow(ref FriendshipData friendshipdata, EntityFriendship friendship)
 {
     #region
     DataRow dr = friendshipdata.Tables[0].NewRow();
     friendshipdata.Assign(dr, FriendshipData.fid, friendship.fid);
     friendshipdata.Assign(dr, FriendshipData.meId, friendship.meId);
     friendshipdata.Assign(dr, FriendshipData.friendId, friendship.friendId);
     friendshipdata.Assign(dr, FriendshipData.gid, friendship.gid);
     friendshipdata.Assign(dr, FriendshipData.writeTime, friendship.writeTime);
     friendshipdata.Tables[0].Rows.Add(dr);
     #endregion
 }
Exemple #6
0
        public void ResponseFriendRequest(uint id, bool newState)
        {
            // Create a new request
            uint           thisUserId = LoggedInUserModel.Instance.User.Id;
            FriendshipData friendship = model.GetFriendshipById(id);

            if (!(friendship.Status) && (friendship.Latter == thisUserId))
            {
                friendship.Status = newState;
                RMessage msg = new RMessage(MessageType.UPDATE_FRIENDSHIP_REQ, friendship);

                // Handle the request to the service
                Service.Instance.AddMessage(msg);
            }
        }
Exemple #7
0
 /// <summary>
 /// 删除friendshipdata数据集中指定的行数据
 /// </summary>
 /// <param name="friendshipdata">数据集对象</param>
 /// <param name="fid">主键-朋友关系序号</param>
 public void DeleteRow(ref FriendshipData friendshipdata, string fid)
 {
     #region
     if (friendshipdata.Tables[0].Rows.Count <= 0)
     {
         friendshipdata = this.getData(fid);
     }
     DataRow dr = friendshipdata.Tables[0].Rows.Find(new object[1] {
         fid
     });
     if (dr != null)
     {
         dr.Delete();
     }
     #endregion
 }
Exemple #8
0
 /// <summary>
 /// 编辑friendshipdata数据集中指定的行数据
 /// </summary>
 /// <param name="friendshipdata">数据集对象</param>
 /// <param name="friendship">实体对象</param>
 public void EditRow(ref FriendshipData friendshipdata, EntityFriendship friendship)
 {
     #region
     if (friendshipdata.Tables[0].Rows.Count <= 0)
     {
         friendshipdata = this.getData(friendship.fid);
     }
     DataRow dr = friendshipdata.Tables[0].Rows.Find(new object[1] {
         friendship.fid
     });
     friendshipdata.Assign(dr, FriendshipData.fid, friendship.fid);
     friendshipdata.Assign(dr, FriendshipData.meId, friendship.meId);
     friendshipdata.Assign(dr, FriendshipData.friendId, friendship.friendId);
     friendshipdata.Assign(dr, FriendshipData.gid, friendship.gid);
     friendshipdata.Assign(dr, FriendshipData.writeTime, friendship.writeTime);
     #endregion
 }
        /* The GetFriendList MessageHandler
         * It handles messages of ADD_FRIEND_REQ type.
         */
        private static void AddFriend(RMessage message, TcpClient connection)
        {
            Console.WriteLine("AddFriend");
            uint     thisUserId = ServerCore.GetIdByConnection(connection);
            UserData friend     = UserConnector.GetUser((String)message.Data);
            UserData thisUser   = UserConnector.GetUser(thisUserId);

            if (friend == null)
            {
                return;
            }
            if (friend.Id == thisUserId)
            {
                return;
            }
            List <FriendshipData> friendships = FriendshipConnector.GetFriendshipList(thisUserId);

            foreach (FriendshipData friendshipIt in friendships)
            {
                if (friendshipIt.Former == friend.Id || friendshipIt.Latter == friend.Id)
                {
                    return;
                }
            }
            FriendshipData friendship = new FriendshipData(thisUserId, friend.Id, false);

            FriendshipConnector.AddFriendship(friendship);

            ClientWorker formerWorker = ServerCore.GetWorkerById(friendship.Former);
            ClientWorker latterWorker = ServerCore.GetWorkerById(friendship.Latter);

            RMessage replyMessageFormer = new RMessage(MessageType.ADD_FRIEND_REPLY, friend);
            RMessage replyMessageLatter = new RMessage(MessageType.ADD_FRIEND_REPLY, thisUser);
            RMessage replyMessage       = new RMessage(MessageType.ADD_FRIENDSHIP_REPLY, friendship);

            if (formerWorker != null)
            {
                formerWorker.SendMessage(replyMessageFormer);
                formerWorker.SendMessage(replyMessage);
            }
            if (latterWorker != null)
            {
                latterWorker.SendMessage(replyMessageLatter);
                latterWorker.SendMessage(replyMessage);
            }
        }
Exemple #10
0
        /// <summary>
        /// 根据条件筛选所有Friendship指定页码的数据(分页型)
        /// </summary>
        /// <param name="friendship">实体对象</param>
        /// <param name="pageparams">分页对象</param>
        /// <param name="totalCount">符合条件的记录总数量</param>
        /// <returns></returns>
        public FriendshipData GetData(EntityFriendship friendship, PageParams pageparams, out int totalCount)
        {
            #region
            DBConditions querybusinessparams = new DBConditions(pageparams);
            querybusinessparams.Add(FriendshipData.fid, EnumSqlType.sqlint,
                                    EnumCondition.Equal, friendship.fid);
            querybusinessparams.Add(FriendshipData.meId, EnumSqlType.sqlint,
                                    EnumCondition.Equal, friendship.meId);
            querybusinessparams.Add(FriendshipData.friendId, EnumSqlType.sqlint,
                                    EnumCondition.Equal, friendship.friendId);
            querybusinessparams.Add(FriendshipData.gid, EnumSqlType.sqlint,
                                    EnumCondition.Equal, friendship.gid);
            querybusinessparams.Add(FriendshipData.writeTime, EnumSqlType.datetime,
                                    EnumCondition.Equal, friendship.writeTime);
            FriendshipData friendshipdata = new FriendshipData();
            totalCount = this._friendshipclass.GetSingleT(friendshipdata, querybusinessparams);
            return(friendshipdata);

            #endregion
        }
Exemple #11
0
 //-------------------------------------------------------------------------------
 /// <summary>
 /// XElementからFriendShipData型に変換します
 /// </summary>
 /// <returns></returns>
 private FriendshipData ConvertToFriendShipData(XElement el)
 {
     try {
         var fsd = new FriendshipData() {
             UserID = long.Parse(el.Element("id").Value),
             UserName = el.Element("name").Value,
             UserScreenName = el.Element("screen_name").Value,
             Followed = false,
             Following = false
         };
         foreach (var c in el.Elements("connecton")) {
             switch (c.Value) {
                 case "following":
                     fsd.Following = true;
                     break;
                 case "followed_by":
                     fsd.Followed = true;
                     break;
             }
         }
         return fsd;
     }
     catch (NullReferenceException ex) {
         Log.DebugLog(ex);
         Log.DebugLog(el.ToString());
         throw new TwitterAPIException(1001, "予期しないXmlです。");
     }
 }
Exemple #12
0
        private void PutUserOnList(uint thisUserId, int index, UserData user, FriendListModel model, bool friendshipStatus, bool onlineStatus)
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FriendListView));
            PictureBox icon = new PictureBox();

            ((System.ComponentModel.ISupportInitialize)(icon)).BeginInit();
            if (!friendshipStatus)
            {
                icon.Image = global::REACH.Client.Properties.Resources.user_pending;
            }
            else if (onlineStatus)
            {
                icon.Image = global::REACH.Client.Properties.Resources.user_online;
            }
            else
            {
                icon.Image = global::REACH.Client.Properties.Resources.user_offline;
            }
            icon.Location = new Point(lineHeight - 20, index * lineHeight + 2);
            icon.Size     = new Size(20, 20);
            panel1.Controls.Add(icon);

            FriendshipData friendship = model.GetFriendshipById(user.Id);

            if (!(friendship.Status))
            {
                if (friendship.Latter == thisUserId)
                {
                    Button acceptButton = new Button();
                    acceptButton.Text     = "accept";
                    acceptButton.Location = new Point(130, index * lineHeight);
                    acceptButton.Size     = new Size(80, lineHeight);
                    acceptButton.AutoSize = false;
                    acceptButton.Click   += new System.EventHandler(this.OnAccept);
                    acceptButtons.Add(acceptButton, user.Id);
                    panel1.Controls.Add(acceptButton);

                    Button denyButton = new Button();
                    denyButton.Text     = "deny";
                    denyButton.Location = new Point(210, index * lineHeight);
                    denyButton.Size     = new Size(80, lineHeight);
                    denyButton.AutoSize = false;
                    denyButton.Click   += new System.EventHandler(this.OnDeny);
                    denyButtons.Add(denyButton, user.Id);
                    panel1.Controls.Add(denyButton);
                }
            }

            Label friendname = new Label();

            friendname.Text     = user.Username;
            friendname.Location = new Point(30, index * lineHeight);
            friendname.Font     = new Font(
                "Microsoft Sans Serif",
                9.75F,
                FontStyle.Regular,
                GraphicsUnit.Point, ((byte)(0)));
            friendname.AutoSize    = false;
            friendname.Size        = new Size(panel1.Width - 55, lineHeight);
            friendname.Click      += new System.EventHandler(this.OnNameClick);
            friendname.MouseEnter += new System.EventHandler(this.ColorNameLabel);
            friendname.MouseLeave += new System.EventHandler(this.UncolorNameLabel);
            nameLabels.Add(friendname, user.Id);
            panel1.Controls.Add(friendname);
        }
Exemple #13
0
        /*
         * Handlers for external events
         */
        #region external_events

        private void OnFriendListStateChanged(FriendListModel model)
        {
            while (!this.IsHandleCreated)
            {
                ;
            }
            if (this.InvokeRequired)
            {
                this.Invoke((FriendListController.ExternalEventHandler)
                            OnFriendListStateChanged, model);
                return;
            }
            nameLabels.Clear();
            denyButtons.Clear();
            acceptButtons.Clear();
            uint thisUserId = LoggedInUserModel.Instance.User.Id;
            int  index      = 0;

            panel1.Controls.Clear();
            panel1.Focus();
            panel1.SuspendLayout();
            // Online users
            foreach (UserData user in model.Users)
            {
                FriendshipData friendship = model.GetFriendshipById(user.Id);
                if (friendship.Status && user.Status)
                {
                    PutUserOnList(thisUserId, index++, user, model, friendship.Status, user.Status);
                }
            }
            // Offline users
            if (offlineCheckBox.Checked)
            {
                foreach (UserData user in model.Users)
                {
                    FriendshipData friendship = model.GetFriendshipById(user.Id);
                    if (friendship.Status && !user.Status)
                    {
                        PutUserOnList(thisUserId, index++, user, model, friendship.Status, user.Status);
                    }
                }
            }
            // Inviting users
            if (invitingCheckBox.Checked)
            {
                foreach (UserData user in model.Users)
                {
                    FriendshipData friendship = model.GetFriendshipById(user.Id);
                    if (!friendship.Status && friendship.Latter == thisUserId)
                    {
                        PutUserOnList(thisUserId, index++, user, model, friendship.Status, user.Status);
                    }
                }
            }
            // Invited users
            if (invitedCheckBox.Checked)
            {
                foreach (UserData user in model.Users)
                {
                    FriendshipData friendship = model.GetFriendshipById(user.Id);
                    if (!friendship.Status && friendship.Latter != thisUserId)
                    {
                        PutUserOnList(thisUserId, index++, user, model, friendship.Status, user.Status);
                    }
                }
            }
            panel1.ResumeLayout();
            panel1.PerformLayout();
        }