/// <summary>
 /// Add_s the specified web virtual dir.
 /// </summary>
 /// <param name="WebVirtualDir">The web virtual dir.</param>
 internal void Add_(IISWebVirtualDir WebVirtualDir)
 {
     try
     {
         this.List.Add(WebVirtualDir);
     }
     catch
     {
         throw (new Exception("发生意外错误,可能是某节点将该节点的上级节点作为它自己的子级插入"));
     }
 }
 /// <summary>
 /// Removes the specified web virtual dir.
 /// </summary>
 /// <param name="WebVirtualDir">The web virtual dir.</param>
 public void Remove(IISWebVirtualDir WebVirtualDir)
 {
     for (int i = 0; i < this.List.Count; i++)
     {
         if ((IISWebVirtualDir)this.List[i] == WebVirtualDir)
         {
             this.List.RemoveAt(i);
             IISManagement.RemoveIISWebVirtualDir(WebVirtualDir);
             return;
         }
     }
 }
 /// <summary>
 /// Adds the specified web virtual dir.
 /// </summary>
 /// <param name="WebVirtualDir">The web virtual dir.</param>
 public void Add(IISWebVirtualDir WebVirtualDir)
 {
     WebVirtualDir.Parent = this.Parent;
     try
     {
         this.List.Add(WebVirtualDir);
     }
     catch
     {
         throw (new Exception("发生意外错误,可能是某节点将该节点的上级节点作为它自己的子级插入"));
     }
     IISManagement.CreateIISWebVirtualDir(WebVirtualDir, true);
 }
 /// <summary>
 /// Adds the specified web virtual dir.
 /// </summary>
 /// <param name="WebVirtualDir">The web virtual dir.</param>
 public void Add(IISWebVirtualDir WebVirtualDir)
 {
     WebVirtualDir.Parent = this.Parent;
     try
     {
         this.List.Add(WebVirtualDir);
     }
     catch
     {
         throw (new Exception("发生意外错误,可能是某节点将该节点的上级节点作为它自己的子级插入"));
     }
     IISManagement.CreateIISWebVirtualDir(WebVirtualDir, true);
 }
示例#5
0
        /// <summary>
        /// 创建虚拟目录
        /// </summary>
        /// <param name="iisVir">The IIS vir.</param>
        /// <param name="deleteIfExist">if set to <c>true</c> [delete if exist].</param>
        public static void CreateIISWebVirtualDir(IISWebVirtualDir iisVir, bool deleteIfExist)
        {
            if (iisVir.Parent == null)
            {
                throw (new Exception("IISWebVirtualDir没有所属的IISWebServer!"));
            }

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

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

            Server = GetRoot(Server);
            if (deleteIfExist)
            {
                foreach (DirectoryEntry VirDir in Server.Children)
                {
                    if (VirDir.Name.ToLower().Trim() == iisVir.Name.ToLower())
                    {
                        Server.Children.Remove(VirDir);
                        Server.CommitChanges();
                        break;
                    }
                }
            }

            try {
                DirectoryEntry vir;
                vir = Server.Children.Add(iisVir.Name, "IIsWebVirtualDir");
                vir.Properties["Path"][0]             = iisVir.Path;
                vir.Properties["DefaultDoc"][0]       = iisVir.DefaultDoc;
                vir.Properties["EnableDefaultDoc"][0] = iisVir.EnableDefaultDoc;
                vir.Properties["AccessScript"][0]     = iisVir.AccessScript;
                vir.Properties["AccessRead"][0]       = iisVir.AccessRead;
                vir.Invoke("AppCreate2", new object[1] {
                    2
                });

                Server.CommitChanges();
                vir.CommitChanges();
            }
            catch (Exception ex) {
                throw (ex);
            }
        }
示例#6
0
        /// <summary>
        /// 删除虚拟目录
        /// </summary>
        /// <param name="iisVir"></param>
        public static void RemoveIISWebVirtualDir(IISWebVirtualDir iisVir)
        {
            DirectoryEntry Service = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
            DirectoryEntry Server  = GetIISWebserver(iisVir.Parent.index);

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

            Server = GetRoot(Server);
            foreach (DirectoryEntry VirDir in Server.Children)
            {
                if (VirDir.Name.ToLower().Trim() == iisVir.Name.ToLower())
                {
                    Server.Children.Remove(VirDir);
                    Server.CommitChanges();
                    return;
                }
            }

            throw (new Exception("找不到给定的虚拟目录!"));
        }
 /// <summary>
 /// Adds the range.
 /// </summary>
 /// <param name="WebVirtualDirs">The web virtual dirs.</param>
 public void AddRange(IISWebVirtualDir[] WebVirtualDirs)
 {
     for (int i = 0; i <= WebVirtualDirs.GetUpperBound(0); i++)
     {
         Add(WebVirtualDirs[i]);
     }
 }
 /// <summary>
 /// Add_s the specified web virtual dir.
 /// </summary>
 /// <param name="WebVirtualDir">The web virtual dir.</param>
 internal void Add_(IISWebVirtualDir WebVirtualDir)
 {
     try
     {
         this.List.Add(WebVirtualDir);
     }
     catch
     {
         throw (new Exception("发生意外错误,可能是某节点将该节点的上级节点作为它自己的子级插入"));
     }
 }
 /// <summary>
 /// Removes the specified web virtual dir.
 /// </summary>
 /// <param name="WebVirtualDir">The web virtual dir.</param>
 public void Remove(IISWebVirtualDir WebVirtualDir)
 {
     for (int i = 0; i < this.List.Count; i++)
     {
         if ((IISWebVirtualDir)this.List[i] == WebVirtualDir)
         {
             this.List.RemoveAt(i);
             IISManagement.RemoveIISWebVirtualDir(WebVirtualDir);
             return;
         }
     }
 }
示例#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);
                    }
                }
            }
        }
示例#11
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);
                    }
                }
            }
        }
示例#12
0
        /// <summary>
        /// 删除虚拟目录
        /// </summary>
        /// <param name="iisVir"></param>
        public static void RemoveIISWebVirtualDir(IISWebVirtualDir iisVir)
        {
            DirectoryEntry Service = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
            DirectoryEntry Server = GetIISWebserver(iisVir.Parent.index);

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

            Server = GetRoot(Server);
            foreach (DirectoryEntry VirDir in Server.Children) {
                if (VirDir.Name.ToLower().Trim() == iisVir.Name.ToLower()) {
                    Server.Children.Remove(VirDir);
                    Server.CommitChanges();
                    return;
                }
            }

            throw (new Exception("找不到给定的虚拟目录!"));
        }
示例#13
0
        /// <summary>
        /// 创建虚拟目录
        /// </summary>
        /// <param name="iisVir">The IIS vir.</param>
        /// <param name="deleteIfExist">if set to <c>true</c> [delete if exist].</param>
        public static void CreateIISWebVirtualDir(IISWebVirtualDir iisVir, bool deleteIfExist)
        {
            if (iisVir.Parent == null)
                throw (new Exception("IISWebVirtualDir没有所属的IISWebServer!"));

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

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

            Server = GetRoot(Server);
            if (deleteIfExist) {
                foreach (DirectoryEntry VirDir in Server.Children) {
                    if (VirDir.Name.ToLower().Trim() == iisVir.Name.ToLower()) {
                        Server.Children.Remove(VirDir);
                        Server.CommitChanges();
                        break;
                    }
                }
            }

            try {
                DirectoryEntry vir;
                vir = Server.Children.Add(iisVir.Name, "IIsWebVirtualDir");
                vir.Properties["Path"][0] = iisVir.Path;
                vir.Properties["DefaultDoc"][0] = iisVir.DefaultDoc;
                vir.Properties["EnableDefaultDoc"][0] = iisVir.EnableDefaultDoc;
                vir.Properties["AccessScript"][0] = iisVir.AccessScript;
                vir.Properties["AccessRead"][0] = iisVir.AccessRead;
                vir.Invoke("AppCreate2", new object[1] { 2 });

                Server.CommitChanges();
                vir.CommitChanges();
            }
            catch (Exception ex) {
                throw (ex);
            }
        }