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