Example #1
0
        static private List <Friend> GetFriendListFromDB()
        {
            List <Friend> friendsFromDB = new List <Friend>();

            using (var cnn = new SqlConnection(CNN_STRING))
            {
                cnn.Open();

                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandType = CommandType.Text;
                    string cmdTxt = "SELECT [ID],[Name],[BestFriendID] FROM x02Friends";
                    cmd.CommandText = cmdTxt;

                    cmd.ExecuteNonQuery();

                    using (var rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            var frn = new FriendEntity()
                            {
                                ID       = (int)rdr["ID"],
                                Name     = rdr["Name"].ToString(),
                                FriendID = (rdr["BestFriendID"] == DBNull.Value) ? null : (int?)rdr["BestFriendID"]
                            };

                            friendsFromDB.Add(frn);
                        }
                    }
                }
            }

            return(FromFriendEntityListToFriendList(friendsFromDB));
        }
Example #2
0
        public bool Delete(FriendEntity friendEntity)
        {
            _context.Set <FriendEntity>().Remove(friendEntity);
            var result = _context.SaveChanges();

            return(result > 0);
        }
Example #3
0
        //changed here
        async void Handle_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            FriendEntity request        = (FriendEntity)e.Item;
            bool         approveRequest = await DisplayAlert("Friend Request", "Add this person?", "Yes", "No");

            await Rg.Plugins.Popup.Services.PopupNavigation.Instance.PushAsync(
                new LoadingPage());

            if (approveRequest)
            {
                await DisplayAlert(null, "You added this person successfully!", "OK");

                FriendEntity newFriend = await Communications.acceptFriend(request.FriendID);

                //use and parse this string afterwards
                Constants.Friend.Friends.Add(newFriend);
                Constants.mainPage.addNewFriendView(newFriend);
            }
            else
            {
                await DisplayAlert(null, "You denied the friend request.", "OK");
            }
            newFriends.Remove(request);

            FriendRequestsView.ItemsSource = null;
            FriendRequestsView.ItemsSource = newFriends;

            await Communications.DeleteFriendRequest(Constants.me.userid, request.FriendID);

            await Rg.Plugins.Popup.Services.PopupNavigation.Instance.PopAsync();

            //No need request for this one
        }
Example #4
0
        public bool Update(FriendEntity friend)
        {
            _context.Entry(friend).State = EntityState.Modified;
            var result = _context.SaveChanges();

            return(result > 0);
        }
Example #5
0
        public override object parseDataRespone(object result)
        {
            Dictionary <string, object> data = (Dictionary <string, object>)result;
            List <object> list = (List <object>)data[GameConstants.RESPONE_KEY_LIST];

            List <FriendEntity> resultData = new List <FriendEntity>();

            foreach (object obj in list)
            {
                Dictionary <string, object> friend = (Dictionary <string, object>)obj;

                string avt    = Helpers.GetStringNotNull(friend [GameConstants.RESPONE_KEY_AVATAR]);
                string name   = Helpers.GetStringNotNull(friend [GameConstants.RESPONE_KEY_DISPLAYNAME]);
                string userId = Helpers.GetStringNotNull(friend [GameConstants.RESPONE_KEY_USER_ID]);
                string level  = Helpers.GetStringNotNull(friend [GameConstants.RESPONE_KEY_LEVEL]);
                string score  = Helpers.GetStringNotNull(friend [GameConstants.RESPONE_KEY_SCORE]);

                FriendEntity entity = new FriendEntity();
                entity.Avatar = avt;
                entity.Name   = name;
                entity.UserId = userId;
                entity.Level  = int.Parse(level);
                entity.Score  = score;

                resultData.Add(entity);
            }

            return(resultData);
        }
Example #6
0
        public static void ChangeGroupMessage(SocketAsyncEventArgs e)
        {
            MClient        mClient = MClient.CreateInstance();
            AsyncUserToken token   = (AsyncUserToken)e.UserToken;
            //得到一个完整的包的数据,放入新list,第二个参数是数据长度,所以要减去8
            List <byte> onePackage = token.receiveBuffer.GetRange(8, token.packageLen - 8);

            //将复制出来的数据从receiveBuffer旧list中删除
            token.receiveBuffer.RemoveRange(0, token.packageLen);
            //list要先转换成数组,再转换成字符串
            String jsonStr = Encoding.Default.GetString(onePackage.ToArray());
            //得到用户名和密码
            JArray jArray = JArray.Parse(jsonStr);

            //先保存好友信息
            if (jArray[0]["isOk"].ToString().Equals("True"))
            {
                Console.WriteLine("保存好友信息");

                foreach (var obj in jArray)
                {
                    SqliteConnect.SaveFriendInfo(obj["id"].ToString(), obj["Group"].ToString(), obj["UserName"].ToString(), obj["RealName"].ToString(), obj["Sex"].ToString(),
                                                 obj["BirthDay"].ToString(), obj["Address"].ToString(), obj["Email"].ToString(), obj["PhoneNumber"].ToString(),
                                                 obj["Remarks"].ToString());
                }
            }
            //然后删除原分组List中的好友
            Application.Current.Dispatcher.Invoke(
                new Action(() =>
            {
                FriendListViewModel friendListViewModel = FriendListViewModel.CreateInstance();
                FriendEntity.InGroupListDelete(friendListViewModel.friendGroups, jArray[0]["id"].ToString());
            })
                );
        }
 /// <summary>
 /// Update the saved friend details with the new details downloaded
 /// </summary>
 /// <param name="downloadedFriend">The newly downloaded friend object</param>
 /// <param name="existingFriend">The existing friend details stored locally</param>
 private static void UpdateExistingFriendToList(FriendEntity downloadedFriend, FriendEntity existingFriend)
 {
     //update the properties of existing friend
     existingFriend.Birthday          = downloadedFriend.Birthday;
     existingFriend.Name              = downloadedFriend.Name;
     existingFriend.ProfilePictureUrl = downloadedFriend.ProfilePictureUrl;
 }
Example #8
0
 public Penalties(FriendEntity fe)
 {
     InitializeComponent();
     this.fe    = fe;
     this.Title = "Penalties of " + fe.FriendName;
     loadPenalties();
 }
Example #9
0
        //更新好友状态
        public static void FriendStatusMessage(SocketAsyncEventArgs e)
        {
            MClient        mClient = MClient.CreateInstance();
            AsyncUserToken token   = (AsyncUserToken)e.UserToken;
            //得到一个完整的包的数据,放入新list,第二个参数是数据长度,所以要减去8
            List <byte> onePackage = token.receiveBuffer.GetRange(8, token.packageLen - 8);

            //将复制出来的数据从receiveBuffer旧list中删除
            token.receiveBuffer.RemoveRange(0, token.packageLen);
            //list要先转换成数组,再转换成字符串
            String jsonStr = Encoding.Default.GetString(onePackage.ToArray());

            //得到用户名和密码
            Console.WriteLine("jsonStr = " + jsonStr);
            JArray jArray = JArray.Parse(jsonStr);

            foreach (var obj in jArray)
            {
                //修改好友状态
                Application.Current.Dispatcher.Invoke(
                    new Action(() =>
                {
                    FriendListViewModel friendListViewModel = FriendListViewModel.CreateInstance();
                    try
                    {
                        FriendEntity.UpdateFriendStatus(friendListViewModel.friendGroups, obj["id"].ToString(), obj["Group"].ToString(), obj["Status"].ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.Write(ex);
                    }
                })
                    );
            }
        }
Example #10
0
        public Friend Create(string friendEmail, User user)
        {
            var friendEntity = FindByEmail(friendEmail);

            if (friendEntity.id == user.Id)
            {
                throw new WrongFriendException();
            }

            var createFriendEntity = new FriendEntity()
            {
                user_id   = user.Id,
                friend_id = friendEntity.id
            };

            if (this.friendRepository.Create(createFriendEntity) == 0)
            {
                throw new Exception();
            }

            return(new Friend()
            {
                user_id = user.Id,
                friend_id = friendEntity.id,
                Email = friendEmail,
                FirstName = friendEntity.firstname,
                LastName = friendEntity.lastname
            });
        }
Example #11
0
        public static void DeleteFriendMessage(SocketAsyncEventArgs e)
        {
            MClient        mClient = MClient.CreateInstance();
            AsyncUserToken token   = (AsyncUserToken)e.UserToken;
            //得到一个完整的包的数据,放入新list,第二个参数是数据长度,所以要减去8
            List <byte> onePackage = token.receiveBuffer.GetRange(8, token.packageLen - 8);

            //将复制出来的数据从receiveBuffer旧list中删除
            token.receiveBuffer.RemoveRange(0, token.packageLen);
            //list要先转换成数组,再转换成字符串
            String jsonStr = Encoding.Default.GetString(onePackage.ToArray());

            //得到用户名和密码
            Console.WriteLine("jsonStr = " + jsonStr);
            JObject obj = JObject.Parse(jsonStr);

            //先从数据库中删除
            SqliteConnect.DeleteFriendById(obj["Id"].ToString());
            //然后从好友队列中删除
            Application.Current.Dispatcher.Invoke(
                new Action(() =>
            {
                FriendListViewModel friendListViewModel = FriendListViewModel.CreateInstance();
                FriendEntity.InGroupListDelete(friendListViewModel.friendGroups, obj["Id"].ToString());
            })
                );
        }
Example #12
0
        public FriendEntity Add(FriendEntity friend)
        {
            _context.Add(friend);
            _context.SaveChanges();

            return(friend);
        }
Example #13
0
        private async void CheckInbox()
        {
            List <int> friendChanged = await Communications.FriendInbox();

            foreach (int i in friendChanged)
            {
                //update database!!!
                if (i >= 0)
                {
                    FriendEntity fe = await Communications.GetFriendEntity(i);

                    Constants.Friend.Friends.Add(fe);
                    View v = fe.GetView();
                    FriendList.Children.Add(v);
                }
                else
                {
                    foreach (FriendEntity fe in Constants.Friend.Friends)
                    {
                        if (fe.FriendID == i)
                        {
                            Constants.Friend.Friends.Remove(fe);
                            //undone
                        }
                    }
                    //delete friend
                }
            }
        }
Example #14
0
 /// <summary>
 /// 修改或增加好友信息记录XML
 /// </summary>
 /// <param name="FilePath">文件位置</param>
 /// <param name="Friend">好友实体</param>
 /// <param name="CallStyle">调用方式 --"M"修改;"R"读取</param>
 public static void ModifyEntityXMLFile(string FilePath, FriendEntity Friend, string CallStyle)
 {
     if (!File.Exists(FilePath))
     {
         return;
     }
     if (Friend == null)
     {
         return;
     }
     try
     {
         XElement NewEle = XElement.Load(FilePath);
         IEnumerable <XElement> Element = from ele in NewEle.Elements("FriendEntity")
                                          where (string)ele.Attribute("name") == Friend.ComputerName
                                          select ele;
         if (Element.Count() == 1 && CallStyle == "M")//已存在,修改
         {
             //foreach(var ele in Element)
             var ele = Element.First();
             ele.Element("ComputerName").SetValue(Friend.ComputerName);
             ele.Element("IPAdress").SetValue(Friend.IPAdress);
             ele.Element("NickName").SetValue(Friend.NickName);
             ele.Element("TrueName").SetValue(Friend.TrueName);
             ele.Element("Sex").SetValue(Friend.Sex);
             ele.Element("Picture").SetValue(Friend.Picture);
             ele.Element("Department").SetValue(Friend.Department);
             ele.Element("Sigenature").SetValue(Friend.Sigenature);
             NewEle.Save(FilePath);
         }
         else if (Element.Count() > 1 && CallStyle == "M")//存在重复数据
         {
             Element.Remove();
             NewEle.Save(FilePath);
             ModifyEntityXMLFile(FilePath, Friend, CallStyle); //递归增加节点
         }
         else if (Element.Count() == 0)                        //不存在
         {
             XElement AddEle = new XElement("FriendEntity",
                                            new XAttribute("name", Friend.ComputerName),
                                            new XElement("ComputerName", Friend.ComputerName),
                                            new XElement("IPAdress", Friend.IPAdress),
                                            new XElement("NickName", Friend.NickName),
                                            new XElement("TrueName", Friend.TrueName),
                                            new XElement("Sex", Friend.Sex),
                                            new XElement("Picture", Friend.Picture),
                                            new XElement("Department", Friend.Department),
                                            new XElement("Staturs", "在线"),
                                            new XElement("Sigenature", Friend.Sigenature)
                                            );
             NewEle.Add(AddEle);
             NewEle.Save(FilePath);
         }
     }
     catch (Exception ex)
     {
         return;
     }
 }
Example #15
0
 /// <summary>
 /// 把实体类转换成键/值对集合
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="dict"></param>
 private static void GetParameters(FriendEntity entity, Dictionary <string, object> dict)
 {
     dict.Add("ID", entity.ID);
     dict.Add("UserName", entity.UserName);
     dict.Add("FriendName", entity.FriendName);
     dict.Add("AddTime", entity.AddTime);
     dict.Add("GroupID", entity.GroupID);
 }
Example #16
0
        //查询所有好友的详细信息
        public static void QueryFriendInfo(ref ObservableCollection <FriendGroup> friendCollection)
        {            //先获得一个数据库连接
            Console.WriteLine("好友信息查询开始");
            SQLiteConnection sQLiteConnection = SqliteConnect.GetSqliteConnect();

            sQLiteConnection.Open();
            try
            {
                SQLiteCommand qLiteCommand = sQLiteConnection.CreateCommand();


                //先分组,再排序
                qLiteCommand.CommandText = "select * from friendinformation order by friendgroup desc";
                //获得查询结果集
                SQLiteDataReader sqlitreader = qLiteCommand.ExecuteReader();


                //循环改变friendcollection的值
                //保存上一个分组
                FriendGroup  friendgroup = null;
                FriendEntity friendEntity;
                while (sqlitreader.Read())
                {
                    //TODO已经被删除的好友,想办法从分组中删除
                    //如果这个分组与上个分组不一致
                    //还要看分组列表中是不是已经有这个列表了
                    //如果有,就从分组列表中取出这个分组进行操作
                    //还要看分组中是不是已经有好友信息了,如果已经有了,那么只需要进行更新就行

                    //检查分组List中有没有此分组,有这个分组,返回这个分组。没有,则新建分组,返回新建的分组
                    friendgroup = FriendGroup.InGroupListAdd(ref friendCollection, sqlitreader[1].ToString());

                    //检查好友List中有没有此好友,有这个好友,返回这个好友。没有,那么新建好友,返回新建的好友
                    //这个里面还要加一层检测
                    friendEntity = FriendEntity.InGroupAdd(ref friendgroup, sqlitreader[2].ToString());
                    //获得好友信息
                    friendEntity.Id          = sqlitreader[0].ToString();
                    friendEntity.Name        = sqlitreader[2].ToString();
                    friendEntity.RealName    = sqlitreader[3].ToString();
                    friendEntity.Sex         = sqlitreader[4].ToString();
                    friendEntity.BirthDay    = sqlitreader[5].ToString();
                    friendEntity.Address     = sqlitreader[6].ToString();
                    friendEntity.Email       = sqlitreader[7].ToString();
                    friendEntity.PhoneNumber = sqlitreader[8].ToString();
                    friendEntity.Remarks     = sqlitreader[9].ToString();
                }
                sqlitreader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("SaveFriendInfo Error : " + ex);
            }
            sQLiteConnection.Close();
            Console.WriteLine("好友信息查询结束");
        }
Example #17
0
        public ActionResult <FriendDto> PostFriend(CreateFriendRequest request)
        {
            var newFriend = new FriendEntity()
            {
                Name = request.Name
            };

            var Friend = _friendService.CreateFriend(newFriend);

            return(CreatedAtAction("GetFriend", new { id = Friend.Id }, Friend));
        }
Example #18
0
        public IActionResult GetFriendship(string username, string friendUsername)
        {
            FriendEntity friends = _friendService.GetFriendship(username, friendUsername);

            if (friends != null)
            {
                return(Ok(friends));
            }

            return(NoContent());
        }
Example #19
0
 public Task <int> SaveFriendAsync(FriendEntity friend)
 {
     if (friend.FriendID != 0)
     {
         return(database.UpdateAsync(friend));
     }
     else
     {
         return(database.InsertAsync(friend));
     }
 }
Example #20
0
        public VideoApplyFrm(FriendEntity FriendInfo)
        {
            InitializeComponent();
            this.labelControl1.Text = FriendInfo.NickName + " 正在请求视频通话!";
            string PicPath = System.Environment.CurrentDirectory + @"\HeadPicture" + FriendInfo.Picture;

            if (File.Exists(PicPath))
            {
                this.pictureEdit1.Image = Image.FromFile(PicPath);
            }
        }
Example #21
0
        /// <summary>
        /// 通过数据读取器生成实体类
        /// </summary>
        /// <param name="rdr"></param>
        /// <returns></returns>
        private static FriendEntity GetEntityFromrdr(NullableDataReader rdr)
        {
            FriendEntity info = new FriendEntity();

            info.ID         = rdr.GetInt32("ID");
            info.UserName   = rdr.GetString("UserName");
            info.FriendName = rdr.GetString("FriendName");
            info.AddTime    = rdr.GetNullableDateTime("AddTime");
            info.GroupID    = rdr.GetInt32("GroupID");
            return(info);
        }
Example #22
0
 public VideoTalkFrm(FriendEntity friend)
 {
     InitializeComponent();
     InitializeMixing();
     if (friend != null)
     {
         this.FrienInfo  = friend;
         this.FriendIP   = System.Net.IPAddress.Parse(friend.IPAdress);
         this.FriendPort = int.Parse(friend.Poin);
         this.Tag        = friend.IPAdress;
     }
 }
        /// <summary>
        /// Returns a friend based on the close factor
        /// </summary>
        /// <param name="IsClose">"close" if he/she is close or "not close"</param>
        /// <param name="data">the FriendEntity object</param>
        /// <returns>a new FriendEntity with the close factor filled</returns>
        public override FriendEntity GetFriend(string IsClose, FriendEntity data)
        {
            bool check = false;

            if (IsClose.Equals("close"))
            {
                check = true;
            }
            return(new FriendEntity {
                IsClose = check, Username = data.Username
            });
        }
        private void AddAppBarButtons(FriendEntity friendDetails)
        {
            ApplicationBar.Buttons.Clear();
            IsSaveButtonEnabled = false;

            if (friendDetails.TypeOfContact == ContactType.Facebook)
            {
                var postToWallButton = new ApplicationBarIconButton
                {
                    IconUri = new Uri("/Assets/Images/FbButtonIcon_48x48 copy.PNG", UriKind.Relative),
                    Text    = AppResources.PostToWall
                };

                postToWallButton.Click += PostToWallButtonClick;
                ApplicationBar.Buttons.Add(postToWallButton);
            }

            if (!string.IsNullOrEmpty(friendDetails.Email))
            {
                var sendEmailButton = new ApplicationBarIconButton
                {
                    IconUri = new Uri("/Assets/Images/EmailButtonIcon_48x48.png", UriKind.Relative),
                    Text    = AppResources.EmailLabel
                };

                sendEmailButton.Click += SendEmailButtonClick;
                ApplicationBar.Buttons.Add(sendEmailButton);
            }

            if (!string.IsNullOrEmpty(friendDetails.PhoneNumber))
            {
                var callButton = new ApplicationBarIconButton
                {
                    IconUri = new Uri("/Assets/AppBar/feature.phone.png", UriKind.Relative),
                    Text    = AppResources.CallLabel
                };

                callButton.Click += CallButtonClick;
                ApplicationBar.Buttons.Add(callButton);

                var sendMessageButton = new ApplicationBarIconButton
                {
                    IconUri = new Uri("/Assets/AppBar/feature.email.png", UriKind.Relative),
                    Text    = AppResources.MessageLabel
                };

                sendMessageButton.Click += SendMessageButtonClick;
                ApplicationBar.Buttons.Add(sendMessageButton);
            }

            ApplicationBar.IsVisible = ApplicationBar.Buttons.Count > 0;
        }
        public void AddFriend(User user, User friend)
        {
            var entity = new FriendEntity
            {
                user_id   = user.Id,
                friend_id = friend.Id
            };

            if (friendRepo.Create(entity) == 0)
            {
                throw new Exception();
            }
        }
Example #26
0
        public void TestCreateFriend()
        {
            var objTest = new FriendEntity()
            {
                Name = "Name test"
            };

            var result = _friendService.CreateFriend(objTest);

            Assert.NotNull(result);
            Assert.True(result.Id != default);
            Assert.Equal(result.Name, objTest.Name);
        }
        public void FriendsListSizeShouldBeZero()
        {
            // Arrange
            List <FriendEntity> friendsList;
            FriendEntity        expected = null;
            string username = "******";

            // Act
            friendsList = friendService.GetFriendList(username);

            // Assert
            Assert.AreEqual(expected, friendsList);
        }
Example #28
0
        /// <summary>
        /// Updates the details of a particulat friend
        /// </summary>
        /// <param name="friendDetails">The details of the friend to update</param>
        public static void UpdateFriendDetails(FriendEntity friendDetails)
        {
            using (var context = new BirthdayDataContext(Database.DbConnectionString))
            {
                var existingFriend = (from friend in context.Friends
                                      where friend.UniqueId == friendDetails.UniqueId
                                      select friend).FirstOrDefault();

                CopyProperties(existingFriend, friendDetails);
                //considering the scenario where the data should be automatically updated as reference has been updated
                context.SubmitChanges();
            }
        }
Example #29
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param>
        /// <param name="dict">参数的名/值集合</param>
        /// <returns></returns>
        public virtual FriendEntity GetEntity(string strWhere, Dictionary <string, object> dict = null)
        {
            FriendEntity obj    = null;
            string       strSQL = "select top 1 * from Friend where 1=1 " + strWhere;

            using (NullableDataReader reader = _DB.GetDataReader(strSQL, dict))
            {
                if (reader.Read())
                {
                    obj = GetEntityFromrdr(reader);
                }
            }
            return(obj);
        }
Example #30
0
        /// <summary>
        /// 获取实体(异步方式)
        /// </summary>
        /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param>
        /// <param name="dict">参数的名/值集合</param>
        /// <returns></returns>
        public virtual async Task <FriendEntity> GetEntityAsync(string strWhere, Dictionary <string, object> dict = null)
        {
            FriendEntity obj    = null;
            string       strSQL = "select top 1 * from Friend where 1=1 " + strWhere;

            using (NullableDataReader reader = await Task.Run(() => _DB.GetDataReader(strSQL, dict)))
            {
                if (reader.Read())
                {
                    obj = GetEntityFromrdr(reader);
                }
            }
            return(obj);
        }