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 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
9 |
|
---|
10 | namespace 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 | }
|
---|