PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/stable-1.1.2/Client/Settings/RuntimeLimitsPage.cs

#
C# | 209 lines | 164 code | 36 blank | 9 comment | 10 complexity | 6e2b63f26af806c8c5e81de40e39028f 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.Collections.Generic;
  11. using Microsoft.Web.Management.Client;
  12. using Microsoft.Web.Management.Client.Win32;
  13. using Microsoft.Web.Management.Server;
  14. using Web.Management.PHP.Config;
  15. namespace Web.Management.PHP.Settings
  16. {
  17. [ModulePageIdentifier(Globals.RuntimeLimitsPageIdentifier)]
  18. internal sealed class RuntimeLimitsPage : ModulePropertiesPage, IModuleChildPage
  19. {
  20. // If adding properties here make sure to update the RuntimeLimistGlobal.cs
  21. private readonly string [] _settingNames = {
  22. "max_execution_time",
  23. "max_input_time",
  24. "memory_limit",
  25. "post_max_size",
  26. "upload_max_filesize",
  27. "max_file_uploads"
  28. };
  29. private PropertyBag _clone;
  30. private PropertyBag _bag;
  31. private PageTaskList _taskList;
  32. private IModulePage _parentPage;
  33. protected override bool CanApplyChanges
  34. {
  35. get
  36. {
  37. return true;
  38. }
  39. }
  40. protected override bool ConfigNamesPresent
  41. {
  42. get
  43. {
  44. return true;
  45. }
  46. }
  47. internal bool IsReadOnly
  48. {
  49. get
  50. {
  51. return Connection.ConfigurationPath.PathType == Microsoft.Web.Management.Server.ConfigurationPathType.Site &&
  52. !Connection.IsUserServerAdministrator;
  53. }
  54. }
  55. private new PHPModule Module
  56. {
  57. get
  58. {
  59. return (PHPModule)base.Module;
  60. }
  61. }
  62. public IModulePage ParentPage
  63. {
  64. get
  65. {
  66. return _parentPage;
  67. }
  68. set
  69. {
  70. _parentPage = value;
  71. }
  72. }
  73. protected override TaskListCollection Tasks
  74. {
  75. get
  76. {
  77. TaskListCollection tasks = base.Tasks;
  78. if (_taskList == null)
  79. {
  80. _taskList = new PageTaskList(this);
  81. }
  82. tasks.Add(_taskList);
  83. return tasks;
  84. }
  85. }
  86. protected override PropertyBag GetProperties()
  87. {
  88. PropertyBag result = new PropertyBag();
  89. object o = Module.Proxy.GetPHPIniSettings();
  90. PHPIniFile file = new PHPIniFile();
  91. file.SetData(o);
  92. for (int i = 0; i < _settingNames.Length; i++)
  93. {
  94. PHPIniSetting setting = file.GetSetting(_settingNames[i]);
  95. if (setting != null)
  96. {
  97. result[i] = setting.Value;
  98. }
  99. }
  100. return result;
  101. }
  102. private void GoBack()
  103. {
  104. Navigate(typeof(PHPPage));
  105. }
  106. protected override void ProcessProperties(PropertyBag properties)
  107. {
  108. _bag = properties;
  109. _clone = _bag.Clone();
  110. RuntimeLimitSettings settings = TargetObject as RuntimeLimitSettings;
  111. if (settings == null)
  112. {
  113. settings = new RuntimeLimitSettings(this, this.IsReadOnly, _clone);
  114. TargetObject = settings;
  115. }
  116. else
  117. {
  118. settings.Initialize(_clone);
  119. }
  120. ClearDirty();
  121. }
  122. protected override bool ShowHelp()
  123. {
  124. return ShowOnlineHelp();
  125. }
  126. protected override bool ShowOnlineHelp()
  127. {
  128. return Helper.Browse(Globals.RuntimeLimitsOnlineHelp);
  129. }
  130. protected override PropertyBag UpdateProperties(out bool updateSuccessful)
  131. {
  132. updateSuccessful = false;
  133. RemoteObjectCollection<PHPIniSetting> settings = new RemoteObjectCollection<PHPIniSetting>();
  134. for (int i = 0; i < _settingNames.Length; i++)
  135. {
  136. settings.Add(new PHPIniSetting(_settingNames[i], (string)_clone[i], "PHP"));
  137. }
  138. try
  139. {
  140. Module.Proxy.AddOrUpdateSettings(settings);
  141. _bag = _clone;
  142. updateSuccessful = true;
  143. }
  144. catch(Exception ex)
  145. {
  146. DisplayErrorMessage(ex, Resources.ResourceManager);
  147. }
  148. return _bag;
  149. }
  150. private class PageTaskList : TaskList
  151. {
  152. private RuntimeLimitsPage _page;
  153. public PageTaskList(RuntimeLimitsPage page)
  154. {
  155. _page = page;
  156. }
  157. public override System.Collections.ICollection GetTaskItems()
  158. {
  159. List<TaskItem> tasks = new List<TaskItem>();
  160. if (_page.IsReadOnly)
  161. {
  162. tasks.Add(new MessageTaskItem(MessageTaskItemType.Information, Resources.AllPagesPageIsReadOnly, "Information"));
  163. }
  164. tasks.Add(new MethodTaskItem("GoBack", Resources.AllPagesGoBackTask, "Tasks", null, Resources.GoBack16));
  165. return tasks;
  166. }
  167. public void GoBack()
  168. {
  169. _page.GoBack();
  170. }
  171. }
  172. }
  173. }