void SetNewUserToList(ListBox lB, ChatInfoDAL.User user)
 {
     lB.Items.Add(user);
 }
 public MessageQueue(ChatInfoDAL.User us, string mess)
 {
     User = us;
     Message = mess;
 }
        void PrimarySend(ChatInfoDAL.User user, Socket socket)
        {
            //byte []code0 = Encoding.UTF8.GetBytes("00");
            //socket.Send(code0);

            //IFormatter formatter0 = new BinaryFormatter();
            //Stream stream0 = new MemoryStream();

            //formatter0.Serialize(stream0, mainEvent);

            //byte[] buffer0 = new byte[1024];
            //stream0.Position = 0;
            //while (stream0.Position < stream0.Length)
            //{
            //    int readCount = stream0.Read(buffer0, 0, 1024);
            //    socket.Send(buffer0, readCount, 0);
            //}
            //stream0.Close();
            //Thread.Sleep(50);

            byte[] code = Encoding.UTF8.GetBytes("02");
            socket.Send(code);

            IFormatter formatter = new BinaryFormatter();
            Stream stream = new MemoryStream();

            formatter.Serialize(stream, UserManager.Users);

            byte[] buffer = new byte[1024];
            stream.Position = 0;
            while (stream.Position < stream.Length)
            {
                int readCount = stream.Read(buffer, 0, 1024);
                socket.Send(buffer, readCount, 0);
            }
            stream.Close();

            Thread.Sleep(50);

            code = Encoding.UTF8.GetBytes("03");
            socket.Send(code);

            IFormatter formatter2 = new BinaryFormatter();
            Stream stream2 = new MemoryStream();

            formatter2.Serialize(stream2, GroupManager.Groups);

            byte[] buffer2 = new byte[1024];
            stream2.Position = 0;
            while (stream2.Position < stream2.Length)
            {
                int readCount = stream2.Read(buffer2, 0, 1024);
                socket.Send(buffer2, readCount, 0);
            }
            stream2.Close();

            Thread.Sleep(50);

            List<Message> messGen = new List<Message>();
            List<int> numOfGroup = new List<int>();
            foreach (MemberOfGroup mem in MemberOfGroupManager.MembersOfGroup)
            {
                if (user.UserID == mem.UserID) numOfGroup.Add(mem.GroupID);
            }
            foreach (Message mes in MessageManager.Messages)
            {
                if (numOfGroup.Contains(mes.GroupID)) messGen.Add(mes);
            }
            code = Encoding.UTF8.GetBytes("04");
            socket.Send(code);

            IFormatter formatter3 = new BinaryFormatter();
            Stream stream3 = new MemoryStream();

            formatter3.Serialize(stream3, messGen);

            byte[] buffer3 = new byte[1024];
            stream3.Position = 0;
            while (stream3.Position < stream3.Length)
            {
                int readCount = stream3.Read(buffer3, 0, 1024);
                socket.Send(buffer3, readCount, 0);
            }
            stream3.Close();

            Thread.Sleep(50);

            code = Encoding.UTF8.GetBytes("05");
            socket.Send(code);

            List<BanPair> bPair = new List<BanPair>();
            foreach (BanPair bP in BanPairManager.BanPairs)
            {
                if (bP.Id1 == user.UserID) { bPair.Add(bP); }
            }
            IFormatter formatter4 = new BinaryFormatter();
            Stream stream4 = new MemoryStream();

            formatter4.Serialize(stream4, bPair);

            byte[] buffer4 = new byte[1024];
            stream4.Position = 0;
            while (stream4.Position < stream4.Length)
            {
                int readCount = stream4.Read(buffer4, 0, 1024);
                socket.Send(buffer4, readCount, 0);
            }
            stream4.Close();

            Thread.Sleep(50);

            code = Encoding.UTF8.GetBytes("06");
            socket.Send(code);

            List<MemberOfGroup> memberOfGroup = new List<MemberOfGroup>();
            foreach (MemberOfGroup mG in MemberOfGroupManager.MembersOfGroup)
            {
                if (mG.UserID == user.UserID) { memberOfGroup.Add(mG); }
            }
            IFormatter formatter5 = new BinaryFormatter();
            Stream stream5 = new MemoryStream();

            formatter5.Serialize(stream5, memberOfGroup);

            byte[] buffer5 = new byte[1024];
            stream5.Position = 0;
            while (stream5.Position < stream5.Length)
            {
                int readCount = stream5.Read(buffer5, 0, 1024);
                socket.Send(buffer5, readCount, 0);
            }
            stream5.Close();

            for (int i = 0; i < messInQueue.Count; i++ )
            {
                if (messInQueue[i].User.UserID == user.UserID)
                {
                    Thread.Sleep(50);

                    code = Encoding.UTF8.GetBytes("07");
                    socket.Send(code);

                    IFormatter formatter6 = new BinaryFormatter();
                    Stream stream6 = new MemoryStream();

                    formatter6.Serialize(stream6, messInQueue[i].Message);

                    byte[] buffer6 = new byte[1024];
                    stream6.Position = 0;
                    while (stream6.Position < stream6.Length)
                    {
                        int readCount = stream6.Read(buffer6, 0, 1024);
                        socket.Send(buffer6, readCount, 0);
                    }
                    stream6.Close();
                    messInQueue.RemoveAt(i);
                    i--;
                }
            }
        }
 public ClaimToGroup(ChatInfoDAL.User us, Group gr)
 {
     User = us;
     Group = gr;
 }