PageRenderTime 22ms CodeModel.GetById 10ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Powershell/NewPHPVersionCmdlet.cs

#
C# | 52 lines | 40 code | 4 blank | 8 comment | 1 complexity | 53f17c82b0529cdaaba8702c66a953b1 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.IO;
12using System.Management.Automation;
13using Microsoft.Web.Administration;
14using Web.Management.PHP.Config;
15
16namespace Web.Management.PHP.Powershell
17{
18    [Cmdlet(VerbsCommon.New, "PHPVersion")]
19    public sealed class NewPHPVersionCmdlet : BaseCmdlet
20    {
21        [Parameter(Mandatory = true, Position = 0)]
22        public string ScriptProcessor { get; set; }
23
24        protected override void DoProcessing()
25        {
26            try
27            {
28                using (var serverManager = new ServerManager())
29                {
30                    var serverManagerWrapper = new ServerManagerWrapper(serverManager, SiteName, VirtualPath);
31                    var configHelper = new PHPConfigHelper(serverManagerWrapper);
32                    var phpCgiExePath = PrepareFullScriptProcessorPath(ScriptProcessor);
33                    configHelper.RegisterPHPWithIIS(phpCgiExePath);
34                }
35            }
36            catch (DirectoryNotFoundException ex)
37            {
38                ReportTerminatingError(ex, "DirectoryNotFound", ErrorCategory.ObjectNotFound);
39            }
40        }
41
42        private static string PrepareFullScriptProcessorPath(string scriptProcessor)
43        {
44            var fullPath = Path.GetFullPath(scriptProcessor);
45            if (!fullPath.EndsWith("php-cgi.exe", StringComparison.OrdinalIgnoreCase))
46            {
47                fullPath = Path.Combine(fullPath, "php-cgi.exe");
48            }
49            return fullPath;
50        }
51    }
52}