📄 iiswebsitecollection.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.Collections;
namespace IIsAdmin
{
/// <summary>
/// Defines a list of IIsWebSite objects
/// </summary>
public class IIsWebSiteCollection : CollectionBase, IDisposable
{
private bool _disposed;
public event IIsWebSiteEventHandler WebSiteStarted;
public event IIsWebSiteEventHandler WebSiteStopped;
/// <summary>
/// Initializes a new instance of the IIsWebSiteCollection class
/// </summary>
public IIsWebSiteCollection()
{
}
/// <summary>
/// Adds an IIsWebSite instance to the list
/// </summary>
/// <param name="site"></param>
public void Add(IIsWebSite site)
{
if (this.Contains(site))
{
throw new ArgumentException(string.Format("A web site with the ID '{0}' already exists in the collection", site.Index));
}
site.Started += new IIsWebSiteEventHandler(OnWebSiteStarted);
site.Stopped += new IIsWebSiteEventHandler(OnWebSiteStopped);
base.InnerList.Add(site);
}
/// <summary>
/// Removes an IIsWebSite instance from the list
/// </summary>
/// <param name="site"></param>
public void Remove(IIsWebSite site)
{
if (this.Contains(site))
{
site.Started -= new IIsWebSiteEventHandler(OnWebSiteStarted);
site.Stopped -= new IIsWebSiteEventHandler(OnWebSiteStopped);
base.InnerList.Remove(site);
}
}
/// <summary>
/// Determines if an IIsWebSite instance exists in the list
/// </summary>
/// <param name="site"></param>
/// <returns></returns>
public bool Contains(IIsWebSite site)
{
if (site == null)
{
throw new ArgumentNullException("site", "The site parameter must not be null.");
}
foreach(IIsWebSite ws in base.InnerList)
{
if (ws.Index == site.Index)
{
return true;
}
}
return false;
}
/// <summary>
/// Returns the active web site in IIs
/// </summary>
public IIsWebSite ActiveWebSite
{
get
{
foreach (IIsWebSite site in base.InnerList)
{
if (site.State == IIsWebSiteStates.Started)
{
return site;
}
}
return null;
}
}
/// <summary>
/// Returns the IIsWebSite instance at the specified index in the list
/// </summary>
public IIsWebSite this[int index]
{
get
{
return base.InnerList[index] as IIsWebSite;
}
}
/// <summary>
/// Raises the Started event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected virtual void OnWebSiteStarted(object sender, IIsWebSiteEventArgs e)
{
if (this.WebSiteStarted != null)
{
this.WebSiteStarted(sender, e);
}
}
/// <summary>
/// Raises the Stopped event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected virtual void OnWebSiteStopped(object sender, IIsWebSiteEventArgs e)
{
if (this.WebSiteStopped != null)
{
this.WebSiteStopped(sender, e);
}
}
#region IDisposable Members
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (_disposed)
{
if (disposing)
{
foreach (IIsWebSite site in base.InnerList)
{
site.Dispose();
}
base.InnerList.Clear();
}
_disposed = true;
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -