Exemplo n.º 1
0
        public ActionResult SearchFiles(FileSearcherViewModel model)
        {
            if(!ModelState.IsValid)
            {
                return View(model);
            }
            var searcher = new FileSearcher();

            if (!string.IsNullOrEmpty(model.FileSearcherId))
            {
                FileSearchContainer.AddSearcher(model.FileSearcherId, searcher);
            }
            try
            {
                var result = searcher.SearchFiles(new FileSearcherQuery { SearchString = model.SearchString, TargetDirectory = model.Directory });
                model.Files = result.Files.Select(x => x.FullName);
            }
            catch (Exception ex)
            {
                return RedirectToAction("BadRequest", "Error");
            }
            finally
            {
                if (!string.IsNullOrEmpty(model.FileSearcherId))
                {
                    FileSearchContainer.RemoveSearcher(model.FileSearcherId);
                }
            }
            return View(model);
        }
Exemplo n.º 2
0
 //
 // GET: /Home/
 public ActionResult Index()
 {
     var id = Guid.NewGuid().ToString("n");
     var model = new FileSearcherViewModel { FileSearcherId = id };
     return View("SearchFiles",model);
 }