PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
C# | 79 lines | 64 code | 7 blank | 8 comment | 5 complexity | 9637b94b07c10af356475c565f51a76f 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.Remove, "PHPSetting",
  16. SupportsShouldProcess = true,
  17. ConfirmImpact = ConfirmImpact.Medium)]
  18. public sealed class RemovePHPSettingCmdlet : BaseCmdlet
  19. {
  20. private string _name;
  21. private bool _force;
  22. [Parameter(Mandatory = false)]
  23. public SwitchParameter Force
  24. {
  25. get {
  26. return _force;
  27. }
  28. set {
  29. _force = value;
  30. }
  31. }
  32. [Parameter(Mandatory = true,
  33. Position = 0)]
  34. public string Name
  35. {
  36. get
  37. {
  38. return _name;
  39. }
  40. set
  41. {
  42. _name = 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. PHPIniSetting setting = Helper.FindSetting(phpIniFile.Settings, Name);
  53. if (setting != null)
  54. {
  55. if (ShouldProcess(Name))
  56. {
  57. string warningMessage = String.Format(Resources.DeleteSettingWarningMessage, setting.Name, setting.Value);
  58. if (Force || ShouldContinue(warningMessage, Resources.DeleteSettingWarningCaption))
  59. {
  60. configHelper.RemovePHPIniSetting(setting);
  61. }
  62. }
  63. }
  64. else
  65. {
  66. ArgumentException ex = new ArgumentException(String.Format(Resources.SettingDoesNotExistError, Name));
  67. ReportNonTerminatingError(ex, "InvalidArgument", ErrorCategory.ObjectNotFound);
  68. }
  69. }
  70. }
  71. }
  72. }