Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/23/09 20:27:43 (15 years ago)
Author:
gkronber
Message:

Implemented changes as requested by swagner. #799

Location:
branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/Advanced
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/Advanced/InstallationManager.cs

    r2517 r2527  
    116116
    117117    private static IEnumerable<string> GetDeclaredDependencies(PluginDescription desc) {
    118       var plugin = DefaultApplicationManager.GetInstances<IPlugin>(desc).Single();
     118      var plugin = ApplicationManager.GetInstances<IPlugin>(desc).Single();
    119119      return plugin.GetType().GetCustomAttributes(typeof(PluginDependencyAttribute), false).Cast<PluginDependencyAttribute>().Select(x => x.Dependency);
    120120    }
     
    146146
    147147    public void Install(IEnumerable<string> pluginNames) {
    148       IEnumerable<PluginInformation> pluginsToInstall;
    149       using (UpdateLocationClient updateLocation = new UpdateLocationClient()) {
    150         pluginsToInstall = from pluginName in pluginNames
    151                                select GetMatchingPluginInformation(pluginName, updateLocation.GetAvailablePlugins());
    152 
    153         var args = new PluginInfrastructureCancelEventArgs("Installing", pluginsToInstall);
    154         OnPreInstall(args);
    155         foreach (var pluginInfo in pluginsToInstall) {
    156           var s = updateLocation.GetPackedPlugin(pluginInfo);
    157           Console.WriteLine("Downloading: {0} {1} {2}", pluginInfo.Name, pluginInfo.Version, pluginInfo.BuildDate);
    158         }
    159       }
    160       OnInstalled(new PluginInfrastructureEventArgs("Installed", pluginsToInstall));
    161     }
    162 
    163     private static PluginInformation GetMatchingPluginInformation(string pluginName, IEnumerable<PluginInformation> plugins) {
    164       var exactMatch = from pluginDesc in plugins
    165                        where string.Equals(pluginName, pluginDesc.Name, StringComparison.InvariantCultureIgnoreCase)
    166                        select pluginDesc;
    167       var inexactMatch = from pluginDesc in plugins
    168                          where MatchPluginNameInexact(pluginName, pluginDesc.Name)
    169                          select pluginDesc;
    170       return exactMatch.Count() > 0 ? exactMatch.Single() : inexactMatch.First();
    171     }
     148      throw new NotImplementedException();
     149      //IEnumerable<PluginInformation> pluginsToInstall;
     150      //using (UpdateLocationClient updateLocation = new UpdateLocationClient()) {
     151      //  pluginsToInstall = from pluginName in pluginNames
     152      //                     from matchingPlugin in updateLocation.GetAvailablePluginsByName(pluginName)
     153      //                     select matchingPlugin;
     154
     155      //  var args = new PluginInfrastructureCancelEventArgs("Installing", pluginsToInstall);
     156      //  OnPreInstall(args);
     157      //  foreach (var pluginInfo in pluginsToInstall) {
     158      //    var s = updateLocation.GetPluginFiles(pluginInfo);
     159      //    Console.WriteLine("Downloading: {0} {1} {2}", pluginInfo.Name, pluginInfo.Version, pluginInfo.BuildDate);
     160      //  }
     161      //}
     162      //OnInstalled(new PluginInfrastructureEventArgs("Installed", pluginsToInstall));
     163    }
     164
     165    //private static PluginInformation GetMatchingPluginInformation(string pluginName, IEnumerable<PluginInformation> plugins) {
     166    //  var exactMatch = from pluginDesc in plugins
     167    //                   where string.Equals(pluginName, pluginDesc.Name, StringComparison.InvariantCultureIgnoreCase)
     168    //                   select pluginDesc;
     169    //  var inexactMatch = from pluginDesc in plugins
     170    //                     where MatchPluginNameInexact(pluginName, pluginDesc.Name)
     171    //                     select pluginDesc;
     172    //  return exactMatch.Count() > 0 ? exactMatch.Single() : inexactMatch.First();
     173    //}
    172174
    173175    public void Remove(IEnumerable<string> pluginNames) {
     
    188190
    189191    public void Update(IEnumerable<string> pluginNames) {
    190       throw new NotImplementedException();
     192      var pluginDescriptions = from name in pluginNames
     193                               select GetPluginDescription(name);
     194      Dictionary<PluginInformation, string> matchingPlugins = new Dictionary<PluginInformation, string>();
     195      foreach (var updateLocation in HeuristicLab.PluginInfrastructure.Properties.Settings.Default.UpdateLocations) {
     196        using (UpdateLocationClient client = new UpdateLocationClient("", updateLocation)) {
     197          var updateLocationMatchingPlugins = from desc in pluginDescriptions
     198                                              from info in client.GetAvailablePluginsByName(desc.Name)
     199                                              select info;
     200          foreach (PluginInformation info in updateLocationMatchingPlugins) {
     201            // keep only the highest version and most recent build of any plugin
     202            var existingPlugin = matchingPlugins.Keys.FirstOrDefault(x => x.Name == info.Name);
     203            if (existingPlugin == null || existingPlugin.Version < info.Version || (existingPlugin.Version == info.Version && existingPlugin.BuildDate < info.BuildDate)) {
     204              matchingPlugins.Remove(existingPlugin);
     205              matchingPlugins.Add(info, updateLocation);
     206            }
     207          }
     208        }
     209      }
     210      PluginInfrastructureCancelEventArgs args = new PluginInfrastructureCancelEventArgs("Updating", matchingPlugins.Keys);
     211      OnPreUpdate(args);
     212      if (!args.Cancel) {
     213        var groupedInfos = matchingPlugins.GroupBy(x => x.Value);
     214        foreach (var group in groupedInfos) {
     215          using (UpdateLocationClient client = new UpdateLocationClient(group.Key)) {
     216            foreach (var info in group) {
     217              client.GetPluginFiles(info.Key);
     218            }
     219          }
     220        }
     221        OnUpdated(new PluginInfrastructureEventArgs("Updated", matchingPlugins.Keys));
     222      }
     223    }
     224
     225    private void OnPreUpdate(PluginInfrastructureCancelEventArgs args) {
     226      if (PreUpdatePlugin != null) PreUpdatePlugin(this, args);
     227    }
     228
     229    private void OnUpdated(PluginInfrastructureEventArgs args) {
     230      if (PluginUpdated != null) PluginUpdated(this, args);
    191231    }
    192232
  • branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/Advanced/InstallationManagerConsole.cs

    r2517 r2527  
    66using System.IO;
    77using System.ComponentModel;
     8using HeuristicLab.PluginInfrastructure.UpdateLocationReference;
    89
    910namespace HeuristicLab.PluginInfrastructure.Advanced {
    1011  public class InstallationManagerConsole {
    1112    private InstallationManager installManager;
    12     public InstallationManagerConsole() {
    13       this.installManager = new InstallationManager(Path.GetFullPath(HeuristicLab.PluginInfrastructure.Properties.Settings.Default.PluginDir));
     13    public InstallationManagerConsole(string pluginDir) {
     14      this.installManager = new InstallationManager(pluginDir);
    1415      installManager.PreInstallPlugin += new EventHandler<PluginInfrastructureCancelEventArgs>(installManager_PreInstallPlugin);
    1516      installManager.PreRemovePlugin += new EventHandler<PluginInfrastructureCancelEventArgs>(installManager_PreRemovePlugin);
     
    2122
    2223    void installManager_PreUpdatePlugin(object sender, PluginInfrastructureCancelEventArgs e) {
    23       throw new NotImplementedException();
     24      Console.WriteLine("Following plugins are updated:");
     25      var infos = (IEnumerable<PluginInformation>)e.Entity;
     26      foreach (var info in infos) {
     27        Console.WriteLine(info.Name + " " + info.Version + " " + info.BuildDate);
     28      }
     29      if (GetUserConfirmation()) e.Cancel = false;
     30      else e.Cancel = true;
     31      return;
    2432    }
    2533
    2634    void installManager_PluginUpdated(object sender, PluginInfrastructureEventArgs e) {
    27       throw new NotImplementedException();
     35      foreach (var info in (IEnumerable<PluginInformation>)e.Entity)
     36        Console.WriteLine("Updated: {0}", info.Name);
    2837    }
    2938
     
    4554
    4655    void installManager_PreInstallPlugin(object sender, PluginInfrastructureCancelEventArgs e) {
    47      
     56
    4857    }
    4958
    5059    void installManager_PluginInstalled(object sender, PluginInfrastructureEventArgs e) {
    51      
     60
    5261    }
    5362
Note: See TracChangeset for help on using the changeset viewer.