Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/27/10 21:30:24 (14 years ago)
Author:
gkronber
Message:

Implemented review comments in plugin manager. #989 (Implement review comments in plugin infrastructure)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.PluginInfrastructure/Advanced/InstallationManagerForm.cs

    r3508 r3547  
    3131
    3232namespace HeuristicLab.PluginInfrastructure.Advanced {
    33   internal partial class InstallationManagerForm : Form {
    34     private class UpdateOrInstallPluginsBackgroundWorkerArgument {
    35       public IEnumerable<IPluginDescription> PluginsToUpdate { get; set; }
    36       public IEnumerable<IPluginDescription> PluginsToInstall { get; set; }
    37     }
    38 
    39     private class RemovePluginsBackgroundWorkerArgument {
    40       public IEnumerable<IPluginDescription> PluginsToRemove { get; set; }
    41     }
    42 
    43     private class RefreshBackgroundWorkerResult {
    44       public IEnumerable<IPluginDescription> RemotePlugins { get; set; }
    45       public IEnumerable<DeploymentService.ProductDescription> RemoteProducts { get; set; }
    46     }
    47 
     33  internal partial class InstallationManagerForm : Form, IStatusView {
    4834    private InstallationManager installationManager;
    49     private BackgroundWorker refreshServerPluginsBackgroundWorker;
    50     private BackgroundWorker updateOrInstallPluginsBackgroundWorker;
    51     private BackgroundWorker removePluginsBackgroundWorker;
    52     private BackgroundWorker refreshLocalPluginsBackgroundWorker;
    53     private BackgroundWorker updateAllPluginsBackgroundWorker;
    5435    private PluginManager pluginManager;
    5536    private string pluginDir;
     
    5839      InitializeComponent();
    5940      this.pluginManager = pluginManager;
     41
    6042      pluginManager.PluginLoaded += pluginManager_PluginLoaded;
    6143      pluginManager.PluginUnloaded += pluginManager_PluginUnloaded;
     
    6446
    6547      pluginDir = Application.StartupPath;
    66 
    67       #region initialize background workers
    68       refreshServerPluginsBackgroundWorker = new BackgroundWorker();
    69       refreshServerPluginsBackgroundWorker.DoWork += new DoWorkEventHandler(refreshServerPluginsBackgroundWorker_DoWork);
    70       refreshServerPluginsBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(refreshServerPluginsBackgroundWorker_RunWorkerCompleted);
    71 
    72       updateOrInstallPluginsBackgroundWorker = new BackgroundWorker();
    73       updateOrInstallPluginsBackgroundWorker.DoWork += new DoWorkEventHandler(updateOrInstallPluginsBackgroundWorker_DoWork);
    74       updateOrInstallPluginsBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(updateOrInstallPluginsBackgroundWorker_RunWorkerCompleted);
    75 
    76       removePluginsBackgroundWorker = new BackgroundWorker();
    77       removePluginsBackgroundWorker.DoWork += new DoWorkEventHandler(removePluginsBackgroundWorker_DoWork);
    78       removePluginsBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(removePluginsBackgroundWorker_RunWorkerCompleted);
    79 
    80       refreshLocalPluginsBackgroundWorker = new BackgroundWorker();
    81       refreshLocalPluginsBackgroundWorker.DoWork += new DoWorkEventHandler(refreshLocalPluginsBackgroundWorker_DoWork);
    82       refreshLocalPluginsBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(refreshLocalPluginsBackgroundWorker_RunWorkerCompleted);
    83 
    84       updateAllPluginsBackgroundWorker = new BackgroundWorker();
    85       updateAllPluginsBackgroundWorker.DoWork += new DoWorkEventHandler(updateAllPluginsBackgroundWorker_DoWork);
    86       updateAllPluginsBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(updateAllPluginsBackgroundWorker_RunWorkerCompleted);
    87       #endregion
    8848
    8949      installationManager = new InstallationManager(pluginDir);
     
    9959        tabControl.Controls.Remove(uploadPluginsTabPage);
    10060        tabControl.Controls.Remove(manageProductsTabPage);
    101       }
    102 
    103       UpdateLocalPluginList(pluginManager.Plugins);
    104       UpdateControlsConnected();
    105     }
    106 
    107     #region event handlers for update all plugins backgroundworker
    108     void updateAllPluginsBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
    109       if (e.Error != null) {
    110         MessageBox.Show("There was an error while connecting to the server." + Environment.NewLine +
    111            "Please check your connection settings and user credentials.");
    112         UpdateControlsDisconnected();
    11361      } else {
    114         RefreshLocalPluginListAsync();
    115         UpdateControlsConnected();
    116       }
    117     }
    118 
    119     void updateAllPluginsBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) {
    120       IEnumerable<IPluginDescription> installedPlugins = (IEnumerable<IPluginDescription>)e.Argument;
    121       var remotePlugins = installationManager.GetRemotePluginList();
    122       // if there is a local plugin with same name and same major and minor version then it's an update
    123       var pluginsToUpdate = from remotePlugin in remotePlugins
    124                             let matchingLocalPlugins = from installedPlugin in installedPlugins
    125                                                        where installedPlugin.Name == remotePlugin.Name
    126                                                        where installedPlugin.Version.Major == remotePlugin.Version.Major
    127                                                        where installedPlugin.Version.Minor == remotePlugin.Version.Minor
    128                                                        where installedPlugin.Version.Build <= remotePlugin.Version.Build ||
    129                                                          installedPlugin.Version.Revision < remotePlugin.Version.Revision
    130                                                        select installedPlugin
    131                             where matchingLocalPlugins.Count() > 0
    132                             select remotePlugin;
    133       installationManager.Update(pluginsToUpdate);
    134     }
    135     #endregion
    136 
    137     #region event handlers for refresh local plugin list backgroundworker
    138     void refreshLocalPluginsBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
    139       if (!e.Cancelled && e.Error == null) {
    140         UpdateLocalPluginList((IEnumerable<PluginDescription>)e.Result);
    141         UpdateControlsConnected();
    142       }
    143     }
    144 
    145     void refreshLocalPluginsBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) {
    146       pluginManager.DiscoverAndCheckPlugins();
    147       e.Result = new List<PluginDescription>(pluginManager.Plugins);
    148     }
    149     #endregion
    150 
    151     #region event handlers for plugin removal background worker
    152     void removePluginsBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
    153       if (e.Error != null) {
    154         MessageBox.Show("There was problem while deleting files." + Environment.NewLine +
    155               e.Error.Message);
    156         UpdateControlsDisconnected();
    157       } else {
    158         RefreshLocalPluginListAsync();
    159         UpdateControlsConnected();
    160       }
    161     }
    162 
    163     void removePluginsBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) {
    164       IEnumerable<IPluginDescription> pluginsToRemove = (IEnumerable<IPluginDescription>)e.Argument;
    165       installationManager.Remove(pluginsToRemove);
    166     }
    167     #endregion
    168 
    169     #region event handlers for plugin update background worker
    170     void updateOrInstallPluginsBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
    171       if (e.Error != null) {
    172         MessageBox.Show("There was an error while connecting to the server." + Environment.NewLine +
    173           "Please check your connection settings and user credentials.");
    174         UpdateControlsDisconnected();
    175       } else {
    176         RefreshLocalPluginListAsync();
    177         RefreshRemotePluginListAsync();
    178         UpdateControlsConnected();
    179       }
    180     }
    181 
    182     void updateOrInstallPluginsBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) {
    183       UpdateOrInstallPluginsBackgroundWorkerArgument info = (UpdateOrInstallPluginsBackgroundWorkerArgument)e.Argument;
    184       installationManager.Install(info.PluginsToInstall);
    185       installationManager.Update(info.PluginsToUpdate);
    186     }
    187     #endregion
    188 
    189     #region event handlers for refresh server plugins background worker
    190     void refreshServerPluginsBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
    191       if (e.Error != null) {
    192         MessageBox.Show("There was an error while connecting to the server." + Environment.NewLine +
    193           "Please check your connection settings and user credentials.");
    194         UpdateControlsDisconnected();
    195       } else {
    196         RefreshBackgroundWorkerResult refreshResult = (RefreshBackgroundWorkerResult)e.Result;
    197         UpdateRemotePluginList(refreshResult.RemoteProducts, refreshResult.RemotePlugins);
    198         UpdateControlsConnected();
    199       }
    200     }
    201 
    202     void refreshServerPluginsBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) {
    203       RefreshBackgroundWorkerResult result = new RefreshBackgroundWorkerResult();
    204       result.RemotePlugins = installationManager.GetRemotePluginList();
    205       result.RemoteProducts = installationManager.GetRemoteProductList();
    206       e.Cancel = false;
    207       e.Result = result;
    208     }
    209 
    210 
    211 
    212     #endregion
     62        pluginEditor.PluginManager = pluginManager;
     63      }
     64
     65      localPluginsView.StatusView = this;
     66      localPluginsView.PluginManager = pluginManager;
     67      localPluginsView.InstallationManager = installationManager;
     68
     69      basicUpdateView.StatusView = this;
     70      basicUpdateView.PluginManager = pluginManager;
     71      basicUpdateView.InstallationManager = installationManager;
     72
     73      remotePluginInstaller.StatusView = this;
     74      remotePluginInstaller.InstallationManager = installationManager;
     75      remotePluginInstaller.PluginManager = pluginManager;
     76    }
     77
    21378
    21479    #region plugin manager event handlers
     
    267132    #endregion
    268133
    269 
    270 
    271134    #region button events
    272 
    273     private void refreshRemoteButton_Click(object sender, EventArgs e) {
    274       Cursor = Cursors.AppStarting;
    275       RefreshRemotePluginListAsync();
    276       toolStripProgressBar.Visible = true;
    277       DisableControls();
    278     }
    279 
    280     private void updateOrInstallButton_Click(object sender, EventArgs e) {
    281       Cursor = Cursors.AppStarting;
    282       toolStripProgressBar.Visible = true;
    283       DisableControls();
    284       var updateOrInstallInfo = new UpdateOrInstallPluginsBackgroundWorkerArgument();
    285       // if there is a local plugin with same name and same major and minor version then it's an update
    286       var pluginsToUpdate = from remotePlugin in remotePluginInstaller.CheckedPlugins
    287                             let matchingLocalPlugins = from localPlugin in localPluginManagerView.Plugins
    288                                                        where localPlugin.Name == remotePlugin.Name
    289                                                        where localPlugin.Version.Major == remotePlugin.Version.Major
    290                                                        where localPlugin.Version.Minor == remotePlugin.Version.Minor
    291                                                        select localPlugin
    292                             where matchingLocalPlugins.Count() > 0
    293                             select remotePlugin;
    294 
    295       // otherwise install a new plugin
    296       var pluginsToInstall = remotePluginInstaller.CheckedPlugins.Except(pluginsToUpdate);
    297 
    298       updateOrInstallInfo.PluginsToInstall = pluginsToInstall;
    299       updateOrInstallInfo.PluginsToUpdate = pluginsToUpdate;
    300       updateOrInstallPluginsBackgroundWorker.RunWorkerAsync(updateOrInstallInfo);
    301     }
    302 
    303     private void removeLocalButton_Click(object sender, EventArgs e) {
    304       Cursor = Cursors.AppStarting;
    305       toolStripProgressBar.Visible = true;
    306       DisableControls();
    307       removePluginsBackgroundWorker.RunWorkerAsync(localPluginManagerView.CheckedPlugins);
    308     }
    309 
    310     private void updateAllButton_Click(object sender, EventArgs e) {
    311       Cursor = Cursors.AppStarting;
    312       toolStripProgressBar.Visible = true;
    313       updateButton.Enabled = false;
    314       var installedPlugins = pluginManager.Plugins.OfType<IPluginDescription>();
    315       updateAllPluginsBackgroundWorker.RunWorkerAsync(installedPlugins);
    316     }
    317 
    318135    private void connectionSettingsToolStripMenuItem_Click(object sender, EventArgs e) {
    319136      new ConnectionSetupView().ShowDialog();
     
    321138
    322139    private void tabControl_Selected(object sender, TabControlEventArgs e) {
    323       viewToolStripMenuItem.Enabled = e.TabPage == availablePluginsTabPage;
     140      viewToolStripMenuItem.Enabled = e.TabPage == availablePluginsTabPage;     
     141      toolStripStatusLabel.Text = string.Empty;
     142      toolStripProgressBar.Visible = false;
    324143    }
    325144
     
    377196    }
    378197
    379     private void UpdateLocalPluginList(IEnumerable<PluginDescription> plugins) {
    380       localPluginManagerView.Plugins = plugins;
    381     }
    382 
    383     private void UpdateRemotePluginList(
    384       IEnumerable<DeploymentService.ProductDescription> remoteProducts,
    385       IEnumerable<IPluginDescription> remotePlugins) {
    386 
    387       var mostRecentRemotePlugins = from remote in remotePlugins
    388                                     where !remotePlugins.Any(x => x.Name == remote.Name && x.Version > remote.Version) // same name and higher version
    389                                     select remote;
    390 
    391       var newPlugins = from remote in mostRecentRemotePlugins
    392                        let matchingLocal = (from local in localPluginManagerView.Plugins
    393                                             where local.Name == remote.Name
    394                                             where local.Version < remote.Version
    395                                             select local).FirstOrDefault()
    396                        where matchingLocal != null
    397                        select remote;
    398 
    399       remotePluginInstaller.NewPlugins = newPlugins;
    400       remotePluginInstaller.Products = remoteProducts;
    401       remotePluginInstaller.AllPlugins = remotePlugins;
    402     }
    403 
    404     private void RefreshRemotePluginListAsync() {
    405       Cursor = Cursors.AppStarting;
    406       toolStripProgressBar.Visible = true;
    407       refreshButton.Enabled = false;
    408       refreshServerPluginsBackgroundWorker.RunWorkerAsync();
    409     }
    410 
    411     private void RefreshLocalPluginListAsync() {
    412       Cursor = Cursors.AppStarting;
    413       toolStripProgressBar.Visible = true;
    414       DisableControls();
    415       refreshLocalPluginsBackgroundWorker.RunWorkerAsync();
    416     }
    417 
    418     private void UpdateControlsDisconnected() {
    419       //localPluginsListView.Enabled = false;
    420       //ClearPluginsList(remotePluginsListView);
    421       refreshButton.Enabled = true;
    422       toolStripProgressBar.Visible = false;
    423       Cursor = Cursors.Default;
    424     }
    425 
    426     private void UpdateControlsConnected() {
    427       refreshButton.Enabled = true;
    428       updateButton.Enabled = true;
    429       toolStripProgressBar.Visible = false;
    430       Cursor = Cursors.Default;
    431     }
    432 
    433     private void DisableControls() {
    434       refreshButton.Enabled = false;
    435       Cursor = Cursors.Default;
    436     }
    437     #endregion
    438 
    439     private void localPluginManager_ItemChecked(object sender, ItemCheckedEventArgs e) {
    440       removeButton.Enabled = localPluginManagerView.CheckedPlugins.Count() > 0;
    441     }
    442 
    443     private void remotePluginInstaller_ItemChecked(object sender, ItemCheckedEventArgs e) {
    444       installButton.Enabled = remotePluginInstaller.CheckedPlugins.Count() > 0;
    445     }
     198    #endregion
     199
    446200
    447201    protected override void OnClosing(CancelEventArgs e) {
     
    455209    }
    456210
    457 
    458 
    459 
     211    #region IStatusView Members
     212
     213    public void ShowProgressIndicator(double percentProgress) {
     214      if (percentProgress < 0.0 || percentProgress > 1.0) throw new ArgumentException();
     215      toolStripProgressBar.Visible = true;
     216      toolStripProgressBar.Style = ProgressBarStyle.Continuous;
     217      int range = toolStripProgressBar.Maximum - toolStripProgressBar.Minimum;
     218      toolStripProgressBar.Value = (int)(percentProgress * range + toolStripProgressBar.Minimum);
     219    }
     220
     221    public void ShowProgressIndicator() {
     222      toolStripProgressBar.Visible = true;
     223      toolStripProgressBar.Style = ProgressBarStyle.Marquee;
     224    }
     225
     226    public void HideProgressIndicator() {
     227      toolStripProgressBar.Visible = false;
     228    }
     229
     230    public void ShowMessage(string message) {
     231      if (toolStripStatusLabel.Text == string.Empty)
     232        toolStripStatusLabel.Text = message;
     233      else
     234        toolStripStatusLabel.Text += "; " + message;
     235    }
     236
     237    public void RemoveMessage(string message) {
     238      if (toolStripStatusLabel.Text.IndexOf("; " + message) > 0) {
     239        toolStripStatusLabel.Text = toolStripStatusLabel.Text.Replace("; " + message, "");
     240      }
     241      toolStripStatusLabel.Text = toolStripStatusLabel.Text.Replace(message, "");
     242      toolStripStatusLabel.Text = toolStripStatusLabel.Text.TrimStart(' ', ';');
     243    }
     244    public void LockUI() {
     245      Cursor = Cursors.AppStarting;
     246      tabControl.Enabled = false;
     247    }
     248    public void UnlockUI() {
     249      tabControl.Enabled = true;
     250      Cursor = Cursors.Default;
     251    }
     252    public void ShowError(string shortMessage, string description) {
     253      logTextBox.Text += DateTime.Now + ": " + shortMessage + Environment.NewLine + description + Environment.NewLine;
     254      MessageBox.Show(description, shortMessage);
     255    }
     256    #endregion
    460257  }
    461258}
Note: See TracChangeset for help on using the changeset viewer.