Exemplo n.º 1
0
            private static PluginInstance ActivePlugin(string directoryName)
            {
                PackageMetadata metadata = null;
                string          errorMessage;

                try
                {
                    metadata = PackageUtils.GetPackageMetadataFromPlugins(directoryName, out errorMessage);

                    var dllDirectoryPath = PathUtils.GetPluginDllDirectoryPath(directoryName);
                    if (string.IsNullOrEmpty(dllDirectoryPath))
                    {
                        throw new Exception($"插件可执行文件 {directoryName}.dll 不存在");
                    }

                    //foreach (var filePath in DirectoryUtils.GetFilePaths(DirectoryUtils.GetDirectoryPath(metadata.ExecuteFilePath)))
                    //{

                    //    if (!StringUtils.EqualsIgnoreCase(PathUtils.GetExtension(filePath), ".dll")) continue;
                    //    var fileName = PathUtils.GetFileName(filePath);
                    //    if (StringUtils.EqualsIgnoreCase(fileName, PathUtils.GetFileName(metadata.ExecuteFilePath))) continue;
                    //    if (FileUtils.IsFileExists(PathUtils.Combine(WebConfigUtils.PhysicalApplicationPath, "Bin", fileName))) continue;
                    //    Assembly.Load(File.ReadAllBytes(filePath));
                    //}
                    //var assembly = Assembly.Load(File.ReadAllBytes(metadata.ExecuteFilePath));

                    //metadata.GetDependencyGroups()

                    CopyDllsToBin(metadata.Id, dllDirectoryPath);

                    //var assembly = Assembly.Load(File.ReadAllBytes(PathUtils.Combine(WebConfigUtils.PhysicalApplicationPath, "Bin", PathUtils.GetFileName(metadata.ExecuteFilePath))));
                    var assembly = Assembly.Load(metadata.Id);  // load the dll from bin directory

                    var type = assembly.GetExportedTypes().FirstOrDefault(exportedType => typeof(PluginBase).IsAssignableFrom(exportedType));

                    //var type = assembly.GetTypes().First(o => o.IsClass && !o.IsAbstract && o.IsSubclassOf(typeof(PluginBase)));

                    return(ActiveAndAdd(metadata, type));
                }
                catch (Exception ex)
                {
                    errorMessage = ex.Message;
                    LogUtils.AddErrorLog(ex, $"插件加载:{directoryName}");
                }

                return(new PluginInstance(directoryName, metadata, errorMessage));
            }
Exemplo n.º 2
0
            private static PluginInfo ActivePlugin(string directoryName)
            {
                string errorMessage;

                try
                {
                    string dllDirectoryPath;
                    var    metadata = PackageUtils.GetPackageMetadataFromPlugins(directoryName, out dllDirectoryPath, out errorMessage);
                    if (metadata != null)
                    {
                        //foreach (var filePath in DirectoryUtils.GetFilePaths(DirectoryUtils.GetDirectoryPath(metadata.ExecuteFilePath)))
                        //{

                        //    if (!StringUtils.EqualsIgnoreCase(PathUtils.GetExtension(filePath), ".dll")) continue;
                        //    var fileName = PathUtils.GetFileName(filePath);
                        //    if (StringUtils.EqualsIgnoreCase(fileName, PathUtils.GetFileName(metadata.ExecuteFilePath))) continue;
                        //    if (FileUtils.IsFileExists(PathUtils.Combine(WebConfigUtils.PhysicalApplicationPath, "Bin", fileName))) continue;
                        //    Assembly.Load(File.ReadAllBytes(filePath));
                        //}
                        //var assembly = Assembly.Load(File.ReadAllBytes(metadata.ExecuteFilePath));

                        //metadata.GetDependencyGroups()

                        CopyDllsToBin(metadata.Id, dllDirectoryPath);

                        //var assembly = Assembly.Load(File.ReadAllBytes(PathUtils.Combine(WebConfigUtils.PhysicalApplicationPath, "Bin", PathUtils.GetFileName(metadata.ExecuteFilePath))));
                        var assembly = Assembly.Load(metadata.Id);  // load the dll from bin directory

                        var type = assembly.GetTypes().First(o => o.IsClass && !o.IsAbstract && o.IsSubclassOf(typeof(PluginBase)));

                        return(ActiveAndAdd(metadata, type));
                    }
                }
                catch (Exception ex)
                {
                    errorMessage = ex.Message;
                    LogUtils.AddSystemErrorLog(ex, $"插件加载:{directoryName}");
                }

                return(new PluginInfo(directoryName, errorMessage));
            }