PageRenderTime 19ms CodeModel.GetById 15ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 1ms

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

#
C# | 79 lines | 62 code | 9 blank | 8 comment | 2 complexity | 906243983c1ff5cd77675cf6215a598b 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, "PHPSetting")]
19    [OutputType(typeof(PHPSettingItem))]
20    public sealed class GetPHPSettingCmdlet : BaseCmdlet
21    {
22        private string _name;
23        private string _section;
24
25        [Parameter(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]
39        public string Section
40        {
41            get
42            {
43                return _section;
44            }
45            set
46            {
47                _section = 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 nameWildcard = PrepareWildcardPattern(Name);
60                WildcardPattern sectionWildcard = PrepareWildcardPattern(Section);
61
62                foreach (PHPIniSetting setting in phpIniFile.Settings)
63                {
64                    if (!nameWildcard.IsMatch(setting.Name))
65                    {
66                        continue;
67                    }
68                    if (!sectionWildcard.IsMatch(setting.Section))
69                    {
70                        continue;
71                    }
72
73                    PHPSettingItem settingItem = new PHPSettingItem(setting);
74                    WriteObject(settingItem);
75                }
76            }
77        }
78    }
79}