PageRenderTime 28ms CodeModel.GetById 25ms app.highlight 1ms RepoModel.GetById 2ms app.codeStats 0ms

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

#
C# | 64 lines | 51 code | 5 blank | 8 comment | 1 complexity | 9739b198c4b28585de97b05cabd7f329 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        private string _scriptProcessor;
22
23        [Parameter(Mandatory = true, Position = 0)]
24        public string ScriptProcessor
25        {
26            get
27            {
28                return _scriptProcessor;
29            }
30            set
31            {
32                _scriptProcessor = value;
33            }
34        }
35
36        protected override void DoProcessing()
37        {
38            try
39            {
40                using (ServerManager serverManager = new ServerManager())
41                {
42                    ServerManagerWrapper serverManagerWrapper = new ServerManagerWrapper(serverManager, this.SiteName, this.VirtualPath);
43                    PHPConfigHelper _configHelper = new PHPConfigHelper(serverManagerWrapper);
44                    string phpCgiExePath = PrepareFullScriptProcessorPath(ScriptProcessor);
45                    _configHelper.RegisterPHPWithIIS(phpCgiExePath);
46                }
47            }
48            catch (DirectoryNotFoundException ex)
49            {
50                ReportTerminatingError(ex, "DirectoryNotFound", ErrorCategory.ObjectNotFound);
51            }
52        }
53
54        private string PrepareFullScriptProcessorPath(string scriptProcessor)
55        {
56            string fullPath = Path.GetFullPath(scriptProcessor);
57            if (!fullPath.EndsWith("php-cgi.exe", StringComparison.OrdinalIgnoreCase))
58            {
59                fullPath = Path.Combine(fullPath, "php-cgi.exe");
60            }
61            return fullPath;
62        }
63    }
64}