/// <summary> /// 输出不规范文件 /// </summary> private int PintnoConformEncodingFile(EncodingScrutatorFolder encodingScrutatorFolder) { var count = 0; for (var i = 0; i < encodingScrutatorFolder.File.Count; i++) { var temp = encodingScrutatorFolder.File[i]; if (!temp.Ignore) { if (encodingScrutatorFolder.SitpulationEncodingSetting.ConformtotheDefaultEncoding(temp.Encoding)) { encodingScrutatorFolder.File.RemoveAt(i); i--; } else { count++; } } else { encodingScrutatorFolder.File.RemoveAt(i); i--; } } count = PintnoConformEncodingFolder(encodingScrutatorFolder, count); return(count); }
/// <summary> /// 获取当前目录下的文件夹递归文件编码 /// </summary> private void InspectFaceFolderEncoding() { foreach (var temp in FaceFolder.GetDirectories()) { var folder = new EncodingScrutatorFolder(temp, InspectFileWhiteListSetting, IncludeFileSetting) { //IncludeFileSetting = IncludeFileSetting, //InspectFileWhiteListSetting = InspectFileWhiteListSetting, SitpulationEncodingSetting = SitpulationEncodingSetting, _includeRegexFile = _includeRegexFile, //Parent = FaceFolder, Parent = this, Progress = Progress }; Folder.Add(folder); //不包含 if (InspectFileWhiteListSetting.FolderWhiteList.Any(t => String.Equals(t, temp.Name))) { folder.Ignore = true; } if (!folder.Ignore) { //递归 folder.InspectFolderEncoding(); } } }
/// <summary> /// 把所有的要检测的文件夹放到虚拟目录 /// </summary> /// <param name="folder"></param> /// <param name="progress"></param> /// <returns></returns> private List <EncodingScrutatorFolder> FolderToVirtualDirectory(List <string> folder, EncodingScrutatorProgress progress) { var encodingScrutatorFolder = new List <EncodingScrutatorFolder>(); foreach (var temp in folder) { encodingScrutatorFolder.Add( new EncodingScrutatorFolder(new DirectoryInfo(temp), _whiteList, _includeFile) { Progress = progress, SitpulationEncodingSetting = new SitpulationEncodingSetting { SitpulationEncoding = SitpulationEncoding } }); } _encodingScrutatorFolder = new EncodingScrutatorFolder(new DirectoryInfo(Environment.SystemDirectory)) { Folder = encodingScrutatorFolder }; foreach (var temp in encodingScrutatorFolder) { temp.Parent = _encodingScrutatorFolder; } return(encodingScrutatorFolder); }
private void EncodingScrutatorFolderBeCriterion(EncodingScrutatorFolder encodingScrutatorFolder) { foreach (var temp in encodingScrutatorFolder.Folder) { EncodingScrutatorFolder.Add(new Model.EncodingScrutatorFolder(temp, null)); } foreach (var temp in encodingScrutatorFolder.File) { EncodingScrutatorFolder.Add(new Model.EncodingScrutatorFile(temp, null)); } }
/// <summary> /// 写入失败文件 /// </summary> private void FailWriteSitpulation() { SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(Application.Current.Dispatcher)); SynchronizationContext.Current.Send(obj => { var encodingScrutatorFolder = EncodingScrutatorFolder.ToList <IEncodingScrutatorFile>(); EncodingScrutatorFolder.Clear(); FailWriteSitpulation(encodingScrutatorFolder); foreach (var temp in encodingScrutatorFolder) { EncodingScrutatorFolder.Add((EncodingScrutatorFolderFile)temp); } }, null); }
private int PintnoConformEncodingFolder(EncodingScrutatorFolder encodingScrutatorFolder, int count) { //输出不规范文件夹 for (var i = 0; i < encodingScrutatorFolder.Folder.Count; i++) { count += PintnoConformEncodingFile(encodingScrutatorFolder.Folder[i]); if (encodingScrutatorFolder.Folder[i].Folder.Count == 0 && encodingScrutatorFolder.Folder[i].File.Count == 0) { encodingScrutatorFolder.Folder.RemoveAt(i); i--; } } return(count); }
public EncodingScrutatorFolder(EncodingNormalior.Model.EncodingScrutatorFolder encodingScrutatorFolder, EncodingScrutatorFolder parent) : base(encodingScrutatorFolder.Name, parent) { Folder = new List <IEncodingScrutatorFile>(); foreach (var temp in encodingScrutatorFolder.File) { Folder.Add(new EncodingScrutatorFile(temp, parent)); } foreach (var temp in encodingScrutatorFolder.Folder) { Folder.Add(new EncodingScrutatorFolder(temp, this)); } SitpulationEncodingSetting = encodingScrutatorFolder.SitpulationEncodingSetting; }
private void Progress_ProgressChanged(object sender, EncodingScrutatorFile e) { if (e == null) { //完成检测 InspectCompleted?.Invoke(this, null); } else { StringBuilder str = new StringBuilder(); str.Append(e.File.Name); EncodingScrutatorFolder folder = e.Parent; while (folder != null) { str.Insert(0, folder.Name + "\\"); folder = folder.Parent; } str.Insert(0, "正在扫描\r\n"); Circular = str.ToString(); } }
/// <summary> /// 获取文件夹所有文件的编码,异步函数 /// </summary> public static async Task InspectFolderEncodingAsync(EncodingScrutatorFolder encodingScrutatorFolder, IProgress <EncodingScrutatorFile> progress) { encodingScrutatorFolder.Progress = progress; //await new Task(encodingScrutatorFolder.InspectFolderEncoding); await Task.Run(() => encodingScrutatorFolder.InspectFolderEncoding()); }