private void BtnGo_Click(object sender, EventArgs e)
        {
            try
            {
                this.Enabled       = false;
                this.UseWaitCursor = true;
                Cursor.Current     = Cursors.WaitCursor;

                if (string.IsNullOrWhiteSpace(txtAccountNumber.Text) ||
                    string.IsNullOrWhiteSpace(txtAWBNumber.Text))
                {
                    MessageBox.Show(@"Missing data.");
                    return;
                }

                txtAccountNumber.Text = txtAccountNumber.Text.Trim();
                txtAWBNumber.Text     = txtAWBNumber.Text.Trim();

                GloWS glows = new GloWS(Common.username, Common.password, (Common.IsProduction ? Common.restProductionBaseUrl : Common.restTestingBaseUrl));

                EPodResponse ePod = glows.GetEPod(txtAWBNumber.Text
                                                  , txtAccountNumber.Text
                                                  // ReSharper disable once PossibleInvalidCastException
                                                  , (Enums.EPodType)cmbPODType.SelectedItem);

                _lastJsonRequest  = glows.LastJSONRequest;
                _lastJsonResponse = glows.LastJSONResponse;

                if (null != ePod)
                {
                    string tempFilename = System.IO.Path.GetTempFileName();
                    System.IO.File.WriteAllBytes(tempFilename, ePod.EPod.Image);

                    System.Diagnostics.Process.Start(tempFilename);
                }
            }
            catch (GloWSValidationException gvx)
            {
                txtResult.Text = GloWSValidationException.PrintResults(gvx.ExtractValidationResults(), 0);
            }
            catch (Exception ex)
            {
                txtResult.Text = ex.Message;
            }
            finally
            {
                this.Enabled       = true;
                this.UseWaitCursor = false;
                Cursor.Current     = Cursors.Default;
            }
        }
예제 #2
0
        public CreateShipmentResponse RequestShipment(CreateShipmentRequest req)
        {
            // Validate the request

            List <ValidationResult> validationResult = Common.Validate(ref req);

            if (validationResult.Any())
            {
                string errors = GloWSValidationException.PrintResults(validationResult);
                throw new GloWSValidationException(validationResult);
            }

            LastJSONRequest  = JsonConvert.SerializeObject(req, Formatting.Indented);
            LastJSONResponse = SendRequestAndReceiveResponse(LastJSONRequest, "ShipmentRequest");

            CreateShipmentResponse retval;

            try
            {
                // Deserialize the result back to an object.
                List <string> errors = new List <string>();

                retval = JsonConvert.DeserializeObject <CreateShipmentResponse>(LastJSONResponse, new JsonSerializerSettings()
                {
                    Error = delegate(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
                    {
                        errors.Add(args.ErrorContext.Error.Message);
                        args.ErrorContext.Handled = true;
                    }
                });
            }
            catch
            {
                retval = new CreateShipmentResponse();
            }

            return(retval);
        }