Changeset 3608 for trunk/sources/HeuristicLab.PluginInfrastructure/Advanced/RemotePluginInstaller.cs
- Timestamp:
- 05/04/10 16:37:10 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.PluginInfrastructure/Advanced/RemotePluginInstaller.cs
r3600 r3608 43 43 private BackgroundWorker updateOrInstallPluginsBackgroundWorker; 44 44 45 private ListViewGroup newPluginsGroup;46 private ListViewGroup productsGroup;47 private ListViewGroup allPluginsGroup;48 49 private bool showAllPlugins;50 public bool ShowAllPlugins {51 get { return showAllPlugins; }52 set {53 if (value != showAllPlugins) {54 showAllPlugins = value;55 UpdateControl();56 }57 }58 }59 60 45 private IEnumerable<DeploymentService.ProductDescription> products; 61 public IEnumerable<DeploymentService.ProductDescription> Products {62 get { return products ?? Enumerable.Empty<DeploymentService.ProductDescription>(); }63 set {64 if (value != this.products) {65 this.products = value;66 UpdateControl();67 }68 }69 }70 71 46 private IEnumerable<IPluginDescription> plugins; 72 public IEnumerable<IPluginDescription> AllPlugins { 73 get { return plugins ?? Enumerable.Empty<IPluginDescription>(); } 74 set { 75 if (value != this.plugins) { 76 this.plugins = value; 77 UpdateControl(); 78 } 79 } 80 } 81 82 private IEnumerable<IPluginDescription> newPlugins; 83 public IEnumerable<IPluginDescription> NewPlugins { 84 get { return newPlugins ?? Enumerable.Empty<IPluginDescription>(); } 85 set { 86 if (value != this.newPlugins) { 87 this.newPlugins = value; 88 UpdateControl(); 89 } 90 } 91 } 92 93 public IEnumerable<IPluginDescription> CheckedPlugins { 47 48 private IEnumerable<IPluginDescription> CheckedPlugins { 94 49 get { 95 return (from item in remotePluginsListView.Items.OfType<ListViewItem>()50 return (from item in pluginsListView.Items.OfType<ListViewItem>() 96 51 where item.Checked 97 52 let plugin = item.Tag as IPluginDescription … … 113 68 public RemotePluginInstallerView() { 114 69 InitializeComponent(); 115 70 productImageList.Images.Add(HeuristicLab.PluginInfrastructure.Resources.Resources.Setup_Install); 71 productLargeImageList.Images.Add(HeuristicLab.PluginInfrastructure.Resources.Resources.Setup_Install); 72 pluginsImageList.Images.Add(HeuristicLab.PluginInfrastructure.Resources.Resources.plugin_16); 116 73 refreshServerPluginsBackgroundWorker = new BackgroundWorker(); 117 74 refreshServerPluginsBackgroundWorker.DoWork += new DoWorkEventHandler(refreshServerPluginsBackgroundWorker_DoWork); … … 121 78 updateOrInstallPluginsBackgroundWorker.DoWork += new DoWorkEventHandler(updateOrInstallPluginsBackgroundWorker_DoWork); 122 79 updateOrInstallPluginsBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(updateOrInstallPluginsBackgroundWorker_RunWorkerCompleted); 123 124 newPluginsGroup = remotePluginsListView.Groups["newPluginsGroup"];125 productsGroup = remotePluginsListView.Groups["productsGroup"];126 allPluginsGroup = remotePluginsListView.Groups["allPluginsGroup"];127 80 } 128 81 … … 136 89 } else { 137 90 RefreshBackgroundWorkerResult refreshResult = (RefreshBackgroundWorkerResult)e.Result; 138 UpdateRemotePluginList(refreshResult.RemoteProducts, refreshResult.RemotePlugins); 91 products = refreshResult.RemoteProducts; 92 plugins = refreshResult.RemotePlugins; 93 UpdateControl(); 139 94 } 140 95 StatusView.UnlockUI(); … … 183 138 refreshServerPluginsBackgroundWorker.RunWorkerAsync(); 184 139 } 185 private void install Button_Click(object sender, EventArgs e) {140 private void installPluginsButton_Click(object sender, EventArgs e) { 186 141 StatusView.LockUI(); 187 142 StatusView.ShowProgressIndicator(); … … 205 160 updateOrInstallPluginsBackgroundWorker.RunWorkerAsync(updateOrInstallInfo); 206 161 } 162 private void installProductsButton_Click(object sender, EventArgs e) { 163 StatusView.LockUI(); 164 StatusView.ShowProgressIndicator(); 165 var updateOrInstallInfo = new UpdateOrInstallPluginsBackgroundWorkerArgument(); 166 var selectedProduct = (DeploymentService.ProductDescription)productsListView.SelectedItems[0].Tag; 167 // if there is a local plugin with same name and same major and minor version then it's an update 168 var pluginsToUpdate = from plugin in selectedProduct.Plugins 169 let matchingLocalPlugins = from localPlugin in pluginManager.Plugins 170 where localPlugin.Name == plugin.Name 171 where localPlugin.Version.Major == plugin.Version.Major 172 where localPlugin.Version.Minor == plugin.Version.Minor 173 where IsNewerThan(plugin, localPlugin) 174 select localPlugin 175 where matchingLocalPlugins.Count() > 0 176 select plugin; 177 178 // otherwise install a new plugin 179 var pluginsToInstall = selectedProduct.Plugins.Except(pluginsToUpdate); 180 181 updateOrInstallInfo.PluginsToInstall = (IEnumerable<IPluginDescription>)pluginsToInstall.ToList(); 182 updateOrInstallInfo.PluginsToUpdate = (IEnumerable<IPluginDescription>)pluginsToUpdate.ToList(); 183 updateOrInstallPluginsBackgroundWorker.RunWorkerAsync(updateOrInstallInfo); 184 } 185 186 private void showLargeIconsButton_CheckedChanged(object sender, EventArgs e) { 187 productsListView.View = View.LargeIcon; 188 } 189 190 private void showDetailsButton_CheckedChanged(object sender, EventArgs e) { 191 productsListView.View = View.Details; 192 } 193 207 194 #endregion 208 195 209 196 private void UpdateControl() { 210 ClearListView(); 211 remotePluginsListView.SuppressItemCheckedEvents = true; 212 foreach (var newPlugin in NewPlugins) { 213 var item = CreateListViewItem(newPlugin); 214 item.Group = newPluginsGroup; 215 remotePluginsListView.Items.Add(item); 216 } 217 218 foreach (var product in Products) { 197 // clear products view 198 List<ListViewItem> productItemsToDelete = new List<ListViewItem>(productsListView.Items.OfType<ListViewItem>()); 199 productItemsToDelete.ForEach(item => productsListView.Items.Remove(item)); 200 201 // populate products list view 202 foreach (var product in products) { 219 203 var item = CreateListViewItem(product); 220 item.Group = productsGroup; 221 remotePluginsListView.Items.Add(item); 222 } 223 224 if (showAllPlugins) { 225 foreach (var plugin in AllPlugins) { 226 var item = CreateListViewItem(plugin); 227 item.Group = allPluginsGroup; 228 remotePluginsListView.Items.Add(item); 229 } 230 } 231 foreach (ColumnHeader column in remotePluginsListView.Columns) 232 if (remotePluginsListView.Items.Count > 0) 204 productsListView.Items.Add(item); 205 } 206 var allPluginsListViewItem = new ListViewItem(); 207 allPluginsListViewItem.Text = "All Plugins"; 208 allPluginsListViewItem.ImageIndex = 0; 209 productsListView.Items.Add(allPluginsListViewItem); 210 foreach (ColumnHeader column in productsListView.Columns) 211 if (productsListView.Items.Count > 0) 233 212 column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); 234 213 else column.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize); 235 236 remotePluginsListView.SuppressItemCheckedEvents = false; 237 } 238 239 private void ClearListView() { 240 List<ListViewItem> itemsToDelete = new List<ListViewItem>(remotePluginsListView.Items.OfType<ListViewItem>()); 241 itemsToDelete.ForEach(item => remotePluginsListView.Items.Remove(item)); 214 } 215 216 private void UpdatePluginsList() { 217 // clear plugins list view 218 List<ListViewItem> pluginItemsToDelete = new List<ListViewItem>(pluginsListView.Items.OfType<ListViewItem>()); 219 pluginItemsToDelete.ForEach(item => pluginsListView.Items.Remove(item)); 220 221 // populate plugins list 222 if (productsListView.SelectedItems.Count > 0) { 223 pluginsListView.SuppressItemCheckedEvents = true; 224 225 var selectedItem = productsListView.SelectedItems[0]; 226 if (selectedItem.Text == "All Plugins") { 227 foreach (var plugin in plugins) { 228 var item = CreateListViewItem(plugin); 229 pluginsListView.Items.Add(item); 230 } 231 } else { 232 var selectedProduct = (DeploymentService.ProductDescription)productsListView.SelectedItems[0].Tag; 233 foreach (var plugin in selectedProduct.Plugins) { 234 var item = CreateListViewItem(plugin); 235 pluginsListView.Items.Add(item); 236 } 237 } 238 239 foreach (ColumnHeader column in pluginsListView.Columns) 240 if (pluginsListView.Items.Count > 0) 241 column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); 242 else column.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize); 243 244 pluginsListView.SuppressItemCheckedEvents = false; 245 } 242 246 } 243 247 244 248 private ListViewItem CreateListViewItem(DeploymentService.ProductDescription product) { 245 ListViewItem item = new ListViewItem(new string[] { product.Name, product.Version.ToString() , string.Empty});249 ListViewItem item = new ListViewItem(new string[] { product.Name, product.Version.ToString() }); 246 250 item.Tag = product; 251 item.ImageIndex = 0; 247 252 return item; 248 253 } … … 251 256 ListViewItem item = new ListViewItem(new string[] { plugin.Name, plugin.Version.ToString(), plugin.Description }); 252 257 item.Tag = plugin; 258 item.ImageIndex = 0; 253 259 return item; 254 260 } 261 262 #region products list view events 263 private void productsListView_SelectedIndexChanged(object sender, EventArgs e) { 264 UpdatePluginsList(); 265 installProductsButton.Enabled = (productsListView.SelectedItems.Count > 0 && 266 productsListView.SelectedItems[0].Text != "All Plugins"); 267 } 268 #endregion 255 269 256 270 #region item checked event handler 257 271 private void remotePluginsListView_ItemChecked(object sender, ItemCheckedEventArgs e) { 258 foreach (ListViewItem item in remotePluginsListView.SelectedItems) {272 foreach (ListViewItem item in pluginsListView.SelectedItems) { 259 273 // dispatch by check state and type of item (product/plugin) 260 274 IPluginDescription plugin = item.Tag as IPluginDescription; … … 273 287 } 274 288 } 275 install Button.Enabled = remotePluginsListView.CheckedItems.Count > 0;289 installPluginsButton.Enabled = pluginsListView.CheckedItems.Count > 0; 276 290 } 277 291 … … 287 301 } 288 302 } 289 remotePluginsListView.UncheckItems(modifiedItems);303 pluginsListView.UncheckItems(modifiedItems); 290 304 } 291 305 … … 303 317 } 304 318 } 305 remotePluginsListView.CheckItems(modifiedItems);319 pluginsListView.CheckItems(modifiedItems); 306 320 } 307 321 … … 333 347 } 334 348 } 335 remotePluginsListView.UncheckItems(modifiedItems);349 pluginsListView.UncheckItems(modifiedItems); 336 350 } 337 351 … … 349 363 } 350 364 } 351 remotePluginsListView.CheckItems(modifiedItems);365 pluginsListView.CheckItems(modifiedItems); 352 366 } 353 367 … … 356 370 #region helper methods 357 371 private IEnumerable<ListViewItem> FindItemsForPlugin(IPluginDescription plugin) { 358 return (from item in remotePluginsListView.Items.OfType<ListViewItem>()372 return (from item in pluginsListView.Items.OfType<ListViewItem>() 359 373 let otherPlugin = item.Tag as IPluginDescription 360 374 where otherPlugin != null && otherPlugin.Name == plugin.Name && otherPlugin.Version == plugin.Version … … 363 377 364 378 private ListViewItem FindItemForProduct(DeploymentService.ProductDescription product) { 365 return (from item in remotePluginsListView.Items.OfType<ListViewItem>()379 return (from item in pluginsListView.Items.OfType<ListViewItem>() 366 380 let otherProduct = item.Tag as DeploymentService.ProductDescription 367 381 where otherProduct != null && otherProduct.Name == product.Name && otherProduct.Version == product.Version … … 369 383 } 370 384 371 private void UpdateRemotePluginList(372 IEnumerable<DeploymentService.ProductDescription> remoteProducts,373 IEnumerable<IPluginDescription> remotePlugins) {374 375 var mostRecentRemotePlugins = from remote in remotePlugins376 where !remotePlugins.Any(x => x.Name == remote.Name && x.Version > remote.Version) // same name and higher version377 select remote;378 379 var newPlugins = from remote in mostRecentRemotePlugins380 let matchingLocal = (from local in pluginManager.Plugins381 where local.Name == remote.Name382 where local.Version < remote.Version383 select local).FirstOrDefault()384 where matchingLocal != null385 select remote;386 387 NewPlugins = newPlugins;388 Products = remoteProducts;389 AllPlugins = remotePlugins;390 }391 385 private bool IsNewerThan(IPluginDescription plugin1, IPluginDescription plugin2) { 392 386 // newer: build version is higher, or if build version is the same revision is higher … … 397 391 #endregion 398 392 399 400 393 } 401 394 }
Note: See TracChangeset
for help on using the changeset viewer.