Пример #1
0
        public static string AsString(this QpxResponse response)
        {
            StringBuilder sb = new StringBuilder();

            if (response != null)
            {
                if (response.trips != null)
                {
                    foreach (var trip in response.trips.tripOption)
                    {
                        sb.AppendLine();
                        sb.AppendLine();
                        sb.AppendLine("PRICE: " + trip.saleTotal);
                        sb.AppendLine("DURATION: " + trip.DurationTotal.ToReadableString());

                        int legno = 0;

                        foreach (var leg in trip.Legs())
                        {
                            legno++;

                            sb.AppendLine(leg.departureTime.ToString(legno + "     " + "yyyy-MM-dd hh:mm") + " " + leg.origin + " -> " + leg.destination + " " + leg.arrivalTime.ToString("yyyy-MM-dd hh:mm"));
                            sb.AppendLine("                  [Terminal = " + leg.destinationTerminal + " ] [ Class = " + leg.Parent.cabin + " ] [ " + leg.mileage + " miles ] [ AcType = " + leg.aircraft + " ]");
                        }
                    }
                }
            }

            return(sb.ToString());
        }
Пример #2
0
        private void getFlights()
        {
            if (MessageBox.Show("confirm?", "Confirm then wait! app will be frozen ;)", MessageBoxButtons.OKCancel) != DialogResult.OK)
            {
                return;
            }

            jsonTextBox.Text     = "";
            responseTextBox.Text = "";

            Application.DoEvents();

            try
            {
                //// Create a request using a URL that can receive a post.
                WebRequest request = WebRequest.Create(urlTextBox.Text + "?key=" + apiKeyTextBox.Text);

                // Set the Method property of the request to POST.
                request.Method = "POST";
                // Create POST data and convert it to a byte array.
                string postData  = RequestString(depTextBox.Text, arrTextBox.Text, dateTimePicker.Value, roundTripCheckBox.Checked);//
                byte[] byteArray = Encoding.UTF8.GetBytes(postData);
                // Set the ContentType property of the WebRequest.
                request.ContentType = "application/json";
                // Set the ContentLength property of the WebRequest.
                request.ContentLength = byteArray.Length;
                // Get the request stream.
                using (Stream dataStream = request.GetRequestStream())
                {
                    // Write the data to the request stream.
                    dataStream.Write(byteArray, 0, byteArray.Length);
                    // Close the Stream object.
                    dataStream.Close();
                    // Get the response.
                    using (WebResponse response = request.GetResponse())
                    {
                        // Display the status.
                        //Console.WriteLine(((HttpWebResponse)response).StatusDescription);
                        // Get the stream containing content returned by the server.
                        using (Stream dataStream1 = response.GetResponseStream())
                        {
                            // Open the stream using a StreamReader for easy access.
                            using (StreamReader reader = new StreamReader(dataStream1))
                            {
                                // Read the content.
                                string responseFromServer = reader.ReadToEnd();

                                jsonTextBox.Text = JsonHelper.FormatJson(responseFromServer);

                                QpxResponse responseData = Newtonsoft.Json.JsonConvert.DeserializeObject <QpxResponse>(responseFromServer);

                                responseTextBox.Text = responseData.AsString();

                                reader.Close();
                            }
                            dataStream1.Close();
                        }
                        response.Close();
                    }
                    dataStream.Close();
                }
            }
            catch (Exception exception)
            {
                jsonTextBox.Text = exception.ToString();
                //System.Windows.Forms.MessageBox.Show(exception.Message, "Error getting tickets", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
            }
        }