// 递归扫描插件基目录下的所有子目录以查找程序集和数据文件
        static bool ScanSubdirecotires(ScanFilePack filePack, string subdirectory, AddinFilePack matchingFilePack)
        {
            var shouldRescan = false;
            var files        = Directory.GetFiles(subdirectory);

            foreach (var file in files)
            {
                if (IsAssembly(file))
                {
                    shouldRescan |= IsScannableAssemblyFile(file, matchingFilePack);
                    filePack.AddAssemblyFile(file);
                }
                else
                {
                    filePack.AddDataFile(file);
                }
            }

            var childDirectories = Directory.GetDirectories(subdirectory);

            foreach (var childDirectory in childDirectories)
            {
                shouldRescan |= ScanSubdirecotires(filePack, childDirectory, matchingFilePack);
            }

            return(shouldRescan);
        }
        internal override ScanFilePack ScanForFilePack(string probingDirectory, string addinDirectory, string manifestFileName,
                                                       AddinFilePack matchingFilePack)
        {
            //var addinDirectoryName = Path.GetFileName(addinDirectory);
            var filePack = new ScanFilePack {
                AddinDirectory = addinDirectory, AddinProbingDirectory = probingDirectory
            };

            return(matchingFilePack != null
                ? DoScanForFilePack(filePack, addinDirectory, manifestFileName, matchingFilePack)
                : DoScanForFilePack(filePack, addinDirectory, manifestFileName));
        }
Example #3
0
        static void GetScanFilePack(string addinDirectory, string probingDir,
                                    IEnumerable <AddinFilePack> existingFilePacks, ref ScanFilePackResult scanFilePackResult)
        {
            ScanFilePack scanFilePack     = null;
            var          matchingFilePack = existingFilePacks != null?GetMatchingFilePack(addinDirectory, existingFilePacks) : null;

            foreach (var fileScanner in _fileScanners)
            {
                scanFilePack = fileScanner.ScanForFilePack(probingDir, addinDirectory, AddinFileSettings.ManifestFileName, matchingFilePack);
                if (scanFilePack != null)
                {
                    break;
                }
            }
            if (scanFilePack != null)
            {
                scanFilePackResult.AddScanFilePack(scanFilePack);
            }
        }
        static ScanFilePack DoScanForFilePack(ScanFilePack filePack, string addinDirectory, string manifestFileName, AddinFilePack matchingFilePack)
        {
            //位于插件文件夹下面的文件都被视为潜在包含插件配置的清单文件或程序集文件
            //但最终这些文件到底是插件配置文件、程序集文件或数据文件,要根据文件名来决定
            var files = Directory.GetFiles(addinDirectory);

            var shouldRescan = false;

            foreach (var file in files)
            {
                if (IsAssembly(file))
                {
                    shouldRescan |= IsScannableAssemblyFile(file, matchingFilePack);
                    filePack.AddAssemblyFile(file);
                }
                else if (filePack.ManifestFile == null && file.EndsWith(manifestFileName, StringComparison.InvariantCultureIgnoreCase))
                {
                    shouldRescan         |= IsScannableManifestFile(file, matchingFilePack);
                    filePack.ManifestFile = file;
                }
                else
                {
                    filePack.AddDataFile(file);
                }
            }

            if (filePack.ManifestFile == null) // 插件清单文件必须位于插件基目录下,如果在插件基目录下未找到清单文件,则认为这不是一个插件
            {
                return(null);
            }

            // 递归扫描插件基目录下的所有子目录以查找程序集和数据文件
            var subdirectories = Directory.GetDirectories(addinDirectory);

            foreach (var subdirectory in subdirectories)
            {
                shouldRescan |= ScanSubdirecotires(filePack, subdirectory, matchingFilePack);
            }

            return(shouldRescan ? filePack : null);
        }
        // 递归扫描插件基目录下的所有子目录以查找程序集和数据文件
        static void ScanSubdirecotires(ScanFilePack filePack, string subdirectory)
        {
            var files = Directory.GetFiles(subdirectory);

            foreach (var file in files)
            {
                if (IsAssembly(file))
                {
                    filePack.AddAssemblyFile(file);
                }
                else
                {
                    filePack.AddDataFile(file);
                }
            }

            var childDirectories = Directory.GetDirectories(subdirectory);

            foreach (var childDirectory in childDirectories)
            {
                ScanSubdirecotires(filePack, childDirectory);
            }
        }
Example #6
0
 internal void AddScanFilePack(ScanFilePack scanFilePack)
 {
     _scanFilePacks = _scanFilePacks ?? new List <ScanFilePack>();
     _scanFilePacks.Add(scanFilePack);
 }