public PluginLoadOptionsBuilder <T> WithLocalDiskAssemblyLoader(
            PluginPlatformVersion pluginPlatformVersion = null,
            bool useCollectibleAssemblies = true,
            NativeDependencyLoadPreference nativeDependencyLoadPreference = NativeDependencyLoadPreference.PreferInstalledRuntime
            )
        {
            if (pluginPlatformVersion == null)
            {
                pluginPlatformVersion = PluginPlatformVersion.Empty();
            }

            this.assemblyLoadOptions = new DefaultAssemblyLoadOptions <T>(
                pluginPlatformVersion,
                this.ignorePlatformInconsistencies,
                useCollectibleAssemblies,
                nativeDependencyLoadPreference
                );

#if NETCORE3_0 || NETCORE3_1
            return(this.WithAssemblyLoader <DefaultAssemblyLoaderWithNativeResolver <T> >());
#endif
#if NETCORE2_1
            return(this.WithAssemblyLoader <DefaultAssemblyLoader <T> >());
#endif
        }
        public PluginLoadOptionsBuilder <T> WithDefaultOptions(string pluginPath = null)
        {
            if (String.IsNullOrEmpty(pluginPath))
            {
                pluginPath = Path.Join(GetLocalExecutionPath(), "Plugins");
            }

            this.pluginPathProvider     = new DefaultPluginPathProvider <T>(pluginPath);
            this.dependencyPathProvider = new DependencyPathProvider <T>(pluginPath);

            this.runtimePlatformContext = new RuntimePlatformContext();
            this.ScanForAssemblies(composer =>
                                   composer.WithDefaultOptions <DefaultAssemblyScanner <T>, DefaultAssemblyScannerOptions <T> >());

            this.pluginAssemblyNameProvider = new PluginAssemblyNameProvider <T>($"{typeof(T).Name}.dll");
            this.sharedServicesProvider     = new DefaultSharedServicesProvider <T>(new ServiceCollection());
            this.activator    = new DefaultRemotePluginActivator <T>(this.sharedServicesProvider);
            this.proxyCreator = new PluginProxyCreator <T>();

            // Use System.Text.Json in 3.0
#if NETCORE3_0
            this.parameterConverter = new JsonSerializerParameterConverter();
            this.resultConverter    = new JsonSerializerResultConverter();
            this.assemblyLoaderType = typeof(DefaultAssemblyLoaderWithNativeResolver <T>);
#endif
            // Use Newtonsoft.Json in 2.1
#if NETCORE2_1
            this.parameterConverter = new NewtonsoftParameterConverter();
            this.resultConverter    = new NewtonsoftResultConverter();
            this.assemblyLoaderType = typeof(DefaultAssemblyLoader <T>);
#endif
            this.assemblySelector    = new DefaultAssemblySelector <T>();
            this.assemblyLoadOptions = new DefaultAssemblyLoadOptions <T>(
                PluginPlatformVersion.Empty(),
                false,
                NativeDependencyLoadPreference.PreferInstalledRuntime);

            this.probingPathsProvider = new ProbingPathsProvider <T>();

            var hostTypesProvider = new HostTypesProvider();
            hostTypesProvider.AddHostType(typeof(Prise.Plugin.PluginAttribute)); // Add the Prise.Infrastructure assembly to the host types
            hostTypesProvider.AddHostType(typeof(ServiceCollection));            // Adds the BuildServiceProvider assembly to the host types
            this.hostTypesProvider = hostTypesProvider;

            var remoteTypesProvider = new RemoteTypesProvider <T>();
            remoteTypesProvider.AddRemoteType(typeof(T)); // Add the contract to the remote types, so that we can have backwards compatibility
            this.remoteTypesProvider = remoteTypesProvider;

            this.pluginSelector               = new DefaultPluginSelector <T>();
            this.depsFileProviderType         = typeof(DefaultDepsFileProvider <T>);
            this.pluginDependencyResolverType = typeof(DefaultPluginDependencyResolver <T>);
            // Typically used for downloading and storing plugins from the network, but it could be useful for caching local plugins as well
            this.tempPathProviderType = typeof(UserProfileTempPathProvider <T>);

            this.nativeAssemblyUnloaderType = typeof(DefaultNativeAssemblyUnloader);
            this.hostFrameworkProviderType  = typeof(HostFrameworkProvider);

            return(this);
        }
Exemple #3
0
 public DefaultNetworkAssemblyLoaderOptions(string baseUrl,
                                            PluginPlatformVersion pluginPlatformVersion = null,
                                            bool ignorePlatformInconsistencies          = false,
                                            NativeDependencyLoadPreference nativeDependencyLoadPreference = NativeDependencyLoadPreference.PreferInstalledRuntime
                                            )
     : base(pluginPlatformVersion, ignorePlatformInconsistencies, nativeDependencyLoadPreference)
 {
     this.baseUrl = baseUrl;
 }
 public PluginLoadOptionsBuilder <T> UseCollectibleAssemblies(bool useCollectibleAssemblies)
 {
     this.useCollectibleAssemblies = useCollectibleAssemblies;
     this.assemblyLoadOptions      = new DefaultAssemblyLoadOptions <T>(
         PluginPlatformVersion.Empty(),
         false,
         this.useCollectibleAssemblies,
         NativeDependencyLoadPreference.PreferInstalledRuntime);
     return(this);
 }
        public DefaultAssemblyLoadOptions(
            PluginPlatformVersion pluginPlatformVersion = null,
            bool ignorePlatformInconsistencies          = false,
            NativeDependencyLoadPreference nativeDependencyLoadPreference = NativeDependencyLoadPreference.PreferInstalledRuntime)
        {
            if (pluginPlatformVersion == null)
            {
                this.pluginPlatformVersion = PluginPlatformVersion.Empty();
            }
            else
            {
                this.pluginPlatformVersion = pluginPlatformVersion;
            }

            this.ignorePlatformInconsistencies  = ignorePlatformInconsistencies;
            this.nativeDependencyLoadPreference = nativeDependencyLoadPreference;
        }
Exemple #6
0
        public PluginLoadOptionsBuilder <T> WithLocalDiskAssemblyLoader(
            PluginPlatformVersion pluginPlatformVersion = null,
            bool useCollectibleAssemblies = true,
            NativeDependencyLoadPreference nativeDependencyLoadPreference = NativeDependencyLoadPreference.PreferInstalledRuntime
            )
        {
            if (pluginPlatformVersion == null)
            {
                pluginPlatformVersion = PluginPlatformVersion.Empty();
            }

            this.assemblyLoadOptions = new DefaultAssemblyLoadOptions <T>(
                pluginPlatformVersion,
                false,
                useCollectibleAssemblies,
                nativeDependencyLoadPreference);

            return(this.WithAssemblyLoader <DefaultAssemblyLoaderWithNativeResolver <T> >());
        }
        public PluginLoadOptionsBuilder <T> WithNetworkAssemblyLoader(
            string baseUrl,
            PluginPlatformVersion pluginPlatformVersion = null,
            NativeDependencyLoadPreference nativeDependencyLoadPreference = NativeDependencyLoadPreference.PreferInstalledRuntime)
        {
            if (pluginPlatformVersion == null)
            {
                pluginPlatformVersion = PluginPlatformVersion.Empty();
            }

            this.networkAssemblyLoaderOptions = new DefaultNetworkAssemblyLoaderOptions <T>(
                baseUrl,
                pluginPlatformVersion,
                false,
                nativeDependencyLoadPreference);

            this.depsFileProviderType         = typeof(NetworkDepsFileProvider <T>);
            this.pluginDependencyResolverType = typeof(NetworkPluginDependencyResolver <T>);
            this.assemblyLoaderType           = typeof(NetworkAssemblyLoader <T>);
            return(this);
        }
        public PluginLoadOptionsBuilder <T> WithLocalDiskAssemblyLoader(
            PluginPlatformVersion pluginPlatformVersion = null,
            NativeDependencyLoadPreference nativeDependencyLoadPreference = NativeDependencyLoadPreference.PreferInstalledRuntime
            )
        {
            if (pluginPlatformVersion == null)
            {
                pluginPlatformVersion = PluginPlatformVersion.Empty();
            }

            this.assemblyLoadOptions = new DefaultAssemblyLoadOptions <T>(
                pluginPlatformVersion,
                false,
                nativeDependencyLoadPreference);

#if NETCORE3_0
            return(this.WithAssemblyLoader <DefaultAssemblyLoaderWithNativeResolver <T> >());
#endif
#if NETCORE2_1
            return(this.WithAssemblyLoader <DefaultAssemblyLoader <T> >());
#endif
        }
Exemple #9
0
        public virtual string ResolvePlatformDependencyPathToRuntime(PluginPlatformVersion pluginPlatformVersion, string platformDependencyPath)
        {
            var platformDependencyFileVersion = FileVersionInfo.GetVersionInfo(platformDependencyPath);
            var platformDependencyName        = Path.GetFileName(platformDependencyPath);
            var runtimeInformation            = this.runtimePlatformContext.GetRuntimeInformation();

            var runtimes = runtimeInformation.Runtimes;

            if (pluginPlatformVersion.IsSpecified)
            {
                // First filter on specific version
                runtimes = runtimes.Where(r => r.Version == pluginPlatformVersion.Version);
                // Then, filter on target runtime, this is not always provided
                if (pluginPlatformVersion.Runtime != RuntimeType.UnSpecified)
                {
                    runtimes = runtimes.Where(r => r.RuntimeType == pluginPlatformVersion.Runtime);
                }

                if (!runtimes.Any())
                {
                    throw new PrisePluginException($"Requisted platform was not installed {pluginPlatformVersion.Runtime} {pluginPlatformVersion.Version}");
                }
            }

            foreach (var runtime in runtimes.OrderByDescending(r => r.Version))
            {
                var candidateFilePath = Directory.GetFiles(runtime.Location).FirstOrDefault(f => String.Compare(Path.GetFileName(f), platformDependencyName) == 0);
                if (!String.IsNullOrEmpty(candidateFilePath))
                {
                    var candidateFileVersion = FileVersionInfo.GetVersionInfo(candidateFilePath);
                    if (String.Compare(platformDependencyFileVersion.FileVersion, candidateFileVersion.FileVersion) == 0)
                    {
                        return(candidateFilePath);
                    }
                }
            }

            return(null);
        }
Exemple #10
0
 public PluginLoadContext(string fullPathToPluginAssembly, Type pluginType, string hostFramework)
 {
     this.FullPathToPluginAssembly = fullPathToPluginAssembly.ThrowIfNullOrEmpty(nameof(pluginType));
     this.PluginType    = pluginType.ThrowIfNull(nameof(pluginType));
     this.HostFramework = hostFramework.ThrowIfNullOrEmpty(nameof(hostFramework));
     this.HostTypes     = new List <Type>()
     {
         typeof(Prise.Plugin.PluginAttribute), typeof(Microsoft.Extensions.DependencyInjection.ServiceCollection)
     };
     this.HostAssemblies        = new List <string>();
     this.DowngradableHostTypes = new List <Type>()
     {
         typeof(Prise.Plugin.PluginAttribute)
     };
     this.DowngradableHostAssemblies = new List <string>();
     this.RemoteTypes = new List <Type>()
     {
         pluginType
     };
     this.NativeDependencyLoadPreference = NativeDependencyLoadPreference.PreferInstalledRuntime;
     this.IgnorePlatformInconsistencies  = false;
     this.PluginPlatformVersion          = PluginPlatformVersion.Empty();
     this.HostServices = new ServiceCollection();
 }
Exemple #11
0
 public static PluginLoadContext SetPlatformVersion(this PluginLoadContext pluginLoadContext, PluginPlatformVersion pluginPlatformVersion)
 {
     pluginLoadContext.PluginPlatformVersion = pluginPlatformVersion;
     return(pluginLoadContext);
 }
        public PluginLoadOptionsBuilder <T> WithDefaultOptions(string pluginPath = null, ServiceLifetime serviceLifetime = ServiceLifetime.Scoped)
        {
            if (String.IsNullOrEmpty(pluginPath))
            {
                pluginPath = Path.Join(GetLocalExecutionPath(), "Plugins");
            }

            this.priseServiceLifetime   = serviceLifetime;
            this.loggerType             = typeof(NullPluginLogger <T>);
            this.pluginPathProvider     = new DefaultPluginPathProvider <T>(pluginPath);
            this.dependencyPathProvider = new DependencyPathProvider <T>(pluginPath);
            this.cacheOptions           = CacheOptions <IPluginCache <T> > .ScopedPluginCache();

            this.runtimePlatformContext = new RuntimePlatformContext();
            this.ScanForAssemblies(composer =>
                                   composer.WithDefaultOptions <DefaultAssemblyScanner <T>, DefaultAssemblyScannerOptions <T> >());

            this.pluginAssemblyNameProvider          = new PluginAssemblyNameProvider <T>($"{typeof(T).Name}.dll");
            this.sharedServicesProvider              = new DefaultSharedServicesProvider <T>(this.hostServices, this.sharedServices);
            this.pluginActivationContextProviderType = typeof(DefaultPluginActivationContextProvider <T>);
            this.pluginTypesProviderType             = typeof(DefaultPluginTypesProvider <T>);
            this.activatorType    = typeof(DefaultRemotePluginActivator <T>);
            this.proxyCreatorType = typeof(PluginProxyCreator <T>);

            this.parameterConverterType = typeof(JsonSerializerParameterConverter);
            this.resultConverterType    = typeof(JsonSerializerResultConverter);

            this.assemblyLoaderType = typeof(DefaultAssemblyLoader <T>);
#if NETCORE3_0 || NETCORE3_1 // Replace with 3.x loader
            this.assemblyLoaderType = typeof(DefaultAssemblyLoaderWithNativeResolver <T>);
#endif
            this.assemblySelectorType = typeof(DefaultAssemblySelector <T>);
            this.assemblyLoadOptions  = new DefaultAssemblyLoadOptions <T>(
                PluginPlatformVersion.Empty(),
                this.ignorePlatformInconsistencies,
                this.useCollectibleAssemblies,
                NativeDependencyLoadPreference.PreferInstalledRuntime
                );

            this.probingPathsProviderType = typeof(ProbingPathsProvider <T>);

            var hostTypesProvider = new HostTypesProvider <T>();
            hostTypesProvider.AddHostType(typeof(Prise.Plugin.PluginAttribute)); // Add the Prise.Infrastructure assembly to the host types
            hostTypesProvider.AddHostType(typeof(ServiceCollection));            // Adds the BuildServiceProvider assembly to the host types
            this.hostTypesProvider = hostTypesProvider;

            var downgradableDependenciesProvider = new DowngradableDependenciesProvider <T>();
            downgradableDependenciesProvider.AddDowngradableType(typeof(Prise.Plugin.PluginAttribute)); // Add the Prise.Infrastructure assembly to the host types
            this.downgradableDependenciesProvider = downgradableDependenciesProvider;

            var remoteTypesProvider = new RemoteTypesProvider <T>();
            remoteTypesProvider.AddRemoteType(typeof(T)); // Add the contract to the remote types, so that we can have backwards compatibility
            this.remoteTypesProvider = remoteTypesProvider;

            this.pluginSelectorType           = typeof(DefaultPluginSelector <T>);
            this.depsFileProviderType         = typeof(DefaultDepsFileProvider <T>);
            this.pluginDependencyResolverType = typeof(DefaultPluginDependencyResolver <T>);
            // Typically used for downloading and storing plugins from the network, but it could be useful for caching local plugins as well
            this.tempPathProviderType = typeof(UserProfileTempPathProvider <T>);

            this.nativeAssemblyUnloaderType = typeof(DefaultNativeAssemblyUnloader);
            this.hostFrameworkProviderType  = typeof(HostFrameworkProvider);

            return(this);
        }