/// <summary>
 /// Adds the range.
 /// </summary>
 /// <param name="WebServers">The web servers.</param>
 public void AddRange(IISWebServer[] WebServers)
 {
     for (int i = 0; i <= WebServers.GetUpperBound(0); i++)
     {
         Add(WebServers[i]);
     }
 }
 /// <summary>
 /// Adds the specified web server.
 /// </summary>
 /// <param name="WebServer">The web server.</param>
 public void Add(IISWebServer WebServer)
 {
     try {
         this.List.Add(WebServer);
         IISManagement.CreateIISWebServer(WebServer);
     }
     catch {
         throw (new Exception("发生意外错误,可能是某节点将该节点的上级节点作为它自己的子级插入"));
     }
 }
        /// <summary>
        /// 创建站点
        /// </summary>
        /// <param name="iisServer">The IIS server.</param>
        public static void CreateIISWebServer(IISWebServer iisServer)
        {
            if (iisServer.ServerComment.ToString() == "")
                throw (new Exception("IISWebServer的ServerComment不能为空!"));
            DirectoryEntry Service = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
            DirectoryEntry Server;
            int i = 0;
            IEnumerator ie = Service.Children.GetEnumerator();

            while (ie.MoveNext()) {
                Server = (DirectoryEntry)ie.Current;
                if (Server.SchemaClassName == "IIsWebServer") {
                    if (Convert.ToInt32(Server.Name) > i)
                        i = Convert.ToInt32(Server.Name);
                    //     if( Server.Properties["Serverbindings"][0].ToString() == ":" + iisServer.Port + ":" )
                    //     {
                    //      Server.Invoke("stop",new object[0]);
                    //     }
                }
            }

            i++;

            try {
                iisServer.index = i;
                Server = Service.Children.Add(i.ToString(), "IIsWebServer");
                Server.Properties["ServerComment"][0] = iisServer.ServerComment;
                Server.Properties["Serverbindings"].Add(":" + iisServer.Port + ":");
                Server.Properties["AccessScript"][0] = iisServer.AccessScript;
                Server.Properties["AccessRead"][0] = iisServer.AccessRead;
                Server.Properties["EnableDirBrowsing"][0] = iisServer.EnableDirBrowsing;
                Server.Properties["DefaultDoc"][0] = iisServer.DefaultDoc;
                Server.Properties["EnableDefaultDoc"][0] = iisServer.EnableDefaultDoc;

                DirectoryEntry root = Server.Children.Add("Root", "IIsWebVirtualDir");
                root.Properties["path"][0] = iisServer.Path;

                Service.CommitChanges();
                Server.CommitChanges();
                root.CommitChanges();
                root.Invoke("AppCreate2", new object[1] { 2 });
                //Server.Invoke("start",new object[0]);
            }
            catch (Exception ex) {
                throw (ex);
            }
        }
 /// <summary>
 /// Add_s the specified web server.
 /// </summary>
 /// <param name="WebServer">The web server.</param>
 internal void AddWebServer(IISWebServer WebServer)
 {
     this.List.Add(WebServer);
 }
 /// <summary>
 /// Removes the specified web server.
 /// </summary>
 /// <param name="WebServer">The web server.</param>
 public void Remove(IISWebServer WebServer)
 {
     for (int i = 0; i < this.List.Count; i++)
     {
         if ((IISWebServer)this.List[i] == WebServer)
         {
             this.List.RemoveAt(i);
             return;
         }
     }
     IISManagement.RemoveIISWebServer(WebServer.index);
 }
 /// <summary>
 /// Add_s the specified web server.
 /// </summary>
 /// <param name="WebServer">The web server.</param>
 internal void AddWebServer(IISWebServer WebServer)
 {
     this.List.Add(WebServer);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="IISWebVirtualDirCollection"/> class.
 /// </summary>
 /// <param name="Parent">The parent.</param>
 public IISWebVirtualDirCollection(IISWebServer Parent)
 {
     this.Parent = Parent;
 }
Beispiel #8
0
        /// <summary>
        /// Starts this instance.
        /// </summary>
        private void Start()
        {
            DirectoryEntry   Service = new DirectoryEntry("IIS://" + Machinename + "/W3SVC");
            DirectoryEntry   Server;
            DirectoryEntry   Root = null;
            DirectoryEntry   VirDir;
            IEnumerator      ie = Service.Children.GetEnumerator();
            IEnumerator      ieRoot;
            IISWebServer     item;
            IISWebVirtualDir item_virdir;
            bool             finded = false;

            // 枚举所有Web网站
            while (ie.MoveNext())
            {
                Server = (DirectoryEntry)ie.Current;
                if (Server.SchemaClassName == "IIsWebServer")
                {
                    item       = new IISWebServer();
                    item.index = Convert.ToInt32(Server.Name);

                    item.ServerComment     = (string)Server.Properties["ServerComment"][0];
                    item.AccessRead        = (bool)Server.Properties["AccessRead"][0];
                    item.AccessScript      = (bool)Server.Properties["AccessScript"][0];
                    item.DefaultDoc        = (string)Server.Properties["DefaultDoc"][0];
                    item.EnableDefaultDoc  = (bool)Server.Properties["EnableDefaultDoc"][0];
                    item.EnableDirBrowsing = (bool)Server.Properties["EnableDirBrowsing"][0];

                    // 确认其是否是站点
                    ieRoot = Server.Children.GetEnumerator();
                    while (ieRoot.MoveNext())
                    {
                        Root = (DirectoryEntry)ieRoot.Current;
                        if (Root.SchemaClassName == "IIsWebVirtualDir")
                        {
                            finded = true;
                            break;
                        }
                    }

                    if (finded)
                    {
                        item.Path = Root.Properties["path"][0].ToString(); // 获取站点路径
                    }
                    string[] bindings = Server.Properties["ServerBindings"][0].ToString().Split(':');
                    item.Port = Convert.ToInt32(bindings[1]); // 获取站点的端口
                    this.WebServers.AddWebServer(item);

                    // 枚举网点下的虚拟目录
                    ieRoot = Root.Children.GetEnumerator();
                    while (ieRoot.MoveNext())
                    {
                        VirDir = (DirectoryEntry)ieRoot.Current;
                        if (VirDir.SchemaClassName != "IIsWebVirtualDir" && VirDir.SchemaClassName != "IIsWebDirectory")
                        {
                            continue;
                        }

                        item_virdir                  = new IISWebVirtualDir(item.ServerComment);
                        item_virdir.Name             = VirDir.Name;
                        item_virdir.AccessRead       = (bool)VirDir.Properties["AccessRead"][0];
                        item_virdir.AccessScript     = (bool)VirDir.Properties["AccessScript"][0];
                        item_virdir.DefaultDoc       = (string)VirDir.Properties["DefaultDoc"][0];
                        item_virdir.EnableDefaultDoc = (bool)VirDir.Properties["EnableDefaultDoc"][0];

                        switch (VirDir.SchemaClassName)
                        {
                        case "IIsWebVirtualDir":
                            item_virdir.Path = (string)VirDir.Properties["Path"][0];
                            break;

                        case "IIsWebDirectory":
                            item_virdir.Path = Root.Properties["Path"][0] + "\\" + VirDir.Name;
                            break;
                        }
                        item.WebVirtualDirs.Add_(item_virdir);
                    }
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="IISWebVirtualDirCollection"/> class.
 /// </summary>
 /// <param name="Parent">The parent.</param>
 public IISWebVirtualDirCollection(IISWebServer Parent)
 {
     this.Parent = Parent;
 }
Beispiel #10
0
        /// <summary>
        /// Starts this instance.
        /// </summary>
        private void Start()
        {
            DirectoryEntry Service = new DirectoryEntry("IIS://" + Machinename + "/W3SVC");
            DirectoryEntry Server;
            DirectoryEntry Root = null;
            DirectoryEntry VirDir;
            IEnumerator ie = Service.Children.GetEnumerator();
            IEnumerator ieRoot;
            IISWebServer item;
            IISWebVirtualDir item_virdir;
            bool finded = false;

            // 枚举所有Web网站
            while (ie.MoveNext()) {
                Server = (DirectoryEntry)ie.Current;
                if (Server.SchemaClassName == "IIsWebServer") {
                    item = new IISWebServer();
                    item.index = Convert.ToInt32(Server.Name);

                    item.ServerComment = (string)Server.Properties["ServerComment"][0];
                    item.AccessRead = (bool)Server.Properties["AccessRead"][0];
                    item.AccessScript = (bool)Server.Properties["AccessScript"][0];
                    item.DefaultDoc = (string)Server.Properties["DefaultDoc"][0];
                    item.EnableDefaultDoc = (bool)Server.Properties["EnableDefaultDoc"][0];
                    item.EnableDirBrowsing = (bool)Server.Properties["EnableDirBrowsing"][0];

                    // 确认其是否是站点
                    ieRoot = Server.Children.GetEnumerator();
                    while (ieRoot.MoveNext()) {
                        Root = (DirectoryEntry)ieRoot.Current;
                        if (Root.SchemaClassName == "IIsWebVirtualDir") {
                            finded = true;
                            break;
                        }
                    }

                    if (finded)
                        item.Path = Root.Properties["path"][0].ToString(); // 获取站点路径

                    string[] bindings = Server.Properties["ServerBindings"][0].ToString().Split(':');
                    item.Port = Convert.ToInt32(bindings[1]); // 获取站点的端口
                    this.WebServers.AddWebServer(item);

                    // 枚举网点下的虚拟目录
                    ieRoot = Root.Children.GetEnumerator();
                    while (ieRoot.MoveNext()) {
                        VirDir = (DirectoryEntry)ieRoot.Current;
                        if (VirDir.SchemaClassName != "IIsWebVirtualDir" && VirDir.SchemaClassName != "IIsWebDirectory")
                            continue;

                        item_virdir = new IISWebVirtualDir(item.ServerComment);
                        item_virdir.Name = VirDir.Name;
                        item_virdir.AccessRead = (bool)VirDir.Properties["AccessRead"][0];
                        item_virdir.AccessScript = (bool)VirDir.Properties["AccessScript"][0];
                        item_virdir.DefaultDoc = (string)VirDir.Properties["DefaultDoc"][0];
                        item_virdir.EnableDefaultDoc = (bool)VirDir.Properties["EnableDefaultDoc"][0];

                        switch (VirDir.SchemaClassName) {
                            case "IIsWebVirtualDir" :
                                item_virdir.Path = (string)VirDir.Properties["Path"][0];
                                break;

                            case "IIsWebDirectory" :
                                item_virdir.Path = Root.Properties["Path"][0] + "\\" + VirDir.Name;
                                break;
                        }
                        item.WebVirtualDirs.Add_(item_virdir);
                    }
                }
            }
        }
Beispiel #11
0
        /// <summary>
        /// 修改与给定的IISWebServer具有相同网站说明的站点配置
        /// </summary>
        /// <param name="iisServer">给定的IISWebServer</param>
        public static void EditIISWebServer(IISWebServer iisServer)
        {
            if (iisServer.index == -1)
                throw (new Exception("找不到给定的站点!"));

            DirectoryEntry Service = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
            DirectoryEntry Server;

            IEnumerator ie = Service.Children.GetEnumerator();

            while (ie.MoveNext()) {
                Server = (DirectoryEntry)ie.Current;
                if (Server.SchemaClassName == "IIsWebServer") {
                    if (Server.Properties["Serverbindings"][0].ToString() == ":" + iisServer.Port + ":") {
                        Server.Invoke("stop", new object[0]);
                    }
                }
            }

            Server = GetIISWebserver(iisServer.index);
            if (Server == null) {
                throw (new Exception("找不到给定的站点!"));
            }

            try {
                Server.Properties["ServerComment"][0] = iisServer.ServerComment;
                Server.Properties["Serverbindings"][0] = ":" + iisServer.Port + ":";
                Server.Properties["AccessScript"][0] = iisServer.AccessScript;
                Server.Properties["AccessRead"][0] = iisServer.AccessRead;
                Server.Properties["EnableDirBrowsing"][0] = iisServer.EnableDirBrowsing;
                Server.Properties["DefaultDoc"][0] = iisServer.DefaultDoc;
                Server.Properties["EnableDefaultDoc"][0] = iisServer.EnableDefaultDoc;

                DirectoryEntry root = GetRoot(Server);

                Server.CommitChanges();
                if (root != null) {
                    root.Properties["path"][0] = iisServer.Path;
                    root.CommitChanges();
                }

                Server.Invoke("start", new object[0]);
            }
            catch (Exception ex) {
                throw (ex);
            }
        }