Free cookie consent management tool by TermsFeed Policy Generator

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

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

various changes (#467)

File size: 2.0 KB
Line 
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;
8using HeuristicLab.Hive.Contracts.BusinessObjects;
9
10namespace HeuristicLab.Hive.Client.Core {
11  public class PluginCache {
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   
22    private List<CachedHivePluginInfo> pluginCache;
23   
24
25    public PluginCache() {
26      pluginCache = new List<CachedHivePluginInfo>();
27    }
28   
29    public void AddPlugin(CachedHivePluginInfo plugin) {
30      pluginCache.Add(plugin);   
31    }
32
33    public List<CachedHivePluginInfo> GetPlugins(List<HivePluginInfo> requests) {
34      List<CachedHivePluginInfo> neededPlugins = new List<CachedHivePluginInfo>();
35      List<HivePluginInfo> missingPlugins = new List<HivePluginInfo>();
36      bool found = false;
37           
38      foreach (HivePluginInfo info in requests) {
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
40        foreach (CachedHivePluginInfo cache in pluginCache) {
41          if (info.Name.Equals(cache.Name) && info.Version.Equals(cache.Version) && info.BuildDate <= cache.BuildDate) {
42            neededPlugins.Add(cache);
43            found = true;
44            break;
45          }
46        }
47        if (!found)
48          missingPlugins.Add(info);
49        found = false;
50      }
51
52      List<CachedHivePluginInfo> receivedPlugins = WcfService.Instance.RequestPlugins(missingPlugins);
53      if (receivedPlugins != null) {
54        neededPlugins.AddRange(receivedPlugins);
55        pluginCache.AddRange(receivedPlugins);
56      } else
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.