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