Exemple #1
0
        /// <summary>
        /// Установка контента
        /// </summary>
        /// <param name="profile">Окно</param>
        /// <param name="person">Профиль пользователя</param>
        public static void SetPanels(Profile profile, Person person)
        {
            profile.Dispatcher.Invoke(new ThreadStart(async() =>
            {
                OperationServer.SendMsgClient(256, 2004, person.login, Person.thisUser.login);

                try
                {
                    profile.imageRec.Fill = new ImageBrush(new BitmapImage(new Uri(person.image, UriKind.Absolute)));
                }
                catch { profile.imageRec.Fill = new ImageBrush(new BitmapImage(new Uri("https://api.icons8.com/download/bc2e75add07ff32fbbe55b371c9f3a03ee46846a/windows8/PNG/512/Users/user_male-512.png", UriKind.Absolute))); }

                profile.loginUser.Content     = person.login;
                profile.fioUser.Text          = person.lastname + " " + person.name;
                profile.emailUser.Text        = person.email;
                profile.levelUser.Content     = $"Ур : {person.level}";
                profile.noteUser.Text         = person.note;
                profile.countProject.Content  = $"Количество проектов : {person.countProject}";
                profile.countLikeUser.Content = person.likes;
                profile.countSub.Content      = $"Количество подписчиков : {person.countSub}";

                await PersonalArea.SetStatisticPublicUser(profile.statisticPublic, person);
                SetProjectList(profile, person.listProject);
            }));
        }
        private bool changeInfoUser = false;    // Проверка на изменение данных пользователя;

        public PersonalArea()
        {
            InitializeComponent();

            thisWindow = this;
        }
Exemple #3
0
        }                                                  // Файл, который скачивается из сервера;

        /// <summary>
        /// Получение ответа от сервера
        /// </summary>
        /// <param name="soketClient">Сокет клиента</param>
        private static void GettingAnswerServer(object soketClient)
        {
            Socket soket = (Socket)soketClient;

            MemoryStream ms     = new MemoryStream(new byte[2048], 0, 2048, true, true);
            BinaryReader reader = new BinaryReader(ms);

            try
            {
                while (true)
                {
                    // Если файл пользователь отправлял файл, продолжить отправку файла в другом окне;
                    if (fileSend != null)
                    {
                        ContinueSendFile(ref fileSend.bytesSend);
                    }

                    soket.Receive(ms.GetBuffer());
                    ms.Position = 0;

                    int idOperation = reader.ReadInt32();
                    switch (idOperation)
                    {
                    case 1:
                        #region Проверка данных на валидность (Connect 1)

                        switch (reader.ReadBoolean())
                        {
                        case true:
                            Authorization.GoToPersonalArea();
                            break;

                        case false:
                            Authorization.thisWindow.Dispatcher.BeginInvoke(new ThreadStart(() => {
                                Authorization.thisWindow.signIn.IsEnabled = true;
                                MessageBox.Show("Неверный логин или пароль!");
                            }));
                            break;
                        }
                        #endregion
                        break;

                    case 2:
                        #region Проверка на повторяющийся логин (CheckDataUser 2)

                        switch (reader.ReadBoolean())
                        {
                        case true:
                            MessageBox.Show("Регистрация прошла успешно!");
                            Authorization.CreateNewPerson();
                            break;

                        case false:
                            MessageBox.Show("Такой логин\\email уже существует!");
                            break;
                        }
                        #endregion
                        break;

                    case 3:
                        #region Получение ответа от сервера насчёт данных о данном пользователе (CheckFullInfoOfPerson 3)

                        if (reader.ReadBoolean())
                        {
                            Person.thisUser.name         = reader.ReadString();
                            Person.thisUser.lastname     = reader.ReadString();
                            Person.thisUser.level        = reader.ReadInt32();
                            Person.thisUser.likes        = reader.ReadInt32();
                            Person.thisUser.image        = reader.ReadString();
                            Person.thisUser.email        = reader.ReadString();
                            Person.thisUser.countProject = Int32.Parse(reader.ReadString());
                            Person.thisUser.note         = reader.ReadString();
                            Person.thisUser.countSub     = Int32.Parse(reader.ReadString());

                            PersonalArea.SetPersonalInfo();
                        }
                        else
                        {
                            Profile.profileUser.name         = reader.ReadString();
                            Profile.profileUser.lastname     = reader.ReadString();
                            Profile.profileUser.level        = reader.ReadInt32();
                            Profile.profileUser.likes        = reader.ReadInt32();
                            Profile.profileUser.image        = reader.ReadString();
                            Profile.profileUser.email        = reader.ReadString();
                            Profile.profileUser.countProject = Int32.Parse(reader.ReadString());
                            Profile.profileUser.note         = reader.ReadString();
                            Profile.profileUser.countSub     = Int32.Parse(reader.ReadString());

                            Profile.SetPanels(Profile.thisWindow, Profile.profileUser);
                        }
                        #endregion
                        break;

                    case 4:
                        #region Проверка на наличие введенной почты в базе (CheckUnique 4)
                        SendMailPass.thisWindow.ShowPanelCode(!reader.ReadBoolean());
                        #endregion
                        break;

                    case 5:
                        #region Получение в изменении количества лайков на профиле пользователя от сервера

                        MessageBox.Show("321");

                        #endregion
                        break;

                    case 6:
                        #region Получение ответ от сервера по поводу отправки кода восстановления;
                        SendMailPass.codeU = reader.ReadInt32();
                        #endregion
                        break;

                    case 7:
                        #region Получение списка с категориями проекта
                        YourProject.thisWindow.Dispatcher.BeginInvoke(new ThreadStart(() => {
                            foreach (string item in reader.ReadString().Split('#').ToList())
                            {
                                YourProject.thisWindow.comboBoxTypeProj.Items.Add(item);
                            }

                            YourProject.thisWindow.comboBoxTypeProj.Items.RemoveAt(YourProject.thisWindow.comboBoxTypeProj.Items.Count - 1);
                            SendMsgClient(256, 9, Person.thisUser.login, (YourProject.thisWindow.listViewProjects.SelectedValue as Project.MyItemProject).nameProject);
                        }));
                        #endregion
                        break;

                    case 8:
                        #region Получение информации о проекте (YouProject)
                        YourProject.thisWindow.Dispatcher.BeginInvoke(new ThreadStart(() =>
                        {
                            string nameProj = reader.ReadString();
                            string dateU    = reader.ReadString();
                            double ratingU  = double.Parse(reader.ReadString().Replace('.', ','));
                            int countVoteU  = Int32.Parse(reader.ReadString());
                            string noteU    = reader.ReadString();
                            string imageU   = reader.ReadString();
                            YourProject.SetInfoForSettingsPanel(YourProject.thisWindow, nameProj, dateU,
                                                                ratingU, countVoteU, noteU, imageU, Int32.Parse(reader.ReadString()));
                            //YourProject.SetInfoForSettingsPanel(YourProject.thisWindow, reader.ReadString(), reader.ReadString(),
                            //        double.Parse(reader.ReadString().Replace('.', ',')), Int32.Parse(reader.ReadString()),
                            //        reader.ReadString(), reader.ReadString(), Int32.Parse(reader.ReadString()));

                            YourProject.thisWindow.settingsPanel.Visibility = Visibility.Visible;
                        }));
                        #endregion
                        break;

                        #region  абота с файлами (1000 - 2000)

                    case 1001:
                        #region Отправка файла серверу

                        if (fileSend != null)
                        {
                            ContinueSendFile(ref fileSend.bytesSend);
                        }

                        #endregion
                        break;

                    case 1002:
                        #region  Получение списка проектов сохраненные на сервере;

                        bool isThisUser = reader.ReadBoolean();

                        int    idProject       = reader.ReadInt32();
                        string name            = reader.ReadString();
                        int    countVote       = reader.ReadInt32();
                        double rating          = reader.ReadDouble();
                        string date            = reader.ReadString();
                        string note            = reader.ReadString();
                        string image           = reader.ReadString();
                        string viewApplication = reader.ReadString();

                        if (isThisUser)
                        {
                            Person.thisUser.listProject.Add(new Project(idProject, name, countVote, rating, date, viewApplication, note, image));
                        }
                        else
                        {
                            Profile.profileUser.listProject.Add(new Project(idProject, name, countVote, rating, date, viewApplication, note, image));
                        }
                        #endregion
                        break;

                    case 1003:
                        #region Получение свойств файла который будет отправлятся от сервера;
                        fileReceiving = new FileSend(reader.ReadInt32(), reader.ReadString());
                        SendMsgClient(16, 1007);

                        YourProject.IsEnabledForm(false);
                        YourProject.SetSettingsPanelLoad(YourProject.thisWindow, fileReceiving.nameFile, false);
                        #endregion
                        break;

                    case 1004:
                        #region Получение пакетов файла;

                        int    countRecByte = reader.ReadInt32();
                        byte[] byteFile     = reader.ReadBytes(countRecByte);

                        ReceivedFile(fileReceiving, byteFile, countRecByte);
                        fileReceiving.bytesSend += countRecByte;

                        ///Отображение прогресса отправки
                        if (YourProject.loadUIPB != null)
                        {
                            double percent = ((double)fileReceiving.bytesSend / fileReceiving.fileByte.Length) * 100;
                            YourProject.SetValueProgressLoad((int)percent, true);
                        }
                        #endregion
                        break;

                    case 1005:
                        #region Создание файла по полученным байтам;
                        string nameFile = $"Project File\\{fileReceiving.nameFile}";
                        File.WriteAllBytes(nameFile, fileReceiving.fileByte);
                        fileReceiving = null;
                        #endregion
                        break;

                    case 1006:
                        #region Добавление проекта в лист;
                        YourProject.thisWindow.Dispatcher.BeginInvoke(new ThreadStart(() =>
                        {
                            YourProject.AddProjectToList(Int32.Parse(reader.ReadString()));
                        }));
                        #endregion
                        break;

                    case 1007:
                        #region Изменение имени у проекта
                        YourProject.thisWindow.Dispatcher.BeginInvoke(new ThreadStart(() =>
                        {
                            YourProject.RenameProject(reader.ReadString());
                        }));
                        #endregion
                        break;
                        #endregion

                        #region Новостная лента(2000-3000)
                    case 2000:
                        #region Поиск людей по введеной строке
                        string loginUser = reader.ReadString();

                        if (!loginUser.Equals("###ThisNull###"))
                        {
                            string imageU       = reader.ReadString();
                            int    level        = Int32.Parse(reader.ReadString());
                            int    countProject = Int32.Parse(reader.ReadString());

                            FeedPublic.listSearchPeople.Add(new Person(loginUser, imageU, level, countProject));
                        }
                        else
                        {
                            FeedPublic.thisWindow.Dispatcher.BeginInvoke(new ThreadStart(() => {
                                FeedPublic.SetFindsPeople(FeedPublic.listSearchPeople);
                            }));
                        }
                        #endregion
                        break;

                    case 2001:
                        #region Получение списока проектов с лучшим рейтингом;
                        loginUser = reader.ReadString();

                        if (!loginUser.Equals("###ThisNull###"))
                        {
                            string nameProj = reader.ReadString();
                            string imageU   = reader.ReadString();
                            double ratingU  = double.Parse(reader.ReadString().Replace('.', ','));
                            string noteU    = reader.ReadString();

                            FeedPublic.listTopProject.Add(new Person(loginUser, new Project(new MyItemProject(nameProj, ratingU), imageU, noteU)));
                        }
                        else
                        {
                            FeedPublic.thisWindow.Dispatcher.BeginInvoke(new ThreadStart(() => {
                                FeedPublic.SetTopProject(FeedPublic.listTopProject);
                                SendMsgClient(128, 2002, Person.thisUser.login);
                            }));
                        }
                        #endregion
                        break;

                    case 2002:
                        #region Получение рандомных людей;
                        loginUser = reader.ReadString();

                        if (!loginUser.Equals("###ThisNull###"))
                        {
                            int    level  = Int32.Parse(reader.ReadString());
                            string imageU = reader.ReadString();

                            FeedPublic.listInterestingPeople.Add(new Person(loginUser, imageU, level, -1));
                        }
                        else
                        {
                            FeedPublic.thisWindow.Dispatcher.BeginInvoke(new ThreadStart(() => {
                                FeedPublic.PanelRandomPeople(FeedPublic.listInterestingPeople);
                            }));
                        }
                        #endregion
                        break;
                        #endregion

                    case 2003:
                        #region Провка на подпику у профиля другого пользователя;
                        Profile.thisWindow.Dispatcher.BeginInvoke(new ThreadStart(() =>
                        {
                            int a = reader.ReadInt32();
                            Profile.IsSubscribe(Profile.thisWindow.subButton, (a == 1) ? false : true);
                        }));
                        #endregion
                        break;
                    }

                    if (!soket.Connected)
                    {
                        break;
                    }
                }
            }
            //catch(Exception ex)
            //{
            //    MessageBox.Show("GettingAnswerServer  :  " + ex.Message);

            //    try
            //    {
            //        Application.Current.Dispatcher.Invoke(new ThreadStart(()=>
            //        {
            //            Application.Current.Shutdown();

            //        }));
            //    }
            //    catch { }
            //}
            finally
            {
                Thread.CurrentThread.Abort();
                soket.Close();
            }
        }