/// <summary> /// Updates the plugin cache with missing plugins and /// then copies the required plugins for the task. /// </summary> public void PreparePlugins(Task task, out string configFileName) { lock (locker) { log.LogMessage("Fetching plugins for task " + task.Id); List <Guid> missingGuids = new List <Guid>(); List <Plugin> neededPlugins = new List <Plugin>(); lock (cachedPluginsGuids) { foreach (Guid pluginId in task.PluginsNeededIds) { Plugin plugin = pluginService.GetPlugin(pluginId); if (plugin != null) { neededPlugins.Add(plugin); } if (!cachedPluginsGuids.Contains(pluginId)) { missingGuids.Add(pluginId); } } } IEnumerable <PluginData> pluginDatas = pluginService.GetPluginDatas(missingGuids); if (pluginDatas != null) { foreach (PluginData pluginData in pluginDatas) { string pluginDir = Path.Combine(PluginCacheDir, pluginData.PluginId.ToString()); //put all files belonging to a plugin in the same directory SafelyCreateDirectory(pluginDir); File.WriteAllBytes(Path.Combine(pluginDir, Path.GetFileName(pluginData.FileName)), pluginData.Data); } if (missingGuids.Count > 0) { DoUpdateRun(); } CopyPluginsForJob(neededPlugins, task.Id, out configFileName); } else { configFileName = ""; } log.LogMessage(string.Format("Fetched {0} plugins for task {1}", missingGuids.Count, task.Id)); } }