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

Last change on this file since 1450 was 1450, checked in by kgrading, 12 years ago

first implementation (#547)

File size: 1.4 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;
8
9namespace HeuristicLab.Hive.Client.Core {
10  public class PluginCache {
11    private List<CachedPlugin> pluginCache;
12   
13    public PluginCache() {
14      pluginCache = new List<CachedPlugin>();
15    }
16   
17    public void AddPlugin(CachedPlugin plugin) {
18      pluginCache.Add(plugin);   
19    }
20
21    public List<CachedPlugin> GetPlugins(List<PluginInfo> requests) {
22      List<CachedPlugin> neededPlugins = new List<CachedPlugin>();
23      List<PluginInfo> missingPlugins = new List<PluginInfo>();
24      bool found = false;
25      foreach (PluginInfo info in requests) {
26        foreach (CachedPlugin cache in pluginCache) {
27          if (info.Equals(cache)) {
28            neededPlugins.Add(cache);
29            found = true;
30            break;
31          }
32        }
33        if (!found)
34          missingPlugins.Add(info);
35        found = false;
36      }
37
38      List<CachedPlugin> receivedPlugins = WcfService.Instance.RequestPlugins(missingPlugins);
39      if (receivedPlugins != null)
40        neededPlugins.AddRange(receivedPlugins);
41      else
42        Logging.Instance.Error(this.ToString(), "Fetching of the plugins failed!");
43
44      return neededPlugins;
45    }
46
47  }
48}
Note: See TracBrowser for help on using the repository browser.