PageRenderTime 102ms CodeModel.GetById 98ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Powershell/GetPHPExtensionCmdlet.cs

#
C# | 59 lines | 42 code | 9 blank | 8 comment | 7 complexity | 398a27db6a294b6bbfb36fa9fe9e4e30 MD5 | raw file
 1//-----------------------------------------------------------------------
 2// <copyright>
 3// Copyright (C) Ruslan Yakushev for the PHP Manager for IIS project.
 4//
 5// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
 6// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
 7// </copyright>
 8//----------------------------------------------------------------------- 
 9
10using System.Management.Automation;
11using Microsoft.Web.Administration;
12using Web.Management.PHP.Config;
13
14namespace Web.Management.PHP.Powershell
15{
16
17    [Cmdlet(VerbsCommon.Get, "PHPExtension")]
18    [OutputType(typeof(PHPExtensionItem))]
19    public sealed class GetPHPExtensionCmdlet : BaseCmdlet
20    {
21        [Parameter(ValueFromPipelineByPropertyName = true, Position = 0)]
22        public string Name { get; set; }
23
24        [Parameter(ValueFromPipeline = false, Position = 1)]
25        public PHPExtensionStatus Status { get; set; }
26
27        protected override void DoProcessing()
28        {
29            using (var serverManager = new ServerManager())
30            {
31                var serverManagerWrapper = new ServerManagerWrapper(serverManager, SiteName, VirtualPath);
32                var configHelper = new PHPConfigHelper(serverManagerWrapper);
33                var phpIniFile = configHelper.GetPHPIniFile();
34
35                WildcardPattern wildcard = PrepareWildcardPattern(Name);
36
37                foreach (var extension in phpIniFile.Extensions)
38                {
39                    if (!wildcard.IsMatch(extension.Name))
40                    {
41                        continue;
42                    }
43                    if (Status == PHPExtensionStatus.Disabled && extension.Enabled)
44                    {
45                        continue;
46                    }
47                    if (Status == PHPExtensionStatus.Enabled && !extension.Enabled)
48                    {
49                        continue;
50                    }
51
52                    var extensionItem = new PHPExtensionItem(extension);
53
54                    WriteObject(extensionItem);
55                }
56            }
57        }
58    }
59}