PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Powershell/SetPHPVersionCmdlet.cs

#
C# | 48 lines | 37 code | 3 blank | 8 comment | 3 complexity | 97b720c7b52d0886143120fabca7401d 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.Management.Automation;
  11. using Microsoft.Web.Administration;
  12. using Web.Management.PHP.Config;
  13. namespace Web.Management.PHP.Powershell
  14. {
  15. [Cmdlet(VerbsCommon.Set, "PHPVersion",
  16. SupportsShouldProcess = true,
  17. ConfirmImpact = ConfirmImpact.Medium)]
  18. public sealed class SetPHPVersionCmdlet : BaseCmdlet
  19. {
  20. [Parameter(Mandatory = true,
  21. ValueFromPipelineByPropertyName = true,
  22. Position = 0)]
  23. public string HandlerName { get; set; }
  24. protected override void DoProcessing()
  25. {
  26. using (var serverManager = new ServerManager())
  27. {
  28. var serverManagerWrapper = new ServerManagerWrapper(serverManager, SiteName, VirtualPath);
  29. var configHelper = new PHPConfigHelper(serverManagerWrapper);
  30. if (configHelper.GetPHPHandlerByName(HandlerName) != null)
  31. {
  32. if (ShouldProcess(HandlerName))
  33. {
  34. configHelper.SelectPHPHandler(HandlerName);
  35. }
  36. }
  37. else
  38. {
  39. var ex = new ArgumentException(String.Format(Resources.HandlerDoesNotExistError, HandlerName));
  40. ReportNonTerminatingError(ex, "InvalidArgument", ErrorCategory.ObjectNotFound);
  41. }
  42. }
  43. }
  44. }
  45. }