/// <summary>
        /// Makes sure matching assemblies in the supplied folder are loaded in the app domain.
        /// 加载指定目录匹配的应用程序集
        /// </summary>
        /// <param name="directoryPath">
        ///     The physical path to a directory containing dlls to load in the app domain.
        /// </param>
        public void LoadMatchingAssemblies(string directoryPath)
        {
            var loadedAssemblyNames = new List <string>();

            foreach (var assembly in GetAssemblies())
            {
                loadedAssemblyNames.Add(assembly.FullName);
            }

            if (!FileCommon.IsExistDirectory(directoryPath))
            {
                return;
            }

            foreach (var dllPath in FileCommon.GetFiles(directoryPath, "*.dll"))
            {
                try
                {
                    var an = AssemblyName.GetAssemblyName(dllPath);
                    if (Matches(an.FullName) && !loadedAssemblyNames.Contains(an.FullName))
                    {
                        App.Load(an);
                    }
                }
                catch (BadImageFormatException ex)
                {
                    _logger?.LogError(ex.ExtractAllStackTrace());
                }
            }
        }
        /// <summary>
        /// 获取指定文件夹下的应用程序集
        /// </summary>
        /// <param name="directoryPaths">指定文件目录集合</param>
        /// <returns></returns>
        public IEnumerable <Assembly> GetAssemblies(IEnumerable <string> directoryPaths)
        {
            List <Assembly> assemblies          = new List <Assembly>();
            var             loadedAssemblyNames = new List <string>();

            TryAddAssembly(assemblies, loadedAssemblyNames, GetAssemblies());

            foreach (var directoryPath in directoryPaths)
            {
                if (!FileCommon.IsExistDirectory(directoryPath))
                {
                    continue;
                }

                foreach (var dllPath in FileCommon.GetFiles(directoryPath, "*.dll"))
                {
                    try
                    {
                        var an = AssemblyName.GetAssemblyName(dllPath);
                        if (Matches(an.FullName) && !loadedAssemblyNames.Contains(an.FullName))
                        {
                            App.Load(an);
                            assemblies.Add(Assembly.Load(an.FullName));
                        }
                    }
                    catch (BadImageFormatException ex)
                    {
                        _logger?.LogError(ex.ExtractAllStackTrace());
                    }
                }
            }

            return(assemblies.Distinct());
        }
Esempio n. 3
0
        internal static void Initialize(IWordService wordService, string path)
        {
            _wordService = wordService;
            var files = FileCommon.GetFiles(path, "*.scel");
            HashSet <PinYinWords> pyws = new HashSet <PinYinWords>();

            foreach (var file in files)
            {
                GetPinYinWords(file, pyws);
            }

            var list = SimplifyPinYinWords(pyws);

            list = list.OrderBy(q => q.Words).Distinct().ToList();

            for (int i = list.Count - 1; i >= 1; i--)
            {
                var t  = list[i];
                var t0 = list[i - 1];
                if (t.Words == t0.Words)
                {
                    list.RemoveAt(i);
                }
            }

            list = list.OrderByDescending(q => q.Words.Length).ToList();

            var text    = "";
            var py      = "";
            var index   = 0;
            var pyIndex = "0,";

            for (int i = 0; i < list.Count; i++)
            {
                if (i > 0)
                {
                    text += ",";
                    py   += ",";
                }

                text += list[i].Words;
                var pys = list[i].GetPinYinIndex();
                py      += string.Join(",", pys);
                index   += pys.Count();
                pyIndex += "," + index;
            }
            //PinYinIndexPath
//            WordPinYinPath
//                PinYinDataPath
            File.WriteAllText(BaseWordService.DictPinYinPathConfig.WordPath, text);//确定
//            File.WriteAllText(BaseWordService.DictPinYinPathConfig., pyIndex);
            File.WriteAllText(BaseWordService.DictPinYinPathConfig.WordPinYinPath, py);
        }
Esempio n. 4
0
        /// <summary>
        /// 压缩指定文件夹下的文件
        /// </summary>
        /// <param name="sourceFilePath">文件夹目录</param>
        /// <param name="zipDirectory">压缩包保存目录,默认与源文件在同一目录</param>
        /// <param name="zipName">压缩包保存目录</param>
        /// <param name="searchPattern">要与 path 中的文件名匹配的搜索字符串。此参数可以包含有效文本路径和通配符(* 和 ?)的组合(请参见“备注”),但不支持正则表达式。</param>
        /// <param name="searchOption">默认当前文件夹下 TopDirectoryOnly,若查询包含所有子目录为AllDirectories</param>
        /// <param name="overWrite">是否覆盖</param>
        /// <param name="isEncrypt">是否加密</param>
        /// <param name="password">密码</param>
        /// <param name="compressionLevel">压缩等级(0 无 - 9 最高,默认 5)</param>
        /// <param name="zipMaxFile">压缩包内最多文件数量(-1不限)</param>
        /// <param name="blockSize">缓存大小(每次写入文件大小,默认 2048)</param>
        /// <returns></returns>
        public override string[] CompressCatalogAndFiltrate(string sourceFilePath, string zipDirectory, string zipName,
                                                            string searchPattern      = "*.*",
                                                            SearchOption searchOption = SearchOption.AllDirectories, bool overWrite = true, bool isEncrypt = false,
                                                            string password           = "", int compressionLevel = 5, int zipMaxFile = -1, int blockSize = 2048)
        {
            CheckZipSourceDirectory(sourceFilePath);
            CheckZipDirectory(zipDirectory);
            CheckZipName(zipName);

            var files = FileCommon.GetFiles(sourceFilePath, searchPattern, searchOption);

            return(CompressMulti(files, zipDirectory, zipName, overWrite, isEncrypt, password, compressionLevel,
                                 zipMaxFile,
                                 blockSize));
        }