[3081] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
[2802] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Drawing;
|
---|
| 26 | using System.Data;
|
---|
| 27 | using System.Linq;
|
---|
| 28 | using System.Text;
|
---|
| 29 | using System.Windows.Forms;
|
---|
| 30 | using HeuristicLab.MainForm;
|
---|
[2816] | 31 | using PluginDeploymentService = HeuristicLab.PluginInfrastructure.Advanced.DeploymentService;
|
---|
[3015] | 32 | using System.ServiceModel;
|
---|
| 33 | using HeuristicLab.PluginInfrastructure;
|
---|
[2802] | 34 |
|
---|
[3081] | 35 | namespace HeuristicLab.PluginAdministrator {
|
---|
| 36 | internal partial class ProductEditor : HeuristicLab.MainForm.WindowsForms.View {
|
---|
[2802] | 37 | private BackgroundWorker refreshProductsWorker;
|
---|
| 38 | private BackgroundWorker uploadChangedProductsWorker;
|
---|
[2816] | 39 | private List<PluginDeploymentService.ProductDescription> products;
|
---|
| 40 | private List<PluginDeploymentService.PluginDescription> plugins;
|
---|
| 41 | private HashSet<PluginDeploymentService.ProductDescription> dirtyProducts;
|
---|
[2802] | 42 |
|
---|
| 43 | public ProductEditor() {
|
---|
| 44 | InitializeComponent();
|
---|
| 45 | Caption = "Products";
|
---|
| 46 |
|
---|
[3015] | 47 | productImageList.Images.Add(HeuristicLab.Common.Resources.VS2008ImageLibrary.Assembly);
|
---|
| 48 | productImageList.Images.Add(HeuristicLab.Common.Resources.VS2008ImageLibrary.ArrowUp);
|
---|
| 49 | pluginImageList.Images.Add(HeuristicLab.Common.Resources.VS2008ImageLibrary.Assembly);
|
---|
| 50 |
|
---|
[2816] | 51 | dirtyProducts = new HashSet<PluginDeploymentService.ProductDescription>();
|
---|
[2802] | 52 | refreshProductsWorker = new BackgroundWorker();
|
---|
| 53 | refreshProductsWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(refreshProductsWorker_RunWorkerCompleted);
|
---|
| 54 | refreshProductsWorker.DoWork += new DoWorkEventHandler(refreshProductsWorker_DoWork);
|
---|
| 55 |
|
---|
| 56 | uploadChangedProductsWorker = new BackgroundWorker();
|
---|
| 57 | uploadChangedProductsWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(uploadChangedProductsWorker_RunWorkerCompleted);
|
---|
| 58 | uploadChangedProductsWorker.DoWork += new DoWorkEventHandler(uploadChangedProductsWorker_DoWork);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[3015] | 61 | #region event handlers for upload products background worker
|
---|
| 62 | private void uploadChangedProductsWorker_DoWork(object sender, DoWorkEventArgs e) {
|
---|
[2816] | 63 | var products = (IEnumerable<PluginDeploymentService.ProductDescription>)e.Argument;
|
---|
[3015] | 64 | var adminClient = PluginDeploymentService.AdminClientFactory.CreateClient();
|
---|
| 65 | try {
|
---|
[2802] | 66 | foreach (var product in products) {
|
---|
| 67 | adminClient.DeployProduct(product);
|
---|
| 68 | }
|
---|
[3015] | 69 | e.Cancel = false;
|
---|
[2802] | 70 | }
|
---|
[3015] | 71 | catch (FaultException) {
|
---|
| 72 | }
|
---|
[2802] | 73 | }
|
---|
| 74 |
|
---|
[3015] | 75 | private void uploadChangedProductsWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
|
---|
[2802] | 76 | this.Enabled = true;
|
---|
[3015] | 77 | refreshProductsWorker.RunWorkerAsync();
|
---|
[2802] | 78 | }
|
---|
[3015] | 79 | #endregion
|
---|
[2802] | 80 |
|
---|
[3015] | 81 | #region event handlers for refresh products background worker
|
---|
| 82 | private void refreshProductsWorker_DoWork(object sender, DoWorkEventArgs e) {
|
---|
| 83 | var updateClient = PluginDeploymentService.UpdateClientFactory.CreateClient();
|
---|
| 84 | try {
|
---|
| 85 | e.Result = new object[] { updateClient.GetProducts(), updateClient.GetPlugins() };
|
---|
| 86 | }
|
---|
| 87 | catch (FaultException) {
|
---|
| 88 | e.Cancel = true;
|
---|
| 89 | }
|
---|
[2802] | 90 | }
|
---|
| 91 |
|
---|
[3015] | 92 | private void refreshProductsWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
|
---|
[3179] | 93 | if (!e.Cancelled && e.Result != null) {
|
---|
| 94 | this.products = new List<PluginDeploymentService.ProductDescription>(
|
---|
| 95 | (PluginDeploymentService.ProductDescription[])((object[])e.Result)[0]);
|
---|
| 96 | this.plugins = new List<PluginDeploymentService.PluginDescription>(
|
---|
| 97 | (PluginDeploymentService.PluginDescription[])((object[])e.Result)[1]);
|
---|
[2802] | 98 |
|
---|
[3179] | 99 | UpdateProductsList();
|
---|
| 100 | dirtyProducts.Clear();
|
---|
[2802] | 101 |
|
---|
[3179] | 102 | Cursor = Cursors.Default;
|
---|
| 103 | SetControlsEnabled(true);
|
---|
| 104 | }
|
---|
[2802] | 105 | }
|
---|
[3015] | 106 | #endregion
|
---|
[2802] | 107 |
|
---|
| 108 | private void UpdateProductsList() {
|
---|
[3015] | 109 | productsListView.Items.Clear();
|
---|
[2802] | 110 | foreach (var prodDesc in products) {
|
---|
[3015] | 111 | productsListView.Items.Add(CreateListViewItem(prodDesc));
|
---|
[2802] | 112 | }
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | private void productsListBox_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
[3015] | 116 | if (productsListView.SelectedItems.Count == 0) return;
|
---|
| 117 | PluginDeploymentService.ProductDescription activeProduct = (PluginDeploymentService.ProductDescription)((ListViewItem)productsListView.SelectedItems[0]).Tag;
|
---|
[2802] | 118 | UpdateProductDetails(activeProduct);
|
---|
| 119 | }
|
---|
| 120 |
|
---|
[2816] | 121 | private void UpdateProductDetails(PluginDeploymentService.ProductDescription activeProduct) {
|
---|
[2802] | 122 | nameTextBox.Text = activeProduct.Name;
|
---|
| 123 | versionTextBox.Text = activeProduct.Version.ToString();
|
---|
| 124 |
|
---|
[3045] | 125 | UpdatePluginsListView();
|
---|
[2802] | 126 | }
|
---|
| 127 |
|
---|
[3015] | 128 | private ListViewItem CreateListViewItem(PluginDeploymentService.ProductDescription productDescription) {
|
---|
| 129 | ListViewItem item = new ListViewItem(new string[] { productDescription.Name, productDescription.Version.ToString() });
|
---|
| 130 | item.Tag = productDescription;
|
---|
| 131 | item.ImageIndex = 0;
|
---|
| 132 | return item;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
[2802] | 135 | private void SetControlsEnabled(bool enabled) {
|
---|
| 136 | saveButton.Enabled = enabled;
|
---|
| 137 | refreshButton.Enabled = enabled;
|
---|
[3045] | 138 | newProductButton.Enabled = enabled;
|
---|
[2802] | 139 | splitContainer.Enabled = enabled;
|
---|
[3179] | 140 | productsListView.Enabled = enabled;
|
---|
| 141 | nameLabel.Enabled = enabled;
|
---|
| 142 | nameTextBox.Enabled = enabled;
|
---|
| 143 | versionLabel.Enabled = enabled;
|
---|
| 144 | versionTextBox.Enabled = enabled;
|
---|
| 145 | pluginListView.Enabled = enabled;
|
---|
[2802] | 146 | }
|
---|
| 147 |
|
---|
[3045] | 148 | #region button event handlers
|
---|
[2802] | 149 | private void newProductButton_Click(object sender, EventArgs e) {
|
---|
[2816] | 150 | var newProduct = new PluginDeploymentService.ProductDescription("New product", new Version("0.0.0.0"));
|
---|
[2802] | 151 | ListViewItem item = CreateListViewItem(newProduct);
|
---|
[3015] | 152 | productsListView.Items.Add(item);
|
---|
| 153 | MarkProductDirty(newProduct);
|
---|
[2802] | 154 | }
|
---|
| 155 |
|
---|
| 156 | private void saveButton_Click(object sender, EventArgs e) {
|
---|
| 157 | this.Enabled = false;
|
---|
| 158 | uploadChangedProductsWorker.RunWorkerAsync(dirtyProducts);
|
---|
| 159 | }
|
---|
[3045] | 160 | private void refreshButton_Click(object sender, EventArgs e) {
|
---|
| 161 | SetControlsEnabled(false);
|
---|
| 162 | Cursor = Cursors.AppStarting;
|
---|
| 163 | refreshProductsWorker.RunWorkerAsync();
|
---|
| 164 | }
|
---|
[2802] | 165 |
|
---|
[3045] | 166 | #endregion
|
---|
| 167 |
|
---|
| 168 | #region textbox changed event handlers
|
---|
[2802] | 169 | private void nameTextBox_TextChanged(object sender, EventArgs e) {
|
---|
[3015] | 170 | ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0];
|
---|
[2816] | 171 | PluginDeploymentService.ProductDescription activeProduct = (PluginDeploymentService.ProductDescription)activeItem.Tag;
|
---|
[2802] | 172 | if (string.IsNullOrEmpty(nameTextBox.Name)) {
|
---|
| 173 | errorProvider.SetError(nameTextBox, "Invalid value");
|
---|
| 174 | } else {
|
---|
[3015] | 175 | if (activeProduct.Name != nameTextBox.Text) {
|
---|
| 176 | activeProduct.Name = nameTextBox.Text;
|
---|
| 177 | activeItem.SubItems[0].Text = activeProduct.Name;
|
---|
| 178 | errorProvider.SetError(nameTextBox, string.Empty);
|
---|
| 179 | MarkProductDirty(activeProduct);
|
---|
| 180 | }
|
---|
[2802] | 181 | }
|
---|
| 182 | }
|
---|
| 183 |
|
---|
[3015] | 184 |
|
---|
[2802] | 185 | private void versionTextBox_TextChanged(object sender, EventArgs e) {
|
---|
[3015] | 186 | ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0];
|
---|
[2816] | 187 | PluginDeploymentService.ProductDescription activeProduct = (PluginDeploymentService.ProductDescription)activeItem.Tag;
|
---|
[2802] | 188 | try {
|
---|
[3015] | 189 | var newVersion = new Version(versionTextBox.Text);
|
---|
| 190 | if (activeProduct.Version != newVersion) {
|
---|
| 191 | activeProduct.Version = newVersion;
|
---|
| 192 | activeItem.SubItems[1].Text = versionTextBox.Text;
|
---|
| 193 | errorProvider.SetError(versionTextBox, string.Empty);
|
---|
| 194 | MarkProductDirty(activeProduct);
|
---|
| 195 | }
|
---|
[2802] | 196 | }
|
---|
[3081] | 197 | catch (OverflowException) {
|
---|
[2802] | 198 | errorProvider.SetError(versionTextBox, "Invalid value");
|
---|
| 199 | }
|
---|
| 200 |
|
---|
[3081] | 201 | catch (ArgumentException) {
|
---|
[2802] | 202 | errorProvider.SetError(versionTextBox, "Invalid value");
|
---|
| 203 | }
|
---|
[3081] | 204 | catch (FormatException) {
|
---|
[2802] | 205 | errorProvider.SetError(versionTextBox, "Invalid value");
|
---|
| 206 | }
|
---|
| 207 | }
|
---|
[3045] | 208 | #endregion
|
---|
[3015] | 209 |
|
---|
[3045] | 210 |
|
---|
| 211 | #region plugin list view
|
---|
| 212 | private void UpdatePluginsListView() {
|
---|
[3015] | 213 | ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0];
|
---|
| 214 | PluginDeploymentService.ProductDescription activeProduct = (PluginDeploymentService.ProductDescription)activeItem.Tag;
|
---|
[3045] | 215 | pluginListView.Plugins = plugins.OfType<IPluginDescription>();
|
---|
| 216 | foreach (var plugin in activeProduct.Plugins) pluginListView.CheckPlugin(plugin);
|
---|
[3015] | 217 | }
|
---|
| 218 |
|
---|
[3045] | 219 | private void pluginListView_ItemChecked(object sender, ItemCheckedEventArgs e) {
|
---|
| 220 | ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0];
|
---|
| 221 | PluginDeploymentService.ProductDescription activeProduct = (PluginDeploymentService.ProductDescription)activeItem.Tag;
|
---|
| 222 | activeProduct.Plugins = pluginListView.CheckedPlugins.Cast<PluginDeploymentService.PluginDescription>().ToArray();
|
---|
| 223 | MarkProductDirty(activeProduct);
|
---|
| 224 | }
|
---|
| 225 | #endregion
|
---|
| 226 |
|
---|
[3015] | 227 | private void MarkProductDirty(HeuristicLab.PluginInfrastructure.Advanced.DeploymentService.ProductDescription activeProduct) {
|
---|
| 228 | if (!dirtyProducts.Contains(activeProduct)) {
|
---|
| 229 | dirtyProducts.Add(activeProduct);
|
---|
| 230 | var item = FindItemForProduct(activeProduct);
|
---|
| 231 | item.ImageIndex = 1;
|
---|
| 232 | }
|
---|
| 233 | }
|
---|
| 234 | private ListViewItem FindItemForProduct(HeuristicLab.PluginInfrastructure.Advanced.DeploymentService.ProductDescription activeProduct) {
|
---|
| 235 | return (from item in productsListView.Items.OfType<ListViewItem>()
|
---|
| 236 | let product = item.Tag as PluginDeploymentService.ProductDescription
|
---|
| 237 | where product != null
|
---|
| 238 | where product == activeProduct
|
---|
| 239 | select item).Single();
|
---|
| 240 | }
|
---|
[2802] | 241 | }
|
---|
| 242 | }
|
---|