⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iiscreatesitewindow.cs

📁 用ADSI操作IIS文件
💻 CS
字号:
// IIsAdmin.NET
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This softwareis provided "AS IS" with no warranties of any kind.
// The entire risk arising out of the use or performance of the software
// and source code is with you.
//
// THIS NOTICE MAY NOT BE REMOVED FROM THIS FILE.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;

namespace IIsAdmin
{
    /// <summary>
    /// Summary description for CreateSite.
    /// </summary>
    public class IIsCreateSiteWindow : System.Windows.Forms.Form
    {
        private System.Windows.Forms.Label _labelDescription;
        private System.Windows.Forms.Label _labelPort;
        private System.Windows.Forms.Label _labelDirectory;
        private System.Windows.Forms.Button _buttonBrowse;
        private System.Windows.Forms.Button _buttonSave;
        private System.Windows.Forms.Button _buttonCancel;
        private System.Windows.Forms.TextBox _textBoxDescription;
        private System.Windows.Forms.TextBox _textBoxPort;
        private System.Windows.Forms.TextBox _textBoxDirectory;
        private System.Windows.Forms.FolderBrowserDialog _fileBrowserDialogHomeDirectory;
        private Container components = null;

        public IIsCreateSiteWindow()
        {
            InitializeComponent();

            _buttonSave.Click += new EventHandler(this.ButtonSave_Click);
            _buttonBrowse.Click += new EventHandler(this.ButtonBrowse_Click);
        }

        /// <summary>
        /// Validate the form and save the new website
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonSave_Click(object sender, EventArgs e)
        {
            if(this.IsValid())
            {
                IIsWebSite ws = IIsAdministrator.CreateWebSite(_textBoxDescription.Text, _textBoxDirectory.Text, Convert.ToInt32(_textBoxPort.Text));
                this._buttonSave.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        /// <summary>
        /// Open the file browser dialog
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonBrowse_Click(object sender, EventArgs e)
        {
            if(Directory.Exists(this._textBoxDirectory.Text))
            {
                this._fileBrowserDialogHomeDirectory.SelectedPath = this._textBoxDirectory.Text;
            }
            else if(Directory.Exists(IIsConstants.DefaultRootDirectory))
            {
                this._fileBrowserDialogHomeDirectory.SelectedPath = IIsConstants.DefaultRootDirectory;
            }

            if(_fileBrowserDialogHomeDirectory.ShowDialog(this) == DialogResult.OK)
            {
                _textBoxDirectory.Text = _fileBrowserDialogHomeDirectory.SelectedPath;
            }
        }

        /// <summary>
        /// Validates the create site form
        /// </summary>
        /// <returns></returns>
        private bool IsValid()
        {
            if(_textBoxDescription.Text == string.Empty)
            {
                ExceptionUtilities.DisplayValidation("Please enter your site's name.");
                _textBoxDescription.Focus();
                return false;
            }

            if(_textBoxPort.Text.Length != 0 && !ExceptionUtilities.IsNumeric(_textBoxPort.Text))
            {
                ExceptionUtilities.DisplayValidation("Please enter a valid port.");
                _textBoxPort.Focus();
                return false;
            }

            if(!Directory.Exists(_textBoxDirectory.Text))
            {
                ExceptionUtilities.DisplayValidation("Please enter a valid home directory.");
                _textBoxDirectory.Focus();
                return false;
            }

            return true;
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this._fileBrowserDialogHomeDirectory = new System.Windows.Forms.FolderBrowserDialog();
            this._labelDescription = new System.Windows.Forms.Label();
            this._labelPort = new System.Windows.Forms.Label();
            this._textBoxDescription = new System.Windows.Forms.TextBox();
            this._textBoxPort = new System.Windows.Forms.TextBox();
            this._labelDirectory = new System.Windows.Forms.Label();
            this._textBoxDirectory = new System.Windows.Forms.TextBox();
            this._buttonBrowse = new System.Windows.Forms.Button();
            this._buttonSave = new System.Windows.Forms.Button();
            this._buttonCancel = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // _labelDescription
            // 
            this._labelDescription.Location = new System.Drawing.Point(32, 14);
            this._labelDescription.Name = "_labelDescription";
            this._labelDescription.Size = new System.Drawing.Size(64, 16);
            this._labelDescription.TabIndex = 0;
            this._labelDescription.Text = "Description:";
            // 
            // _labelPort
            // 
            this._labelPort.Location = new System.Drawing.Point(64, 40);
            this._labelPort.Name = "_labelPort";
            this._labelPort.Size = new System.Drawing.Size(32, 16);
            this._labelPort.TabIndex = 1;
            this._labelPort.Text = "Port:";
            // 
            // _textBoxDescription
            // 
            this._textBoxDescription.Location = new System.Drawing.Point(96, 12);
            this._textBoxDescription.Name = "_textBoxDescription";
            this._textBoxDescription.Size = new System.Drawing.Size(152, 20);
            this._textBoxDescription.TabIndex = 2;
            this._textBoxDescription.Text = "";
            // 
            // _textBoxPort
            // 
            this._textBoxPort.Location = new System.Drawing.Point(96, 40);
            this._textBoxPort.Name = "_textBoxPort";
            this._textBoxPort.TabIndex = 3;
            this._textBoxPort.Text = "80";
            // 
            // _labelDirectory
            // 
            this._labelDirectory.Location = new System.Drawing.Point(9, 67);
            this._labelDirectory.Name = "_labelDirectory";
            this._labelDirectory.Size = new System.Drawing.Size(88, 20);
            this._labelDirectory.TabIndex = 4;
            this._labelDirectory.Text = "Home Directory:";
            // 
            // _textBoxDirectory
            // 
            this._textBoxDirectory.Location = new System.Drawing.Point(95, 67);
            this._textBoxDirectory.Name = "_textBoxDirectory";
            this._textBoxDirectory.Size = new System.Drawing.Size(257, 20);
            this._textBoxDirectory.TabIndex = 5;
            this._textBoxDirectory.Text = "";
            // 
            // _buttonBrowse
            // 
            this._buttonBrowse.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._buttonBrowse.Location = new System.Drawing.Point(357, 64);
            this._buttonBrowse.Name = "_buttonBrowse";
            this._buttonBrowse.TabIndex = 6;
            this._buttonBrowse.Text = "Browse...";
            // 
            // _buttonSave
            // 
            this._buttonSave.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._buttonSave.Location = new System.Drawing.Point(277, 112);
            this._buttonSave.Name = "_buttonSave";
            this._buttonSave.TabIndex = 7;
            this._buttonSave.Text = "Save";
            // 
            // _buttonCancel
            // 
            this._buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this._buttonCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this._buttonCancel.Location = new System.Drawing.Point(357, 112);
            this._buttonCancel.Name = "_buttonCancel";
            this._buttonCancel.TabIndex = 8;
            this._buttonCancel.Text = "Cancel";
            // 
            // IIsCreateSiteWindow
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(442, 144);
            this.Controls.Add(this._buttonCancel);
            this.Controls.Add(this._buttonSave);
            this.Controls.Add(this._buttonBrowse);
            this.Controls.Add(this._textBoxDirectory);
            this.Controls.Add(this._labelDirectory);
            this.Controls.Add(this._textBoxPort);
            this.Controls.Add(this._textBoxDescription);
            this.Controls.Add(this._labelPort);
            this.Controls.Add(this._labelDescription);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "IIsCreateSiteWindow";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            this.Text = "Create New Site";
            this.ResumeLayout(false);

        }
        #endregion
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -