Пример #1
0
        public static List <IISTreeNode> Build()
        {
            var rootName = $"{Environment.MachineName}({Environment.UserDomainName}\\{Environment.UserName})";
            var rootNode = new IISTreeNode {
                Id = -1, Text = rootName, HasContextMenu = false, Nodes = new List <IISTreeNode>()
            };

            var controller = IISController.GetController();

            var appPools    = controller.GetAllPoolInfos();
            var appPoolNode = new IISTreeNode {
                Id = -2, Text = "Application Pools", State = new { Expanded = false }, HasContextMenu = false, Nodes = new List <IISTreeNode>()
            };

            appPoolNode.Nodes.AddRange(appPools.Data.Select((a, i) => new IISTreeNode {
                Id = appPoolNode.Id - i - 1, Text = a.Name, HasContextMenu = false
            }));
            rootNode.Nodes.Add(appPoolNode);

            var sites    = controller.GetAllSites();
            var siteNode = new IISTreeNode {
                Id = 0, Text = "Web Sites", HasContextMenu = false, Nodes = new List <IISTreeNode>()
            };

            siteNode.Nodes.AddRange(sites.Data.Select(s => new IISTreeNode {
                Id = s.ID, Text = s.Name, HasContextMenu = true, IsSite = true, Status = (int)s.State
            }));
            rootNode.Nodes.Add(siteNode);

            var nodes = new List <IISTreeNode>();

            nodes.Add(rootNode);
            return(nodes);
        }
Пример #2
0
        private dynamic ExecSiteCommand()
        {
            var cmd        = Context.Request.Form["cmd"].Value;
            var id         = long.Parse(Context.Request.Form["id"].Value);
            var controller = IISController.GetController();

            if (cmd != "start" && cmd != "stop")
            {
                return(Response.AsJson <dynamic>(new { success = false, message = "Invalid command." }));
            }
            if (cmd == "start")
            {
                controller.StartSite(new Core.Domain.IISStartInfo {
                    ParentID = id
                });
                return(Response.AsJson <dynamic>(new { success = true, status = 2 }));
            }
            else
            {
                controller.StopSite(new Core.Domain.IISStartInfo {
                    ParentID = id
                });
                return(Response.AsJson <dynamic>(new { success = true, status = 4 }));
            }
        }
Пример #3
0
        private void BindViewSitesDataGrid()
        {
            this.sites = IISController.GetSites(true).OrderBy(s => s.Name);
            using (var deleteButton = new DataGridViewButtonColumn())
            {
                deleteButton.Text       = "Delete";
                deleteButton.Name       = "Delete";
                deleteButton.HeaderText = string.Empty;

                this.dataGridViewSites.AllowUserToDeleteRows = true;
                this.dataGridViewSites.Columns.Clear();
                this.dataGridViewSites.Columns.Add(deleteButton);
                this.dataGridViewSites.Columns.Add("Id", "ID");
                this.dataGridViewSites.Columns.Add(new DataGridViewLinkColumn()
                {
                    Name = "SiteName", HeaderText = "Site Name"
                });
                this.dataGridViewSites.Columns.Add("ApplicationPool", "Application Pool");
                this.dataGridViewSites.Columns.Add("State", "State");
                this.dataGridViewSites.Columns.Add("Path", "Path");

                this.dataGridViewSites.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                this.dataGridViewSites.Columns["Id"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
                this.dataGridViewSites.Columns["Path"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            }

            this.dataGridViewSites.Rows.Clear();
            foreach (var site in this.sites)
            {
                this.dataGridViewSites.Rows.Add(
                    "Delete",
                    site.Id,
                    site.Name,
                    site.ApplicationDefaults.ApplicationPoolName,
                    site.State.ToString(),
                    site.Applications["/"].VirtualDirectories["/"].PhysicalPath);
            }

            this.dataGridViewSites.AutoResizeColumns();
            this.dataGridViewSites.CellContentClick += this.DataGridViewSites_CellContentClick;
        }
Пример #4
0
        private async void DeleteSite()
        {
            using (var iisManager = new ServerManager())
            {
                // Stop Site
                var stopSiteProgress = new Progress <int>(percent =>
                {
                    this.progressStopSite.Value = percent;
                    this.UpdateTotalProgress();
                });
                try
                {
                    await Task.Run(() => IISController.StopSite(this.site.Id, stopSiteProgress)).ConfigureAwait(true);
                }
                catch (ArgumentException ex)
                {
                    this.Abort(ex.Source, ex.Message);
                }

                // Stop AppPool
                var stopAppPoolProgress = new Progress <int>(percent =>
                {
                    this.progressStopAppPool.Value = percent;
                    this.UpdateTotalProgress();
                });
                try
                {
                    await Task.Run(() => IISController.StopAppPool(this.site.Id, stopAppPoolProgress)).ConfigureAwait(true);
                }
                catch (ArgumentException ex)
                {
                    this.Abort(ex.Source, ex.Message);
                }

                // Delete Database
                var deleteDatabaseProgress = new Progress <int>(percent =>
                {
                    this.progressDeleteDatabae.Value = percent;
                    this.UpdateTotalProgress();
                });
                try
                {
                    var installFolder      = Directory.GetParent(this.sitePath);
                    var databaseController = new DatabaseController(
                        this.site.Name.Split('.')[0],
                        Properties.Settings.Default.DatabaseServerNameRecent,
                        true,
                        string.Empty,
                        string.Empty,
                        installFolder.FullName,
                        true,
                        this.site.Name);
                    await Task.Run(() => databaseController.DeleteDatabase(deleteDatabaseProgress)).ConfigureAwait(true);
                }
                catch (ArgumentException ex)
                {
                    this.Abort(ex.Source, ex.Message);
                    throw;
                }

                // Delete files
                var deleteFilesProgress = new Progress <string>(name =>
                {
                    if (this.progressDeleteFiles.Value < this.progressDeleteFiles.Maximum)
                    {
                        this.progressDeleteFiles.Value++;
                        this.UpdateTotalProgress();
                    }
                });
                try
                {
                    await Task.Run(() => FileSystemController.DeleteDirectory(this.sitePath, deleteFilesProgress, true)).ConfigureAwait(true);
                }
                catch (IOException)
                {
                    // Files mights still be streaming (logs for instance) after the site is stopped and deleted. Let's wait a bit and retry once after waiting 10 seconds.
                    Thread.Sleep(10000);
                    await Task.Run(() => FileSystemController.DeleteDirectory(this.sitePath, deleteFilesProgress, true)).ConfigureAwait(true);
                }

                this.progressDeleteFiles.Value = this.progressDeleteFiles.Maximum;
                this.UpdateTotalProgress();

                // Delete entry from HOSTS file
                var deleteHostEntryProgress = new Progress <int>(percent =>
                {
                    this.progressRemoveHostEntry.Value = percent;
                    this.UpdateTotalProgress();
                });
                await Task.Run(() => FileSystemController.RemoveHostEntry(this.site.Name, deleteHostEntryProgress)).ConfigureAwait(true);

                // Delete Site
                var deleteSiteProgress = new Progress <int>(percent =>
                {
                    this.progressDeletingSite.Value = percent;
                    this.UpdateTotalProgress();
                });
                try
                {
                    await Task.Run(() => IISController.DeleteSite(this.site.Id, deleteSiteProgress)).ConfigureAwait(true);
                }
                catch (ArgumentException ex)
                {
                    this.Abort(ex.Source, ex.Message);
                }

                // Try to delete AppPool if possible
                var deleteAppPoolProgress = new Progress <int>(percent =>
                {
                    this.progressDeleteAppPool.Value = percent;
                    this.UpdateTotalProgress();
                });
                try
                {
                    await Task.Run(() => IISController.DeleteAppPool(this.site.ApplicationDefaults.ApplicationPoolName, deleteAppPoolProgress)).ConfigureAwait(true);
                }
                catch (ArgumentException ex)
                {
                    DialogController.ShowMessage(
                        ex.Source,
                        ex.Message,
                        SystemIcons.Error,
                        DialogController.DialogButtons.OK);
                }
            }

            this.progressTotal.Value = this.progressTotal.Maximum;

            DialogController.ShowMessage(
                "Site Deleted",
                $"{this.site.Name} has been deleted successfully.",
                SystemIcons.Information,
                DialogController.DialogButtons.OK);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Пример #5
0
        private void btnDatabaseInfoNext_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(this.txtDBServerName.Text) || string.IsNullOrWhiteSpace(this.txtDBName.Text))
            {
                DialogController.ShowMessage(
                    "Database Info",
                    "Please make sure you have entered a Database Server Name and\na Database Name.",
                    SystemIcons.Warning,
                    DialogController.DialogButtons.OK);

                return;
            }

            try
            {
                IISController.CreateSite(
                    this.SiteName,
                    this.InstallFolder,
                    this.chkSiteSpecificAppPool.Checked,
                    this.chkDeleteSiteIfExists.Checked);

                FileSystemController.UpdateHostsFile(this.SiteName);

                FileSystemController.CreateDirectories(
                    this.InstallFolder,
                    this.SiteName,
                    this.chkSiteSpecificAppPool.Checked,
                    this.txtDBServerName.Text.Trim(),
                    this.txtDBServerName.Text,
                    this.rdoWindowsAuthentication.Checked,
                    this.txtDBUserName.Text,
                    this.txtDBPassword.Text);

                var databaseController = new DatabaseController(
                    this.txtDBName.Text,
                    this.txtDBServerName.Text,
                    this.rdoWindowsAuthentication.Checked,
                    this.txtDBUserName.Text,
                    this.txtDBPassword.Text,
                    this.InstallFolder,
                    this.chkSiteSpecificAppPool.Checked,
                    this.SiteName);
                databaseController.CreateDatabase();
                databaseController.SetDatabasePermissions();

                this.tabInstallPackage.Enabled = false;
                this.tabSiteInfo.Enabled       = false;
                this.tabDatabaseInfo.Enabled   = false;
                this.tabControl.TabPages.Insert(3, this.tabProgress);
                this.tabProgress.Enabled      = true;
                this.lblProgress.Visible      = true;
                this.progressBar.Visible      = true;
                this.tabControl.SelectedIndex = 3;

                this.SaveUserSettings();

                this.ReadAndExtract(this.txtLocalInstallPackage.Text, Path.Combine(this.txtInstallBaseFolder.Text, this.txtInstallSubFolder.Text, "Website"));
                FileSystemController.ModifyConfig(
                    this.txtDBServerName.Text,
                    this.rdoWindowsAuthentication.Checked,
                    this.txtDBUserName.Text,
                    this.txtDBPassword.Text,
                    this.txtDBName.Text,
                    this.InstallFolder);

                this.btnVisitSite.Visible = true;
                Log.Logger.Information("Site {siteName} ready to visit", this.SiteName);
            }
            catch (SiteExistsException ex)
            {
                DialogController.ShowMessage(ex.Source, ex.Message, SystemIcons.Warning, DialogController.DialogButtons.OK);
            }
            catch (IISControllerException ex)
            {
                DialogController.ShowMessage(ex.Source, ex.Message, SystemIcons.Error, DialogController.DialogButtons.OK);
            }
            catch (FileSystemControllerException ex)
            {
                DialogController.ShowMessage(ex.Source, ex.Message, SystemIcons.Error, DialogController.DialogButtons.OK);
            }
            catch (DatabaseControllerException ex)
            {
                DialogController.ShowMessage(ex.Source, ex.Message, SystemIcons.Error, DialogController.DialogButtons.OK);
            }
            catch (Exception ex)
            {
                DialogController.ShowMessage("Database Info Next", ex.Message, SystemIcons.Error, DialogController.DialogButtons.OK);
                throw;
            }
        }