PageRenderTime 72ms CodeModel.GetById 67ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/stable-1.2.0/Powershell/GetPHPExtensionCmdlet.cs

#
C# | 83 lines | 65 code | 10 blank | 8 comment | 7 complexity | 33063c464b1c0941400c877e4c00f422 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;
11using System.Management.Automation;
12using Microsoft.Web.Administration;
13using Web.Management.PHP.Config;
14
15namespace Web.Management.PHP.Powershell
16{
17
18    [Cmdlet(VerbsCommon.Get, "PHPExtension")]
19    [OutputType(typeof(PHPExtensionItem))]
20    public sealed class GetPHPExtensionCmdlet : BaseCmdlet
21    {
22        private string _name;
23        private PHPExtensionStatus _status;
24
25        [Parameter(ValueFromPipelineByPropertyName = true, Position = 0)]
26        public string Name
27        {
28            get
29            {
30                return _name;
31            }
32            set
33            {
34                _name = value;
35            }
36        }
37
38        [Parameter(ValueFromPipeline = false, Position = 1)]
39        public PHPExtensionStatus Status
40        {
41            get
42            {
43                return _status;
44            }
45            set
46            {
47                _status = value;
48            }
49        }
50
51        protected override void DoProcessing()
52        {
53            using (ServerManager serverManager = new ServerManager())
54            {
55                ServerManagerWrapper serverManagerWrapper = new ServerManagerWrapper(serverManager, this.SiteName, this.VirtualPath);
56                PHPConfigHelper configHelper = new PHPConfigHelper(serverManagerWrapper);
57                PHPIniFile phpIniFile = configHelper.GetPHPIniFile();
58
59                WildcardPattern wildcard = PrepareWildcardPattern(Name);
60
61                foreach (PHPIniExtension extension in phpIniFile.Extensions)
62                {
63                    if (!wildcard.IsMatch(extension.Name))
64                    {
65                        continue;
66                    }
67                    if (Status == PHPExtensionStatus.Disabled && extension.Enabled)
68                    {
69                        continue;
70                    }
71                    if (Status == PHPExtensionStatus.Enabled && !extension.Enabled)
72                    {
73                        continue;
74                    }
75
76                    PHPExtensionItem extensionItem = new PHPExtensionItem(extension);
77
78                    WriteObject(extensionItem);
79                }
80            }
81        }
82    }
83}