Esempio n. 1
0
        private void FindTogetherMac(object obj)
        {
            List <MacObj> list   = new List <MacObj>();
            FindMacEntity entity = obj as FindMacEntity;
            Dictionary <string, string> logDic = new Dictionary <string, string>();
            //查找 ZIP文件列表,并解压到临时目录处理
            var files = Directory.EnumerateFiles(entity.DataPath, "*", SearchOption.TopDirectoryOnly);

            files.ToList().ForEach(file =>
            {
                Disply("开始解压文件" + file + "");
                using (ZipFile zipFile = new ZipFile(file))
                {
                    zipFile.ExtractAll(entity.TempPath + "/" + Path.GetFileNameWithoutExtension(file), true);
                }
                Disply("文件" + file + "解压成功,开始数据分析,该操作耗时较长,请耐心等待...");
                //只获取终端特征信息的文件
                var zipFiles = Directory.EnumerateFiles(entity.TempPath + "/" + Path.GetFileNameWithoutExtension(file), "*_WifiTerminalInfoLog_*", SearchOption.TopDirectoryOnly);
                int i        = 0;
                int count    = zipFiles.Count();
                zipFiles.ToList().ForEach(macFile =>
                {
                    try
                    {
                        i++;
                        Disply("文件" + file + "解压成功,开始数据分析,该操作耗时较长,请耐心等待..." + "当前步骤" + i + "/" + count);
                        string data  = Methods.ReadGzip(File.ReadAllBytes(macFile));
                        DataTable dt = Methods.String2DataTable(data);
                        foreach (DataRow row in dt.Rows)
                        {
                            var mac = row["terminal_mac"].ToString();
                            if (this.textBox1.Text.Contains(mac))
                            {
                                list.Add(new MacObj()
                                {
                                    SiteId      = row["site_id"].ToString(),
                                    DetectTime  = Convert.ToInt64(row["detect_time"]),
                                    TerminalMac = row["terminal_mac"].ToString(),
                                });
                            }
                        }
                    }
                    catch
                    {
                    }
                });
            });

            StringBuilder sb = new StringBuilder("terminal_mac\tdetect_time\tsite_id\r\n");

            foreach (var item in list)
            {
                sb.AppendFormat("{0}\t{1}\t{2}\r\n", item.TerminalMac,
                                item.DetectTime,
                                item.SiteId);
            }
            File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "/" + "查找MAC转换结果.txt", sb.ToString());
            Disply("文件分析完成,结果保存在根目录");
        }
Esempio n. 2
0
        private void FindTogether(object obj)
        {
            FindMacEntity entity = obj as FindMacEntity;
            Dictionary <string, string> logDic = new Dictionary <string, string>();
            //查找 ZIP文件列表,并解压到临时目录处理
            var files = Directory.EnumerateFiles(entity.DataPath, "*", SearchOption.TopDirectoryOnly);

            files.ToList().ForEach(file =>
            {
                Disply("开始解压文件" + file + "");
                using (ZipFile zipFile = new ZipFile(file))
                {
                    zipFile.ExtractAll(entity.TempPath + "/" + Path.GetFileNameWithoutExtension(file), true);
                }
                Disply("文件" + file + "解压成功,开始数据分析,该操作耗时较长,请耐心等待...");
                //只获取终端特征信息的文件
                var zipFiles = Directory.EnumerateFiles(entity.TempPath + "/" + Path.GetFileNameWithoutExtension(file), "*_WifiTerminalInfoLog_*", SearchOption.TopDirectoryOnly);
                int i        = 0;
                int count    = zipFiles.Count();
                zipFiles.ToList().ForEach(macFile =>
                {
                    try
                    {
                        i++;
                        Disply("文件" + file + "解压成功,开始数据分析,该操作耗时较长,请耐心等待..." + "当前步骤" + i + "/" + count);
                        string data  = Methods.ReadGzip(File.ReadAllBytes(macFile));
                        DataTable dt = Methods.String2DataTable(data);
                        foreach (DataRow row in dt.Rows)
                        {
                            var site_id      = row["site_id"].ToString();
                            var terminal_mac = row["terminal_mac"].ToString();
                            var detect_time  = Convert.ToInt64(row["detect_time"]);

                            foreach (var item in anList)
                            {
                                var minValue = item.DetectTime - this.nudSecond.Value;
                                var maxValue = item.DetectTime + this.nudSecond.Value;
                                if (site_id == item.SiteId &&
                                    detect_time >= minValue &&
                                    detect_time <= maxValue)
                                {
                                    //同行
                                    if (dicList.ContainsKey(item.TerminalMac))
                                    {
                                        var list   = dicList[item.TerminalMac];
                                        var macObj = list.SingleOrDefault(f => f.TerminalMac == terminal_mac && f.SiteId == site_id);
                                        if (macObj == null)
                                        {
                                            list.Add(new MacObj()
                                            {
                                                SiteId      = site_id,
                                                TerminalMac = terminal_mac,
                                                Times       = 1
                                            });
                                        }
                                        else
                                        {
                                            macObj.Times += 1;
                                        }
                                        dicList[item.TerminalMac] = list;
                                    }
                                    else
                                    {
                                        dicList.Add(item.TerminalMac, new List <MacObj>()
                                        {
                                            new MacObj()
                                            {
                                                SiteId      = site_id,
                                                TerminalMac = terminal_mac,
                                                Times       = 1
                                            }
                                        });
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                    }
                });
            });

            //写入
            foreach (var key in dicList.Keys)
            {
                var           item = dicList[key];
                StringBuilder sb   = new StringBuilder();

                var group = item.GroupBy(f => f.TerminalMac).Select(k => new { mac = k.Key, times = k.Sum(l => l.Times) });
                foreach (var groupItem in group.OrderByDescending(f => f.times))
                {
                    if (groupItem.times >= this.nudTimes.Value)
                    {
                        var detail = item.Where(f => f.TerminalMac == groupItem.mac).GroupBy(f => f.SiteId).Select(k => new { siteId = k.Key, times = k.Sum(l => l.Times) });

                        sb.AppendFormat("mac:{0}和mac{1}总共同行了{2}次。", key, groupItem.mac, groupItem.times);

                        foreach (var detailItem in detail)
                        {
                            sb.AppendFormat("在场所{0}同行了{1}次。", detailItem.siteId, detailItem.times);
                        }
                        sb.AppendFormat("\r\n");
                    }
                }

                var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "同行分析");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                File.WriteAllText(Path.Combine(path, key + ".txt"), sb.ToString());
            }
            Disply("文件分析完成,结果保存在根目录");
        }
Esempio n. 3
0
        private void FindMAC(object obj)
        {
            try
            {
                FindMacEntity entity = obj as FindMacEntity;
                Dictionary <string, string> logDic = new Dictionary <string, string>();
                //查找 ZIP文件列表,并解压到临时目录处理
                var files = Directory.EnumerateFiles(entity.DataPath, "*", SearchOption.TopDirectoryOnly);
                files.ToList().ForEach(file =>
                {
                    var extPath = Path.Combine(entity.TempPath, Path.GetFileNameWithoutExtension(file));

                    Disply("开始解压文件" + file + "");
                    using (ZipFile zipFile = new ZipFile(file))
                    {
                        zipFile.ExtractAll(extPath);
                    }
                    Disply("文件" + file + "解压成功,开始分析数据文件,该操作耗时较长,请耐心等待...");
                    //只获取终端特征信息的文件
                    var zipFiles = Directory.EnumerateFiles(extPath, "*_WifiTerminalInfoLog_*", SearchOption.TopDirectoryOnly);
                    zipFiles.ToList().ForEach(macFile =>
                    {
                        try
                        {
                            string data  = Methods.ReadGzip(File.ReadAllBytes(macFile));
                            DataTable dt = Methods.String2DataTable(data);

                            var row = dt.AsEnumerable().Where(x =>
                            {
                                return((from a in entity.MacList where a.Equals(x.Field <string>("terminal_mac"), StringComparison.OrdinalIgnoreCase) select a).Any());
                            });

                            row.ToList().ForEach(r =>
                            {
                                string siteId = r["site_id"].ToString();
                                string mac    = r["terminal_mac"].ToString();
                                string time   = Methods.ConvertIntDateTime(long.Parse(r["detect_time"].ToString())).ToString();
                                string log    = string.Format("被{0}在{1}采集到,gz数据文件为{2},压缩包文件为{3}", siteId, time, Path.GetFileName(macFile), Path.GetFileName(file));
                                if (logDic.ContainsKey(mac))
                                {
                                    logDic[mac] = logDic[mac] + Environment.NewLine + log;
                                }
                                else
                                {
                                    logDic.Add(mac, log);
                                }
                            });
                        }
                        catch (Exception ex)
                        {
                            LogWriter.WriteLog("错误,文件名:" + macFile + "\r\n" + ex.ToString());
                        }
                    });
                });

                foreach (string ss in logDic.Keys)
                {
                    LogWriter.WriteLog(ss + Environment.NewLine + logDic[ss]);
                }
                Disply("分析完成,请到程序根目录下查看XXX.LOG日志文件查看结果");
                logDic = new Dictionary <string, string>();
            }
            catch (Exception ex)
            {
                LogWriter.WriteLog("错误:" + ex.ToString());
            }
        }