Ejemplo n.º 1
0
        private void open_Click(object sender, RoutedEventArgs e)
        {
            var fileContent = string.Empty;
            var filePath    = string.Empty;

            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.InitialDirectory = "D:\\";
                openFileDialog.Filter           = "(*.xml)|*.xml";
                openFileDialog.FilterIndex      = 2;
                openFileDialog.RestoreDirectory = true;

                if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    //Get the path of specified file
                    filePath = openFileDialog.FileName;

                    //Read the contents of the file into a stream
                    var fileStream = openFileDialog.OpenFile();

                    using (StreamReader reader = new StreamReader(fileStream))
                    {
                        fileContent = reader.ReadToEnd();
                    }
                    if (filePath.Length > 0)
                    {
                        OldGame oldGame = new OldGame();
                        oldGame = SerializeAndDeserialize.DeserializeObjectToXML <OldGame>(filePath);
                        var temp = new BoardVM(oldGame);

                        DataContext = temp;
                    }
                }
            }
        }
Ejemplo n.º 2
0
 private void InitComponentMessage(object first, object second, int status)
 {
     this.m1         = SerializeAndDeserialize.Serialize(first);
     this.m2         = SerializeAndDeserialize.Serialize(second);
     cm.First        = m1;
     cm.Second       = m2;
     cm.NumberStatus = status;
     m         = SerializeAndDeserialize.Serialize(cm);
     this.data = m.Data;
 }
Ejemplo n.º 3
0
        private void EnterButtton_Click(object sender, EventArgs e)
        {
            this.m1              = SerializeAndDeserialize.Serialize(textBox1.Text);
            this.m2              = SerializeAndDeserialize.Serialize(textBox2.Text);
            this.cm.First        = this.m1;
            this.cm.Second       = this.m2;
            this.cm.NumberStatus = 1;
            this.m = SerializeAndDeserialize.Serialize(this.cm);
            data   = this.m.Data;
            stream.Write(data, 0, data.Length);
            if (stream.CanRead)
            {
                int    numberOfBytesRead = 0;
                byte[] readingData       = new byte[6297630];
                do
                {
                    numberOfBytesRead = stream.Read(readingData, 0, readingData.Length);
                } while (stream.DataAvailable);
                this.m.Data = readingData;
                this.cm     = (ComplexMessage)SerializeAndDeserialize.Deserialize(m);

                // Успешная авторизация
                if (cm.NumberStatus == 2)
                {
                    ComplexMessage complexMessage = (ComplexMessage)SerializeAndDeserialize.Deserialize(m);
                    User           user1          = (User)SerializeAndDeserialize.Deserialize(complexMessage.First);
                    Bonus          bonus          = (Bonus)SerializeAndDeserialize.Deserialize(complexMessage.Second);
                    if (user1.Role == "Admin")
                    {
                        AdminForm adminForm = new AdminForm();
                        adminForm.form1       = this;
                        adminForm.label1.Text = user1.Login;
                        adminForm.Show();
                    }
                    else
                    {
                        Form4 userForm = new Form4();
                        userForm.labelLogin.Text = user1.Login;
                        userForm.currentUser     = user1;
                        userForm.Show();
                        userForm.form1 = this;
                    }
                    // Здесь осуществляется вход в новую прогу (для 6 лабы)

                    this.Hide();
                }

                // Ошибка авторизации
                else if (cm.NumberStatus == 3)
                {
                    MessageBox.Show("Неверный логин или пароль");
                }
            }
        }
Ejemplo n.º 4
0
        private void save_Click(object sender, RoutedEventArgs e)
        {
            Stream         myStream;
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter           = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
            saveFileDialog1.FilterIndex      = 2;
            saveFileDialog1.RestoreDirectory = true;

            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if ((myStream = saveFileDialog1.OpenFile()) != null)
                {
                    myStream.Close();

                    OldGame oldGame = new OldGame();
                    oldGame.Pieces           = (DataContext as BoardVM).Pieces;
                    oldGame.Player1Serialize = BoardVM.Player1;
                    oldGame.Player2Serialize = BoardVM.Player2;

                    SerializeAndDeserialize.SerializeObjectToXML <OldGame>(oldGame, saveFileDialog1.FileName);
                }
            }
        }
Ejemplo n.º 5
0
        private void changePasButton_Click(object sender, EventArgs e)
        {
            this.m1              = SerializeAndDeserialize.Serialize(newPasTextBox.Text);
            this.m2              = SerializeAndDeserialize.Serialize(textBoxEmail.Text);
            this.cm.First        = this.m1;
            this.cm.Second       = this.m2;
            this.cm.NumberStatus = 2;
            this.m = SerializeAndDeserialize.Serialize(this.cm);
            data   = this.m.Data;
            stream.Write(data, 0, data.Length);
            if (stream.CanRead)
            {
                int    numberOfBytesRead = 0;
                byte[] readingData       = new byte[6297630];
                do
                {
                    numberOfBytesRead = stream.Read(readingData, 0, readingData.Length);
                } while (stream.DataAvailable);
                this.m.Data = readingData;
                this.cm     = (ComplexMessage)SerializeAndDeserialize.Deserialize(m);

                // Успешная смена пароля
                if (cm.NumberStatus == 2)
                {
                    MessageBox.Show("Пароль успешно изменён");
                    form1.Show();
                    this.Hide();
                }

                // Ошибка смены пароля
                else if (cm.NumberStatus == 3)
                {
                    MessageBox.Show("Произошла ошибка при смене пароля");
                }
            }
        }
Ejemplo n.º 6
0
        public void Process()
        {
            while (true)
            {
                if (Stream.CanRead)
                {
                    byte[] myReadBuffer = new byte[6297630];
                    do
                    {
                        Stream.Read(myReadBuffer, 0, myReadBuffer.Length);
                    }while (Stream.DataAvailable);
                    Bonus bonus;
                    User  user;
                    MyLib.ComplexMessage complexMessage = new ComplexMessage();
                    MyLib.Message        message        = new MyLib.Message();
                    message.Data   = myReadBuffer;
                    complexMessage = (ComplexMessage)SerializeAndDeserialize.Deserialize(message);
                    // Регистрация
                    if (complexMessage.NumberStatus == 0)
                    {
                        try
                        {
                            bonus = (Bonus)SerializeAndDeserialize.Deserialize(complexMessage.First);
                        }
                        catch
                        {
                            bonus = null;
                        }

                        using (UserContainer db = new UserContainer())
                        {
                            user = (User)SerializeAndDeserialize.Deserialize(complexMessage.Second);
                            Bonus newBonus = new Bonus()
                            {
                                AmountBonus = bonus.AmountBonus
                            };
                            User newUser = new User()
                            {
                                Login = user.Login, Email = user.Email, Balance = user.Balance, Password = user.Password, Role = user.Role, Bonus = newBonus
                            };
                            db.UserSet.Add(newUser);
                            db.SaveChanges();
                        }
                    }
                    // Авторизация
                    else if (complexMessage.NumberStatus == 1)
                    {
                        using (UserContainer db = new UserContainer())
                        {
                            byte[] responseData;
                            for (int i = 0; i < db.UserSet.ToList().Count; i++)
                            {
                                if (db.UserSet.ToList()[i].Login == Convert.ToString(SerializeAndDeserialize.Deserialize(complexMessage.First)) && db.UserSet.ToList()[i].Password == CryptoService.GetHashString(Convert.ToString(SerializeAndDeserialize.Deserialize(complexMessage.Second))))
                                {
                                    Bonus bonus1 = db.UserSet.ToList()[i].Bonus;
                                    Bonus bonus2 = new Bonus()
                                    {
                                        Id          = bonus1.Id,
                                        AmountBonus = bonus1.AmountBonus
                                    };
                                    User user1 = db.UserSet.ToList()[i];
                                    User user2 = new User()
                                    {
                                        Id = user1.Id, Login = user1.Login, Password = user1.Password, Role = user1.Role, Balance = user1.Balance, basket = user1.basket, Email = user1.Email, Bonus = bonus2
                                    };
                                    m1 = SerializeAndDeserialize.Serialize(user2);

                                    m2 = SerializeAndDeserialize.Serialize(bonus2);

                                    cm.First        = m1;
                                    cm.Second       = m2;
                                    cm.NumberStatus = 2;
                                    m            = SerializeAndDeserialize.Serialize(cm);
                                    responseData = m.Data;
                                    Stream.Write(responseData, 0, responseData.Length);
                                    goto label;
                                }
                            }
                            cm.NumberStatus = 3;
                            m = SerializeAndDeserialize.Serialize(cm);

                            responseData = m.Data;
                            Stream.Write(responseData, 0, responseData.Length);
label:
                            responseData = null;
                        }
                    }
                    // Восстановление пароля
                    else if (complexMessage.NumberStatus == 2)
                    {
                        // First - новый пароль, Second - почта
                        string newPassword = Convert.ToString(SerializeAndDeserialize.Deserialize(complexMessage.First));
                        using (UserContainer db = new UserContainer())
                        {
                            byte[] responseData;
                            foreach (User usr in db.UserSet)
                            {
                                if (usr.Email == Convert.ToString(SerializeAndDeserialize.Deserialize(complexMessage.Second)))
                                {
                                    usr.Password    = CryptoService.GetHashString(newPassword);
                                    cm.First        = m1;
                                    cm.Second       = m2;
                                    cm.NumberStatus = 2;
                                    m            = SerializeAndDeserialize.Serialize(cm);
                                    responseData = m.Data;
                                    Stream.Write(responseData, 0, responseData.Length);
                                    goto labelSucess;
                                }
                            }
                            cm.NumberStatus = 3;
                            m = SerializeAndDeserialize.Serialize(cm);

                            responseData = m.Data;
                            Stream.Write(responseData, 0, responseData.Length);
labelSucess:
                            responseData = null;
                            db.SaveChanges();
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
 private void exit_Click(object sender, RoutedEventArgs e)
 {
     SerializeAndDeserialize.SerializeObjectToXML <HashSet <Player> >((DataContext as BoardVM).Players, @"../../Resources/players.xml");
     Close();
 }
Ejemplo n.º 8
0
 private void LoadPlayersFromMemory()
 {
     Players = new HashSet <Player>();
     Players = SerializeAndDeserialize.DeserializeObjectToXML <HashSet <Player> >(@"../../Resources/players.xml");
 }