//static string LogPath = @"D:\workspace\Code\Trunk\APPLogTest\Log\"; //static string FilePath = LogPath + "AndriodAppLog.txt"; //static string iOSFilePath = LogPath + "iOSAppLog.txt"; //public static string ActionCommonMap = LogPath + "ActionCommonMap.java"; //public static string OldActionPath = LogPath + "ActionCommonMap7.2.java"; //public static string NewActionPath = LogPath + "ActionCommonMap7.3.java"; public static Actions ReadStreamFromFile(string filePath, string parameter) { string actid, pageid; string mac = ""; string app = ""; string s = ""; Actions actions = new Actions(); actions._oneAction = new List<OneAction>(); OneAction oneAction = new OneAction(); List<string> undefineAction = new List<string>(); //int bufferSize = 1024000; //每次读取的字节数 int bufferSize = 128000; //每次读取的字节数 byte[] buffer = new byte[bufferSize]; System.IO.FileStream stream = null; FileStream tempStream = null; try { stream = new System.IO.FileStream(filePath, System.IO.FileMode.Open); long fileLength = stream.Length;//文件流的长度 int readCount = (int)Math.Ceiling((double)(fileLength / bufferSize)); //需要对文件读取的次数 int tempCount = 0;//当前已经读取的次数 do { stream.Read(buffer, tempCount * bufferSize, bufferSize); //分readCount次读取这个文件流,每次从上次读取的结束位置开始读取bufferSize个字节 //这里加入接收和处理数据的逻辑 string str = "Testing 1-2-3"; //convert string 2 stream byte[] array = Encoding.ASCII.GetBytes(str); StreamReader reader = new StreamReader(stream); s = reader.ReadToEnd(); if (mac == null) { mac = ""; } if (app == null) { app = ""; } string[] oneActionTextList = s.Split('}'); for (int i = 0; i < oneActionTextList.Length - 1; i++) { string[] oneActionText = oneActionTextList[i].Replace('[', ' ').Replace('{', ' ').Replace('\"', ' ').Replace(" ", "").Replace("]", "").Replace("\n", "").Split(','); if (oneActionTextList[i].Contains(app) && oneActionTextList[i].Contains(mac)) { oneAction = GetActID(oneActionText, parameter); if (oneAction._actID != null) { actions._oneAction.Add(oneAction); } } } // } while (tempCount < readCount); } catch { } finally { if (stream != null) stream.Dispose(); } return actions; }
public static Actions ReadFileByLines(Actions actions,string FilePath, string parameter) { string actid, pageid; string s = null; string mac = ""; string app = ""; string strLine = null; StreamReader sr = new StreamReader(FilePath); //string content = sr.ReadToEnd(); //MemoryStream ms = new MemoryStream(Encoding.GetEncoding("GB2312").GetBytes(content)); //while ((strLine = sr.ReadLine()) != null) //{ // //MessageBox.Show(strLine); // s = s + strLine; //} sr.BaseStream.Seek(0, SeekOrigin.Begin); s = sr.ReadToEnd(); //string s = null; //StringBuilder sb = ReadBigFile.GetFileContent(FilePath); //s = sb.ToString(); //actions = new Actions(); //actions._oneAction = new List<OneAction>(); OneAction oneAction = new OneAction(); List<string> undefineAction = new List<string>(); if (mac == null) { mac = ""; } if (app == null) { app = ""; } //s = s.Replace("%22%20%3A%20%22", ":"); //s = s.Replace("%22%3A%22", ":"); //s = s.Replace("%22%0A%20%20%7D%0A%5D", "}"); //s = s.Replace("%22%2C%0A%20%20%20%20%22", ","); s = s.Replace("%22", "\""); s = s.Replace("%7D", "}"); s = s.Replace("%5D", "]"); s = s.Replace("%3A", ":"); s = s.Replace("%2C", ","); s = s.Replace("%7B", "{"); s = s.Replace("%5B", "["); s = s.Replace("%20", ""); s = s.Replace("%0A", ""); string[] oneActionTextList = s.Split('{'); for (int i = 0; i < oneActionTextList.Length - 1; i++) { bool flag = oneActionTextList[i].Contains("\"act\":\"22002\"") || oneActionTextList[i].Contains("\"act\":110002") || oneActionTextList[i].Contains("\"act\":\"21000\"") || oneActionTextList[i].Contains("\"act\":\"22001\"") || oneActionTextList[i].Contains("\"act\":\"100001") || oneActionTextList[i].Contains("\"act\":\"200001\"") || oneActionTextList[i].Contains("\"act\":\"301001\""); if (oneActionTextList[i].Contains(app) && oneActionTextList[i].Contains(mac) && oneActionTextList[i].Contains("-") && !flag) { string[] oneActionText = oneActionTextList[i].Replace('[', ' ').Replace('{', ' ').Replace('\"', ' ').Replace(" ", "").Replace("]", "").Replace("\n", "").Replace("\\", "").Replace("log:", "").Split(','); oneAction = GetActID(oneActionText, parameter); if (oneAction._actID != null) { actions._oneAction.Add(oneAction); } } } return actions; }