[2802] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.ComponentModel;
|
---|
| 4 | using System.Drawing;
|
---|
| 5 | using System.Data;
|
---|
| 6 | using System.Linq;
|
---|
| 7 | using System.Text;
|
---|
| 8 | using System.Windows.Forms;
|
---|
| 9 | using HeuristicLab.MainForm;
|
---|
| 10 | using HeuristicLab.PluginInfrastructure;
|
---|
| 11 |
|
---|
| 12 | namespace HeuristicLab.DeploymentService.AdminClient {
|
---|
| 13 | public partial class PluginListView : HeuristicLab.MainForm.WindowsForms.View {
|
---|
| 14 | private List<ListViewItem> localPlugins;
|
---|
| 15 | private List<ListViewItem> serverPlugins;
|
---|
| 16 | private BackgroundWorker pluginUploadWorker;
|
---|
| 17 |
|
---|
| 18 | public PluginListView() {
|
---|
| 19 | InitializeComponent();
|
---|
| 20 | Caption = "Plugins";
|
---|
| 21 |
|
---|
| 22 | localPlugins = new List<ListViewItem>();
|
---|
| 23 | serverPlugins = new List<ListViewItem>();
|
---|
| 24 |
|
---|
| 25 | pluginUploadWorker = new BackgroundWorker();
|
---|
| 26 | pluginUploadWorker.DoWork += new DoWorkEventHandler(pluginUploadWorker_DoWork);
|
---|
| 27 | pluginUploadWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(pluginUploadWorker_RunWorkerCompleted);
|
---|
| 28 |
|
---|
| 29 | UpdateLocalPlugins();
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | void pluginUploadWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
|
---|
| 33 | this.Enabled = true;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | void pluginUploadWorker_DoWork(object sender, DoWorkEventArgs e) {
|
---|
| 37 | var selectedPlugins = (IEnumerable<IPluginDescription>)e.Argument;
|
---|
| 38 | AdminService.AdminClient adminClient = new HeuristicLab.DeploymentService.AdminClient.AdminService.AdminClient();
|
---|
| 39 |
|
---|
| 40 | foreach (var plugin in IteratePlugins(selectedPlugins)) {
|
---|
| 41 | adminClient.DeployPlugin(MakePluginDescription(plugin), new byte[0]);
|
---|
| 42 | }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | private HeuristicLab.PluginInfrastructure.PluginUpdateService.PluginDescription MakePluginDescription(IPluginDescription plugin) {
|
---|
| 46 | var desc = new HeuristicLab.PluginInfrastructure.PluginUpdateService.PluginDescription();
|
---|
| 47 | desc.Name = plugin.Name;
|
---|
| 48 | desc.Version = plugin.Version;
|
---|
| 49 | foreach (var dep in plugin.Dependencies) {
|
---|
| 50 | // TODO implement
|
---|
| 51 | }
|
---|
| 52 | return desc;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | private IEnumerable<IPluginDescription> IteratePlugins(IEnumerable<IPluginDescription> plugins) {
|
---|
| 56 | foreach (var plugin in plugins) {
|
---|
| 57 | foreach (var dependency in IteratePlugins(plugin.Dependencies)) {
|
---|
| 58 | yield return dependency;
|
---|
| 59 | }
|
---|
| 60 | yield return plugin;
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | public void UpdateLocalPlugins() {
|
---|
| 65 | localPlugins.ForEach(x => listView.Items.Remove(x));
|
---|
| 66 | localPlugins.Clear();
|
---|
| 67 | foreach (var plugin in ApplicationManager.Manager.Plugins) {
|
---|
| 68 | var item = MakeListViewItem(plugin);
|
---|
| 69 | item.Group = listView.Groups["Local plugins"];
|
---|
| 70 | listView.Items.Add(item);
|
---|
| 71 | localPlugins.Add(item);
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | public void UpdateServerPlugins() {
|
---|
| 76 | serverPlugins.ForEach(x => listView.Items.Remove(x));
|
---|
| 77 | serverPlugins.Clear();
|
---|
| 78 | var client = new HeuristicLab.PluginInfrastructure.PluginUpdateService.UpdateClient();
|
---|
| 79 | foreach (var plugin in client.GetPlugins()) {
|
---|
| 80 | var item = MakeListViewItem(plugin);
|
---|
| 81 | item.Group = listView.Groups["Server plugins"];
|
---|
| 82 | listView.Items.Add(item);
|
---|
| 83 | localPlugins.Add(item);
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | private static ListViewItem MakeListViewItem(HeuristicLab.PluginInfrastructure.PluginUpdateService.PluginDescription plugin) {
|
---|
| 88 | ListViewItem item = new ListViewItem(new string[] { plugin.Name, plugin.Version.ToString() });
|
---|
| 89 | item.Tag = plugin;
|
---|
| 90 | return item;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | private static ListViewItem MakeListViewItem(IPluginDescription plugin) {
|
---|
| 94 | ListViewItem item = new ListViewItem(new string[] { plugin.Name, plugin.Version.ToString() });
|
---|
| 95 | item.Tag = plugin;
|
---|
| 96 | return item;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | private void listView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 100 | if (listView.SelectedItems.Count > 0) {
|
---|
| 101 | var plugin = (IPluginDescription)listView.SelectedItems[0].Tag;
|
---|
| 102 | StringBuilder strBuilder = new StringBuilder();
|
---|
| 103 |
|
---|
| 104 | strBuilder.Append("Name: ").AppendLine(plugin.Name);
|
---|
| 105 | strBuilder.Append("Version: ").AppendLine(plugin.Version.ToString());
|
---|
| 106 | strBuilder.AppendLine("Files:");
|
---|
| 107 | foreach (var file in plugin.Files) {
|
---|
| 108 | strBuilder.Append(file.Name + " " + file.Type);
|
---|
| 109 | }
|
---|
| 110 | detailsTextBox.Text = strBuilder.ToString();
|
---|
| 111 | } else {
|
---|
| 112 | detailsTextBox.Text = string.Empty;
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | private void uploadButton_Click(object sender, EventArgs e) {
|
---|
| 117 | if (listView.SelectedItems.Count > 0) {
|
---|
| 118 | var selectedPlugins = from item in listView.SelectedItems.Cast<ListViewItem>()
|
---|
| 119 | where item.Tag is IPluginDescription
|
---|
| 120 | select item.Tag as IPluginDescription;
|
---|
| 121 | this.Enabled = false;
|
---|
| 122 | pluginUploadWorker.RunWorkerAsync(selectedPlugins.ToList());
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 | }
|
---|
| 126 | }
|
---|