Exemplo n.º 1
0
        public NewVirtualDirectoryDialog(IServiceProvider serviceProvider, VirtualDirectory existing, string pathToSite, Application application)
            : base(serviceProvider)
        {
            InitializeComponent();
            txtSite.Text      = application.Site.Name;
            txtPath.Text      = pathToSite;
            btnBrowse.Visible = application.Server.IsLocalhost;
            VirtualDirectory  = existing;
            Text = VirtualDirectory == null ? "Add Virtual Directory" : "Edit Virtual Directory";
            txtAlias.ReadOnly = VirtualDirectory != null;
            if (VirtualDirectory == null)
            {
                // TODO: test if IIS does this
            }
            else
            {
                txtAlias.Text        = VirtualDirectory.Path.PathToName();
                txtPhysicalPath.Text = VirtualDirectory.PhysicalPath;
                RefreshButton();
            }

            var item = new ConnectAsItem(VirtualDirectory);

            var container = new CompositeDisposable();

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

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnBrowse, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                DialogHelper.ShowBrowseDialog(txtPhysicalPath, application.GetActualExecutable());
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(txtAlias, "TextChanged")
                .Merge(Observable.FromEventPattern <EventArgs>(txtPhysicalPath, "TextChanged"))
                .Sample(TimeSpan.FromSeconds(0.5))
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                RefreshButton();
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnOK, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                foreach (var ch in ApplicationCollection.InvalidApplicationPathCharacters())
                {
                    if (txtAlias.Text.Contains(ch.ToString(CultureInfo.InvariantCulture)))
                    {
                        ShowMessage("The application path cannot contain the following characters: \\, ?, ;, :, @, &, =, +, $, ,, |, \", <, >, *.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        return;
                    }
                }

                foreach (var ch in SiteCollection.InvalidSiteNameCharactersJexus())
                {
                    if (txtAlias.Text.Contains(ch.ToString(CultureInfo.InvariantCulture)))
                    {
                        ShowMessage("The site name cannot contain the following characters: ' '.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        return;
                    }
                }

                if (!application.Server.Verify(txtPhysicalPath.Text, application.GetActualExecutable()))
                {
                    ShowMessage("The specified directory does not exist on the server.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    return;
                }

                if (VirtualDirectory == null)
                {
                    string path = "/" + txtAlias.Text;
                    foreach (VirtualDirectory virtualDirectory in application.VirtualDirectories)
                    {
                        if (string.Equals(virtualDirectory.Path, path, StringComparison.OrdinalIgnoreCase))
                        {
                            ShowMessage("This virtual directory already exists.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                            return;
                        }
                    }

                    var fullPath = $"{txtPath.Text}{path}";
                    foreach (Application app in application.Site.Applications)
                    {
                        if (string.Equals(fullPath, app.Path))
                        {
                            ShowMessage("An application with this virtual path already exists.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                            return;
                        }
                    }

                    try
                    {
                        VirtualDirectory = new VirtualDirectory(null, application.VirtualDirectories)
                        {
                            Path = path
                        };
                    }
                    catch (COMException ex)
                    {
                        ShowError(ex, Text, false);
                        return;
                    }

                    VirtualDirectory.PhysicalPath = txtPhysicalPath.Text;
                    VirtualDirectory.Parent.Add(VirtualDirectory);

                    item.Element = VirtualDirectory;
                    item.Apply();
                }
                else
                {
                    VirtualDirectory.PhysicalPath = txtPhysicalPath.Text;
                }

                DialogResult = DialogResult.OK;
            }));

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

                item.Apply();
                RefreshButton();
                txtConnectAs.Text = string.IsNullOrEmpty(item.UserName)
                        ? "Pass-through authentication"
                        : $"connect as '{item.UserName}'";
            }));

            txtConnectAs.Text = string.IsNullOrEmpty(item.UserName)
                ? "Pass-through authentication"
                : $"connect as '{item.UserName}'";
        }
Exemplo n.º 2
0
        public override void Expand(MainForm mainForm)
        {
            if (_loaded)
            {
                return;
            }

            _loaded = true;
            Nodes.Clear();
            var rootFolder = Application.PhysicalPath.ExpandIisExpressEnvironmentVariables(Application.GetActualExecutable());
            var rootLevel  = GetLevel(Application.Path);

            LoadChildren(Application, rootLevel, rootFolder, Application.Path, mainForm.PhysicalDirectoryMenu, mainForm.VirtualDirectoryMenu, mainForm.ApplicationMenu);
        }
Exemplo n.º 3
0
        public EditSiteDialog(IServiceProvider serviceProvider, Application application)
            : base(serviceProvider)
        {
            InitializeComponent();
            _application         = application;
            txtPool.Text         = application.ApplicationPoolName;
            txtAlias.Text        = application.Site.Name;
            txtPhysicalPath.Text = application.PhysicalPath;
            btnBrowse.Visible    = application.Server.IsLocalhost;
            btnSelect.Enabled    = application.Server.Mode != WorkingMode.Jexus;
            RefreshButton();

            var container = new CompositeDisposable();

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

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnOK, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                if (!_application.Server.Verify(txtPhysicalPath.Text, _application.GetActualExecutable()))
                {
                    MessageBox.Show("The specified directory does not exist on the server.", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                _application.PhysicalPath        = txtPhysicalPath.Text;
                _application.ApplicationPoolName = txtPool.Text;
                _application.Server.CommitChanges();
                DialogResult = DialogResult.OK;
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(txtPhysicalPath, "TextChanged")
                .Merge(Observable.FromEventPattern <EventArgs>(txtPool, "TextChanged"))
                .Sample(TimeSpan.FromSeconds(1))
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                RefreshButton();
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnBrowse, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                DialogHelper.ShowBrowseDialog(txtPhysicalPath, _application.GetActualExecutable());
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnSelect, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                var dialog = new SelectPoolDialog(txtPool.Text, _application.Server);
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                txtPool.Text = dialog.Selected.Name;
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnConnect, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                var item   = new ConnectAsItem(_application.VirtualDirectories[0]);
                var dialog = new ConnectAsDialog(ServiceProvider, item);
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                item.Apply();
                txtConnectAs.Text = string.IsNullOrEmpty(application.VirtualDirectories[0].UserName)
                        ? "Pass-through authentication"
                        : $"connect as '{application.VirtualDirectories[0].UserName}'";
                RefreshButton();
            }));

            txtConnectAs.Text = string.IsNullOrEmpty(application.VirtualDirectories[0].UserName)
                ? "Pass-through authentication"
                : $"connect as '{application.VirtualDirectories[0].UserName}'";
        }