Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Client.Core/3.2/PluginCache.cs @ 1861

Last change on this file since 1861 was 1635, checked in by kgrading, 16 years ago

various changes (#467)

File size: 2.0 KB
RevLine 
[1450]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.PluginInfrastructure;
6using HeuristicLab.Hive.Client.Communication;
7using HeuristicLab.Hive.Client.Common;
[1594]8using HeuristicLab.Hive.Contracts.BusinessObjects;
[1450]9
10namespace HeuristicLab.Hive.Client.Core {
11  public class PluginCache {
[1602]12
13    private static PluginCache instance = null;
14    public static PluginCache Instance {
15      get {
16        if (instance == null)
17          instance = new PluginCache();
18        return instance;
19      }
20    }
21   
[1589]22    private List<CachedHivePluginInfo> pluginCache;
[1450]23   
[1602]24
[1450]25    public PluginCache() {
[1589]26      pluginCache = new List<CachedHivePluginInfo>();
[1450]27    }
28   
[1589]29    public void AddPlugin(CachedHivePluginInfo plugin) {
[1450]30      pluginCache.Add(plugin);   
31    }
32
[1594]33    public List<CachedHivePluginInfo> GetPlugins(List<HivePluginInfo> requests) {
[1589]34      List<CachedHivePluginInfo> neededPlugins = new List<CachedHivePluginInfo>();
[1594]35      List<HivePluginInfo> missingPlugins = new List<HivePluginInfo>();
[1450]36      bool found = false;
[1635]37           
[1594]38      foreach (HivePluginInfo info in requests) {
[1635]39        //we MAY run in problems here - if there is a plugin twice in requests, there may be added two different versions of the plugin
[1589]40        foreach (CachedHivePluginInfo cache in pluginCache) {
[1635]41          if (info.Name.Equals(cache.Name) && info.Version.Equals(cache.Version) && info.BuildDate <= cache.BuildDate) {
[1450]42            neededPlugins.Add(cache);
43            found = true;
44            break;
45          }
46        }
47        if (!found)
48          missingPlugins.Add(info);
49        found = false;
50      }
51
[1589]52      List<CachedHivePluginInfo> receivedPlugins = WcfService.Instance.RequestPlugins(missingPlugins);
[1481]53      if (receivedPlugins != null) {
[1450]54        neededPlugins.AddRange(receivedPlugins);
[1481]55        pluginCache.AddRange(receivedPlugins);
56      } else
[1450]57        Logging.Instance.Error(this.ToString(), "Fetching of the plugins failed!");
58
59      return neededPlugins;
60    }
61
62  }
63}
Note: See TracBrowser for help on using the repository browser.