PageRenderTime 42ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Powershell/NewPHPVersionCmdlet.cs

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