Ejemplo n.º 1
0
        private void CheckStringOption(GroupBuilder group, OptionType type, TextBox textBox)
        {
            String text = textBox.Text.Trim();

            if (!String.IsNullOrEmpty(text))
            {
                group.Add(RequestBuilders.Option(type, text));
            }
        }
Ejemplo n.º 2
0
        private void CheckIntOption(GroupBuilder group, OptionType type, TextBox textBox)
        {
            String text = textBox.Text.Trim();

            if (!String.IsNullOrEmpty(text))
            {
                Int32 val = 0;
                if (Int32.TryParse(text, out val))
                {
                    group.Add(RequestBuilders.Option(type, val));
                }
                else
                {
                    group.Add(RequestBuilders.Option(type, text));
                }
            }
        }
Ejemplo n.º 3
0
        private void CheckHexStringOption(GroupBuilder group, OptionType type, TextBox textBox)
        {
            String text = textBox.Text.Trim();

            if (!String.IsNullOrEmpty(text))
            {
                if (text.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
                {
                    Byte[] bytes = Utils.ToBytes(text);
                    if (bytes != null)
                    {
                        group.Add(RequestBuilders.Option(type, bytes));
                    }
                }
                else
                {
                    group.Add(RequestBuilders.Option(type, text));
                }
            }
        }
Ejemplo n.º 4
0
        private void Save()
        {
            GroupBuilder group = Step.RequestBuilder as GroupBuilder;

            if (group == null)
            {
                group = RequestBuilders.Group();
            }
            else
            {
                group.Clear();
            }

            if (cbxMethod.SelectedIndex >= 0)
            {
                group.Add(RequestBuilders.Method((Method)cbxMethod.SelectedValue));
            }
            if (cbxType.SelectedIndex >= 0)
            {
                group.Add(RequestBuilders.MessageType((MessageType)cbxType.SelectedValue));
            }

            String tokenString = tbxToken.Text.Trim();

            if (!String.IsNullOrEmpty(tokenString))
            {
                Byte[] token;
                if (tokenString.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
                {
                    token = Utils.ToBytes(tokenString);
                }
                else
                {
                    token = System.Text.Encoding.UTF8.GetBytes(tokenString);
                }
                group.Add(RequestBuilders.Token(token));
            }

            Int32 mediaType = MediaType.Undefined;

            if (cbxContentType.SelectedIndex > 0)
            {
                mediaType = (Int32)cbxContentType.SelectedValue;
                group.Add(RequestBuilders.Option(OptionType.ContentType, mediaType));
            }
            String payloadString = tbxPayload.Text.Trim();

            if (!String.IsNullOrEmpty(payloadString))
            {
                if (payloadString.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
                {
                    Byte[] payload = Utils.ToBytes(payloadString);
                    if (payload != null)
                    {
                        group.Add(RequestBuilders.Payload(payload, mediaType));
                    }
                }
                else
                {
                    group.Add(RequestBuilders.Payload(tbxPayload.Text, mediaType));
                }
            }

            if (cbxAccept.SelectedIndex > 0)
            {
                group.Add(RequestBuilders.Option(OptionType.Accept, (Int32)cbxAccept.SelectedValue));
            }

            CheckStringOption(group, OptionType.UriPath, tbxUriPath);
            CheckStringOption(group, OptionType.UriQuery, tbxUriQuery);
            CheckHexStringOption(group, OptionType.ETag, tbxETag);
            CheckHexStringOption(group, OptionType.IfMatch, tbxIfMatch);
            if (checkIfNoneMatch.Checked)
            {
                group.Add(RequestBuilders.Option(OptionType.IfNoneMatch));
            }
            CheckIntOption(group, OptionType.Observe, tbxObserve);
            CheckIntOption(group, OptionType.Block2, tbxBlockDown);
            //CheckIntOption(group, OptionType.Block1, tbxBlockUp);

            CheckStringOption(group, OptionType.UriHost, txtUriHost);

            CheckIntOption(group, OptionType.UriPort, txtUriPort);

            CheckStringOption(group, OptionType.ProxyUri, txtProxyUri);

            CheckIntOption(group, OptionType.MaxAge, txtMaxAge);

            CheckStringOption(group, OptionType.LocationPath, txtLocationPath);
            CheckStringOption(group, OptionType.LocationQuery, txtLocationQuery);

            if (checkProxyScheme.Checked)
            {
                group.Add(RequestBuilders.Option(OptionType.ProxyScheme));
            }
            Step.RequestBuilder = group;
        }