Rev | Line | |
---|
[1450] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using HeuristicLab.PluginInfrastructure;
|
---|
| 6 | using HeuristicLab.Hive.Client.Communication;
|
---|
| 7 | using HeuristicLab.Hive.Client.Common;
|
---|
| 8 |
|
---|
| 9 | namespace 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);
|
---|
[1481] | 39 | if (receivedPlugins != null) {
|
---|
[1450] | 40 | neededPlugins.AddRange(receivedPlugins);
|
---|
[1481] | 41 | pluginCache.AddRange(receivedPlugins);
|
---|
| 42 | } else
|
---|
[1450] | 43 | Logging.Instance.Error(this.ToString(), "Fetching of the plugins failed!");
|
---|
| 44 |
|
---|
| 45 | return neededPlugins;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.