public int parseMaxBearerNumber4GFile() { int line_count = 0; FilesToParse.Add(file_to_parse_gz); FilesToParse.Add(file_to_parse_kt); foreach (string file_to_parse in FilesToParse) { string nodeName = "", st_time = ""; if (file_to_parse.Contains("_GZ_")) { nodeName = "GZ"; } else if (file_to_parse.Contains("_KT_")) { nodeName = "KT"; } char[] delimiterChars = new char[5]; try { if (!File.Exists(file_to_parse)) throw new Exception(); } catch (Exception e) { Console.WriteLine(e.ToString()); Util.writeLog(new StackTrace(1).GetFrame(0).GetMethod().Name, e); return 0; } using (StreamReader sr = File.OpenText(@file_to_parse)) { String input; string[] tokens; sr.ReadLine(); line_count = 0; //int i = 0; while ((input = sr.ReadLine()) != null) { delimiterChars[0] = ','; tokens = input.Split(delimiterChars[0]); st_time = tokens[1]; DateTime oDate = DateTime.ParseExact(st_time, "yyyy-MM-dd HH:mm:ss", null); MaxBearerNumber4G_Model data = new MaxBearerNumber4G_Model(); data.maxDefaultBearerActive = Convert.ToInt32(tokens[54]); data.resultTime = oDate; data.nodeName = nodeName; dataList.Add(data); line_count++; } sr.Close(); } } string queryString = ""; foreach (var data in dataList) { queryString += "INSERT into ps_sgsn_4g_s1_max_bearer_number ( max_bearer_number,node_name,vendor,result_time) values ('" + data.maxDefaultBearerActive + "','" + data.nodeName + "','" + data.vendor + "','" + data.resultTime.ToString("yyyy-MM-dd HH:mm:ss") + "');"; } try { MySqlConnection cn = DatabaseConnection.CreateConnection(); MySqlCommand cmd = new MySqlCommand(queryString, cn); int inserted_rows = cmd.ExecuteNonQuery(); } catch (Exception ex) { DatabaseConnection.CloseConnection(); Console.WriteLine(ex.ToString()); Util.writeLog(new StackTrace(1).GetFrame(0).GetMethod().Name, ex); return 0; } DatabaseConnection.CloseConnection(); return line_count; }
public int parseS1CombAttachSucRate4GFile() { int line_count = 0; FilesToParse.Add(file_to_parse_gz); FilesToParse.Add(file_to_parse_kt); foreach (string file_to_parse in FilesToParse) { string nodeName = "", st_time = ""; if (file_to_parse.Contains("_GZ_")) { nodeName = "GZ"; } else if (file_to_parse.Contains("_KT_")) { nodeName = "KT"; } char[] delimiterChars = new char[5]; try { if (!File.Exists(file_to_parse)) { throw new Exception(); } } catch (Exception e) { Console.WriteLine(e.ToString()); Util.writeLog(new StackTrace(1).GetFrame(0).GetMethod().Name, e); return(0); } using (StreamReader sr = File.OpenText(@file_to_parse)) { String input; string[] tokens; sr.ReadLine(); line_count = 0; //int i = 0; while ((input = sr.ReadLine()) != null) { delimiterChars[0] = ','; tokens = input.Split(delimiterChars[0]); st_time = tokens[1]; DateTime oDate = DateTime.ParseExact(st_time, "yyyy-MM-dd HH:mm:ss", null); S1ModeCombinedAttachSuccessRate4G_Model data = new S1ModeCombinedAttachSuccessRate4G_Model(); data.timesOfCombinedAttachRequest = Convert.ToInt32(tokens[29]); data.timesOfSuccess = Convert.ToInt32(tokens[28]); data.resultTime = oDate; data.nodeName = nodeName; dataList.Add(data); line_count++; } sr.Close(); } } string queryString = ""; foreach (var data in dataList) { queryString += "INSERT into ps_sgsn_4g_s1_mode_combined_attach_success_rate ( s1_mode_combined_attach_request_times,s1_mode_combined_att_succ_times_for_eps_and_non_eps_services,s1_mode_combined_att_succ_times_for_eps_srvces_and_sms_only,node_name,vendor,result_time) values ('" + data.timesOfCombinedAttachRequest + "','" + data.timesOfSuccess + "',0,'" + data.nodeName + "','" + data.vendor + "','" + data.resultTime.ToString("yyyy-MM-dd HH:mm:ss") + "');"; } try { MySqlConnection cn = DatabaseConnection.CreateConnection(); MySqlCommand cmd = new MySqlCommand(queryString, cn); int inserted_rows = cmd.ExecuteNonQuery(); } catch (Exception ex) { DatabaseConnection.CloseConnection(); Console.WriteLine(ex.ToString()); Util.writeLog(new StackTrace(1).GetFrame(0).GetMethod().Name, ex); return(0); } DatabaseConnection.CloseConnection(); return(line_count); }