Ejemplo n.º 1
0
        private void OnDataAvailable(object sender, WaveInEventArgs e)
        {
            var message     = Convert.ToBase64String(e.Buffer);
            var information = new Information(Nickname, message, InformationType.Voice);

            _client.SendMessage(InformationConverter.Serialize(information));
        }
Ejemplo n.º 2
0
        private void InitializeTcpClient()
        {
            var callback = new ChatCallback
            {
                OnConnected = () =>
                              Dispatcher.Invoke(() => PrintMessage("Pomyślnie połączono z " + IpAddress + ":" + Port)),
                OnMessageReceived = message => Dispatcher.Invoke(() =>
                {
                    var format = MessageExtractor.Extract(message);
                    if (format == string.Empty)
                    {
                        return;
                    }

                    var msg = InformationConverter.Deserialize(format);
                    if (mutedUsers.Contains(msg.Nick))
                    {
                        return;
                    }

                    switch (msg.Type)
                    {
                    case InformationType.Message:
                        PrintUserLine(msg.Nick, msg.Message);
                        break;

                    case InformationType.Voice:
                        {
                            if (!UsersSpeakingTextBlock.Text.Contains(msg.Nick))
                            {
                                UsersSpeakingTextBlock.Text += "\uD83D\uDD0A" + msg.Nick + Environment.NewLine;
                            }
                            var byteMessage = Convert.FromBase64String(msg.Message);
                            _audioManager.Play(byteMessage);
                            break;
                        }

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }),
                OnDisconnected = () => Dispatcher.Invoke(() =>
                {
                    _client.Disconnect();
                    Environment.Exit(0);
                }),
                OnCannotConnect = () => Dispatcher.Invoke(() =>
                {
                    var formattedMessage = new ColoredMessageBuilder()
                                           .With("Nie można połączyć się z serwerem. Sprawdź dane połączenia.")
                                           .Build();
                    ChatBlock.Document.Blocks.Add(formattedMessage);
                    ShowConnectionDialog();
                    ConnectToServer();
                })
            };

            _client = new TCPClient(callback);
            ConnectToServer();
        }
Ejemplo n.º 3
0
        private static void InitializeTcpServer(int portNumber)
        {
            var callback = new ChatCallback
            {
                OnClientConnected = endPoint =>
                {
                    Console.WriteLine("Nowy klient połączony: {0}:{1}", endPoint.Address, endPoint.Port);
                },
                OnMessageReceived = (tcpUser, message) =>
                {
                    var endPoint         = (IPEndPoint)tcpUser.Socket.RemoteEndPoint;
                    var formattedMessage = MessageExtractor.Extract(message);
                    var information      = InformationConverter.Deserialize(formattedMessage);
                    if (information?.Type == Message)
                    {
                        Console.WriteLine(
                            $"{information.Nick} ({endPoint.Address}:{endPoint.Port}) : {information.Message}");
                    }
                },
                OnClientDisconnected = endPoint =>
                {
                    Console.WriteLine($"({endPoint.Address}:{endPoint.Port}) has disconnected!");
                }
            };
            var server = new TCPServer(portNumber, callback);

            server.Initialize();
        }
Ejemplo n.º 4
0
 private static ChatCallback CreateChatCallback()
 {
     return(new ChatCallback
     {
         OnConnected = () =>
         {
             _isConnected = true;
             Console.WriteLine("Zostałeś połączony z serwerem. Możesz zacząć pisać!");
         },
         OnMessageReceived = message =>
         {
             var formattedMessage = MessageExtractor.Extract(message);
             var information = InformationConverter.Deserialize(formattedMessage);
             if (information.Type == Message)
             {
                 Console.WriteLine($"{information.Nick} : {information.Message}");
             }
         },
         OnCannotConnect = () =>
         {
             _isConnected = false;
             Console.WriteLine("Brak połączenia z serwerem. Sprawdź dane połączenia oraz spróbuj ponownie.");
         }
     });
 }
        public void ShouldThrowJsonReaderExceptionWhenJsonIsOnlyWhitespace()
        {
            var json = "      ";

            Action act = () => InformationConverter.Deserialize(json);

            act.Should().Throw <ArgumentException>();
        }
        public void ShouldThrowJsonReaderExceptionWhenJsonIsMalformed()
        {
            var json = "{hello:World}";

            Action act = () => InformationConverter.Deserialize(json);

            act.Should().Throw <JsonReaderException>();
        }
        public void ShouldThrowJsonReaderExceptionWhenJsonIsIncorrect()
        {
            var json = "<hello>world</hello>";

            Action act = () => InformationConverter.Deserialize(json);

            act.Should().Throw <JsonReaderException>();
        }
        public void ShouldCorrectlyDeserialize(string json)
        {
            var information = InformationConverter.Deserialize(json);

            information.Nick.Should().Be("nick");
            information.Message.Should().Be("msg");
            information.Type.Should().Be(InformationType.Message);
        }
        public void ShouldCorrectlySerialize()
        {
            var t = new Information("nick", "msg");

            var serialized = InformationConverter.Serialize(t);

            Console.WriteLine(serialized);
            serialized.Should().Be("{\"Nick\":\"nick\",\"Message\":\"msg\",\"Type\":0}");
        }
Ejemplo n.º 10
0
        public async Task <ActionResult> GetOrder(int id)
        {
            ApplicationUser user = await userManager.FindByIdAsync(HttpContext.User.Identity.GetUserId());

            OrderForModel model = new OrderForModel();

            var tempOrder = user.Orders.FirstOrDefault(o => o.Id == id);

            model.Number = tempOrder.Id;
            model.Cost   = tempOrder.TotalCost;

            model.Description = InformationConverter.StringToDescription(tempOrder.Description);

            return(View(model));
        }
Ejemplo n.º 11
0
        public ActionResult GetOrder(int id)
        {
            Order order = repository.Orders.FirstOrDefault(o => o.Id == id);

            AdminOrder model = new AdminOrder();

            if (order != null)
            {
                model.Number = order.Id;
                model.Cost   = order.TotalCost;
                model.CustomerInformation = InformationConverter.StringToUserProfile(order.CustomerInfrom);
                model.Description         = InformationConverter.StringToDescription(order.Description);
            }

            return(View(model));
        }
Ejemplo n.º 12
0
        private void SendButton_Click(object sender, RoutedEventArgs e)
        {
            var messageToSend = ToSendTextBox.Text;

            ToSendTextBox.Text = string.Empty;
            ToSendTextBox.Focus();

            if (messageToSend.StartsWith("?"))
            {
                _commandService.ExecuteCommand(messageToSend);
                return;
            }

            PrintUserLine(Nickname, messageToSend);

            var convertedMessage = InformationConverter.Serialize(new Information(Nickname, messageToSend));

            _client.SendMessage(convertedMessage);
        }
Ejemplo n.º 13
0
        static void Main()
        {
            var tcpClient = InitializeTcpClient();

            while (!_isConnected)
            {
                var(ip, port) = AskUserForInformations();
                tcpClient.Connect(ip, port);
                Thread.Sleep(1500);
            }

            string message;

            while ((message = Console.ReadLine()) != "exit" && tcpClient.IsConnected)
            {
                var i = new Information(_userName, message);
                tcpClient.SendMessage(InformationConverter.Serialize(i));
            }
        }
Ejemplo n.º 14
0
        public async Task <ActionResult> Confirm(Cart cart, CartViewModel model)
        {
            if (ModelState.IsValid)
            {
                StringBuilder resultDescription = new StringBuilder();

                Order order = new Order();

                order.Description = InformationConverter.DescriptionToString(cart.Lines);

                order.TotalCost = cart.CalcTotalPrice();

                order.CustomerInfrom = InformationConverter.UserProfileToString(model.CustomerInformation);

                order.DateTime = DateTime.Now;

                if (HttpContext.User.Identity.IsAuthenticated)
                {
                    order.UserId = HttpContext.User.Identity.GetUserId();
                }

                repository.SaveOrder(order);

                cart.Clear();

                EmailMessenger emailMessenger = new EmailMessenger(model.CustomerInformation.Email);
                await emailMessenger.SendMessageAsync("Оформление заказа TechUniverse",
                                                      string.Format("Добрый день, {2}!<br/><br>" +
                                                                    "Ваша заказ #{0} - {1} грн принят!<br/><br>" +
                                                                    "Ожидайте звонка оператора для подтверждения необходимой информации", order.Id, order.TotalCost, model.CustomerInformation.Name));

                return(View("ConfirmSuccess"));
            }
            else
            {
                model.Cart = cart;
                return(View(model));
            }
        }