Changeset 5325
- Timestamp:
- 01/18/11 15:51:14 (14 years ago)
- Location:
- branches/HeuristicLab.Hive-3.4/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/SlaveTest.cs
r5314 r5325 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.ServiceModel;26 25 using HeuristicLab.Clients.Common; 27 26 using HeuristicLab.Services.Hive.Common; … … 33 32 [TestClass] 34 33 public class SlaveTest { 35 36 private static ServiceHost slaveComm;37 34 private static SlaveCommListener listener; 38 35 … … 42 39 PluginLoader.pluginAssemblies.Any(); 43 40 ServiceLocator.Instance = new MockServiceLocator(); 44 slaveComm = new ServiceHost(typeof(SlaveCommunicationService)); 45 slaveComm.Open(); 46 listener = new SlaveCommListener(); 47 listener.Open(); 41 /* listener = new SlaveCommListener(); 42 listener.Open();*/ 48 43 } 49 44 50 45 [ClassCleanup] 51 46 public static void MyClassCleanup() { 52 listener.Close(); 53 slaveComm.Close(); 47 //listener.Close(); 54 48 } 55 49 … … 97 91 Assert.AreEqual<int>(1, ms.ResultJobs.Count); 98 92 Assert.AreEqual<Guid>(testJob.Id, ms.ResultJobs[0].Id); 93 core.Shutdown(); 99 94 } 100 95 } … … 131 126 HeuristicLab.Clients.Hive.Slave.Core core = new Slave.Core(); 132 127 core.Start(); 133 134 128 } 135 129 } … … 195 189 core.Start(); 196 190 Assert.AreEqual<int>(2, ms.ResultJobs.Count); 197 191 core.Shutdown(); 198 192 } 199 193 } 200 201 202 203 204 205 206 207 208 209 194 } 210 195 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/PluginCache.cs
r5314 r5325 27 27 using System.Runtime.CompilerServices; 28 28 using System.Threading; 29 using HeuristicLab.Clients.Hive.Slave;30 using HeuristicLab.PluginInfrastructure;31 using HeuristicLab.PluginInfrastructure.Manager;32 29 using HeuristicLab.Services.Hive.Common.DataTransfer; 33 30 … … 42 39 public string PluginTempBaseDir { get; set; } 43 40 44 private List<PluginDescription> cachedPlugins = new List<PluginDescription>(); 45 46 private PluginManager pm; 41 private List<Guid> cachedPluginsGuids = new List<Guid>(); 47 42 48 43 public static PluginCache Instance { … … 64 59 PluginTempBaseDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PluginTemp"); 65 60 66 this.pm = new PluginManager(PluginCacheDir);67 61 DoUpdateRun(); 62 } 63 64 private string getFilenameFromPath(string path) { 65 string[] dirParts = path.Split(Path.DirectorySeparatorChar); 66 if (dirParts.Length > 0) { 67 string fileGuid = dirParts[dirParts.Length - 1]; 68 return fileGuid; 69 } else 70 return ""; 68 71 } 69 72 … … 72 75 Directory.CreateDirectory(PluginCacheDir); 73 76 } 74 pm.DiscoverAndCheckPlugins(); 75 cachedPlugins = new List<PluginDescription>(pm.Plugins); 77 78 foreach (string dir in Directory.EnumerateDirectories(PluginCacheDir)) { 79 cachedPluginsGuids.Add(Guid.Parse(getFilenameFromPath(dir))); 80 } 76 81 } 77 82 … … 84 89 Directory.Delete(targetDir, true); 85 90 } 86 87 DirectoryInfo di = Directory.CreateDirectory(targetDir); 91 Directory.CreateDirectory(targetDir); 92 88 93 89 94 foreach (Plugin requestedPlugin in requests) { 90 PluginDescription pd = cachedPlugins.Where(cp => 91 cp.Name == requestedPlugin.Name && 92 cp.Version.Major == requestedPlugin.Version.Major && 93 cp.Version.Minor == requestedPlugin.Version.Minor).SingleOrDefault(); 94 if (pd != null) { 95 foreach (IPluginFile ipf in pd.Files) { 96 File.Copy(ipf.Name, Path.Combine(targetDir, Path.GetFileName(ipf.Name))); 95 string curPath = Path.Combine(PluginCacheDir, requestedPlugin.Id.ToString()); 96 if (Directory.Exists(curPath)) { 97 foreach (string file in Directory.GetFiles(curPath)) { 98 string fn = getFilenameFromPath(file); 99 File.Copy(file, Path.Combine(targetDir, fn)); 97 100 } 98 101 } … … 142 145 143 146 foreach (Plugin info in requiredPlugins) { 144 //we MAY run in problems here - if there is a plugin twice in requests, there may be added two different versions of the plugin 145 foreach (PluginDescription cachedPlugin in cachedPlugins) { 146 if (info.Name == cachedPlugin.Name && info.Version == cachedPlugin.Version) { 147 localPlugins.Add(new Plugin() { Id = new Guid(), Name = info.Name, Version = info.Version }); 147 foreach (Guid cachedPlugin in cachedPluginsGuids) { 148 if (info.Id == cachedPlugin) { 149 localPlugins.Add(new Plugin() { Id = cachedPlugin, Name = info.Name, Version = info.Version }); 148 150 found = true; 149 151 … … 165 167 166 168 foreach (PluginData updateablePlugin in updateablePlugins) { 167 Plugin pluginDescription = pluginDescriptions.Where(desc => desc.Id == updateablePlugin.PluginId).SingleOrDefault(); 168 if (pluginDescription != null) { 169 170 PluginDescription pd = cachedPlugins.Where(cachedPlugin => 171 cachedPlugin.Name == pluginDescription.Name && 172 cachedPlugin.Version.Major == pluginDescription.Version.Major && 173 cachedPlugin.Version.Minor == pluginDescription.Version.Major).SingleOrDefault(); 174 175 if (pd != null) { 176 foreach (IPluginFile ipf in pd.Files) { 177 SlaveClientCom.Instance.ClientCom.LogMessage(string.Format("deleting {0}", Path.GetFileName(ipf.Name))); 178 File.Delete(ipf.Name); 179 } 180 } 181 File.WriteAllBytes(Path.Combine(PluginCacheDir, Path.GetFileName(updateablePlugin.FileName)), updateablePlugin.Data); 182 } 183 //TODO: error handling on pluginDescription, should be found 169 string pluginDir = Path.Combine(PluginCacheDir, updateablePlugin.PluginId.ToString()); 170 171 //put all files belonging to a plugin in the same directory 172 if (!Directory.Exists(pluginDir)) { 173 DirectoryInfo di = Directory.CreateDirectory(pluginDir); 174 } 175 File.WriteAllBytes(Path.Combine(pluginDir, Path.GetFileName(updateablePlugin.FileName)), updateablePlugin.Data); 184 176 } 185 177 … … 212 204 } 213 205 } 214 215 216 206 } 217 207 }
Note: See TracChangeset
for help on using the changeset viewer.