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