public Task SearchAsync(string searchPattern, FileSearchMode mode, int count, IFileCollection files, CancellationToken cancellationToken) { if (String.IsNullOrEmpty(searchPattern)) { files.Clear(); foreach (string filePath in pinStateService.GetList()) files.Add(Path.GetFileNameWithoutExtension(filePath), filePath, true); if (lastCancellation != null) { lastCancellation.Cancel(); lastCancellation = null; } return Task.FromResult(true); } if (cancellationToken.IsCancellationRequested) return Async.CompletedTask; lastCancellation = new CancellationTokenSource(); cancellationToken.Register(() => lastCancellation.Cancel()); Task result = innerService.SearchAsync(searchPattern, mode, count, files, lastCancellation.Token); return result; }
public Task SearchAsync(string searchPattern, FileSearchMode mode, int count, IFileCollection files, CancellationToken cancellationToken) { if (String.IsNullOrEmpty(searchPattern)) { files.Clear(); foreach (string filePath in pinStateService.Enumerate()) { files.Add(Path.GetFileNameWithoutExtension(filePath), filePath, true); } if (lastCancellation != null) { lastCancellation.Cancel(); lastCancellation = null; } return(Task.FromResult(true)); } if (cancellationToken.IsCancellationRequested) { return(Async.CompletedTask); } lastCancellation = new CancellationTokenSource(); cancellationToken.Register(() => lastCancellation.Cancel()); Task result = innerService.SearchAsync(searchPattern, mode, count, files, lastCancellation.Token); return(result); }
public Func <IFileModel, bool> Create(string searchPattern, FileSearchMode mode) { if (searchPattern == null) { searchPattern = String.Empty; } searchPattern = searchPattern.ToLowerInvariant(); Func <IFileModel, bool> filter = null; switch (mode) { case FileSearchMode.StartsWith: filter = f => IsNameStartedWith(f, searchPattern); break; case FileSearchMode.Contains: string[] parts = searchPattern.Split(' '); filter = f => IsPathSearchMatched(f, parts); break; default: throw Ensure.Exception.NotSupportedSearchMode(mode); } return(filter); }
public Task SearchAsync(string searchPattern, FileSearchMode mode, int count, IFileCollection files, CancellationToken cancellationToken) { if (hasItems) { files.Add("Neptuo", @"C:\Development\Framework\Neptuo.sln", true); files.Add("Neptuo.Templates", @"C:\Development\Templates\Neptuo.Templates.sln", false); files.Add("Neptuo.Productivity", @"C:\Development\Productivity\Neptuo.Productivity.sln", false); files.Add("Neptuo.Productivity.SolutionRunner", @"C:\Development\Productivity\Neptuo.Productivity.SolutionRunner.sln", false); files.Add("Sample", @"C:\Development\Sample.sln", false); } return(Task.FromResult(true)); }
public async Task SearchAsync(string searchPattern, FileSearchMode mode, int count, IFileCollection files, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { return; } log.Debug("Searching for query '{0}'.", searchPattern); HashSet <FileModel> result = new HashSet <FileModel>(); await Task.Factory.StartNew(() => { Func <FileModel, bool> filter = matcherFactory.Create(searchPattern, mode); IEnumerable <FileModel> models = Enumerable.Concat( pinStateService.Enumerate().Select(f => new FileModel(f)).OrderBy(f => f.Name), storage.OrderBy(f => f.Name) ); foreach (FileModel model in models.Where(f => filter(f))) { if (result.Add(model) && result.Count == count) { return; } } }); if (cancellationToken.IsCancellationRequested) { return; } log.Debug("Found '{0}' items.", result.Count); files.Clear(); foreach (FileModel model in result) { files.Add(model.Name, model.Path, pinStateService.IsPinned(model.Path)); } }
public Task SearchAsync(string searchPattern, FileSearchMode mode, int count, IFileCollection files, CancellationToken cancellationToken) { TaskCompletionSource<bool> result = new TaskCompletionSource<bool>(); Task.Factory.StartNew( DelayedSearchHandler, new Context() { RequestIndex = ++currentRequestIndex, CompletionSource = result, SearchPattern = searchPattern, Mode = mode, Count = count, Files = files, CancellationToken = cancellationToken }, cancellationToken ); return result.Task; }
public Task SearchAsync(string searchPattern, FileSearchMode mode, int count, IFileCollection files, CancellationToken cancellationToken) { TaskCompletionSource <bool> result = new TaskCompletionSource <bool>(); Task.Factory.StartNew( DelayedSearchHandler, new Context() { RequestIndex = ++currentRequestIndex, CompletionSource = result, SearchPattern = searchPattern, Mode = mode, Count = count, Files = files, CancellationToken = cancellationToken }, cancellationToken ); return(result.Task); }
public Func<IFileModel, bool> Create(string searchPattern, FileSearchMode mode) { if (searchPattern == null) searchPattern = String.Empty; searchPattern = searchPattern.ToLowerInvariant(); Func<IFileModel, bool> filter = null; switch (mode) { case FileSearchMode.StartsWith: filter = f => IsNameStartedWith(f, searchPattern); break; case FileSearchMode.Contains: string[] parts = searchPattern.Split(' '); filter = f => IsPathSearchMatched(f, parts); break; default: throw Ensure.Exception.NotSupportedSearchMode(mode); } return filter; }
/// <summary> /// 获取指定路径的文件信息, /// /// 假设有如下目录和文件 /// C;/MyTest/Liange/MyTest.txt /// /// 现在获取C:/MyTest目录下的文件, /// 如果相对路径(relativePath)为空(""),则MyTest.txt获取出来的相对路径就是Liange/MyTest.txt /// 如果相对路径(relativePath)为"MyDir",则MyTest.txt获取出来的相对路径就是MyDir/Liange/MyTest.txt /// /// </summary> /// <param name="fullDirPath">需要获取文件列表的目录路径</param> /// <param name="relativePath">获取的文件相对路径</param> /// <param name="fileList"></param> /// <param name="mode"></param> /// <param name="fileType">需要处理的文件类别,Ignore:忽略这种文件类型,Special:只查找这种文件类型</param> public static void GetRelativeFileList(string fullDirPath, string relativePath, ref List <FileUnit> fileList, FileSearchMode mode, string fileType) { try { if (string.IsNullOrEmpty(fileType) == false) { if (fileType[0] != '.') { fileType = '.' + fileType; } } DirectoryInfo currentDir = new DirectoryInfo(fullDirPath); FileInfo[] tmpFileList = currentDir.GetFiles(); foreach (FileInfo fi in tmpFileList) { switch (mode) { case FileSearchMode.Ignore: { if (fi.Extension == fileType) { continue; } } break; case FileSearchMode.Special: { if (fi.Extension != fileType) { continue; } } break; } FileUnit unit = new FileUnit(); unit.name = fi.Name; unit.fullPath = fi.FullName.Replace('\\', '/'); if (string.IsNullOrEmpty(relativePath)) { unit.relativePath = fi.Name; } else { unit.relativePath = relativePath + "/" + fi.Name; } fileList.Add(unit); } DirectoryInfo[] dirList = currentDir.GetDirectories(); foreach (DirectoryInfo di in dirList) { string newRelativePath = null; if (string.IsNullOrEmpty(relativePath)) { newRelativePath = di.Name; } else { newRelativePath = relativePath + "/" + di.Name; } GetRelativeFileList(di.FullName, newRelativePath, ref fileList, mode, fileType); } } catch (System.Exception ex) { Debug.LogError("MyFileUtil.GetRelativeFileList:" + ex.Message); } }
public static NotSupportedException NotSupportedSearchMode(this EnsureExceptionHelper ensure, FileSearchMode mode) { return Ensure.Exception.NotSupported("Not supported file search mode '{0}'.", mode); }
public static NotSupportedException NotSupportedSearchMode(this EnsureExceptionHelper ensure, FileSearchMode mode) { return(Ensure.Exception.NotSupported("Not supported file search mode '{0}'.", mode)); }
public Task SearchAsync(string searchPattern, FileSearchMode mode, int count, IFileCollection files, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) return Async.CompletedTask; files.Clear(); Func<FileModel, bool> filter = matcherFactory.Create(searchPattern, mode); foreach (FileModel model in storage.Where(f => filter(f)).Take(count)) files.Add(model.Name, model.Path, pinStateService.IsPinned(model.Path)); return Async.CompletedTask; }