public CustomLogFileFormat(PluginId pluginId, string name, string format, Encoding encoding) { _pluginId = pluginId; _name = name; _format = format; _encoding = encoding; }
public async Task <PluginInformation> InstallPluginAsync(Uri uri, CancellationToken cancellationToken) { var filename = uri.GetFilename(); if (!uri.ToString().ToLowerInvariant().EndsWith(".zip")) { throw new ArgumentException($"Only understands ZIP files: {uri} ({filename})"); } var pluginId = PluginId.With(Path.GetFileNameWithoutExtension(filename).ToLowerInvariant()); if (_plugins.ContainsKey(pluginId)) { await _pluginInstaller.UninstallPluginAsync(pluginId, cancellationToken).ConfigureAwait(false); } using (var tempFile = await _restClient.DownloadAsync(uri, cancellationToken).ConfigureAwait(false)) { var pluginPath = await _pluginInstaller.InstallPluginAsync( pluginId, tempFile, PluginPackageType.Zip, cancellationToken) .ConfigureAwait(false); return(await LoadPluginAsync( pluginPath, cancellationToken) .ConfigureAwait(false)); } }
public async Task <PluginPath> InstallPluginAsync( PluginId pluginId, TempFile tempFile, PluginPackageType packageType, CancellationToken cancellationToken) { var installDirectory = GetInstallDirectory(pluginId); _logger.Verbose($"Installing plugin '{pluginId}' into '{installDirectory}'"); switch (packageType) { case PluginPackageType.Zip: { await tempFile.ExtractZipAsync(installDirectory, cancellationToken).ConfigureAwait(false); var pluginDll = Path.Combine(installDirectory, $"{pluginId}.dll"); _logger.Verbose($"Guessing that plugin location is '{pluginDll}'"); return(new PluginPath(pluginDll)); } default: throw new ArgumentOutOfRangeException(nameof(packageType), packageType, null); } }
internal void Load() { (Assemblies as List <string>).Clear(); foreach (FileInfo f in new DirectoryInfo(Path).GetFiles("*.dll", SearchOption.TopDirectoryOnly)) { if (isDotNetAssembly(f.FullName)) { (Assemblies as List <string>).Add(f.FullName); } } if (Domain != null) { FireHandleUnloadAppDomain(); Domain = null; } Domain = ProxyDomain.CreateDomain(PluginId.ToString(), Path); foreach (string p in Assemblies) { Domain.LoadAssembly(p); } AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve; var m = Domain.Create <IPlugin>(); _plugin = m; }
/// <summary> /// Load all the programs for the given plugin from the given directory. /// </summary> public static bool LoadPluginPrograms(PluginId pluginId, [MarshalAs(UnmanagedType.LPWStr)] string path) { Id.Check(pluginId); Contract.Requires(!string.IsNullOrEmpty(path)); Contract.Requires(Directory.Exists(path)); return(NowSoundGraph_LoadPluginPrograms(pluginId, path)); }
/// <summary> /// Get the name of the Nth plugin. Note that IDs are 1-based. /// </summary> public static void PluginName(PluginId pluginId, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder buffer) { Id.Check(pluginId); Contract.Requires(buffer != null); Contract.Requires(buffer.Capacity > 0); NowSoundGraph_PluginName(pluginId, buffer, buffer.Capacity); }
public async Task UnloadPlugin([FromBody] TenantMessage tenantMessage, CancellationToken cancellationToken) { var pId = RegexUnloadPlugin.Match(tenantMessage.Text).Groups["pluginId"].Value; var pluginId = PluginId.With(pId); await _pluginApi.UnloadPluginAsync(pluginId, cancellationToken).ConfigureAwait(false); await _messageApi.ReplyToAsync(tenantMessage, $"Unloaded plugin {pluginId}", cancellationToken).ConfigureAwait(false); }
/// <summary> /// Get the number of programs for the given plugin. /// </summary> public static int PluginProgramCount(PluginId pluginId) { Id.Check(pluginId); int result = NowSoundGraph_PluginProgramCount(pluginId); Contract.Assert(result >= 0); return(result); }
public PluginProxy( PluginId id, AppDomain appDomain, IPlugin plugin) { Id = id; Plugin = plugin; _appDomain = appDomain; }
public Task RegisterAsync(PluginId pluginId, IEnumerable <CommandDescription> commandDescriptions) { var commandDescriptionList = commandDescriptions.ToList(); _pluginCommandDescriptions[pluginId] = commandDescriptionList; _logger.Verbose($"Registerd commands for '{pluginId}': {string.Join(", ", commandDescriptionList.Select(d => d.ToString()))}"); return(Task.FromResult(0)); }
public static Delegate GetFunction <TDelegate>(PluginId id, string name) { var ptr = get_plugin_function(id.Ptr, name); if (ptr == IntPtr.Zero) { throw new FunctionNotFoundException(name); } return(Marshal.GetDelegateForFunctionPointer(ptr, typeof(TDelegate))); }
public Task UninstallPluginAsync(PluginId pluginId, CancellationToken cancellationToken) { var installDirectory = GetInstallDirectory(pluginId); if (_fileSystemClient.DirectoryExists(installDirectory)) { _logger.Warning($"Plugin '{pluginId}' is now installed, but request to be uninstalled"); return Task.FromResult(0); } return Task.Run(() => _fileSystemClient.DeleteDirectory(installDirectory), cancellationToken); }
public Task UninstallPluginAsync(PluginId pluginId, CancellationToken cancellationToken) { var installDirectory = GetInstallDirectory(pluginId); if (_fileSystemClient.DirectoryExists(installDirectory)) { _logger.Warning($"Plugin '{pluginId}' is now installed, but request to be uninstalled"); return(Task.FromResult(0)); } return(Task.Run(() => _fileSystemClient.DeleteDirectory(installDirectory), cancellationToken)); }
public static PluginInstanceIndex AddPluginInstance(TrackId trackId, PluginId pluginId, ProgramId programId, int dryWet_0_100) { Id.Check(trackId); Id.Check(pluginId); Id.Check(programId); Contract.Requires(dryWet_0_100 >= 0); Contract.Requires(dryWet_0_100 <= 100); PluginInstanceIndex result = NowSoundTrack_AddPluginInstance(trackId, pluginId, programId, dryWet_0_100); Id.Check(result); return(result); }
public override int GetHashCode() { return(Id.GetHashCode() ^ AssemblyId.GetHashCode() ^ PluginId.GetHashCode() ^ StepId.GetHashCode() ^ Attributes.GetHashCode() ^ Name.GetHashCode() ^ RelatedAttribute.GetHashCode() ^ EntityAlias.GetHashCode() ^ ImageType.GetHashCode() ^ MessagePropertyName.GetHashCode()); }
public Task UnloadPluginAsync(PluginId pluginId) { if (!_plugins.ContainsKey(pluginId)) { return(Task.FromResult(0)); } IPluginProxy pluginProxy; _plugins.TryRemove(pluginId, out pluginProxy); pluginProxy.Dispose(); return(Task.FromResult(0)); }
public static PluginInformation With( PluginId id, PluginTitle title, PluginVersion version, PluginDescription description, Uri uri) { return new PluginInformation( id, title, version, description, uri); }
public void Setup() { _serviceContainer = new ServiceContainer(); _registry = new Mock <ILogFileFormatRegistry>(); _serviceContainer.RegisterInstance(_registry.Object); _settings = new Mock <IApplicationSettings>(); _customFormatsSettings = new CustomFormatsSettings(); _settings.SetupGet(x => x.CustomFormats).Returns(_customFormatsSettings); _pluginId = new PluginId("221dwdwaddwa"); _plugin = new Mock <ICustomLogFileFormatCreatorPlugin>(); _encodings = new[] { new EncodingViewModel(Encoding.Default) }; }
public void Start(Action <Action <IPluginRegistration> > pluginRegistra) { pluginRegistra(r => { var assembly = typeof(HelpPluginBootstrapper).Assembly; r.SetPluginInformation(PluginInformation.With( PluginId.From(assembly), PluginTitle.With("Help"), PluginVersion.From(assembly), PluginDescription.With("Provides help for the Borg"), r.Uri)); r.RegisterHttpApi(new HelpApi(r.HttpApi, r.MessageApi, r.PluginApi)); r.RegisterHttpApiCommands(); }); }
public void Start(Action <Action <IPluginRegistration> > pluginRegistra) { pluginRegistra(r => { var assembly = typeof(JokesPluginBootstrapper).Assembly; r.SetPluginInformation(PluginInformation.With( PluginId.From(assembly), PluginTitle.With("Jokes"), PluginVersion.From(assembly), PluginDescription.With("Provides jokes"), r.Uri)); r.RegisterHttpApi(new JokesApi(r.ConfigApi, r.HttpApi, r.MessageApi)); r.RegisterHttpApiCommands(); }); }
public CustomFormatViewModel(IServiceContainer serviceContainer, IApplicationSettings settings, ICustomLogFileFormatCreatorPlugin plugin, IEnumerable <EncodingViewModel> encodings, CustomLogFileFormat customFormat) { _serviceContainer = serviceContainer; _settings = settings; _logFileFormatRegistry = serviceContainer.Retrieve <ILogFileFormatRegistry>(); _pluginId = customFormat.PluginId; _plugin = plugin; _encodings = encodings; _customFormat = customFormat; _name = customFormat.Name; _encoding = Encodings.FirstOrDefault(x => Equals(x.Encoding, customFormat.Encoding)); _format = customFormat.Format; }
public void Start(Action <Action <IPluginRegistration> > pluginRegistra) { pluginRegistra(r => { var assembly = typeof(GitHubPluginBootstrapper).Assembly; var gitHubClientFactory = new GitHubClientFactory(r.ConfigApi); var gitHubService = new GitHubService(gitHubClientFactory); r.SetPluginInformation(PluginInformation.With( PluginId.From(assembly), PluginTitle.With("GitHub"), PluginVersion.From(assembly), PluginDescription.With("Provides GitHub support for the Borg"), r.Uri)); r.RegisterHttpApi(new GitHubApi(r.MessageApi, gitHubService)); r.RegisterHttpApiCommands(); }); }
public PluginInformation( PluginId id, PluginTitle title, PluginVersion version, PluginDescription description, Uri uri) { if (id == null) throw new ArgumentNullException(nameof(id)); if (title == null) throw new ArgumentNullException(nameof(title)); if (version == null) throw new ArgumentNullException(nameof(version)); if (description == null) throw new ArgumentNullException(nameof(description)); if (uri == null) throw new ArgumentNullException(nameof(uri)); Id = id; Title = title; Version = version; Description = description; Uri = uri; }
public CustomFormatPluginViewModel(IServiceContainer serviceContainer, IApplicationSettings settings, PluginId pluginId, ICustomLogFileFormatCreatorPlugin plugin, IEnumerable <EncodingViewModel> encodings) { _serviceContainer = serviceContainer; _settings = settings; _pluginId = pluginId; _plugin = plugin; _encodings = encodings; _name = plugin.FormatName; _addCommand = new DelegateCommand2(Add); _formats = new ObservableCollection <CustomFormatViewModel>(); foreach (var customFormat in _settings.CustomFormats) { Add(customFormat); } }
public void Restore(XmlReader reader) { var count = reader.AttributeCount; for (var i = 0; i < count; ++i) { reader.MoveToAttribute(i); switch (reader.Name) { case "plugin": _pluginId = new PluginId(reader.ReadContentAsString()); break; case "name": _name = reader.ReadContentAsString(); break; case "format": _format = reader.ReadContentAsString(); break; case "encoding": var encodingName = reader.ReadContentAsString(); if (!string.IsNullOrEmpty(encodingName)) { try { _encoding = Encoding.GetEncoding(encodingName); } catch (Exception e) { Log.WarnFormat("Caught exception while trying to get encoding '{0}':\r\n{1}", encodingName, e); } } break; } } }
private void CreatePlugin <T>(string pluginFolder, PluginId actualId, Version actualVersion, PluginId fakeId, Version fakeVersion) where T : IPlugin { using (var stream = new MemoryStream()) { using (var packer = PluginPacker.Create(stream, true)) { var idx = actualId.Value.LastIndexOf("."); var actualNamespace = actualId.Value.Substring(0, idx); var actualName = actualId.Value.Substring(idx + 1); var builder = new PluginBuilder(actualNamespace, actualName, "none of your business", "get of my lawn", version: actualVersion); builder.ImplementInterface <T>("Plugin.FileFormatPlugin"); builder.Save(); packer.AddPluginAssembly(builder.FileName); } stream.Position = 0; var path = Path.Combine(pluginFolder, $"{fakeId.Value}.{fakeVersion}.tvp"); _filesystem.CreateDirectory(pluginFolder); _filesystem.WriteAllBytes(path, stream.ToArray()); } }
public async Task<PluginPath> InstallPluginAsync( PluginId pluginId, TempFile tempFile, PluginPackageType packageType, CancellationToken cancellationToken) { var installDirectory = GetInstallDirectory(pluginId); _logger.Verbose($"Installing plugin '{pluginId}' into '{installDirectory}'"); switch (packageType) { case PluginPackageType.Zip: { await tempFile.ExtractZipAsync(installDirectory, cancellationToken).ConfigureAwait(false); var pluginDll = Path.Combine(installDirectory, $"{pluginId}.dll"); _logger.Verbose($"Guessing that plugin location is '{pluginDll}'"); return new PluginPath(pluginDll); } default: throw new ArgumentOutOfRangeException(nameof(packageType), packageType, null); } }
public void TestIgnoreIdenticalPlugin() { var id = new PluginId("Kittyfisto.Simon"); var version = new Version(4, 3, 2); CreatePlugin <ILogEntryParserPlugin>(Constants.PluginPath, id, version); CreatePlugin <ILogEntryParserPlugin>(Constants.DownloadedPluginsPath, id, version); using (var loader = new PluginArchiveLoader(_filesystem, new [] { Constants.PluginPath, Constants.DownloadedPluginsPath })) { var pluginsWithDescription = loader.LoadAllOfTypeWithDescription <ILogEntryParserPlugin>(); pluginsWithDescription.Should().HaveCount(1, "because only one instance of that plugin should've been loaded"); var plugin1 = pluginsWithDescription.FirstOrDefault(x => x.Description.Id == new PluginId("Kittyfisto.Simon")); plugin1.Should().NotBeNull(); plugin1.Description.Version.Should().Be(new Version(4, 3, 2)); } }
private static string ConfigKey(PluginId pluginId, string key) { return $"{pluginId.Value}:{key}"; }
public Task RegisterAsync(PluginId pluginId, IEnumerable<CommandDescription> commandDescriptions) { var commandDescriptionList = commandDescriptions.ToList(); _pluginCommandDescriptions[pluginId] = commandDescriptionList; _logger.Verbose($"Registerd commands for '{pluginId}': {string.Join(", ", commandDescriptionList.Select(d => d.ToString()))}"); return Task.FromResult(0); }
private string GetInstallDirectory(PluginId pluginId) { var pluginInstallPath = _configuration.PluginInstallPath; return Path.Combine(pluginInstallPath, pluginId.Value); }
public Task UnloadPluginAsync(PluginId pluginId) { if (!_plugins.ContainsKey(pluginId)) { return Task.FromResult(0); } IPluginProxy pluginProxy; _plugins.TryRemove(pluginId, out pluginProxy); pluginProxy.Dispose(); return Task.FromResult(0); }
public Task UnloadPluginAsync(PluginId pluginId, CancellationToken cancellationToken) { return PostAsync($"api/plugins/{pluginId.Value}/unload", null as object, cancellationToken); }
public PluginIdentity( PluginId id) { Id = id; }
private string GetInstallDirectory(PluginId pluginId) { var pluginInstallPath = _configuration.PluginInstallPath; return(Path.Combine(pluginInstallPath, pluginId.Value)); }
private void CreatePlugin <T>(string pluginFolder, PluginId actualId, Version actualVersion) where T : IPlugin { CreatePlugin <T>(pluginFolder, actualId, actualVersion, actualId, actualVersion); }
public static SettingGroupKey ToSettingGroupKey(this PluginId pluginId) { return SettingGroupKey.With($"plugin.{pluginId.Value}"); }
private void CreatePlugin <T>(PluginId actualId, Version actualVersion, PluginId fakeId, Version fakeVersion) where T : IPlugin { CreatePlugin <T>(Constants.PluginPath, actualId, actualVersion, fakeId, fakeVersion); }
public void TestToString() { var id = new PluginId("MyCompany.Namespace.Log"); id.ToString().Should().Be("MyCompany.Namespace.Log"); }
public override int GetHashCode() { return(EditedPluginId.GetHashCode() ^ PluginId.GetHashCode()); }