Ejemplo n.º 1
0
        protected virtual ValueOrProceed <AssemblyFromStrategy> LoadFromDefaultContext(IPluginLoadContext pluginLoadContext, AssemblyName assemblyName)
        {
            try
            {
                var assembly = Default.LoadFromAssemblyName(assemblyName);
                if (assembly != null)
                {
                    return(ValueOrProceed <AssemblyFromStrategy> .FromValue(AssemblyFromStrategy.NotReleasable(assembly), false));
                }
            }
            catch (FileNotFoundException) { } // This can happen if the plugin uses a newer version of a package referenced in the host

            var hostAssembly = this.pluginDependencyContext.HostDependencies.FirstOrDefault(h => h.DependencyName.Name == assemblyName.Name);

            if (hostAssembly != null && !hostAssembly.AllowDowngrade)
            {
                if (!!hostAssembly.AllowDowngrade)
                {
                    throw new PrisePluginException($"Plugin<{typeof(T)}> Assembly reference {assemblyName.Name} with version {assemblyName.Version} was requested but not found in the host. The version from the host is {hostAssembly.DependencyName.Version}. Possible version mismatch. Please downgrade your plugin.");
                }
                this.logger.VersionMismatch(assemblyName, hostAssembly.DependencyName);
            }

            return(ValueOrProceed <AssemblyFromStrategy> .Proceed());
        }
Ejemplo n.º 2
0
        protected virtual ValueOrProceed <Assembly> LoadFromRemote(IPluginLoadContext pluginLoadContext, AssemblyName assemblyName)
        {
            var assemblyFileName = $"{assemblyName.Name}.dll";

            if (File.Exists(Path.Combine(pluginLoadContext.PluginAssemblyPath, assemblyFileName)))
            {
                return(LoadDependencyFromLocalDisk(pluginLoadContext, assemblyFileName));
            }
            return(ValueOrProceed <Assembly> .Proceed());
        }
Ejemplo n.º 3
0
        protected virtual ValueOrProceed <Assembly> LoadDependencyFromLocalDisk(IPluginLoadContext pluginLoadContext, string assemblyFileName)
        {
            var dependency = LoadFileFromLocalDisk(pluginLoadContext.PluginAssemblyPath, assemblyFileName);

            if (dependency == null)
            {
                return(ValueOrProceed <Assembly> .Proceed());
            }

            return(ValueOrProceed <Assembly> .FromValue(Assembly.Load(ToByteArray(dependency)), false));
        }
Ejemplo n.º 4
0
        protected virtual ValueOrProceed <IntPtr> LoadUnmanagedFromDefault(IPluginLoadContext pluginLoadContext, string unmanagedDllName)
        {
            var resolution = base.LoadUnmanagedDll(unmanagedDllName);

            if (resolution == default(IntPtr))
            {
                return(ValueOrProceed <IntPtr> .Proceed());
            }

            return(ValueOrProceed <IntPtr> .FromValue(resolution, false));
        }
Ejemplo n.º 5
0
        protected override ValueOrProceed <Assembly> LoadFromRemote(IPluginLoadContext pluginLoadContext, AssemblyName assemblyName)
        {
            var networkAssembly = LoadDependencyFromNetwork(assemblyName);

            if (networkAssembly != null)
            {
                return(ValueOrProceed <Assembly> .FromValue(networkAssembly, false));
            }

            return(ValueOrProceed <Assembly> .Proceed());
        }
Ejemplo n.º 6
0
        protected virtual ValueOrProceed <Assembly> LoadFromDefaultContext(IPluginLoadContext pluginLoadContext, AssemblyName assemblyName)
        {
            try
            {
                var assembly = Default.LoadFromAssemblyName(assemblyName);
                if (assembly != null)
                {
                    return(ValueOrProceed <Assembly> .FromValue(assembly, false));
                }
            }
            catch (FileNotFoundException) { }

            return(ValueOrProceed <Assembly> .Proceed());
        }
Ejemplo n.º 7
0
        protected virtual ValueOrProceed <Assembly> LoadFromDependencyContext(IPluginLoadContext pluginLoadContext, AssemblyName assemblyName)
        {
            if (IsResourceAssembly(assemblyName))
            {
                foreach (var resourceDependency in this.pluginDependencyContext.PluginResourceDependencies)
                {
                    var resourcePath = Path.Combine(resourceDependency.Path, assemblyName.CultureName, assemblyName.Name + ".dll");
                    if (File.Exists(resourcePath))
                    {
                        return(ValueOrProceed <Assembly> .FromValue(LoadFromAssemblyPath(resourcePath), false));
                    }
                }

                // Do not proceed probing
                return(ValueOrProceed <Assembly> .FromValue(null, false));
            }

            var pluginDependency = this.pluginDependencyContext.PluginDependencies.FirstOrDefault(d => d.DependencyNameWithoutExtension == assemblyName.Name);

            if (pluginDependency != null)
            {
                var dependencyPath = this.dependencyPathProvider.GetDependencyPath();
                if (String.IsNullOrEmpty(dependencyPath))
                {
                    dependencyPath = pluginLoadContext.PluginAssemblyPath;
                }
                var probingPaths = this.probingPathsProvider.GetProbingPaths();
                var dependency   = this.pluginDependencyResolver.ResolvePluginDependencyToPath(dependencyPath, probingPaths, pluginDependency);
                if (dependency != null)
                {
                    return(ValueOrProceed <Assembly> .FromValue(LoadFromStream(dependency), false));
                }
            }

            var localFile = Path.Combine(this.dependencyPathProvider.GetDependencyPath(), assemblyName.Name + ".dll");

            if (File.Exists(localFile))
            {
                return(ValueOrProceed <Assembly> .FromValue(LoadFromAssemblyPath(localFile), false));
            }

            return(ValueOrProceed <Assembly> .Proceed());
        }
Ejemplo n.º 8
0
        protected override ValueOrProceed <Assembly> LoadFromDependencyContext(IPluginLoadContext pluginLoadContext, AssemblyName assemblyName)
        {
            if (IsResourceAssembly(assemblyName))
            {
                foreach (var resourceDependency in this.pluginDependencyContext.PluginResourceDependencies)
                {
                    var resourceNetworkPathToAssembly = Path.Combine(this.baseUrl, Path.Combine(resourceDependency.Path, assemblyName.CultureName, $"{assemblyName.Name}.dll"));
                    var resourceNetworkAssembly       = LoadDependencyFromNetwork(resourceNetworkPathToAssembly);
                    if (resourceNetworkAssembly != null)
                    {
                        return(ValueOrProceed <Assembly> .FromValue(resourceNetworkAssembly, false));
                    }
                }

                // Do not proceed probing
                return(ValueOrProceed <Assembly> .FromValue(null, false));
            }

            var pluginDependency = this.pluginDependencyContext.PluginDependencies.FirstOrDefault(d => d.DependencyNameWithoutExtension == assemblyName.Name);

            if (pluginDependency != null)
            {
                var dependencyPath          = this.dependencyPathProvider.GetDependencyPath();
                var probingPaths            = this.probingPathsProvider.GetProbingPaths();
                var resolvedNetworkAssembly = this.pluginDependencyResolver.ResolvePluginDependencyToPath(dependencyPath, probingPaths, pluginDependency);
                if (resolvedNetworkAssembly != null)
                {
                    return(ValueOrProceed <Assembly> .FromValue(LoadFromStream(resolvedNetworkAssembly), false));
                }
            }

            var networkPathToAssembly = $"{baseUrl}/{Path.Combine(this.dependencyPathProvider.GetDependencyPath(), assemblyName.Name)}.dll";
            var networkAssembly       = LoadDependencyFromNetwork(networkPathToAssembly);

            if (networkAssembly != null)
            {
                return(ValueOrProceed <Assembly> .FromValue(networkAssembly, false));
            }

            return(ValueOrProceed <Assembly> .Proceed());
        }
Ejemplo n.º 9
0
        protected virtual ValueOrProceed <Assembly> LoadFromDefaultContext(IPluginLoadContext pluginLoadContext, AssemblyName assemblyName)
        {
            try
            {
                var assembly = Default.LoadFromAssemblyName(assemblyName);
                if (assembly != null)
                {
                    return(ValueOrProceed <Assembly> .FromValue(assembly, false));
                }
            }
            catch (FileNotFoundException) { } // This can happen if the plugin uses a newer version of a package referenced in the host

            var hostAssembly = this.pluginDependencyContext.HostDependencies.FirstOrDefault(h => h.DependencyName.Name == assemblyName.Name);

            if (hostAssembly != null)
            {
                this.logger.VersionMismatch(assemblyName, hostAssembly.DependencyName);
            }

            return(ValueOrProceed <Assembly> .Proceed());
        }