/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
- //-----------------------------------------------------------------------
- // <copyright>
- // Copyright (C) Ruslan Yakushev for the PHP Manager for IIS project.
- //
- // This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
- // See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
- // </copyright>
- //-----------------------------------------------------------------------
-
- using System;
- using System.Collections.Generic;
- using Microsoft.Web.Management.Client;
- using Microsoft.Web.Management.Client.Win32;
- using Microsoft.Web.Management.Server;
- using Web.Management.PHP.Config;
-
- namespace Web.Management.PHP.Settings
- {
-
- [ModulePageIdentifier(Globals.RuntimeLimitsPageIdentifier)]
- internal sealed class RuntimeLimitsPage : ModulePropertiesPage, IModuleChildPage
- {
- // If adding properties here make sure to update the RuntimeLimistGlobal.cs
- private readonly string [] _settingNames = {
- "max_execution_time",
- "max_input_time",
- "memory_limit",
- "post_max_size",
- "upload_max_filesize",
- "max_file_uploads"
- };
-
- private PropertyBag _clone;
- private PropertyBag _bag;
- private PageTaskList _taskList;
- private IModulePage _parentPage;
-
- protected override bool CanApplyChanges
- {
- get
- {
- return true;
- }
- }
-
- protected override bool ConfigNamesPresent
- {
- get
- {
- return true;
- }
- }
-
- internal bool IsReadOnly
- {
- get
- {
- return Connection.ConfigurationPath.PathType == Microsoft.Web.Management.Server.ConfigurationPathType.Site &&
- !Connection.IsUserServerAdministrator;
- }
- }
-
- private new PHPModule Module
- {
- get
- {
- return (PHPModule)base.Module;
- }
- }
-
- public IModulePage ParentPage
- {
- get
- {
- return _parentPage;
- }
- set
- {
- _parentPage = value;
- }
- }
-
- protected override TaskListCollection Tasks
- {
- get
- {
- TaskListCollection tasks = base.Tasks;
- if (_taskList == null)
- {
- _taskList = new PageTaskList(this);
- }
-
- tasks.Add(_taskList);
-
- return tasks;
- }
- }
-
- protected override PropertyBag GetProperties()
- {
- PropertyBag result = new PropertyBag();
-
- object o = Module.Proxy.GetPHPIniSettings();
- PHPIniFile file = new PHPIniFile();
- file.SetData(o);
-
- for (int i = 0; i < _settingNames.Length; i++)
- {
- PHPIniSetting setting = file.GetSetting(_settingNames[i]);
- if (setting != null)
- {
- result[i] = setting.Value;
- }
- }
-
- return result;
- }
-
- private void GoBack()
- {
- Navigate(typeof(PHPPage));
- }
-
- protected override void ProcessProperties(PropertyBag properties)
- {
- _bag = properties;
- _clone = _bag.Clone();
-
- RuntimeLimitSettings settings = TargetObject as RuntimeLimitSettings;
- if (settings == null)
- {
- settings = new RuntimeLimitSettings(this, this.IsReadOnly, _clone);
- TargetObject = settings;
- }
- else
- {
- settings.Initialize(_clone);
- }
-
- ClearDirty();
- }
-
- protected override bool ShowHelp()
- {
- return ShowOnlineHelp();
- }
-
- protected override bool ShowOnlineHelp()
- {
- return Helper.Browse(Globals.RuntimeLimitsOnlineHelp);
- }
-
- protected override PropertyBag UpdateProperties(out bool updateSuccessful)
- {
- updateSuccessful = false;
-
- RemoteObjectCollection<PHPIniSetting> settings = new RemoteObjectCollection<PHPIniSetting>();
-
- for (int i = 0; i < _settingNames.Length; i++)
- {
- settings.Add(new PHPIniSetting(_settingNames[i], (string)_clone[i], "PHP"));
- }
-
- try
- {
- Module.Proxy.AddOrUpdateSettings(settings);
- _bag = _clone;
- updateSuccessful = true;
- }
- catch(Exception ex)
- {
- DisplayErrorMessage(ex, Resources.ResourceManager);
- }
-
- return _bag;
- }
-
-
- private class PageTaskList : TaskList
- {
- private RuntimeLimitsPage _page;
-
- public PageTaskList(RuntimeLimitsPage page)
- {
- _page = page;
- }
-
- public override System.Collections.ICollection GetTaskItems()
- {
- List<TaskItem> tasks = new List<TaskItem>();
-
- if (_page.IsReadOnly)
- {
- tasks.Add(new MessageTaskItem(MessageTaskItemType.Information, Resources.AllPagesPageIsReadOnly, "Information"));
- }
-
- tasks.Add(new MethodTaskItem("GoBack", Resources.AllPagesGoBackTask, "Tasks", null, Resources.GoBack16));
-
- return tasks;
- }
-
- public void GoBack()
- {
- _page.GoBack();
- }
- }
-
- }
- }