PageRenderTime 46ms CodeModel.GetById 41ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Powershell/GetPHPVersionCmdlet.cs

#
C# | 58 lines | 42 code | 8 blank | 8 comment | 2 complexity | 2fc06c4abcbf3a8de78b6f109cdc2ce8 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, "PHPVersion")]
18    public sealed class GetPHPVersionCmdlet : BaseCmdlet
19    {
20        [Parameter(ValueFromPipelineByPropertyName = true, Position = 0)]
21        public string HandlerName { get; set; }
22
23        [Parameter(ValueFromPipeline = false, Position = 1)]
24        public string Version { get; set; }
25
26        protected override void DoProcessing()
27        {
28            using (var serverManager = new ServerManager())
29            {
30                var serverManagerWrapper = new ServerManagerWrapper(serverManager, SiteName, VirtualPath);
31                var configHelper = new PHPConfigHelper(serverManagerWrapper);
32                var phpVersions = configHelper.GetAllPHPVersions();
33
34                var nameWildcard = PrepareWildcardPattern(HandlerName);
35                var versionWildcard = PrepareWildcardPattern(Version);
36
37                var isActive = true;
38                foreach (var phpVersion in phpVersions)
39                {
40                    if (!nameWildcard.IsMatch(phpVersion.HandlerName))
41                    {
42                        isActive = false;
43                        continue;
44                    }
45                    if (!versionWildcard.IsMatch(phpVersion.Version))
46                    {
47                        isActive = false;
48                        continue;
49                    }
50
51                    var versionItem = new PHPVersionItem(phpVersion, isActive);
52                    WriteObject(versionItem);
53                    isActive = false;
54                }
55            }
56        }
57    }
58}