public void RemovePlugin(string id, string version) { Log.DebugFormat("Removing plugin {0} v{1}...", id, version); if (!Version.TryParse(version, out var v)) { throw new CannotRemovePluginException($"'{version}' is not a valid version."); } using (var transaction = _database.BeginTransaction()) { var identifier = new PluginIdentifier(id, v); if (!_plugins.Remove(identifier)) { throw new CannotRemovePluginException($"No plugin {id} v{version} exists."); } _pluginDescriptions.Remove(identifier); _pluginIcons.Remove(identifier); transaction.Commit(); Log.InfoFormat("Removed plugin {0} v{1}", id, version); } }
public byte[] DownloadPlugin(PluginIdentifier pluginId) { var stopwatch = Stopwatch.StartNew(); Log.DebugFormat("Retrieving plugin '{0}'...", pluginId); try { var pluginContent = _plugins.Get(pluginId); stopwatch.Stop(); Log.InfoFormat("Retrieved plugin '{0}' from disk, {1} bytes (took {2}ms)", pluginId, pluginContent.Length, stopwatch.ElapsedMilliseconds); return(pluginContent); } catch (Exception e) { Log.ErrorFormat("Caught exception while trying to retrieve plugin '{0}':\r\n{1}", pluginId, e); // TODO: Throw different exception throw; } }
private void DownloadPlugin(PluginIdentifier plugin) { var repositories = _applicationSettings.AutoUpdate.PluginRepositories; var task = _pluginUpdater.DownloadPluginAsync(repositories, plugin); task.ContinueWith(t => _dispatcher.BeginInvoke(() => OnPluginDownloaded(t))); }
public void TestRoundtrip([ValueSource(nameof(Versions))] Version version) { var value = new PluginIdentifier("A", version); var actualValue = BinarySerializerTest.Roundtrip(value); actualValue.Should().NotBeNull(); actualValue.Should().NotBeSameAs(value); actualValue.Should().Be(value); }
private void DownloadAndInstall(IPluginRepository repository, PluginIdentifier id) { var content = repository.DownloadPlugin(id); var fileName = $"{id.Id}.{id.Version}.tvp"; var filePath = Path.Combine(Constants.DownloadedPluginsPath, fileName); var folder = Path.GetDirectoryName(filePath); Directory.CreateDirectory(folder); File.WriteAllBytes(filePath, content); }
public void PublishPlugin(byte[] plugin, string accessToken, DateTime publishDate) { Log.DebugFormat("Adding plugin ({0} bytes) to repository...", plugin.Length); IPluginPackageIndex pluginIndex; DateTime builtTime; IReadOnlyList <SerializableChange> changes; byte[] icon; using (var stream = new MemoryStream(plugin)) using (var archive = OpenPlugin(stream)) { pluginIndex = archive.Index; changes = archive.LoadChanges(); builtTime = GetBuildTime(archive.ReadAssembly()); icon = archive.ReadIcon()?.ReadToEnd(); } var id = new PluginIdentifier(pluginIndex.Id, pluginIndex.Version); if (!Guid.TryParse(accessToken, out var token)) { throw new InvalidUserTokenException($"'{accessToken}' is not a valid access token."); } using (var transaction = _database.BeginTransaction()) { if (!_usernamesByAccessToken.TryGet(token, out var userName)) { throw new InvalidUserTokenException($"'{accessToken}' is not a valid access token."); } // TODO: Only throw a temper tantrum in case the plugin to be added differs from the plugin stored in this repository if (_pluginDescriptions.ContainsKey(id) || _plugins.ContainsKey(id)) { throw new PluginAlreadyPublishedException($"The plugin '{id}' already exists and cannot be modified."); } var publishedPlugin = new PublishedPlugin(pluginIndex) { Publisher = userName, Identifier = id, BuildDate = builtTime, SizeInBytes = plugin.Length, PublishDate = publishDate, RequiredInterfaces = pluginIndex.ImplementedPluginInterfaces .Select(x => new PluginInterface(x.InterfaceTypename, x.InterfaceVersion)).ToList(), }; _pluginDescriptions.Put(id, publishedPlugin); _plugins.Put(id, plugin); _pluginIcons.Put(id, icon); transaction.Commit(); Log.InfoFormat("Added plugin '{0}' to repository!", id); } }
private void DownloadPlugin(string repositoryName, PluginIdentifier plugin) { var endPoint = ResolveRepositoryName(repositoryName); using (var client = new SocketEndPoint(EndPointType.Client)) { Connect(client, endPoint); var repository = client.CreateProxy <IPluginRepository>(Archiver.Repository.Constants.PluginRepositoryV1Id); DownloadAndInstall(repository, plugin); } }
private bool TryDownloadAndInstall(IPluginRepository repository, PluginIdentifier id) { try { DownloadAndInstall(repository, id); return(true); } catch (Exception e) { Log.WarnFormat("Unable to download / install plugin '{0}':\r\n{1}", id, e); return(false); } }
private bool TryFindNewestPlugin(IPluginDescription installedPlugin, IReadOnlyList <PluginIdentifier> allPlugins, out PluginIdentifier id) { var candidates = allPlugins.Where(x => x.Id == installedPlugin.Id.Value) .OrderByDescending(x => x.Version) .ToList(); if (candidates.Count == 0) { Log.DebugFormat("No newer version for plugin '{0}' available", installedPlugin.Id); id = null; return(false); } id = candidates[0]; return(true); }
public Task DownloadPluginAsync(IReadOnlyList <string> repositories, PluginIdentifier plugin) { return(Task.Factory.StartNew(() => { Exception lastException = null; foreach (var repository in repositories) { try { DownloadPlugin(repository, plugin); return; } catch (Exception e) { lastException = e; } } throw lastException; })); }
public void PluginManager() { const string debugDirectory = @"C:\Projects\ESME Deliverables\Libraries\ESME.Tests\bin\Debug"; const string pluginDirectory = debugDirectory + @"\Plugins"; if (Directory.Exists(pluginDirectory)) Directory.Delete(pluginDirectory, true); Assert.IsFalse(Directory.Exists(pluginDirectory)); Directory.CreateDirectory(pluginDirectory); Assert.IsTrue(Directory.Exists(pluginDirectory)); File.Copy(Path.Combine(debugDirectory, "InstallableNAVOPlugin.dll"), Path.Combine(pluginDirectory, "InstallableNAVOPlugin.dll")); File.Copy(Path.Combine(debugDirectory, "NAVODatabaseAdapter.dll"), Path.Combine(pluginDirectory, "NAVODatabaseAdapter.dll")); var pluginManager = new PluginManagerService(); Assert.IsNull(pluginManager[PluginType.EnvironmentalDataSource]); pluginManager.PluginDirectory = pluginDirectory; Assert.IsNotNull(pluginManager[PluginType.EnvironmentalDataSource]); var pluginIdentifier = new PluginIdentifier { PluginType = PluginType.EnvironmentalDataSource, PluginSubtype = PluginSubtype.SoundSpeed, Type = typeof(GDEM3ForESME).ToString(), }; Assert.IsTrue(pluginManager[pluginIdentifier] is GDEM3ForESME); }
public byte[] DownloadPlugin(PluginIdentifier pluginId) { return(_inner.DownloadPlugin(pluginId)); }
public DbPluginIdentifier(PluginIdentifier pluginIdentifier) { PluginType = pluginIdentifier.PluginType; PluginSubtype = pluginIdentifier.PluginSubtype; Type = pluginIdentifier.Type; }
public EnvironmentalDataSet LoadOrCreateEnvironmentalDataSet(Location location, float resolution, TimePeriod timePeriod, PluginIdentifier sourcePlugin) { var timePeriodAsByte = ((DbTimePeriod)timePeriod).TimePeriodAsByte; var existing = (from e in Context.EnvironmentalDataSets where e.Location.Guid == location.Guid && e.SourcePlugin.Type == sourcePlugin.Type && e.TimePeriod.TimePeriodAsByte == timePeriodAsByte && e.Resolution == resolution select e).FirstOrDefault(); if (existing != null) return existing; var environmentalDataSet = new EnvironmentalDataSet { FileName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + "." + sourcePlugin.PluginSubtype.ToString().ToLower(), Resolution = resolution, TimePeriod = timePeriod, Location = location, SourcePlugin = sourcePlugin, }; location.EnvironmentalDataSets.Add(environmentalDataSet); Context.EnvironmentalDataSets.Add(environmentalDataSet); Log(environmentalDataSet, "Added new data set to {0}. Data type: {1}, resolution: {2}{3}", location.Name, sourcePlugin.PluginSubtype, resolution, timePeriod != TimePeriod.Invalid ? String.Format(" TimePeriod: {0}", timePeriod) : ""); return environmentalDataSet; }