PageRenderTime 30ms CodeModel.GetById 12ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/stable-1.1.0/Client/Setup/RecommendedConfigDialog.cs

#
C# | 346 lines | 267 code | 30 blank | 49 comment | 10 complexity | 93b9f220fb0ad76832a15ac9c73e44ed 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
 10//#define VSDesigner
 11
 12using System;
 13using System.Collections;
 14using System.ComponentModel;
 15using System.Windows.Forms;
 16using Microsoft.Web.Management.Client.Win32;
 17using Web.Management.PHP.Config;
 18
 19namespace Web.Management.PHP.Setup
 20{
 21
 22    internal sealed class RecommendedConfigDialog :
 23#if VSDesigner
 24        Form
 25#else
 26        TaskForm
 27#endif
 28    {
 29        private const int TagIssueDescription = 0;
 30        private const int TagIssueRecommendation = 1;
 31        private const int TagIssueIndex = 2;
 32        private const int TagSize = 3;
 33
 34        private PHPModule _module;
 35        private ManagementPanel _contentPanel;
 36
 37        private ListView _configIssuesListView;
 38        private ColumnHeader _nameHeader;
 39        private Label _configIssueLabel;
 40        private ColumnHeader _currentValueHeader;
 41        private ColumnHeader _recommendedValueHeader;
 42        private Label _recommendationLabel;
 43        private TextBox _recommendationTextBox;
 44        private Label _issueDescriptionLabel;
 45        private TextBox _issueDescriptionTextBox;
 46        private Label _formDescriptionLabel;
 47        /// <summary>
 48        /// Required designer variable.
 49        /// </summary>
 50        private System.ComponentModel.IContainer components = null;
 51
 52        public RecommendedConfigDialog(PHPModule module): base(module)
 53        {
 54            _module = module;
 55            InitializeComponent();
 56            InitializeUI();
 57        }
 58
 59        protected override bool CanAccept
 60        {
 61            get
 62            {
 63                return (_configIssuesListView.CheckedItems.Count > 0);
 64            }
 65        }
 66
 67        protected override bool CanShowHelp
 68        {
 69            get
 70            {
 71                return true;
 72            }
 73        }
 74
 75        /// <summary>
 76        /// Clean up any resources being used.
 77        /// </summary>
 78        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
 79        protected override void Dispose(bool disposing)
 80        {
 81            if (disposing && (components != null))
 82            {
 83                components.Dispose();
 84            }
 85            base.Dispose(disposing);
 86        }
 87
 88        private static string GetResourceStringByName(string name)
 89        {
 90            string result = Resources.ResourceManager.GetString(name);
 91            if (result == null)
 92            {
 93                result = name;
 94            }
 95            return result;
 96        }
 97
 98        private void InitializeComponent()
 99        {
100            this._configIssuesListView = new System.Windows.Forms.ListView();
101            this._nameHeader = new System.Windows.Forms.ColumnHeader();
102            this._currentValueHeader = new System.Windows.Forms.ColumnHeader();
103            this._recommendedValueHeader = new System.Windows.Forms.ColumnHeader();
104            this._configIssueLabel = new System.Windows.Forms.Label();
105            this._recommendationLabel = new System.Windows.Forms.Label();
106            this._recommendationTextBox = new System.Windows.Forms.TextBox();
107            this._issueDescriptionLabel = new System.Windows.Forms.Label();
108            this._issueDescriptionTextBox = new System.Windows.Forms.TextBox();
109            this._formDescriptionLabel = new System.Windows.Forms.Label();
110            this.SuspendLayout();
111            // 
112            // _configIssuesListView
113            // 
114            this._configIssuesListView.CheckBoxes = true;
115            this._configIssuesListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
116            this._nameHeader,
117            this._currentValueHeader,
118            this._recommendedValueHeader});
119            this._configIssuesListView.FullRowSelect = true;
120            this._configIssuesListView.Location = new System.Drawing.Point(0, 64);
121            this._configIssuesListView.MultiSelect = false;
122            this._configIssuesListView.Name = "_configIssuesListView";
123            this._configIssuesListView.Size = new System.Drawing.Size(480, 130);
124            this._configIssuesListView.TabIndex = 2;
125            this._configIssuesListView.UseCompatibleStateImageBehavior = false;
126            this._configIssuesListView.View = System.Windows.Forms.View.Details;
127            this._configIssuesListView.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.OnConfigIssuesListViewItemChecked);
128            this._configIssuesListView.SelectedIndexChanged += new System.EventHandler(this.OnConfigIssuesListViewSelectedIndexChanged);
129            // 
130            // _nameHeader
131            // 
132            this._nameHeader.Text = global::Web.Management.PHP.Resources.RecommendConfigDialogSettingName;
133            this._nameHeader.Width = 170;
134            // 
135            // _currentValueHeader
136            // 
137            this._currentValueHeader.Text = global::Web.Management.PHP.Resources.RecommendConfigDialogCurrentValue;
138            this._currentValueHeader.Width = 150;
139            // 
140            // _recommendedValueHeader
141            // 
142            this._recommendedValueHeader.Text = global::Web.Management.PHP.Resources.RecommendConfigDialogRecommendedValue;
143            this._recommendedValueHeader.Width = 150;
144            // 
145            // _configIssueLabel
146            // 
147            this._configIssueLabel.AutoSize = true;
148            this._configIssueLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
149            this._configIssueLabel.Location = new System.Drawing.Point(0, 48);
150            this._configIssueLabel.Name = "_configIssueLabel";
151            this._configIssueLabel.Size = new System.Drawing.Size(180, 13);
152            this._configIssueLabel.TabIndex = 1;
153            this._configIssueLabel.Text = global::Web.Management.PHP.Resources.RecommendConfigDialogDetectedIssues;
154            // 
155            // _recommendationLabel
156            // 
157            this._recommendationLabel.AutoSize = true;
158            this._recommendationLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
159            this._recommendationLabel.Location = new System.Drawing.Point(0, 288);
160            this._recommendationLabel.Name = "_recommendationLabel";
161            this._recommendationLabel.Size = new System.Drawing.Size(108, 13);
162            this._recommendationLabel.TabIndex = 5;
163            this._recommendationLabel.Text = global::Web.Management.PHP.Resources.RecommendConfigDialogRecommendation;
164            // 
165            // _recommendationTextBox
166            // 
167            this._recommendationTextBox.Location = new System.Drawing.Point(0, 304);
168            this._recommendationTextBox.Multiline = true;
169            this._recommendationTextBox.Name = "_recommendationTextBox";
170            this._recommendationTextBox.ReadOnly = true;
171            this._recommendationTextBox.Size = new System.Drawing.Size(480, 60);
172            this._recommendationTextBox.TabIndex = 6;
173            // 
174            // _issueDescriptionLabel
175            // 
176            this._issueDescriptionLabel.AutoSize = true;
177            this._issueDescriptionLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
178            this._issueDescriptionLabel.Location = new System.Drawing.Point(0, 215);
179            this._issueDescriptionLabel.Name = "_issueDescriptionLabel";
180            this._issueDescriptionLabel.Size = new System.Drawing.Size(107, 13);
181            this._issueDescriptionLabel.TabIndex = 3;
182            this._issueDescriptionLabel.Text = global::Web.Management.PHP.Resources.RecommendConfigDialogIssueDescription;
183            // 
184            // _issueDescriptionTextBox
185            // 
186            this._issueDescriptionTextBox.Location = new System.Drawing.Point(0, 232);
187            this._issueDescriptionTextBox.Multiline = true;
188            this._issueDescriptionTextBox.Name = "_issueDescriptionTextBox";
189            this._issueDescriptionTextBox.ReadOnly = true;
190            this._issueDescriptionTextBox.Size = new System.Drawing.Size(480, 41);
191            this._issueDescriptionTextBox.TabIndex = 4;
192            // 
193            // _formDescriptionLabel
194            // 
195            this._formDescriptionLabel.Dock = System.Windows.Forms.DockStyle.Top;
196            this._formDescriptionLabel.Location = new System.Drawing.Point(0, 0);
197            this._formDescriptionLabel.Name = "_formDescriptionLabel";
198            this._formDescriptionLabel.Size = new System.Drawing.Size(504, 38);
199            this._formDescriptionLabel.TabIndex = 0;
200            this._formDescriptionLabel.Text = global::Web.Management.PHP.Resources.RecommendConfigDialogDescription;
201            // 
202            // RecommendedConfigDialog
203            // 
204            this.ClientSize = new System.Drawing.Size(504, 442);
205            this.Controls.Add(this._formDescriptionLabel);
206            this.Controls.Add(this._issueDescriptionTextBox);
207            this.Controls.Add(this._issueDescriptionLabel);
208            this.Controls.Add(this._recommendationTextBox);
209            this.Controls.Add(this._recommendationLabel);
210            this.Controls.Add(this._configIssueLabel);
211            this.Controls.Add(this._configIssuesListView);
212            this.Name = "RecommendedConfigDialog";
213            this.ResumeLayout(false);
214#if VSDesigner
215            this.PerformLayout();
216#endif
217        }
218
219        private void InitializeUI()
220        {
221            _contentPanel = new ManagementPanel();
222            _contentPanel.SuspendLayout();
223
224            this._contentPanel.Location = new System.Drawing.Point(0, 0);
225            this._contentPanel.Dock = DockStyle.Fill;
226            this._contentPanel.Controls.Add(_formDescriptionLabel);
227            this._contentPanel.Controls.Add(_configIssueLabel);
228            this._contentPanel.Controls.Add(_configIssuesListView);
229            this._contentPanel.Controls.Add(_issueDescriptionLabel);
230            this._contentPanel.Controls.Add(_issueDescriptionTextBox);
231            this._contentPanel.Controls.Add(_recommendationLabel);
232            this._contentPanel.Controls.Add(_recommendationTextBox);
233
234            this._contentPanel.ResumeLayout(false);
235            this._contentPanel.PerformLayout();
236
237            this.Text = Resources.RecommendConfigDialogTitle;
238
239            SetContent(_contentPanel);
240            UpdateTaskForm();
241
242        }
243
244        protected override void OnAccept()
245        {
246            try
247            {
248                ArrayList selectedIssues = new ArrayList();
249                foreach (ListViewItem item in _configIssuesListView.CheckedItems)
250                {
251                    object[] tag = item.Tag as object[];
252                    selectedIssues.Add(tag[TagIssueIndex]);
253                }
254
255                _module.Proxy.ApplyRecommendedSettings(selectedIssues);
256                DialogResult = DialogResult.OK;
257                Close();
258            }
259            catch (Exception ex)
260            {
261                DisplayErrorMessage(ex, Resources.ResourceManager);
262            }
263        }
264
265        private void OnConfigIssuesDoWork(object sender, DoWorkEventArgs e)
266        {
267            e.Result = _module.Proxy.GetConfigIssues();
268        }
269
270        private void OnConfigIssuesDoWorkCompleted(object sender, RunWorkerCompletedEventArgs e)
271        {
272            _configIssuesListView.BeginUpdate();
273            _configIssuesListView.SuspendLayout();
274
275            try
276            {
277                RemoteObjectCollection<PHPConfigIssue> configIssues = e.Result as RemoteObjectCollection<PHPConfigIssue>;
278                if (configIssues != null)
279                {
280                    foreach (PHPConfigIssue configIssue in configIssues)
281                    {
282                        ListViewItem listViewItem = new ListViewItem(configIssue.SettingName);
283                        if (String.IsNullOrEmpty(configIssue.CurrentValue))
284                        {
285                            listViewItem.SubItems.Add(Resources.ConfigIssueNone);
286                        }
287                        else
288                        {
289                            listViewItem.SubItems.Add(configIssue.CurrentValue);
290                        }
291                        listViewItem.SubItems.Add(configIssue.RecommendedValue);
292                        listViewItem.Tag = new object[TagSize] { GetResourceStringByName(configIssue.IssueDescription), 
293                                                           GetResourceStringByName(configIssue.Recommendation),
294                                                           configIssue.IssueIndex
295                                                         };
296                        _configIssuesListView.Items.Add(listViewItem);
297                    }
298                }
299            }
300            catch (Exception ex)
301            {
302                DisplayErrorMessage(ex, Resources.ResourceManager);
303            }
304            finally
305            {
306                _configIssuesListView.ResumeLayout();
307                _configIssuesListView.EndUpdate();
308            }
309
310            if (_configIssuesListView.Items.Count > 0)
311            {
312                _configIssuesListView.Focus();
313                _configIssuesListView.Items[0].Selected = true;
314                UpdateTaskForm();
315            }
316        }
317
318        private void OnConfigIssuesListViewItemChecked(object sender, ItemCheckedEventArgs e)
319        {
320            UpdateTaskForm();
321        }
322
323        private void OnConfigIssuesListViewSelectedIndexChanged(object sender, EventArgs e)
324        {
325            if (_configIssuesListView.SelectedItems.Count > 0)
326            {
327                object[] tag = _configIssuesListView.SelectedItems[0].Tag as object[];
328                _issueDescriptionTextBox.Text = (string)tag[TagIssueDescription];
329                _recommendationTextBox.Text = (string)tag[TagIssueRecommendation];
330            }
331        }
332
333        protected override void OnLoad(EventArgs e)
334        {
335            base.OnLoad(e);
336
337            StartAsyncTask(OnConfigIssuesDoWork, OnConfigIssuesDoWorkCompleted);
338        }
339
340        protected override void ShowHelp()
341        {
342            Helper.Browse(Globals.RecommendedConfigOnlineHelp);
343        }
344
345    }
346}