/// <summary> /// Checks if plugins are available on Hive Server. If not they are uploaded. Ids are returned. /// </summary> /// <param name="service">An active service-proxy</param> /// <param name="onlinePlugins">List of plugins which are available online</param> /// <param name="alreadyUploadedPlugins">List of plugins which have been uploaded from this Task</param> /// <param name="neededPlugins">List of plugins which need to be uploaded</param> /// <returns></returns> public static List<Guid> GetPluginDependencies(IHiveService service, List<Plugin> onlinePlugins, List<Plugin> alreadyUploadedPlugins, IEnumerable<IPluginDescription> neededPlugins) { var pluginIds = new List<Guid>(); Dictionary<IPluginDescription, byte[]> checksumsNeededPlugins = CalcChecksumsForPlugins(neededPlugins); foreach (var neededPlugin in checksumsNeededPlugins) { Plugin foundPlugin = alreadyUploadedPlugins.FirstOrDefault(p => p.Hash.SequenceEqual(neededPlugin.Value)); if (foundPlugin == null) { foundPlugin = onlinePlugins.FirstOrDefault(p => { if (p.Hash != null) { return p.Hash.SequenceEqual(neededPlugin.Value); } else { return false; } }); if (foundPlugin == null) { Plugin p = CreatePlugin(neededPlugin.Key, neededPlugin.Value); List<PluginData> pd = CreatePluginDatas(neededPlugin.Key); try { p.Id = service.AddPlugin(p, pd); alreadyUploadedPlugins.Add(p); pluginIds.Add(p.Id); } catch (FaultException<PluginAlreadyExistsFault> fault) { onlinePlugins.Add(service.GetPlugin(fault.Detail.Id)); } } else { pluginIds.Add(foundPlugin.Id); } } else { pluginIds.Add(foundPlugin.Id); } } return pluginIds; }
public HivesController(IHiveService hiveService, IHiveSectionService hiveSectionService) { _hiveService = hiveService ?? throw new ArgumentNullException(nameof(hiveService)); _hiveSectionService = hiveSectionService ?? throw new ArgumentNullException(nameof(hiveSectionService)); }
/// <summary> /// Uploads the local configuration file as plugin /// </summary> private static Plugin UploadConfigurationFile(IHiveService service, List<Plugin> onlinePlugins) { string exeFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.Default.HLBinaryName); string configFileName = Path.GetFileName(ConfigurationManager.OpenExeConfiguration(exeFilePath).FilePath); string configFilePath = ConfigurationManager.OpenExeConfiguration(exeFilePath).FilePath; byte[] hash; byte[] data = File.ReadAllBytes(configFilePath); using (SHA1 sha1 = SHA1.Create()) { hash = sha1.ComputeHash(data); } Plugin configPlugin = new Plugin() { Name = "Configuration", Version = new Version(), Hash = hash }; PluginData configFile = new PluginData() { FileName = configFileName, Data = data }; IEnumerable<Plugin> onlineConfig = onlinePlugins.Where(p => p.Hash.SequenceEqual(hash)); if (onlineConfig.Count() > 0) { return onlineConfig.First(); } else { configPlugin.Id = service.AddPlugin(configPlugin, new List<PluginData> { configFile }); return configPlugin; } }