Beispiel #1
0
        /// <summary>
        /// Sends location and date to server
        /// </summary>
        private async void SendLocationAndDate()
        {
            string location   = textBoxLocation.Text;
            string daysPeriod = textBoxDate.Text;

            if (string.IsNullOrWhiteSpace(location) || string.IsNullOrWhiteSpace(daysPeriod))
            {
                MessageBox.Show("Weather location and days period cannot be empty", "Empty weather data",
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                buffer = Encoding.ASCII.GetBytes(location);

                await stream.WriteAsync(buffer, 0, buffer.Length);

                buffer = new byte[1024];

                buffer = Encoding.ASCII.GetBytes(daysPeriod);

                await stream.WriteAsync(buffer, 0, buffer.Length);

                buffer = new byte[2048];

                string data           = "";
                int    locationsCount = location.Where(c => c == ',').Count() + 1;

                ClientLogTextBox.Clear();

                for (int i = 0; i < locationsCount; i++)
                {
                    do
                    {
                        await stream.ReadAsync(buffer, 0, buffer.Length);

                        data = Encoding.ASCII.GetString(buffer).Replace("\0", "");

                        if (data.Contains("Incorrect weather period, try again"))
                        {
                            MessageBox.Show("Incorrect weather period, try different formatting", "Format error",
                                            MessageBoxButton.OK, MessageBoxImage.Error);

                            return;
                        }
                    } while (!data.Contains("Temperature"));

                    ClientLogTextBox.Text += data;

                    Array.Clear(buffer, 0, buffer.Length);
                }
            }
        }
Beispiel #2
0
 private void ClearWeatherForecast_Click(object sender, RoutedEventArgs e)
 {
     ClientLogTextBox.Clear();
 }