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

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

#
C# | 83 lines | 65 code | 10 blank | 8 comment | 7 complexity | 33063c464b1c0941400c877e4c00f422 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.Get, "PHPExtension")]
  16. [OutputType(typeof(PHPExtensionItem))]
  17. public sealed class GetPHPExtensionCmdlet : BaseCmdlet
  18. {
  19. private string _name;
  20. private PHPExtensionStatus _status;
  21. [Parameter(ValueFromPipelineByPropertyName = true, Position = 0)]
  22. public string Name
  23. {
  24. get
  25. {
  26. return _name;
  27. }
  28. set
  29. {
  30. _name = value;
  31. }
  32. }
  33. [Parameter(ValueFromPipeline = false, Position = 1)]
  34. public PHPExtensionStatus Status
  35. {
  36. get
  37. {
  38. return _status;
  39. }
  40. set
  41. {
  42. _status = value;
  43. }
  44. }
  45. protected override void DoProcessing()
  46. {
  47. using (ServerManager serverManager = new ServerManager())
  48. {
  49. ServerManagerWrapper serverManagerWrapper = new ServerManagerWrapper(serverManager, this.SiteName, this.VirtualPath);
  50. PHPConfigHelper configHelper = new PHPConfigHelper(serverManagerWrapper);
  51. PHPIniFile phpIniFile = configHelper.GetPHPIniFile();
  52. WildcardPattern wildcard = PrepareWildcardPattern(Name);
  53. foreach (PHPIniExtension extension in phpIniFile.Extensions)
  54. {
  55. if (!wildcard.IsMatch(extension.Name))
  56. {
  57. continue;
  58. }
  59. if (Status == PHPExtensionStatus.Disabled && extension.Enabled)
  60. {
  61. continue;
  62. }
  63. if (Status == PHPExtensionStatus.Enabled && !extension.Enabled)
  64. {
  65. continue;
  66. }
  67. PHPExtensionItem extensionItem = new PHPExtensionItem(extension);
  68. WriteObject(extensionItem);
  69. }
  70. }
  71. }
  72. }
  73. }