PageRenderTime 32ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/stable-1.1.1/Client/Setup/ChangeVersionDialog.cs

#
C# | 233 lines | 177 code | 30 blank | 26 comment | 4 complexity | eca3a7a0ed9264a4c56560248443e968 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. namespace Web.Management.PHP.Setup
  16. {
  17. internal sealed class ChangeVersionDialog :
  18. #if VSDesigner
  19. Form
  20. #else
  21. TaskForm
  22. #endif
  23. {
  24. private PHPModule _module;
  25. private ManagementPanel _contentPanel;
  26. private Label _selectVersionLabel;
  27. private ComboBox _versionComboBox;
  28. /// <summary>
  29. /// Required designer variable.
  30. /// </summary>
  31. private System.ComponentModel.IContainer components = null;
  32. public ChangeVersionDialog(PHPModule module) : base(module)
  33. {
  34. _module = module;
  35. InitializeComponent();
  36. InitializeUI();
  37. }
  38. protected override bool CanAccept
  39. {
  40. get
  41. {
  42. return (_versionComboBox.Items.Count > 0);
  43. }
  44. }
  45. protected override bool CanShowHelp
  46. {
  47. get
  48. {
  49. return true;
  50. }
  51. }
  52. /// <summary>
  53. /// Clean up any resources being used.
  54. /// </summary>
  55. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  56. protected override void Dispose(bool disposing)
  57. {
  58. if (disposing && (components != null))
  59. {
  60. components.Dispose();
  61. }
  62. base.Dispose(disposing);
  63. }
  64. private void InitializeComponent()
  65. {
  66. this._selectVersionLabel = new System.Windows.Forms.Label();
  67. this._versionComboBox = new System.Windows.Forms.ComboBox();
  68. this.SuspendLayout();
  69. //
  70. // _selectVersionLabel
  71. //
  72. this._selectVersionLabel.AutoSize = true;
  73. this._selectVersionLabel.Location = new System.Drawing.Point(0, 13);
  74. this._selectVersionLabel.Name = "_selectVersionLabel";
  75. this._selectVersionLabel.Size = new System.Drawing.Size(102, 13);
  76. this._selectVersionLabel.TabIndex = 0;
  77. this._selectVersionLabel.Text = Resources.ChangeVersionDialogSelectVersion;
  78. //
  79. // _versionComboBox
  80. //
  81. this._versionComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  82. this._versionComboBox.FormattingEnabled = true;
  83. this._versionComboBox.Location = new System.Drawing.Point(3, 30);
  84. this._versionComboBox.Name = "_versionComboBox";
  85. this._versionComboBox.Size = new System.Drawing.Size(326, 21);
  86. this._versionComboBox.TabIndex = 1;
  87. //
  88. // ChangeVersionDialog
  89. //
  90. this.ClientSize = new System.Drawing.Size(364, 142);
  91. this.Controls.Add(this._versionComboBox);
  92. this.Controls.Add(this._selectVersionLabel);
  93. this.Name = "ChangeVersionDialog";
  94. this.ResumeLayout(false);
  95. #if VSDesigner
  96. this.PerformLayout();
  97. #endif
  98. }
  99. private void InitializeUI()
  100. {
  101. _contentPanel = new ManagementPanel();
  102. _contentPanel.SuspendLayout();
  103. this._contentPanel.Location = new System.Drawing.Point(0, 0);
  104. this._contentPanel.Dock = DockStyle.Fill;
  105. this._contentPanel.Controls.Add(_selectVersionLabel);
  106. this._contentPanel.Controls.Add(_versionComboBox);
  107. this._contentPanel.ResumeLayout(false);
  108. this._contentPanel.PerformLayout();
  109. this.Text = Resources.ChangeVersionDialogTitle;
  110. SetContent(_contentPanel);
  111. UpdateTaskForm();
  112. }
  113. protected override void OnAccept()
  114. {
  115. PHPVersion selectedItem = (PHPVersion)_versionComboBox.SelectedItem;
  116. try
  117. {
  118. _module.Proxy.SelectPHPVersion(selectedItem.Name);
  119. DialogResult = DialogResult.OK;
  120. }
  121. catch (Exception ex)
  122. {
  123. DisplayErrorMessage(ex, Resources.ResourceManager);
  124. }
  125. Close();
  126. }
  127. private void OnGetVersionsDoWork(object sender, DoWorkEventArgs e)
  128. {
  129. e.Result = _module.Proxy.GetAllPHPVersions();
  130. }
  131. private void OnGetVersionsDoWorkCompleted(object sender, RunWorkerCompletedEventArgs e)
  132. {
  133. _versionComboBox.BeginUpdate();
  134. _versionComboBox.SuspendLayout();
  135. try
  136. {
  137. ArrayList versions = e.Result as ArrayList;
  138. foreach (string[] version in versions)
  139. {
  140. _versionComboBox.Items.Add(new PHPVersion(version[0], version[1], version[2]));
  141. }
  142. _versionComboBox.DisplayMember = "Version";
  143. _versionComboBox.SelectedIndex = 0;
  144. if (_versionComboBox.Items.Count > 0)
  145. {
  146. UpdateTaskForm();
  147. }
  148. }
  149. catch (Exception ex)
  150. {
  151. DisplayErrorMessage(ex, Resources.ResourceManager);
  152. }
  153. finally
  154. {
  155. _versionComboBox.ResumeLayout();
  156. _versionComboBox.EndUpdate();
  157. }
  158. }
  159. protected override void OnLoad(EventArgs e)
  160. {
  161. base.OnLoad(e);
  162. StartAsyncTask(OnGetVersionsDoWork, OnGetVersionsDoWorkCompleted);
  163. }
  164. protected override void ShowHelp()
  165. {
  166. Helper.Browse(Globals.ChangeVersionOnlineHelp);
  167. }
  168. // Used internally for the select version combo box
  169. private class PHPVersion
  170. {
  171. private string _name;
  172. private string _scriptProcessor;
  173. private string _version;
  174. public PHPVersion(string name, string scriptProcessor, string version)
  175. {
  176. _name = name;
  177. _scriptProcessor = scriptProcessor;
  178. _version = version;
  179. }
  180. public string Name
  181. {
  182. get
  183. {
  184. return _name;
  185. }
  186. }
  187. public string ScriptProcessor
  188. {
  189. get
  190. {
  191. return _scriptProcessor;
  192. }
  193. }
  194. public string Version
  195. {
  196. get
  197. {
  198. return _version + " (" + _scriptProcessor + ")";
  199. }
  200. }
  201. }
  202. }
  203. }