PageRenderTime 167ms CodeModel.GetById 157ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Powershell/SetPHPVersionCmdlet.cs

#
C# | 48 lines | 37 code | 3 blank | 8 comment | 3 complexity | 97b720c7b52d0886143120fabca7401d 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    [Cmdlet(VerbsCommon.Set, "PHPVersion",
18        SupportsShouldProcess = true,
19        ConfirmImpact = ConfirmImpact.Medium)]
20    public sealed class SetPHPVersionCmdlet : BaseCmdlet
21    {
22        [Parameter(Mandatory = true,
23            ValueFromPipelineByPropertyName = true,
24            Position = 0)]
25        public string HandlerName { 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                if (configHelper.GetPHPHandlerByName(HandlerName) != null)
34                {
35                    if (ShouldProcess(HandlerName))
36                    {
37                        configHelper.SelectPHPHandler(HandlerName);
38                    }
39                }
40                else
41                {
42                    var ex = new ArgumentException(String.Format(Resources.HandlerDoesNotExistError, HandlerName));
43                    ReportNonTerminatingError(ex, "InvalidArgument", ErrorCategory.ObjectNotFound);
44                }
45            }
46        }
47    }
48}