PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
C# | 92 lines | 77 code | 7 blank | 8 comment | 3 complexity | 9cd4ad69d9648afdbaa9fa4bffeb4917 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.New, "PHPSetting",
  16. SupportsShouldProcess = true,
  17. ConfirmImpact = ConfirmImpact.Medium)]
  18. public sealed class NewPHPSettingCmdlet : BaseCmdlet
  19. {
  20. private string _name;
  21. private string _value;
  22. private string _section = "PHP";
  23. [Parameter(Mandatory = true,
  24. Position = 0)]
  25. public string Name
  26. {
  27. get
  28. {
  29. return _name;
  30. }
  31. set
  32. {
  33. _name = value;
  34. }
  35. }
  36. [Parameter(Mandatory = true, Position = 1)]
  37. public string Value
  38. {
  39. get
  40. {
  41. return _value;
  42. }
  43. set
  44. {
  45. _value = value;
  46. }
  47. }
  48. [Parameter(Mandatory = false, Position = 2)]
  49. public string Section
  50. {
  51. get
  52. {
  53. return _section;
  54. }
  55. set
  56. {
  57. _section = value;
  58. }
  59. }
  60. protected override void DoProcessing()
  61. {
  62. using (ServerManager serverManager = new ServerManager())
  63. {
  64. ServerManagerWrapper serverManagerWrapper = new ServerManagerWrapper(serverManager, this.SiteName, this.VirtualPath);
  65. PHPConfigHelper configHelper = new PHPConfigHelper(serverManagerWrapper);
  66. PHPIniFile phpIniFile = configHelper.GetPHPIniFile();
  67. PHPIniSetting setting = Helper.FindSetting(phpIniFile.Settings, Name);
  68. if (setting == null)
  69. {
  70. if (ShouldProcess(Name))
  71. {
  72. RemoteObjectCollection<PHPIniSetting> settings = new RemoteObjectCollection<PHPIniSetting>();
  73. settings.Add(new PHPIniSetting(Name, Value, Section));
  74. configHelper.AddOrUpdatePHPIniSettings(settings);
  75. }
  76. }
  77. else
  78. {
  79. ArgumentException ex = new ArgumentException(String.Format(Resources.SettingAlreadyExistsError, Name));
  80. ReportNonTerminatingError(ex, "InvalidArgument", ErrorCategory.InvalidArgument);
  81. }
  82. }
  83. }
  84. }
  85. }