Example #1
0
        public AddNewUrlSourceDialog(JsonUrlInput input) : this()
        {
            _input = input;

            NameTextBox.Text = _input.Name;
            UrlTextBox.Text  = _input.Url;
            Headers          = input.Headers;

            ExposeAsMethodCheckbox.IsChecked   = _input.GenerateAsMethod;
            ExposeAsPropertyCheckBox.IsChecked = !_input.GenerateAsMethod;

            HeadersListView.ItemsSource = Headers;
        }
Example #2
0
        public AddNewUrlSourceDialog()
        {
            _input = new JsonUrlInput();

            InitializeComponent();

            // sigh, too bad reactiveui doesn't support .net 4
            Action doValidation = () =>
            {
                var name = NameTextBox.Text;
                var uri  = UrlTextBox.Text;

                bool validUri = false;
                try
                {
                    var obj = new Uri(uri, UriKind.Absolute);
                    validUri = true;
                } catch { }

                var nameOk = String.IsNullOrEmpty(name) || char.IsLetter(name.ToCharArray()[0]);
                var jsonOk = validUri || String.IsNullOrEmpty(uri);

                OkButton.IsEnabled = (nameOk && jsonOk && !String.IsNullOrEmpty(name));

                NameTextBox.Background = nameOk ? _goodBrush : _badBrush;
                UrlTextBox.Background  = jsonOk ? _goodBrush : _badBrush;
            };

            NameTextBox.TextChanged += (sender, args) => doValidation();
            UrlTextBox.TextChanged  += (sender, args) => doValidation();

            UrlTextBox.TextChanged += (sender, args) =>
            {
                try
                {
                    var uri  = new Uri(UrlTextBox.Text);
                    var pcol = HttpUtility.ParseQueryString(uri.Query);
                    var ps   = pcol
                               .AllKeys
                               .Select(k => Tuple.Create(k, pcol[k]))
                               .ToList();

                    ParametersListView.ItemsSource = ps;

                    UrlTextBox.Background = _goodBrush;
                }
                catch
                {
                    UrlTextBox.Background          = _badBrush;
                    ParametersListView.ItemsSource = null;
                }

                if (ParametersListView.Items.Count > 0)
                {
                    ExposeAsMethodCheckbox.IsEnabled = true;
                }
                else
                {
                    ExposeAsMethodCheckbox.IsEnabled   = false;
                    ExposeAsPropertyCheckBox.IsChecked = true;
                }
            };

            HeadersListView.SelectionChanged += (sender, args) => RemoveHeaderButton.IsEnabled = HeadersListView.SelectedItem != null;
            AddNewHeaderButton.Click         += (sender, args) =>
            {
                var h = new WebRequestHeader()
                {
                    Name = "Name", Value = "Value"
                };
                Headers.Add(h);
                HeadersListView.SelectedItem = h;
            };
            RemoveHeaderButton.Click += (sender, args) =>
            {
                var h = HeadersListView.SelectedItem as WebRequestHeader;
                Headers.Remove(h);
            };

            CancelButton.Click += (sender, args) => DialogResult = false;
            OkButton.Click     += (sender, args) =>
            {
                _input.Name             = NameTextBox.Text;
                _input.Url              = UrlTextBox.Text;
                _input.Headers          = Headers;
                _input.GenerateAsMethod = ExposeAsMethodCheckbox.IsChecked == true;

                Input        = _input;
                DialogResult = true;
            };

            HeadersListView.ItemsSource = Headers;

            doValidation();

            NameTextBox.Focus();
        }
 public JsonUrlGeneratedClass(JsonUrlInput input)
 {
     OriginalInput = input;
 }
 public JsonUrlGeneratedClass(JsonUrlInput input)
 {
     OriginalInput = input;
 }
        public AddNewUrlSourceDialog()
        {
            _input = new JsonUrlInput();

            InitializeComponent();

            // sigh, too bad reactiveui doesn't support .net 4
            Action doValidation = () =>
            {
                var name = NameTextBox.Text;
                var uri = UrlTextBox.Text;

                bool validUri = false;
                try
                {
                    var obj = new Uri(uri, UriKind.Absolute);
                    validUri = true;
                } catch { }

                var nameOk = String.IsNullOrEmpty(name) || char.IsLetter(name.ToCharArray()[0]);
                var jsonOk = validUri || String.IsNullOrEmpty(uri);

                OkButton.IsEnabled = (nameOk && jsonOk && !String.IsNullOrEmpty(name));

                NameTextBox.Background = nameOk ? _goodBrush : _badBrush;
                UrlTextBox.Background = jsonOk ? _goodBrush : _badBrush;
            };

            NameTextBox.TextChanged += (sender, args) => doValidation();
            UrlTextBox.TextChanged += (sender, args) => doValidation();

            UrlTextBox.TextChanged += (sender, args) =>
            {
                try
                {
                    var uri = new Uri(UrlTextBox.Text);
                    var pcol = HttpUtility.ParseQueryString(uri.Query);
                    var ps = pcol
                        .AllKeys
                        .Select(k => Tuple.Create(k, pcol[k]))
                        .ToList();

                    ParametersListView.ItemsSource = ps;

                    UrlTextBox.Background = _goodBrush;
                }
                catch
                {
                    UrlTextBox.Background = _badBrush;
                    ParametersListView.ItemsSource = null;
                }

                if (ParametersListView.Items.Count > 0)
                    ExposeAsMethodCheckbox.IsEnabled = true;
                else
                {
                    ExposeAsMethodCheckbox.IsEnabled = false;
                    ExposeAsPropertyCheckBox.IsChecked = true;
                }
            };

            HeadersListView.SelectionChanged += (sender, args) => RemoveHeaderButton.IsEnabled = HeadersListView.SelectedItem != null;
            AddNewHeaderButton.Click += (sender, args) =>
            {
                var h = new WebRequestHeader() {Name = "Name", Value = "Value"};
                Headers.Add(h);
                HeadersListView.SelectedItem = h;
            };
            RemoveHeaderButton.Click += (sender, args) =>
            {
                var h = HeadersListView.SelectedItem as WebRequestHeader;
                Headers.Remove(h);
            };

            CancelButton.Click += (sender, args) => DialogResult = false;
            OkButton.Click += (sender, args) =>
            {
                _input.Name = NameTextBox.Text;
                _input.Url = UrlTextBox.Text;
                _input.Headers = Headers;
                _input.GenerateAsMethod = ExposeAsMethodCheckbox.IsChecked == true;

                Input = _input;
                DialogResult = true;
            };

            HeadersListView.ItemsSource = Headers;

            doValidation();

            NameTextBox.Focus();
        }
        public AddNewUrlSourceDialog(JsonUrlInput input)
            : this()
        {
            _input = input;

            NameTextBox.Text = _input.Name;
            UrlTextBox.Text = _input.Url;
            Headers = input.Headers;

            ExposeAsMethodCheckbox.IsChecked = _input.GenerateAsMethod;
            ExposeAsPropertyCheckBox.IsChecked = !_input.GenerateAsMethod;

            HeadersListView.ItemsSource = Headers;
        }