PageRenderTime 45ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
C# | 79 lines | 62 code | 9 blank | 8 comment | 2 complexity | 906243983c1ff5cd77675cf6215a598b 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, "PHPSetting")]
  16. [OutputType(typeof(PHPSettingItem))]
  17. public sealed class GetPHPSettingCmdlet : BaseCmdlet
  18. {
  19. private string _name;
  20. private string _section;
  21. [Parameter(Position = 0)]
  22. public string Name
  23. {
  24. get
  25. {
  26. return _name;
  27. }
  28. set
  29. {
  30. _name = value;
  31. }
  32. }
  33. [Parameter]
  34. public string Section
  35. {
  36. get
  37. {
  38. return _section;
  39. }
  40. set
  41. {
  42. _section = 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 nameWildcard = PrepareWildcardPattern(Name);
  53. WildcardPattern sectionWildcard = PrepareWildcardPattern(Section);
  54. foreach (PHPIniSetting setting in phpIniFile.Settings)
  55. {
  56. if (!nameWildcard.IsMatch(setting.Name))
  57. {
  58. continue;
  59. }
  60. if (!sectionWildcard.IsMatch(setting.Section))
  61. {
  62. continue;
  63. }
  64. PHPSettingItem settingItem = new PHPSettingItem(setting);
  65. WriteObject(settingItem);
  66. }
  67. }
  68. }
  69. }
  70. }