Exemplo n.º 1
0
        public void Notification(BinaryReader binaryReader)
        {
            string code = binaryReader.ReadString();

            if (code == "29")
            {
                NotificationTranslator.GetEnteringUserNotification(binaryReader.ReadString(), "Information");
            }
            else if (code == "30")
            {
                NotificationTranslator.PlaySoundNotificationAsync();
                NotificationTranslator.GetNewMessageNotification(binaryReader.ReadString());
            }
            else if (code == "40")
            {
                NotificationTranslator.RewriteDataNotification("Имя пользователя изменено!", "Success");
                Name = binaryReader.ReadString();
            }
            else if (code == "41")
            {
                NotificationTranslator.RewriteDataNotification("Имя пользователя не изменено! Пользователь с таким именем уже зарегистрирован!", "Error");
            }
            else if (code == "42")
            {
                NotificationTranslator.RewriteDataNotification("Логин пользователя изменён!", "Success");
                UserContainer.Login = binaryReader.ReadString();
            }
            else if (code == "43")
            {
                NotificationTranslator.RewriteDataNotification("Логин пользователя не изменён! Пользователь с таким логином уже зарегистрирован!", "Error");
            }
        }
        public MainChatPageViewModel(string name)
        {
            NotificationTranslator.CreateNotifier();
            NotificationTranslator.GetEnteringUserNotification($"Добро пожаловать, {name}!", "Success");

            Name          = name;
            _serverWorker = ServerWorker.NewInstance();

            Condition = "Visible";

            LoadEnable(true, true, false, true, true);
        }
Exemplo n.º 3
0
        public void Notification(BinaryReader binaryReader)
        {
            string code = binaryReader.ReadString();

            if (code == "29")
            {
                NotificationTranslator.GetEnteringUserNotification(binaryReader.ReadString(), "Information");
            }
            else if (code == "30")
            {
                NotificationTranslator.PlaySoundNotificationAsync();
                NotificationTranslator.GetNewMessageNotification(binaryReader.ReadString());
            }
            else if (code == "32")
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    IFormatter formatter = new BinaryFormatter();
                    var list             = (List <UserDTO>)formatter.Deserialize(_serverWorker.NetworkStream);
                    foreach (var user in list)
                    {
                        string genderForDate = user.Gender == "woman" ? "Была " : "Был ";
                        Users.Add(new UserViewModel
                        {
                            Name           = user.Name,
                            CircleColor    = user.Gender == "woman" ? (Brush) new BrushConverter().ConvertFromString("#CD5C5C") : (Brush) new BrushConverter().ConvertFromString("#32CD32"),
                            PastDateOnline = user.PastOnline != null ? genderForDate + Day.GetParsedDate(user.PastOnline.ToString()).ToLower() : "online",
                            Visibility     = "Visible"
                        });
                    }
                }, DispatcherPriority.Background);
            }
            else if (code == "40")
            {
                NotificationTranslator.RewriteDataNotification("Имя пользователя изменено!", "Success");
                Name = binaryReader.ReadString();
            }
            else if (code == "41")
            {
                NotificationTranslator.RewriteDataNotification("Имя пользователя не изменено! Пользователь с таким именем уже зарегистрирован!", "Error");
            }
            else if (code == "42")
            {
                NotificationTranslator.RewriteDataNotification("Логин пользователя изменён!", "Success");
                UserContainer.Login = binaryReader.ReadString();
            }
            else if (code == "43")
            {
                NotificationTranslator.RewriteDataNotification("Логин пользователя не изменён! Пользователь с таким логином уже зарегистрирован!", "Error");
            }
        }
        public void Notification(BinaryReader binaryReader)
        {
            string code = binaryReader.ReadString();

            switch (code)
            {
            case "29":
                NotificationTranslator.GetEnteringUserNotification(binaryReader.ReadString(), "Information");
                break;

            case "30":
                Application.Current.Dispatcher.Invoke(() =>
                {
                    NewMessage(binaryReader);
                }, DispatcherPriority.Background);
                break;

            case "31":
                Application.Current.Dispatcher.Invoke(PastMessages, DispatcherPriority.Background);
                break;

            case "40":
                NotificationTranslator.RewriteDataNotification("Имя пользователя изменено!", "Success");
                Name = binaryReader.ReadString();
                break;

            case "41":
                NotificationTranslator.RewriteDataNotification("Имя пользователя не изменено! Пользователь с таким именем уже зарегистрирован!", "Error");
                break;

            case "42":
                NotificationTranslator.RewriteDataNotification("Логин пользователя изменён!", "Success");
                UserContainer.Login = binaryReader.ReadString();
                break;

            case "43":
                NotificationTranslator.RewriteDataNotification("Логин пользователя не изменён! Пользователь с таким логином уже зарегистрирован!", "Error");
                break;

            case "67":
                Application.Current.Dispatcher.Invoke(() =>
                {
                    NewMessages(binaryReader);
                }, DispatcherPriority.Background);
                break;
            }
        }
Exemplo n.º 5
0
        public void Notification(BinaryReader binaryReader)
        {
            string code = binaryReader.ReadString();

            if (code == "13-1")
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    IFormatter formatter = new BinaryFormatter();
                    CurrentRating        = (List <RatingDTO>)formatter.Deserialize(_serverWorker.NetworkStream);
                    _ratingOverall       = CurrentRating;
                    _ratingWithUsers     = (List <RatingDTO>)formatter.Deserialize(_serverWorker.NetworkStream);
                    _ratingWithComputer  = (List <RatingDTO>)formatter.Deserialize(_serverWorker.NetworkStream);
                }, DispatcherPriority.Background);
            }
            else if (code == "29")
            {
                NotificationTranslator.GetEnteringUserNotification(binaryReader.ReadString(), "Information");
            }
            else if (code == "30")
            {
                NotificationTranslator.PlaySoundNotificationAsync();
                NotificationTranslator.GetNewMessageNotification(binaryReader.ReadString());
            }
            else if (code == "40")
            {
                NotificationTranslator.RewriteDataNotification("Имя пользователя изменено!", "Success");
                Name = binaryReader.ReadString();
            }
            else if (code == "41")
            {
                NotificationTranslator.RewriteDataNotification("Имя пользователя не изменено! Пользователь с таким именем уже зарегистрирован!", "Error");
            }
            else if (code == "42")
            {
                NotificationTranslator.RewriteDataNotification("Логин пользователя изменён!", "Success");
                UserContainer.Login = binaryReader.ReadString();
            }
            else if (code == "43")
            {
                NotificationTranslator.RewriteDataNotification("Логин пользователя не изменён! Пользователь с таким логином уже зарегистрирован!", "Error");
            }
        }
Exemplo n.º 6
0
        public void Notification(BinaryReader binaryReader)
        {
            string code = binaryReader.ReadString();

            if (code == "1-11")
            {
                IsVisibleGame    = true;
                IsVisibleSpinner = false;
                OpponentName     = binaryReader.ReadString();
                FirstGamerSymbol = binaryReader.ReadString();
                if (FirstGamerSymbol == "X")
                {
                    IsEnable          = true;
                    SecondGamerSymbol = "0";
                    GameInformation   = FIRST_PLAYER_TURN;
                }
                else
                {
                    IsEnable          = false;
                    SecondGamerSymbol = "X";
                    GameInformation   = SECOND_PLAYER_TURN + OpponentName;
                }
                TextNotification = $"Вы играете за {FirstGamerSymbol}";
                ShowNotificationAsync();
            }
            else if (code == "2-11")
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    IsVisibleSpinner        = false;
                    var gameDialogViewModel = new GameDialogViewModel("Соперник не найден! Хотите сыгарть с компьютером?");
                    var gameDialogView      = new GameDialogView(gameDialogViewModel);
                    gameDialogView.ShowDialog();
                    if (gameDialogViewModel.UserResponse == "Да")
                    {
                        IsVisibleGame     = true;
                        OpponentName      = "Компьютер";
                        _delegateMove     = MoveForGameWithComputer;
                        _gameLogic        = new GameLogic(this);
                        FirstGamerSymbol  = _gameLogic.GamerSymbol;
                        SecondGamerSymbol = _gameLogic.ComputerSymbol;
                        TextNotification  = $"Вы играете за {FirstGamerSymbol}";
                        ShowNotificationAsync();
                        if (FirstGamerSymbol == "X")
                        {
                            IsEnable        = true;
                            GameInformation = FIRST_PLAYER_TURN;
                        }
                        else
                        {
                            GameInformation = "Ожидание хода от компьютера";
                        }
                        _delegateMove = MoveForGameWithComputer;
                    }
                    else
                    {
                        Condition = "Collapsed";
                    }
                }, DispatcherPriority.Background);
            }
            else if (code == "11-0")
            {
                SetSymbolInPlayingField(SecondGamerSymbol, binaryReader.ReadString(), false);
                IsEnable        = true;
                GameInformation = FIRST_PLAYER_TURN;
            }
            else if (code == "11-1")
            {
                Application.Current.Dispatcher.Invoke(async() =>
                {
                    GameInformation    = FIRST_PLAYER_WIN;
                    string[] positions = binaryReader.ReadString().Split('-');
                    SetSymbolInPlayingField(FirstGamerSymbol, positions[0], true, "#00FF7F");
                    await Task.Delay(528);
                    SetSymbolInPlayingField(FirstGamerSymbol, positions[1], true, "#00FF7F");
                    await Task.Delay(528);
                    SetSymbolInPlayingField(FirstGamerSymbol, positions[2], true, "#00FF7F");
                    IsVisibleCancel = true;
                }, DispatcherPriority.Background);
            }
            else if (code == "11-2")
            {
                Application.Current.Dispatcher.Invoke(async() =>
                {
                    GameInformation    = SECOND_PLAYER_WIN;
                    string[] positions = binaryReader.ReadString().Split('-');
                    SetSymbolInPlayingField(SecondGamerSymbol, positions[0], true, "#FA8072");
                    await Task.Delay(528);
                    SetSymbolInPlayingField(SecondGamerSymbol, positions[1], true, "#FA8072");
                    await Task.Delay(528);
                    SetSymbolInPlayingField(SecondGamerSymbol, positions[2], true, "#FA8072");
                    IsVisibleCancel = true;
                }, DispatcherPriority.Background);
            }
            else if (code == "11-3")
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    GameInformation = DRAW;
                    SetSymbolInPlayingField(SecondGamerSymbol, binaryReader.ReadString(), false);
                    IsVisibleCancel = true;
                }, DispatcherPriority.Background);
            }
            else if (code == "11-4")
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    GameInformation = OpponentName + SECOND_PLAYER_GIVE_UP;
                    IsVisibleCancel = true;
                }, DispatcherPriority.Background);
            }
            else if (code == "29")
            {
                NotificationTranslator.GetEnteringUserNotification(binaryReader.ReadString(), "Information");
            }
            else if (code == "30")
            {
                NotificationTranslator.PlaySoundNotificationAsync();
                NotificationTranslator.GetNewMessageNotification(binaryReader.ReadString());
            }
            else if (code == "40")
            {
                NotificationTranslator.RewriteDataNotification("Имя пользователя изменено!", "Success");
                Name = binaryReader.ReadString();
            }
            else if (code == "41")
            {
                NotificationTranslator.RewriteDataNotification("Имя пользователя не изменено! Пользователь с таким именем уже зарегистрирован!", "Error");
            }
            else if (code == "42")
            {
                NotificationTranslator.RewriteDataNotification("Логин пользователя изменён!", "Success");
                UserContainer.Login = binaryReader.ReadString();
            }
            else if (code == "43")
            {
                NotificationTranslator.RewriteDataNotification("Логин пользователя не изменён! Пользователь с таким логином уже зарегистрирован!", "Error");
            }
        }