PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/beta-1.0.2/Client/Setup/ChangeVersionDialog.cs

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