示例#1
0
        public Form1()
        {
            InitializeComponent();

            _allRequests       = new List <Request>();
            _currentWebService = new Request();
            _currentUri        = new UriOption();
            _fsh = new FormStateHandler();
        }
示例#2
0
        // TODO: this method gets triggered when the form loads and the SetComboBoxes() is called. The other comboBox doesnt, why is this? Why do we need this 'if' statement.
        private void comboBox_uri_SelectedIndexChanged(object sender, EventArgs e)
        {
            var selection = (string)comboBox_uri.SelectedItem;


            if (selection == "--Select--")
            {
                _currentUri = null;
                parameterPanel.Controls.Clear();
                button_Send.Enabled   = false;
                button_Send.BackColor = Color.LightGray;
            }
            else
            {
                _currentUri = _currentWebService.UriOptions.Where(x => x.Name == selection).SingleOrDefault();
                _fsh.CreateForm(_currentUri.Parameters, parameterPanel);
                button_Send.Enabled   = true;
                button_Send.BackColor = Color.DodgerBlue;
            }
        }
示例#3
0
        private void comboBox_webService_SelectedIndexChanged(object sender, EventArgs e)
        {
            var selectedWS = (string)comboBox_webService.SelectedItem;

            if (selectedWS == "--Select--")
            {
                _currentWebService   = null;
                _currentUri          = null;
                label_uri.Visible    = false;
                comboBox_uri.Visible = false;
                comboBox_uri.Items.Clear();
                parameterPanel.Controls.Clear();
                button_Send.Enabled   = false;
                button_Send.BackColor = Color.LightGray;
            }
            else
            {
                _currentWebService = _allRequests.Where(x => x.Name == selectedWS).SingleOrDefault();
                comboBox_uri.Items.Clear();
                parameterPanel.Controls.Clear();

                _fsh.SetUricomboBox(label_uri, comboBox_uri, _currentWebService.UriOptions);
            }
        }
        public string CreateRequestUrl(string environment, string webService, UriOption uriOption, Panel parameterPanel)
        {
            //Create IEnumerable of TextBoxes
            IEnumerable <TextBox> textBoxes = parameterPanel.Controls.OfType <TextBox>();

            //Transfer textBox values to UriOption Parameters.Value because the Parameters have properties related to how the query string is created
            uriOption.Parameters.ForEach(param => param.Value = textBoxes.Where(tb => tb.Name == param.Name).Select(txb => txb.Text).SingleOrDefault());

            //Same thing, more verbous
            //foreach (Parameter param in uriOption.Parameters)
            //{
            //    param.Value = textBoxes.Where(txtBx => txtBx.Name == param.Name).Select(x => x.Text).SingleOrDefault();
            //}


            StringBuilder requestString = new StringBuilder();

            //Query string?
            if (uriOption.ThereIsQuery == true)
            {
                requestString.Append("?");

                var parametersWithInput = uriOption.Parameters.Where(x => x.Value != "").ToList();

                if (parametersWithInput != null && parametersWithInput.Count > 0)
                {
                    Parameter lastOne = parametersWithInput.Last();        //uriOption.Parameters.Last();
                    foreach (var param in parametersWithInput)
                    {
                        if (param.PreQuery)
                        {
                            requestString.Insert(0, param.Value);
                        }
                        else
                        {
                            if (param.Value != "")
                            {
                                requestString.Append(param.Name);
                                requestString.Append("=");

                                if (!string.IsNullOrWhiteSpace(param.Value))
                                {
                                    requestString.Append(param.Value.Trim());
                                }

                                if (param != lastOne)
                                {
                                    requestString.Append("&");
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                requestString.Append(uriOption.Parameters.FirstOrDefault().Value);
            }

            // prepend Uri
            requestString.Insert(0, uriOption.Value);
            // prepend Web Service
            requestString.Insert(0, webService);
            // prepend Environment
            requestString.Insert(0, environment);

            return(requestString.ToString());
        }