Exemple #1
0
        public ActionResult Index(LogSystemModels model)
        {
            IList <FileInfo> list = new List <FileInfo>();

            model.LogsInfo = new List <FileInfo>();
            if (!string.IsNullOrWhiteSpace(model.DateModify))
            {
                DateTime?DateMod = null;
                DateMod = DateTime.ParseExact(model.DateModify, "dd/MM/yyyy", null);
                list    = logService.GetbyDateMod(DateMod.Value, logFolder);
            }
            else
            {
                list = logService.GetbyDateNow(logFolder);
            }
            if (!string.IsNullOrEmpty(model.Keysearch))
            {
                foreach (FileInfo file in list)
                {
                    var fs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                    try
                    {
                        using (var sr = new StreamReader(fs))
                        {
                            string allRead = sr.ReadToEnd();
                            sr.Close();
                            if (Regex.IsMatch(allRead, model.Keysearch))
                            {
                                model.LogsInfo.Add(file);
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        continue;
                    }
                }
            }
            else
            {
                model.LogsInfo = list;
            }
            //model.pageLogsInfo = new PagedList<FileInfo>(model.LogsInfo, currentPageIndex, defautPagesize, total);
            return(View(model));
        }