public async Task UpdateApplication(CancellationToken token, IComponentUpdater updater) { foreach (var model in ApplicationModels) { await FileService.SearchAsync(RootPaths, model.FileName, token, updater) .ContinueWith(t => { var file = t.Result; if (!string.IsNullOrEmpty(file)) { var newAppInfo = CreateMatchedApplication(model.Id, model.FileName, file); if (newAppInfo != null) { InsertMatchedApplication(newAppInfo); } } }, token); } }
/// <summary> /// Default constructor with a backing adaptee output. /// </summary> /// <param name="id">Id of time buffer adapted output</param> protected TimeBufferer(string id, ITimeSpaceOutput adaptee) : base(id, adaptee) { ComponentUpdater = new TimeComponentUpdater(adaptee); CreateBufferAndTimeSet(); }
private static string Search(IEnumerable <string> roots, string searchPattern, CancellationToken token, IComponentUpdater updater = null) { var listFileFound = new List <string>(); foreach (var root in roots) { if (token.IsCancellationRequested) { break; } var rootIsExist = Directory.Exists(root); if (rootIsExist) { FileSearch(listFileFound, root, searchPattern, token, updater); } } var maxLastWriteTime = DateTime.MinValue; var lastWriteFile = string.Empty; foreach (var file in listFileFound) { if (token.IsCancellationRequested) { break; } var fileInfo = new FileInfo(file); if (fileInfo.LastWriteTime > maxLastWriteTime) { maxLastWriteTime = fileInfo.LastWriteTime; lastWriteFile = file; } } return(lastWriteFile); }
public static async Task <string> SearchAsync(ICollection <string> roots, string searchPattern, CancellationToken token, IComponentUpdater updater = null) { return(await Task.Factory.StartNew(() => Search(roots, searchPattern, token, updater), token)); }
// last write time 기준으로 Search public static async Task <string> SearchAsync(string root, string searchPattern, CancellationToken token, IComponentUpdater updater = null) { if (string.IsNullOrEmpty(root) || string.IsNullOrEmpty(searchPattern)) { return(null); } return(await Task.Factory.StartNew(() => Search(root, searchPattern, token, updater), token)); }
private static void FileSearch(List <string> fileFound, string dir, string searchPattern, CancellationToken token, IComponentUpdater updater = null) { try { var directories = Directory.GetDirectories(dir); foreach (var directory in directories) { if (token.IsCancellationRequested) { break; } updater?.Update(directory); try { var files = Directory.GetFiles(directory, searchPattern); foreach (var file in files) { if (Regex.IsMatch(file, searchPattern)) { fileFound.Add(file); } } } catch (UnauthorizedAccessException) { Console.WriteLine(@"1.권한 없는 폴더임 {0}", dir); } FileSearch(fileFound, directory, searchPattern, token, updater); } updater?.Update(""); } catch (UnauthorizedAccessException) { Console.WriteLine(@"1.권한 없는 폴더임 {0}", dir); } }