您的位置:首页 > 编程语言 > C#

C# 操作IIS

2017-11-01 17:47 183 查看
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Microsoft.Web.Administration;

namespace NetBrain.Utility

{

    public class IIS_Parser

    {

        public static string GetIISPoolEnabel32BitApp(string PoolName)

        {

            ServerManager manager = new ServerManager();

            ApplicationPool pool = manager.ApplicationPools[PoolName];

            if (pool != null)

            {

                return pool.Enable32BitAppOnWin64.ToString();

            }

            else

            {

                return "false";

            }

        }

        public static string GetIISPoolQueueLen(string PoolName)

        {

            ServerManager manager = new ServerManager();

            ApplicationPool pool = manager.ApplicationPools[PoolName];

            if (pool != null)

            {

                return pool.QueueLength.ToString();

            }

            else

            {

                return "false";

            }

        }

        public static string GetIISPoolIdentity(string PoolName)

        {

            ServerManager manager = new ServerManager();

            ApplicationPool pool = manager.ApplicationPools[PoolName];

            if (pool != null)

            {

                return pool.ProcessModel.IdentityType.ToString();

            }

            else

            {

                return "false";

            }

        }

        public static string GetIISPoolRegularTimeInterval(string PoolName)

        {

            ServerManager manager = new ServerManager();

            ApplicationPool pool = manager.ApplicationPools[PoolName];

            if (pool != null)

            {

                string PPTT = pool.Recycling.PeriodicRestart.Time.TotalMinutes.ToString();

                return PPTT;

            }

            else

            {

                return "false";

            }

        }

        public static string GetIISAttribute(string attributeName, string poolName)

        {

            string value = null;

            switch (attributeName)

            {

                case "Identity":

                    value = IIS_Parser.GetIISPoolIdentity(poolName);

                    break;

                case "Queue Length":

                    value = IIS_Parser.GetIISPoolQueueLen(poolName);

                    break;

                case "Enable 32-Bits Applicantions":

                    value = IIS_Parser.GetIISPoolEnabel32BitApp(poolName);

                    break;

                case "Regular Time Interval(minutes)":

                    value = IIS_Parser.GetIISPoolRegularTimeInterval(poolName);

                    break;

            }

            if (value.Equals("false"))

            {

                LogUtility.Information("BAT_logResult", string.Format("Coding Error  Get IIS pool {1} attribute {2} value Fail!!!",  poolName, attributeName));

            }

            return value;

        }

 

       

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: