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

/trunk/Powershell/GetPHPVersionCmdlet.cs

#
C# | 58 lines | 42 code | 8 blank | 8 comment | 2 complexity | 2fc06c4abcbf3a8de78b6f109cdc2ce8 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.Management.Automation;
  10. using Microsoft.Web.Administration;
  11. using Web.Management.PHP.Config;
  12. namespace Web.Management.PHP.Powershell
  13. {
  14. [Cmdlet(VerbsCommon.Get, "PHPVersion")]
  15. public sealed class GetPHPVersionCmdlet : BaseCmdlet
  16. {
  17. [Parameter(ValueFromPipelineByPropertyName = true, Position = 0)]
  18. public string HandlerName { get; set; }
  19. [Parameter(ValueFromPipeline = false, Position = 1)]
  20. public string Version { get; set; }
  21. protected override void DoProcessing()
  22. {
  23. using (var serverManager = new ServerManager())
  24. {
  25. var serverManagerWrapper = new ServerManagerWrapper(serverManager, SiteName, VirtualPath);
  26. var configHelper = new PHPConfigHelper(serverManagerWrapper);
  27. var phpVersions = configHelper.GetAllPHPVersions();
  28. var nameWildcard = PrepareWildcardPattern(HandlerName);
  29. var versionWildcard = PrepareWildcardPattern(Version);
  30. var isActive = true;
  31. foreach (var phpVersion in phpVersions)
  32. {
  33. if (!nameWildcard.IsMatch(phpVersion.HandlerName))
  34. {
  35. isActive = false;
  36. continue;
  37. }
  38. if (!versionWildcard.IsMatch(phpVersion.Version))
  39. {
  40. isActive = false;
  41. continue;
  42. }
  43. var versionItem = new PHPVersionItem(phpVersion, isActive);
  44. WriteObject(versionItem);
  45. isActive = false;
  46. }
  47. }
  48. }
  49. }
  50. }