PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Powershell/NewPHPSettingCmdlet.cs

#
C# | 72 lines | 57 code | 7 blank | 8 comment | 3 complexity | d8d0e13446332d0c6f28c5d9db26e415 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 _section = "PHP";
  21. [Parameter(Mandatory = true,
  22. Position = 0)]
  23. public string Name { get; set; }
  24. [Parameter(Mandatory = true, Position = 1)]
  25. public string Value { get; set; }
  26. [Parameter(Mandatory = false, Position = 2)]
  27. public string Section
  28. {
  29. get
  30. {
  31. return _section;
  32. }
  33. set
  34. {
  35. _section = value;
  36. }
  37. }
  38. protected override void DoProcessing()
  39. {
  40. using (var serverManager = new ServerManager())
  41. {
  42. var serverManagerWrapper = new ServerManagerWrapper(serverManager, SiteName, VirtualPath);
  43. var configHelper = new PHPConfigHelper(serverManagerWrapper);
  44. var phpIniFile = configHelper.GetPHPIniFile();
  45. var setting = Helper.FindSetting(phpIniFile.Settings, Name);
  46. if (setting == null)
  47. {
  48. if (ShouldProcess(Name))
  49. {
  50. var settings = new RemoteObjectCollection<PHPIniSetting>
  51. {
  52. new PHPIniSetting(Name, Value, Section)
  53. };
  54. configHelper.AddOrUpdatePHPIniSettings(settings);
  55. }
  56. }
  57. else
  58. {
  59. var ex = new ArgumentException(String.Format(Resources.SettingAlreadyExistsError, Name));
  60. ReportNonTerminatingError(ex, "InvalidArgument", ErrorCategory.InvalidArgument);
  61. }
  62. }
  63. }
  64. }
  65. }