- Timestamp:
- 05/04/10 20:16:21 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.PluginInfrastructure/Advanced/ProductEditor.cs
r3608 r3612 32 32 33 33 namespace HeuristicLab.PluginInfrastructure.Advanced { 34 internal partial class ProductEditor : UserControl { 34 internal partial class ProductEditor : InstallationManagerControl { 35 private const string RefreshMessage = "Downloading product and plugin information..."; 36 private const string UploadMessage = "Uploading product and plugin information..."; 37 private const string DeleteProductMessage = "Deleting product..."; 38 35 39 private BackgroundWorker refreshProductsWorker; 36 40 private BackgroundWorker uploadChangedProductsWorker; 41 private BackgroundWorker deleteProductWorker; 42 37 43 private List<DeploymentService.ProductDescription> products; 38 44 private List<DeploymentService.PluginDescription> plugins; … … 54 60 uploadChangedProductsWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(uploadChangedProductsWorker_RunWorkerCompleted); 55 61 uploadChangedProductsWorker.DoWork += new DoWorkEventHandler(uploadChangedProductsWorker_DoWork); 56 } 62 63 deleteProductWorker = new BackgroundWorker(); 64 deleteProductWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(deleteProductWorker_RunWorkerCompleted); 65 deleteProductWorker.DoWork += new DoWorkEventHandler(deleteProductWorker_DoWork); 66 } 67 68 #region event handlers for delete product background worker 69 void deleteProductWorker_DoWork(object sender, DoWorkEventArgs e) { 70 var products = (IEnumerable<DeploymentService.ProductDescription>)e.Argument; 71 var adminClient = DeploymentService.AdminClientFactory.CreateClient(); 72 // upload 73 try { 74 foreach (var product in products) { 75 adminClient.DeleteProduct(product); 76 } 77 adminClient.Close(); 78 } 79 catch (TimeoutException) { 80 adminClient.Abort(); 81 throw; 82 } 83 catch (FaultException) { 84 adminClient.Abort(); 85 throw; 86 } 87 catch (CommunicationException) { 88 adminClient.Abort(); 89 throw; 90 } 91 // refresh 92 var updateClient = DeploymentService.UpdateClientFactory.CreateClient(); 93 try { 94 e.Result = new object[] { updateClient.GetProducts(), updateClient.GetPlugins() }; 95 updateClient.Close(); 96 } 97 catch (TimeoutException) { 98 updateClient.Abort(); 99 throw; 100 } 101 catch (FaultException) { 102 updateClient.Abort(); 103 throw; 104 } 105 catch (CommunicationException) { 106 updateClient.Abort(); 107 throw; 108 } 109 } 110 111 void deleteProductWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { 112 if (e.Error != null) { 113 StatusView.ShowError("Connection Error", 114 "There was an error while connecting to the server." + Environment.NewLine + 115 "Please check your connection settings and user credentials."); 116 DisableControls(); 117 } else { 118 this.products = new List<DeploymentService.ProductDescription>( 119 (DeploymentService.ProductDescription[])((object[])e.Result)[0]); 120 this.plugins = new List<DeploymentService.PluginDescription>( 121 (DeploymentService.PluginDescription[])((object[])e.Result)[1]); 122 123 UpdateProductsList(); 124 dirtyProducts.Clear(); 125 EnableControls(); 126 } 127 StatusView.HideProgressIndicator(); 128 StatusView.RemoveMessage(DeleteProductMessage); 129 StatusView.UnlockUI(); 130 } 131 #endregion 57 132 58 133 #region event handlers for upload products background worker … … 60 135 var products = (IEnumerable<DeploymentService.ProductDescription>)e.Argument; 61 136 var adminClient = DeploymentService.AdminClientFactory.CreateClient(); 62 foreach (var product in products) { 63 adminClient.DeployProduct(product); 137 // upload 138 try { 139 foreach (var product in products) { 140 adminClient.DeployProduct(product); 141 } 142 adminClient.Close(); 143 } 144 catch (TimeoutException) { 145 adminClient.Abort(); 146 throw; 147 } 148 catch (FaultException) { 149 adminClient.Abort(); 150 throw; 151 } 152 catch (CommunicationException) { 153 adminClient.Abort(); 154 throw; 155 } 156 // refresh 157 var updateClient = DeploymentService.UpdateClientFactory.CreateClient(); 158 try { 159 e.Result = new object[] { updateClient.GetProducts(), updateClient.GetPlugins() }; 160 updateClient.Close(); 161 } 162 catch (TimeoutException) { 163 updateClient.Abort(); 164 throw; 165 } 166 catch (FaultException) { 167 updateClient.Abort(); 168 throw; 169 } 170 catch (CommunicationException) { 171 updateClient.Abort(); 172 throw; 64 173 } 65 174 } … … 67 176 private void uploadChangedProductsWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { 68 177 if (e.Error != null) { 69 MessageBox.Show("There was an error while connecting to the server." + Environment.NewLine + 178 StatusView.ShowError("Connection Error", 179 "There was an error while connecting to the server." + Environment.NewLine + 70 180 "Please check your connection settings and user credentials."); 181 DisableControls(); 71 182 } else { 72 this.Enabled = true; 73 refreshProductsWorker.RunWorkerAsync(); 74 } 183 this.products = new List<DeploymentService.ProductDescription>( 184 (DeploymentService.ProductDescription[])((object[])e.Result)[0]); 185 this.plugins = new List<DeploymentService.PluginDescription>( 186 (DeploymentService.PluginDescription[])((object[])e.Result)[1]); 187 188 UpdateProductsList(); 189 dirtyProducts.Clear(); 190 EnableControls(); 191 } 192 StatusView.HideProgressIndicator(); 193 StatusView.RemoveMessage(UploadMessage); 194 StatusView.UnlockUI(); 75 195 } 76 196 #endregion … … 79 199 private void refreshProductsWorker_DoWork(object sender, DoWorkEventArgs e) { 80 200 var updateClient = DeploymentService.UpdateClientFactory.CreateClient(); 81 e.Result = new object[] { updateClient.GetProducts(), updateClient.GetPlugins() }; 201 try { 202 e.Result = new object[] { updateClient.GetProducts(), updateClient.GetPlugins() }; 203 updateClient.Close(); 204 } 205 catch (TimeoutException) { 206 updateClient.Abort(); 207 throw; 208 } 209 catch (FaultException) { 210 updateClient.Abort(); 211 throw; 212 } 213 catch (CommunicationException) { 214 updateClient.Abort(); 215 throw; 216 } 82 217 } 83 218 84 219 private void refreshProductsWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { 85 220 if (e.Error != null) { 86 MessageBox.Show("There was an error while connecting to the server." + Environment.NewLine + 221 StatusView.ShowError("Connection Error", 222 "There was an error while connecting to the server." + Environment.NewLine + 87 223 "Please check your connection settings and user credentials."); 224 DisableControls(); 88 225 } else { 89 226 this.products = new List<DeploymentService.ProductDescription>( … … 92 229 (DeploymentService.PluginDescription[])((object[])e.Result)[1]); 93 230 231 94 232 UpdateProductsList(); 95 233 dirtyProducts.Clear(); 96 97 Cursor = Cursors.Default; 98 SetControlsEnabled(true); 99 } 234 EnableControls(); 235 } 236 StatusView.HideProgressIndicator(); 237 StatusView.RemoveMessage(RefreshMessage); 238 StatusView.UnlockUI(); 100 239 } 101 240 #endregion … … 107 246 } 108 247 foreach (ColumnHeader column in productsListView.Columns) 109 column.Width = -1; 248 if (productsListView.Items.Count > 0) 249 column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); 250 else column.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize); 110 251 } 111 252 … … 113 254 bool productSelected = productsListView.SelectedItems.Count > 0; 114 255 detailsGroupBox.Enabled = productSelected; 115 uploadButton.Enabled = productSelected; 116 if (productsListView.SelectedItems.Count == 0) { 117 ClearProductDetails(); 118 return; 119 } 120 DeploymentService.ProductDescription activeProduct = (DeploymentService.ProductDescription)((ListViewItem)productsListView.SelectedItems[0]).Tag; 121 UpdateProductDetails(activeProduct); 122 } 123 124 private void ClearProductDetails() { 125 nameTextBox.Text = string.Empty; 126 versionTextBox.Text = string.Empty; 127 pluginListView.Plugins = new IPluginDescription[0]; 128 } 129 130 private void UpdateProductDetails(DeploymentService.ProductDescription activeProduct) { 131 nameTextBox.Text = activeProduct.Name; 132 versionTextBox.Text = activeProduct.Version.ToString(); 133 134 UpdatePluginsListView(); 135 } 136 137 private ListViewItem CreateListViewItem(DeploymentService.ProductDescription productDescription) { 138 ListViewItem item = new ListViewItem(new string[] { productDescription.Name, productDescription.Version.ToString() }); 139 item.Tag = productDescription; 140 item.ImageIndex = 0; 141 return item; 142 } 143 144 private void SetControlsEnabled(bool enabled) { 145 uploadButton.Enabled = enabled; 146 refreshButton.Enabled = enabled; 147 newProductButton.Enabled = enabled; 148 splitContainer.Enabled = enabled; 149 productsListView.Enabled = enabled; 150 nameLabel.Enabled = enabled; 151 nameTextBox.Enabled = enabled; 152 versionLabel.Enabled = enabled; 153 versionTextBox.Enabled = enabled; 154 pluginListView.Enabled = enabled; 155 } 256 deleteProductButton.Enabled = productSelected; 257 uploadButton.Enabled = dirtyProducts.Count > 0; 258 if (productSelected) { 259 DeploymentService.ProductDescription activeProduct = (DeploymentService.ProductDescription)((ListViewItem)productsListView.SelectedItems[0]).Tag; 260 nameTextBox.Text = activeProduct.Name; 261 versionTextBox.Text = activeProduct.Version.ToString(); 262 263 // populate plugins list view 264 ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0]; 265 foreach (var plugin in plugins.OfType<IPluginDescription>()) { 266 pluginListView.Items.Add(CreateListViewItem(plugin)); 267 } 268 269 pluginListView.CheckItems(from plugin in activeProduct.Plugins 270 let item = FindItemForPlugin(plugin) 271 where item != null 272 select item); 273 274 } else { 275 nameTextBox.Text = string.Empty; 276 versionTextBox.Text = string.Empty; 277 pluginListView.Items.Clear(); 278 } 279 } 280 156 281 157 282 #region button event handlers … … 164 289 165 290 private void saveButton_Click(object sender, EventArgs e) { 166 this.Enabled = false; 291 StatusView.LockUI(); 292 StatusView.ShowProgressIndicator(); 293 StatusView.ShowMessage(UploadMessage); 167 294 uploadChangedProductsWorker.RunWorkerAsync(dirtyProducts); 168 295 } 169 296 private void refreshButton_Click(object sender, EventArgs e) { 170 SetControlsEnabled(false); 171 Cursor = Cursors.AppStarting; 297 StatusView.LockUI(); 298 StatusView.ShowProgressIndicator(); 299 StatusView.ShowMessage(RefreshMessage); 172 300 refreshProductsWorker.RunWorkerAsync(); 301 } 302 private void deleteProductButton_Click(object sender, EventArgs e) { 303 StatusView.LockUI(); 304 StatusView.ShowProgressIndicator(); 305 StatusView.ShowMessage(DeleteProductMessage); 306 var selectedProducts = from item in productsListView.SelectedItems.OfType<ListViewItem>() 307 select (DeploymentService.ProductDescription)item.Tag; 308 deleteProductWorker.RunWorkerAsync(selectedProducts.ToList()); 173 309 } 174 310 … … 177 313 #region textbox changed event handlers 178 314 private void nameTextBox_TextChanged(object sender, EventArgs e) { 179 ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0]; 180 DeploymentService.ProductDescription activeProduct = (DeploymentService.ProductDescription)activeItem.Tag; 181 if (string.IsNullOrEmpty(nameTextBox.Name)) { 182 errorProvider.SetError(nameTextBox, "Invalid value"); 183 } else { 184 if (activeProduct.Name != nameTextBox.Text) { 185 activeProduct.Name = nameTextBox.Text; 186 activeItem.SubItems[0].Text = activeProduct.Name; 187 errorProvider.SetError(nameTextBox, string.Empty); 188 MarkProductDirty(activeProduct); 315 if (productsListView.SelectedItems.Count > 0) { 316 ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0]; 317 DeploymentService.ProductDescription activeProduct = (DeploymentService.ProductDescription)activeItem.Tag; 318 if (string.IsNullOrEmpty(nameTextBox.Name)) { 319 errorProvider.SetError(nameTextBox, "Invalid value"); 320 } else { 321 if (activeProduct.Name != nameTextBox.Text) { 322 activeProduct.Name = nameTextBox.Text; 323 activeItem.SubItems[0].Text = activeProduct.Name; 324 errorProvider.SetError(nameTextBox, string.Empty); 325 MarkProductDirty(activeProduct); 326 } 189 327 } 190 328 } … … 193 331 194 332 private void versionTextBox_TextChanged(object sender, EventArgs e) { 195 ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0]; 196 DeploymentService.ProductDescription activeProduct = (DeploymentService.ProductDescription)activeItem.Tag; 197 try { 198 var newVersion = new Version(versionTextBox.Text); 199 if (activeProduct.Version != newVersion) { 200 activeProduct.Version = newVersion; 201 activeItem.SubItems[1].Text = versionTextBox.Text; 202 errorProvider.SetError(versionTextBox, string.Empty); 203 MarkProductDirty(activeProduct); 204 } 205 } 206 catch (OverflowException) { 207 errorProvider.SetError(versionTextBox, "Invalid value"); 208 } 209 210 catch (ArgumentException) { 211 errorProvider.SetError(versionTextBox, "Invalid value"); 212 } 213 catch (FormatException) { 214 errorProvider.SetError(versionTextBox, "Invalid value"); 333 if (productsListView.SelectedItems.Count > 0) { 334 ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0]; 335 DeploymentService.ProductDescription activeProduct = (DeploymentService.ProductDescription)activeItem.Tag; 336 try { 337 var newVersion = new Version(versionTextBox.Text); 338 if (activeProduct.Version != newVersion) { 339 activeProduct.Version = newVersion; 340 activeItem.SubItems[1].Text = versionTextBox.Text; 341 errorProvider.SetError(versionTextBox, string.Empty); 342 MarkProductDirty(activeProduct); 343 } 344 } 345 catch (OverflowException) { 346 errorProvider.SetError(versionTextBox, "Invalid value"); 347 } 348 349 catch (ArgumentException) { 350 errorProvider.SetError(versionTextBox, "Invalid value"); 351 } 352 catch (FormatException) { 353 errorProvider.SetError(versionTextBox, "Invalid value"); 354 } 215 355 } 216 356 } … … 219 359 220 360 #region plugin list view 221 private void UpdatePluginsListView() {222 ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0];223 DeploymentService.ProductDescription activeProduct = (DeploymentService.ProductDescription)activeItem.Tag;224 pluginListView.Plugins = plugins.OfType<IPluginDescription>();225 foreach (var plugin in activeProduct.Plugins) pluginListView.CheckPlugin(plugin);226 }227 228 361 private void pluginListView_ItemChecked(object sender, ItemCheckedEventArgs e) { 229 362 ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0]; 230 363 DeploymentService.ProductDescription activeProduct = (DeploymentService.ProductDescription)activeItem.Tag; 231 activeProduct.Plugins = pluginListView.CheckedPlugins.Cast<DeploymentService.PluginDescription>().ToArray(); 364 activeProduct.Plugins = (from item in pluginListView.CheckedItems.OfType<ListViewItem>() 365 select (DeploymentService.PluginDescription)item.Tag).ToArray(); 232 366 MarkProductDirty(activeProduct); 233 367 } 234 368 #endregion 235 369 370 #region helper 236 371 private void MarkProductDirty(HeuristicLab.PluginInfrastructure.Advanced.DeploymentService.ProductDescription activeProduct) { 237 372 if (!dirtyProducts.Contains(activeProduct)) { … … 241 376 } 242 377 } 378 private ListViewItem CreateListViewItem(DeploymentService.ProductDescription productDescription) { 379 ListViewItem item = new ListViewItem(new string[] { productDescription.Name, productDescription.Version.ToString() }); 380 item.Tag = productDescription; 381 item.ImageIndex = 0; 382 return item; 383 } 384 385 private ListViewItem CreateListViewItem(IPluginDescription plugin) { 386 ListViewItem item = new ListViewItem(new string[] { plugin.Name, plugin.Version.ToString(), 387 string.Empty, plugin.Description }); 388 item.Tag = plugin; 389 item.ImageIndex = 0; 390 item.Checked = false; 391 return item; 392 } 393 243 394 private ListViewItem FindItemForProduct(HeuristicLab.PluginInfrastructure.Advanced.DeploymentService.ProductDescription activeProduct) { 244 395 return (from item in productsListView.Items.OfType<ListViewItem>() … … 248 399 select item).Single(); 249 400 } 401 402 private ListViewItem FindItemForPlugin(IPluginDescription plugin) { 403 return (from i in pluginListView.Items.Cast<ListViewItem>() 404 let p = i.Tag as IPluginDescription 405 where p != null 406 where p.Name == plugin.Name 407 where p.Version == plugin.Version 408 select i).SingleOrDefault(); 409 } 410 411 private void DisableControls() { 412 newProductButton.Enabled = false; 413 productsListView.Enabled = false; 414 detailsGroupBox.Enabled = false; 415 deleteProductButton.Enabled = false; 416 nameTextBox.Text = string.Empty; 417 versionTextBox.Text = string.Empty; 418 pluginListView.Items.Clear(); 419 } 420 private void EnableControls() { 421 newProductButton.Enabled = true; 422 productsListView.Enabled = true; 423 } 424 #endregion 425 250 426 } 251 427 }
Note: See TracChangeset
for help on using the changeset viewer.