Example #1
0
        private async void BtnAddClick(object sender, EventArgs e)
        {
            var dialog = new BindingDialog(ServiceProvider, null, _site);

            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var binding = dialog.Binding;

            if (binding == null)
            {
                return;
            }

            var node = new ListViewItem(new[]
            {
                binding.Protocol,
                binding.Host.HostToDisplay(),
                binding.EndPoint.Port.ToString(CultureInfo.InvariantCulture),
                binding.EndPoint.Address.AddressToDisplay(),
                string.Empty
            })
            {
                Tag = binding
            };

            listView1.Items.Add(node);
            _site.Bindings.Add(binding);
            await _site.Server.CommitChangesAsync();
        }
Example #2
0
        private async void BtnEditClick(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0)
            {
                return;
            }

            var item    = listView1.SelectedItems[0];
            var binding = (Binding)item.Tag;
            var dialog  = new BindingDialog(ServiceProvider, binding, _site);

            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            item.SubItems[1].Text = binding.Host.HostToDisplay();
            item.SubItems[2].Text = binding.EndPoint.Port.ToString(CultureInfo.InvariantCulture);
            item.SubItems[3].Text = binding.EndPoint.Address.AddressToDisplay();
            await _site.Server.CommitChangesAsync();
        }
Example #3
0
        public BindingsDialog(IServiceProvider serviceProvider, Site site)
            : base(serviceProvider)
        {
            InitializeComponent();
            _site = site;
            foreach (Binding binding in site.Bindings)
            {
                var node = new ListViewItem(new[]
                {
                    binding.Protocol,
                    binding.Host.HostToDisplay(),
                    binding.EndPoint?.Port.ToString(CultureInfo.InvariantCulture),
                    binding.EndPoint?.Address.AddressToDisplay(),
                    binding.CanBrowse ? string.Empty : binding.BindingInformation
                })
                {
                    Tag = binding
                };
                listView1.Items.Add(node);
            }

            var container = new CompositeDisposable();

            FormClosed += (sender, args) => container.Dispose();

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnClose, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                Close();
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(listView1, "SelectedIndexChanged")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                var selected      = listView1.SelectedItems.Count > 0;
                btnEdit.Enabled   = selected && ProtocolMatched(listView1.SelectedItems);
                btnRemove.Enabled = selected && listView1.Items.Count > 1;
                btnBrowse.Enabled = selected && ProtocolMatched(listView1.SelectedItems);

                if (!btnRemove.Enabled)
                {
                    return;
                }

                if (Helper.IsRunningOnMono())
                {
                    return;
                }

                var binding     = (Binding)listView1.SelectedItems[0].Tag;
                var supportsSni = binding.Parent.Parent.Server.SupportsSni;
                var toElevate   = selected && (!supportsSni || (supportsSni && binding.GetIsSni()));
                if (toElevate)
                {
                    JexusManager.NativeMethods.TryAddShieldToButton(btnRemove);
                }
                else
                {
                    JexusManager.NativeMethods.RemoveShieldFromButton(btnRemove);
                }
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnRemove, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                var result = MessageBox.Show("Are you sure you want to remove the selected binding?", Text, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                if (result != DialogResult.Yes)
                {
                    return;
                }

                var binding = (Binding)listView1.SelectedItems[0].Tag;
                binding.CleanUpSni();
                listView1.SelectedItems[0].Remove();
                _site.Bindings.Remove(binding);
                _site.Server.CommitChanges();
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnEdit, "Click")
                .Merge(Observable.FromEventPattern <EventArgs>(listView1, "MouseDoubleClick"))
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                if (listView1.SelectedItems.Count == 0)
                {
                    return;
                }

                var item    = listView1.SelectedItems[0];
                var binding = (Binding)item.Tag;
                var dialog  = new BindingDialog(ServiceProvider, binding, _site);
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                item.SubItems[1].Text = binding.Host.HostToDisplay();
                item.SubItems[2].Text = binding.EndPoint.Port.ToString(CultureInfo.InvariantCulture);
                item.SubItems[3].Text = binding.EndPoint.Address.AddressToDisplay();
                _site.Server.CommitChanges();
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnAdd, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                var dialog = new BindingDialog(ServiceProvider, null, _site);
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                var binding = dialog.Binding;
                if (binding == null)
                {
                    return;
                }

                var node = new ListViewItem(new[]
                {
                    binding.Protocol,
                    binding.Host.HostToDisplay(),
                    binding.EndPoint.Port.ToString(CultureInfo.InvariantCulture),
                    binding.EndPoint.Address.AddressToDisplay(),
                    string.Empty
                })
                {
                    Tag = binding
                };
                listView1.Items.Add(node);
                _site.Bindings.Add(binding);
                _site.Server.CommitChanges();
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnBrowse, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                var binding = (Binding)listView1.SelectedItems[0].Tag;
                DialogHelper.ProcessStart(binding.ToUri());
            }));
        }