/// <summary> /// Get interested file. /// </summary> /// <param name="path">Path to initial directory for search.</param> /// <param name="startValue">File name start with value.</param> public void GetFiles(string path, string startValue) { string[] files = SearchFileService.SearchFile(path, string.Format("*{0}*", startValue), SearchOption.AllDirectories); foreach (string file in files) { FindedFiles.Add(new Model.File(file, Path.GetFileName(file))); } }
//We change the Apartment State of the thread from Multi Thread Apartment(MTA) to Single Thread Apartment (STA) mode //Those threads allow the program to run multiple threads while working. //By default the program has only one thread running, so with those threads we make the program multi-functional. //Also, if we don't have multi-threading program it gives error when trying to run a thread while other thread is running. //The threads are set to be backgound, which means that they are going to stop the service when the program stops. private static void SetSearchFileThread(SearchFileService searchFileService) { Thread thread = new Thread((ThreadStart)(() => { searchFileService.SearchFiles(); })); thread.IsBackground = true; thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); }
public void SourcePathSetCorrectlly(string path) { SearchFileService searchService = new SearchFileService(); FieldInfo[] fields = typeof(SearchFileService).GetFields(BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo sourcePath = fields.FirstOrDefault(x => x.Name == "sourcePath"); sourcePath.SetValue(searchService, path); Thread thread = new Thread((ThreadStart)(() => { searchService.SearchFiles(); })); thread.IsBackground = true; thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); CurrentUser.user.username = "******"; Assert.AreEqual(path, sourcePath.GetValue(searchService)); }
public List <TransferFile> SearchFiles(string fileName) { SearchFileService searchFileService = new SearchFileService(); return(searchFileService.SearchFiles(fileName)); }