Esempio n. 1
0
        private void GenerateParamsForFeature(XDoc feature)
        {
            // clear the parameters list
            parametersPanel.Controls.Clear();

            if (null != feature)
            {
                // add an item for each query parameter
                List <Control> controlsList = new List <Control>();
                foreach (XDoc queryParam in feature["param"])
                {
                    string queryParamName = queryParam["name"].Contents;
                    if (!queryParamName.StartsWith("{"))
                    {
                        string           queryParamValue  = queryParam["valuetype"].Contents;
                        bool             hasValue         = !queryParam["valuetype"].IsEmpty;
                        ParameterControl parameterControl = new ParameterControl(queryParamName, queryParamValue, true, hasValue);
                        parameterControl.Dock         = DockStyle.Top;
                        parameterControl.DataChanged += new EventHandler(parameterControl_DataChanged);
                        controlsList.Add(parameterControl);
                    }
                }
                _queryControls = controlsList.ToArray();
                parametersPanel.Controls.AddRange(_queryControls);

                // add an item for each url parameter
                String          pattern = feature["pattern"].Contents;
                Regex           regex   = new Regex((@"{(?<param>[^}]+)}"), RegexOptions.CultureInvariant);
                MatchCollection matches = regex.Matches(pattern);
                _parameterControls = new Control[matches.Count];
                String[] parameterNames = new String[matches.Count];
                for (int i = 0; i < matches.Count; i++)
                {
                    string           paramName        = matches[i].Groups["param"].Value;
                    ParameterControl parameterControl = new ParameterControl(paramName, null == _defaultValues?String.Empty:_defaultValues[paramName], false, true);
                    parameterControl.Dock         = DockStyle.Top;
                    parameterControl.DataChanged += new EventHandler(parameterControl_DataChanged);
                    _parameterControls[_parameterControls.Length - 1 - i] = parameterControl;
                    parameterNames[_parameterControls.Length - 1 - i]     = paramName;
                }
                parametersPanel.Controls.AddRange(_parameterControls);

                parametersPanel.Refresh();

                // in the case of a write operation, enable the panel for attaching content
                if ("DELETE" == GetOperationType() ||
                    "POST" == GetOperationType() ||
                    "PUT" == GetOperationType())
                {
                    messageContentPanel.Enabled = true;
                    messageContentTextBox.Text  = _defaultValues[pattern];
                }
                else
                {
                    messageContentPanel.Enabled = false;
                }
            }
        }
Esempio n. 2
0
        private String GenerateUrlFromParams()
        {
            String result = _url;

            result += "/";
            XDoc selectedFeature = GetSelectedFeature();

            if (null != selectedFeature)
            {
                String   pattern   = selectedFeature["pattern"].Contents;
                String[] urlString = pattern.Split(':');
                result += urlString[1];

                // replace each url parameter with the user specified value
                if (null != _parameterControls)
                {
                    foreach (Control control in _parameterControls)
                    {
                        ParameterControl parameterControl = control as ParameterControl;
                        result = result.Replace("{" + parameterControl.ParameterName + "}", parameterControl.ParameterValue);
                    }
                }

                // include each selected query parameter value
                if (null != _queryControls)
                {
                    List <ParameterControl> includedParameters = new List <ParameterControl>();
                    foreach (Control control in _queryControls)
                    {
                        ParameterControl parameterControl = control as ParameterControl;
                        if (parameterControl.IncludeInUrl)
                        {
                            includedParameters.Add(parameterControl);
                        }
                    }
                    if (0 < includedParameters.Count)
                    {
                        result += "?";
                        for (int i = includedParameters.Count - 1; i >= 0; i--)
                        {
                            result += includedParameters[i].ParameterName;
                            if (null != includedParameters[i].ParameterValue)
                            {
                                result += "=" + includedParameters[i].ParameterValue;
                            }
                            if (i != 0)
                            {
                                result += "&";
                            }
                        }
                    }
                }
            }
            return(result);
        }
Esempio n. 3
0
        private void GenerateParamsForFeature(XDoc feature)
        {
            // clear the parameters list
            parametersPanel.Controls.Clear();

            if (null != feature) {

                // add an item for each query parameter
                List<Control> controlsList = new List<Control>();
                foreach (XDoc queryParam in feature["param"]) {
                    string queryParamName = queryParam["name"].Contents;
                    if (!queryParamName.StartsWith("{")) {
                        string queryParamValue = queryParam["valuetype"].Contents;
                        bool hasValue = !queryParam["valuetype"].IsEmpty;
                        ParameterControl parameterControl = new ParameterControl(queryParamName, queryParamValue, true, hasValue);
                        parameterControl.Dock = DockStyle.Top;
                        parameterControl.DataChanged += new EventHandler(parameterControl_DataChanged);
                        controlsList.Add(parameterControl);
                    }
                }
                _queryControls = controlsList.ToArray();
                parametersPanel.Controls.AddRange(_queryControls);

                // add an item for each url parameter
                String pattern = feature["pattern"].Contents;
                Regex regex = new Regex((@"{(?<param>[^}]+)}"), RegexOptions.CultureInvariant);
                MatchCollection matches = regex.Matches(pattern);
                _parameterControls = new Control[matches.Count];
                String[] parameterNames = new String[matches.Count];
                for(int i = 0; i < matches.Count; i++)
                {
                    string paramName = matches[i].Groups["param"].Value;
                    ParameterControl parameterControl = new ParameterControl(paramName, null==_defaultValues?String.Empty:_defaultValues[paramName], false, true);
                    parameterControl.Dock = DockStyle.Top;
                    parameterControl.DataChanged += new EventHandler(parameterControl_DataChanged);
                    _parameterControls[_parameterControls.Length - 1 - i] = parameterControl;
                    parameterNames[_parameterControls.Length - 1 - i] = paramName;
                }
                parametersPanel.Controls.AddRange(_parameterControls);

                parametersPanel.Refresh();

                // in the case of a write operation, enable the panel for attaching content
                if ("DELETE" == GetOperationType() ||
                    "POST" == GetOperationType() ||
                    "PUT" == GetOperationType()) {
                    messageContentPanel.Enabled = true;
                    messageContentTextBox.Text = _defaultValues[pattern];
                } else {
                    messageContentPanel.Enabled = false;
                }
            }
        }