PageRenderTime 19ms CodeModel.GetById 2ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 1ms

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

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