Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3011 was 3011, checked in by kgrading, 14 years ago

changed the complete DAL to LINQ 2 SQL (with the exception of the job streaming), did a lot of refactoring, Introduced DTOs (that are named DTOs for better understanding), added the spring.NET Interceptor, reintroduced transactions and cleaned up the whole JobResult thing and updated a part of the config merger (#830)

File size: 2.1 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<CachedHivePluginInfoDto> pluginCache;
23   
24
25    public PluginCache() {
26      pluginCache = new List<CachedHivePluginInfoDto>();
27    }
28   
29    public void AddPlugin(CachedHivePluginInfoDto plugin) {
30      pluginCache.Add(plugin);   
31    }
32
33    public List<CachedHivePluginInfoDto> GetPlugins(List<HivePluginInfoDto> requests) {
34      List<CachedHivePluginInfoDto> neededPlugins = new List<CachedHivePluginInfoDto>();
35      List<HivePluginInfoDto> missingPlugins = new List<HivePluginInfoDto>();
36      bool found = false;
37           
38      foreach (HivePluginInfoDto 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 (CachedHivePluginInfoDto 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<CachedHivePluginInfoDto> 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.