Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/18/11 15:51:14 (13 years ago)
Author:
ascheibe
Message:

#1233

  • allow different versions of the same plugin in PluginCache
  • fixes for the SlaveTests
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/PluginCache.cs

    r5314 r5325  
    2727using System.Runtime.CompilerServices;
    2828using System.Threading;
    29 using HeuristicLab.Clients.Hive.Slave;
    30 using HeuristicLab.PluginInfrastructure;
    31 using HeuristicLab.PluginInfrastructure.Manager;
    3229using HeuristicLab.Services.Hive.Common.DataTransfer;
    3330
     
    4239    public string PluginTempBaseDir { get; set; }
    4340
    44     private List<PluginDescription> cachedPlugins = new List<PluginDescription>();
    45 
    46     private PluginManager pm;
     41    private List<Guid> cachedPluginsGuids = new List<Guid>();
    4742
    4843    public static PluginCache Instance {
     
    6459      PluginTempBaseDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PluginTemp");
    6560
    66       this.pm = new PluginManager(PluginCacheDir);
    6761      DoUpdateRun();
     62    }
     63
     64    private string getFilenameFromPath(string path) {
     65      string[] dirParts = path.Split(Path.DirectorySeparatorChar);
     66      if (dirParts.Length > 0) {
     67        string fileGuid = dirParts[dirParts.Length - 1];
     68        return fileGuid;
     69      } else
     70        return "";
    6871    }
    6972
     
    7275        Directory.CreateDirectory(PluginCacheDir);
    7376      }
    74       pm.DiscoverAndCheckPlugins();
    75       cachedPlugins = new List<PluginDescription>(pm.Plugins);
     77
     78      foreach (string dir in Directory.EnumerateDirectories(PluginCacheDir)) {
     79        cachedPluginsGuids.Add(Guid.Parse(getFilenameFromPath(dir)));
     80      }
    7681    }
    7782
     
    8489          Directory.Delete(targetDir, true);
    8590        }
    86 
    87         DirectoryInfo di = Directory.CreateDirectory(targetDir);
     91        Directory.CreateDirectory(targetDir);
     92
    8893
    8994        foreach (Plugin requestedPlugin in requests) {
    90           PluginDescription pd = cachedPlugins.Where(cp =>
    91             cp.Name == requestedPlugin.Name &&
    92             cp.Version.Major == requestedPlugin.Version.Major &&
    93             cp.Version.Minor == requestedPlugin.Version.Minor).SingleOrDefault();
    94           if (pd != null) {
    95             foreach (IPluginFile ipf in pd.Files) {
    96               File.Copy(ipf.Name, Path.Combine(targetDir, Path.GetFileName(ipf.Name)));
     95          string curPath = Path.Combine(PluginCacheDir, requestedPlugin.Id.ToString());
     96          if (Directory.Exists(curPath)) {
     97            foreach (string file in Directory.GetFiles(curPath)) {
     98              string fn = getFilenameFromPath(file);
     99              File.Copy(file, Path.Combine(targetDir, fn));
    97100            }
    98101          }
     
    142145
    143146        foreach (Plugin info in requiredPlugins) {
    144           //we MAY run in problems here - if there is a plugin twice in requests, there may be added two different versions of the plugin
    145           foreach (PluginDescription cachedPlugin in cachedPlugins) {
    146             if (info.Name == cachedPlugin.Name && info.Version == cachedPlugin.Version) {
    147               localPlugins.Add(new Plugin() { Id = new Guid(), Name = info.Name, Version = info.Version });
     147          foreach (Guid cachedPlugin in cachedPluginsGuids) {
     148            if (info.Id == cachedPlugin) {
     149              localPlugins.Add(new Plugin() { Id = cachedPlugin, Name = info.Name, Version = info.Version });
    148150              found = true;
    149151
     
    165167
    166168        foreach (PluginData updateablePlugin in updateablePlugins) {
    167           Plugin pluginDescription = pluginDescriptions.Where(desc => desc.Id == updateablePlugin.PluginId).SingleOrDefault();
    168           if (pluginDescription != null) {
    169 
    170             PluginDescription pd = cachedPlugins.Where(cachedPlugin =>
    171                 cachedPlugin.Name == pluginDescription.Name &&
    172                 cachedPlugin.Version.Major == pluginDescription.Version.Major &&
    173                 cachedPlugin.Version.Minor == pluginDescription.Version.Major).SingleOrDefault();
    174 
    175             if (pd != null) {
    176               foreach (IPluginFile ipf in pd.Files) {
    177                 SlaveClientCom.Instance.ClientCom.LogMessage(string.Format("deleting {0}", Path.GetFileName(ipf.Name)));
    178                 File.Delete(ipf.Name);
    179               }
    180             }
    181             File.WriteAllBytes(Path.Combine(PluginCacheDir, Path.GetFileName(updateablePlugin.FileName)), updateablePlugin.Data);
    182           }
    183           //TODO: error handling on pluginDescription, should be found
     169          string pluginDir = Path.Combine(PluginCacheDir, updateablePlugin.PluginId.ToString());
     170
     171          //put all files belonging to a plugin in the same directory
     172          if (!Directory.Exists(pluginDir)) {
     173            DirectoryInfo di = Directory.CreateDirectory(pluginDir);
     174          }
     175          File.WriteAllBytes(Path.Combine(pluginDir, Path.GetFileName(updateablePlugin.FileName)), updateablePlugin.Data);
    184176        }
    185177
     
    212204      }
    213205    }
    214 
    215 
    216206  }
    217207}
Note: See TracChangeset for help on using the changeset viewer.