//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 Mac, string App) { string actid, pageid; string mac = Mac; string app = 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 OneAction GetActID(string[] oneActionText, string parameter) { OneAction oneAction = new OneAction(); oneAction._actID = null; oneAction._pageID = null; string actid, pageid, ct, item; actid = FindAct(oneActionText); pageid = FindPage(oneActionText); ct = FindCT(oneActionText); item = FindItem(oneActionText, parameter); oneAction._actID = actid; oneAction._pageID = pageid; oneAction._ct = ct; oneAction._item = item; if (actid != null) { oneAction._isUndefined = false; } return oneAction; }
public static Actions ReadFileByLines(Actions actions, string[] applog, int count, string parameter, string app) { string actid, pageid; string s = null; //string mac = Mac; //string app = App; //string strLine = null; //原来使用的 //for (int i = 0; i < count; i++) //{ // StreamReader sr = new StreamReader(applog[i]); // sr.BaseStream.Seek(0, SeekOrigin.Begin); // string temp = sr.ReadToEnd(); // sr.Close(); // s = s + temp; //} //新的 for (int i = 0; i < count; i++) { string temp = null; StreamReader sr = new StreamReader(applog[i]); while ((temp = sr.ReadLine()) != null) { if (temp.Length > 2) { s = s + temp; } } } 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", ""); s = HttpContext.Current.Server.UrlDecode(s); 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("\n","").Replace('[', ' ').Replace('{', ' ').Replace('\"', ' ').Replace(" ", "").Replace("]", "").Replace("\\", "").Replace("log:", "").Split(','); string[] oneActionText = oneActionTextList[i].Replace("\\n", "").Replace(" ", "").Replace("\\", "").Replace("\"", "").Replace("{", "").Split(','); oneAction = GetActID(oneActionText, parameter); if (oneAction._actID != null) { actions._oneAction.Add(oneAction); } } } return actions; }
public static OneAction GetActID(string[] ActionsText, string[] oneActionText, int j, string parameter) { OneAction oneAction = new OneAction(); oneAction._actID = null; oneAction._pageID = null; string actid, pageid; oneActionText = ActionsText[j].Replace('[', ' ').Replace('{', ' ').Replace('\"', ' ').Replace(" ", "").Split(','); oneAction = GetActID(oneActionText, parameter); return oneAction; }