Changeset 3015 for branches/DeploymentServer Prototype/HeuristicLab.Services/HeuristicLab.DeploymentService.AdminClient/ProductEditor.cs
- Timestamp:
- 03/12/10 14:58:26 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DeploymentServer Prototype/HeuristicLab.Services/HeuristicLab.DeploymentService.AdminClient/ProductEditor.cs
r2816 r3015 9 9 using HeuristicLab.MainForm; 10 10 using PluginDeploymentService = HeuristicLab.PluginInfrastructure.Advanced.DeploymentService; 11 using System.ServiceModel; 12 using HeuristicLab.PluginInfrastructure; 11 13 12 14 namespace HeuristicLab.DeploymentService.AdminClient { … … 22 24 Caption = "Products"; 23 25 26 productImageList.Images.Add(HeuristicLab.Common.Resources.VS2008ImageLibrary.Assembly); 27 productImageList.Images.Add(HeuristicLab.Common.Resources.VS2008ImageLibrary.ArrowUp); 28 pluginImageList.Images.Add(HeuristicLab.Common.Resources.VS2008ImageLibrary.Assembly); 29 24 30 dirtyProducts = new HashSet<PluginDeploymentService.ProductDescription>(); 25 31 refreshProductsWorker = new BackgroundWorker(); … … 32 38 } 33 39 34 void uploadChangedProductsWorker_DoWork(object sender, DoWorkEventArgs e) { 40 #region event handlers for upload products background worker 41 private void uploadChangedProductsWorker_DoWork(object sender, DoWorkEventArgs e) { 35 42 var products = (IEnumerable<PluginDeploymentService.ProductDescription>)e.Argument; 36 using (var adminClient = new PluginDeploymentService.AdminClient()) { 43 var adminClient = PluginDeploymentService.AdminClientFactory.CreateClient(); 44 try { 37 45 foreach (var product in products) { 38 46 adminClient.DeployProduct(product); 39 47 } 40 } 41 e.Cancel = false; 42 } 43 44 void uploadChangedProductsWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { 48 e.Cancel = false; 49 } 50 catch (FaultException) { 51 } 52 } 53 54 private void uploadChangedProductsWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { 45 55 this.Enabled = true; 46 } 47 48 void refreshProductsWorker_DoWork(object sender, DoWorkEventArgs e) { 49 var updateClient = new PluginDeploymentService.UpdateClient(); 50 e.Result = new object[] { updateClient.GetProducts(), updateClient.GetPlugins() }; 51 } 52 53 void refreshProductsWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { 56 refreshProductsWorker.RunWorkerAsync(); 57 } 58 #endregion 59 60 #region event handlers for refresh products background worker 61 private void refreshProductsWorker_DoWork(object sender, DoWorkEventArgs e) { 62 var updateClient = PluginDeploymentService.UpdateClientFactory.CreateClient(); 63 try { 64 e.Result = new object[] { updateClient.GetProducts(), updateClient.GetPlugins() }; 65 } 66 catch (FaultException) { 67 e.Cancel = true; 68 } 69 } 70 71 private void refreshProductsWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { 54 72 this.products = new List<PluginDeploymentService.ProductDescription>( 55 73 (PluginDeploymentService.ProductDescription[])((object[])e.Result)[0]); … … 63 81 SetControlsEnabled(true); 64 82 } 83 #endregion 65 84 66 85 private void UpdateProductsList() { 86 productsListView.Items.Clear(); 67 87 foreach (var prodDesc in products) { 68 productsList Box.Items.Add(CreateListViewItem(prodDesc));88 productsListView.Items.Add(CreateListViewItem(prodDesc)); 69 89 } 70 90 } 71 91 72 92 private void productsListBox_SelectedIndexChanged(object sender, EventArgs e) { 73 if (productsList Box.SelectedItems.Count == 0) return;74 PluginDeploymentService.ProductDescription activeProduct = (PluginDeploymentService.ProductDescription)((ListViewItem)productsList Box.SelectedItem).Tag;93 if (productsListView.SelectedItems.Count == 0) return; 94 PluginDeploymentService.ProductDescription activeProduct = (PluginDeploymentService.ProductDescription)((ListViewItem)productsListView.SelectedItems[0]).Tag; 75 95 UpdateProductDetails(activeProduct); 76 96 } … … 80 100 versionTextBox.Text = activeProduct.Version.ToString(); 81 101 82 pluginsList .Items.Clear();102 pluginsListView.Items.Clear(); 83 103 foreach (PluginDeploymentService.PluginDescription pluginDesc in plugins) { 84 104 var matching = from p in activeProduct.Plugins … … 87 107 select p; 88 108 89 if (matching.Any()) pluginsList.Items.Add(pluginDesc, true); 90 else pluginsList.Items.Add(pluginDesc, false); 91 } 109 if (matching.Any()) pluginsListView.Items.Add(CreateCheckedListViewItem(pluginDesc)); 110 else pluginsListView.Items.Add(CreateUncheckedListViewItem(pluginDesc)); 111 } 112 } 113 114 private ListViewItem CreateUncheckedListViewItem(HeuristicLab.PluginInfrastructure.Advanced.DeploymentService.PluginDescription pluginDesc) { 115 ListViewItem item = new ListViewItem(new string[] { pluginDesc.Name, pluginDesc.Version.ToString() }); 116 item.Checked = false; 117 item.Tag = pluginDesc; 118 item.ImageIndex = 0; 119 return item; 120 } 121 122 private ListViewItem CreateCheckedListViewItem(HeuristicLab.PluginInfrastructure.Advanced.DeploymentService.PluginDescription pluginDesc) { 123 ListViewItem item = new ListViewItem(new string[] { pluginDesc.Name, pluginDesc.Version.ToString() }); 124 item.Checked = true; 125 item.Tag = pluginDesc; 126 item.ImageIndex = 0; 127 return item; 128 } 129 130 private ListViewItem CreateListViewItem(PluginDeploymentService.ProductDescription productDescription) { 131 ListViewItem item = new ListViewItem(new string[] { productDescription.Name, productDescription.Version.ToString() }); 132 item.Tag = productDescription; 133 item.ImageIndex = 0; 134 return item; 92 135 } 93 136 … … 107 150 var newProduct = new PluginDeploymentService.ProductDescription("New product", new Version("0.0.0.0")); 108 151 ListViewItem item = CreateListViewItem(newProduct); 109 productsListBox.Items.Add(item); 110 dirtyProducts.Add(newProduct); 111 } 112 113 private ListViewItem CreateListViewItem(PluginDeploymentService.ProductDescription productDescription) { 114 ListViewItem item = new ListViewItem(); 115 item.Text = productDescription.Name + " " + productDescription.Version; 116 item.Name = productDescription.Name + " " + productDescription.Version; 117 item.Tag = productDescription; 118 return item; 152 productsListView.Items.Add(item); 153 MarkProductDirty(newProduct); 119 154 } 120 155 … … 125 160 126 161 private void nameTextBox_TextChanged(object sender, EventArgs e) { 127 ListViewItem activeItem = (ListViewItem)productsList Box.SelectedItem;162 ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0]; 128 163 PluginDeploymentService.ProductDescription activeProduct = (PluginDeploymentService.ProductDescription)activeItem.Tag; 129 164 if (string.IsNullOrEmpty(nameTextBox.Name)) { 130 165 errorProvider.SetError(nameTextBox, "Invalid value"); 131 166 } else { 132 activeProduct.Name = nameTextBox.Text; 133 activeItem.Text = activeProduct.Name + " " + activeProduct.Version; 134 activeItem.Name = activeProduct.Name + " " + activeProduct.Version; 135 errorProvider.SetError(nameTextBox, string.Empty); 136 } 137 } 167 if (activeProduct.Name != nameTextBox.Text) { 168 activeProduct.Name = nameTextBox.Text; 169 activeItem.SubItems[0].Text = activeProduct.Name; 170 errorProvider.SetError(nameTextBox, string.Empty); 171 MarkProductDirty(activeProduct); 172 } 173 } 174 } 175 138 176 139 177 private void versionTextBox_TextChanged(object sender, EventArgs e) { 140 ListViewItem activeItem = (ListViewItem)productsList Box.SelectedItem;178 ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0]; 141 179 PluginDeploymentService.ProductDescription activeProduct = (PluginDeploymentService.ProductDescription)activeItem.Tag; 142 180 try { 143 activeProduct.Version = new Version(versionTextBox.Text); 144 activeItem.Text = activeProduct.Name + " " + activeProduct.Version; 145 activeItem.Name = activeProduct.Name + " " + activeProduct.Version; 146 errorProvider.SetError(versionTextBox, string.Empty); 181 var newVersion = new Version(versionTextBox.Text); 182 if (activeProduct.Version != newVersion) { 183 activeProduct.Version = newVersion; 184 activeItem.SubItems[1].Text = versionTextBox.Text; 185 errorProvider.SetError(versionTextBox, string.Empty); 186 MarkProductDirty(activeProduct); 187 } 147 188 } 148 189 catch (OverflowException ex) { … … 157 198 } 158 199 } 200 201 private void pluginsListView_ItemChecked(object sender, ItemCheckedEventArgs e) { 202 var pluginItem = e.Item; 203 var activePlugin = (IPluginDescription)pluginItem.Tag; 204 ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0]; 205 PluginDeploymentService.ProductDescription activeProduct = (PluginDeploymentService.ProductDescription)activeItem.Tag; 206 if (pluginItem.Checked && !activeProduct.Plugins.Contains(activePlugin)) { 207 activeProduct.AddPlugin(activePlugin); 208 MarkProductDirty(activeProduct); 209 } else if (!pluginItem.Checked && activeProduct.Plugins.Contains(activePlugin)) { 210 activeProduct.RemovePlugin(activePlugin); 211 MarkProductDirty(activeProduct); 212 } 213 } 214 215 private void MarkProductDirty(HeuristicLab.PluginInfrastructure.Advanced.DeploymentService.ProductDescription activeProduct) { 216 if (!dirtyProducts.Contains(activeProduct)) { 217 dirtyProducts.Add(activeProduct); 218 var item = FindItemForProduct(activeProduct); 219 item.ImageIndex = 1; 220 } 221 } 222 223 private ListViewItem FindItemForProduct(HeuristicLab.PluginInfrastructure.Advanced.DeploymentService.ProductDescription activeProduct) { 224 return (from item in productsListView.Items.OfType<ListViewItem>() 225 let product = item.Tag as PluginDeploymentService.ProductDescription 226 where product != null 227 where product == activeProduct 228 select item).Single(); 229 } 159 230 } 160 231 }
Note: See TracChangeset
for help on using the changeset viewer.