private void button2_Click(object sender, EventArgs e) { if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { string fullPath = folderBrowserDialog1.SelectedPath; List <string> allFiles = new List <string>(); fillAllFiles(allFiles, fullPath); //richTextBox1 Dictionary <string, string> ips = new Dictionary <string, string>(); foreach (string f in allFiles) { string line = string.Empty; using (System.IO.StreamReader sr = new System.IO.StreamReader(f)) { while ((line = sr.ReadLine()) != null) { string ip = LogFileHelper.getClientIP(line); if (!ips.ContainsKey(ip)) { ips.Add(ip, f); } } } } richTextBox1.Clear(); foreach (string ip in ips.Keys) { richTextBox1.AppendText(ip + " " + ips[ip]); richTextBox1.AppendText("\n"); } } }
private void butQAMiddleLayer_Click(object sender, EventArgs e) { if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { string fullPath = folderBrowserDialog1.SelectedPath; List <string> allFiles = new List <string>(); fillAllFiles(allFiles, fullPath); //richTextBox1 Dictionary <string, UserDateInfo> datas = new Dictionary <string, UserDateInfo>(); foreach (string f in allFiles) { string line = string.Empty; using (System.IO.StreamReader sr = new System.IO.StreamReader(f)) { DateTime lastTime = DateTime.MinValue; while ((line = sr.ReadLine()) != null) { if (string.IsNullOrEmpty(line)) { continue; } DateTime dt = LogFileHelper.getDatetime(line); string ip = LogFileHelper.getClientIP(line); string key = ip + " " + dt.ToString("yyyy-MM-dd HH:mm:ss"); if (!datas.ContainsKey(key)) { TimeSpan span = dt.Subtract(lastTime); if (span.TotalSeconds <= 1) { datas.Add(key, new UserDateInfo(ip, dt.ToString("yyyy-MM-dd HH:mm:ss"))); } lastTime = dt; } } sr.Close(); } } if (datas.Count > 0) { frmViewIpAndDate frm = new frmViewIpAndDate(datas.Values.ToList <UserDateInfo>()); frm.ShowDialog(); } } }