public static BaseResultInfo GetLastItem(LOGTYPE logType, string server) { LogItemRepository repository = new LogItemRepository(); BaseResultInfo res = repository.GetLastLogItem(logType.ToString(), server); return(res); }
private void btnLoginLength_Click(object sender, EventArgs e) { DateTime start = dtStart.Value; DateTime end = dtEnd.Value; BaseResultInfo res = DataHelper.GetLogins(start, end); List <LogItem> items = res.GetResult <List <LogItem> >(); BaseResultInfo resLength = DataHelper.GetLoginsLength(start, end); List <LoginLengthInfo> itemsLength = resLength.GetResult <List <LoginLengthInfo> >(); if (items != null) { var clearItems = (from a in items join b in itemsLength on a.SiteId equals b.SiteId where a.AccountId != -23 select new LoginLengthGridData() { SiteId = a.SiteId, AccountId = a.AccountId, Message = a.Message, StartDate = b.StartDate, EndDate = b.EndDate, Length = b.Length }).ToList(); double dbl = clearItems.Average(x => TimeSpan.Parse(x.Length).Ticks); lblResult.Text = "NUMBER OF ITEMS {0} AVERAGE {1}".StringFormat(clearItems.Count, new TimeSpan((long)dbl)); dgGrid.DataSource = clearItems; dgGrid.Update(); } }
public static BaseResultInfo FileToNewDB(string fileName, LOGTYPE logType, bool isUnified) { SiteLogger.ILogger logger = SiteLogger.LoggingFactory.GetLogger; List <string> file = LogReader.LogFileReader.ReadFile(fileName); if (isUnified) { file = LogReader.LogFileReader.UnifiedLogLines(file); } List <LogItem> items = LogReader.LogFileReader.LinesToLogs(file.ToArray(), logType); LogItemRepository repository = new LogItemRepository(); BaseResultInfo res = repository.GetLastLogItem(logType.ToString(), null); LogItem last = res.GetResult <LogItem>(); int itemsSentToDB = items.Count; LogItem lastFound = last == null? null: items.FirstOrDefault(l => l.InsertDate == last.InsertDate); if (lastFound == null) { res = repository.InsertLogItem(items); } else { List <LogItem> itemsToSend = items.FindAll(l => l.Index > lastFound.Index); itemsSentToDB = itemsToSend.Count; res = repository.InsertLogItem(itemsToSend); } logger.Debug(string.Format("FILE NAME = {0} , TOTAL ITEMS = {1} , ITEM TRY INSERT = {2}, TOTAL SUCCESS = {3}, TOTAL FAILD = {4}", fileName, items.Count, itemsSentToDB, res.ReturnValue, itemsSentToDB - res.ReturnValue)); return(res); }
public BaseResultInfo InsertLogItem(LogItem item) { BaseResultInfo result = new BaseResultInfo(); SqlParameterList commandParams = SqlSerializer.Serialize(item); try { using (SqlConnection conn = new SqlConnection(base.ConnectionString)) { conn.Open(); SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, SQL_ADD_LOG_ITEM, commandParams.ToArray()); result.ReturnValue = commandParams.GetReturnValue(); if (result.ReturnValue < 0) { throw new Exception("SQL_ADD_LOG_ITEM"); } } } catch (Exception ex) { if (result.Error == null) { result.Error = new BaseErrorInfo(); } result.Error.BuildException(ex); } return(result); }
private void btnSearch_Click(object sender, EventArgs e) { LogItemRequest request = new LogItemRequest(); request.StartDate = dtStart.Value; request.EndDate = dtEnd.Value; if (!string.IsNullOrEmpty(cbLogType.Text)) { request.logType = (LOGTYPE?)Enum.Parse(typeof(LOGTYPE), cbLogType.Text); } if (!string.IsNullOrEmpty(txtSiteId.Text)) { request.SiteId = txtSiteId.Text; } if (!string.IsNullOrEmpty(txtAccountId.Text)) { request.AccountId = int.Parse(txtAccountId.Text); } BaseResultInfo res = DataHelper.SearchItems(request); List <LogItem> items = res.GetResult <List <LogItem> >(); lblResult.Text = "NUMBER OF ITEMS {0}".StringFormat(items.Count); dgGrid.DataSource = items; dgGrid.Update(); }
private void HotControler_GetDetailsEvent(object sender, ServiceEventArgs e) { this.Invoke(new MethodInvoker(delegate() { if (e != null) { string content = e.Content; try { if (content.Contains("\"examineUser\":\"\"")) { content = content.Replace("\"examineUser\":\"\"", "\"examineUser\":0"); } BaseResultInfo <Fire_Hot> result = JsonHelper.JSONToObject <BaseResultInfo <Fire_Hot> >(content); if (result.status == 10000 && result.obj != null) { FillDetails(result.obj); } else { MessageBox.Show(this, result.msg, "提示"); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "提示"); } } else { MessageBox.Show(this, sender.ToString(), "提示"); } })); }
private void m_LicenseController_EditEvent(object sender, ServiceEventArgs e) { this.Invoke(new MethodInvoker(delegate() { if (e != null) { string content = sender.ToString(); try { BaseResultInfo <string> result = JsonHelper.JSONToObject <BaseResultInfo <string> >(content); if (result.status == 10000) { this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show(this, result.msg, "提示"); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "提示"); } } else { MessageBox.Show(this, sender.ToString(), "提示"); } })); }
private void M_FirePBrigadeController_DeleteMediaEvent(object sender, ServiceEventArgs e) { this.Invoke(new MethodInvoker(delegate() { if (e != null) { string content = e.Content; try { BaseResultInfo <object> result = JsonHelper.JSONToObject <BaseResultInfo <object> >(content); if (result.status == 10000) { this.DialogResult = DialogResult.OK; } else { MessageBox.Show(this, result.msg, "提示"); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "提示"); } } else { MessageBox.Show(this, sender.ToString(), "提示"); } })); }
public BaseResultInfo GetLastLogItem(string logType, string server) { BaseResultInfo result = new BaseResultInfo(); SqlParameterList commandParams = new SqlParameterList(); commandParams.Add("@LogType", SqlDbType.NVarChar, logType); commandParams.Add("@LogServer", SqlDbType.NVarChar, server); try { using (SqlConnection conn = new SqlConnection(base.ConnectionString)) { using (SqlDataReader dr = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, SQL_GET_LAST_LOG_ITEM, commandParams.ToArray())) { while (dr.Read()) { LogItem a = Serializer.DeSerialize <LogItem>(dr); result.ResultObject = a; } } } } catch (Exception ex) { if (result.Error == null) { result.Error = new BaseErrorInfo(); } result.Error.BuildException(ex); } return(result); }
private void m_HotController_DeleteEvent(object sender, ServiceEventArgs e) { this.Invoke(new MethodInvoker(delegate() { if (e != null) { string content = e.Content; try { BaseResultInfo <string> result = JsonHelper.JSONToObject <BaseResultInfo <string> >(content); if (result.status == 10000) { this.GetHotList(this.navigationControl1.Pac); } else { MessageBox.Show(this, result.msg, "提示"); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "提示"); } } else { MessageBox.Show(this, sender.ToString(), "提示"); } })); }
private void AddToDBBTN_Click(object sender, EventArgs e) { CultureInfo cur_culture = CultureInfo.CreateSpecificCulture("en-US"); DateTimeFormatInfo dtfi = cur_culture.DateTimeFormat; Thread.CurrentThread.CurrentCulture = cur_culture; BaseResultInfo res = DataHelper.AllNewLogFilesToDB(); }
public void TEST_GET_UNIQ_LOGINS() { DateTime start = DateTime.Now.AddHours(-DateTime.Now.Hour).AddMinutes(-DateTime.Now.Minute);; DateTime end = DateTime.Now; BaseResultInfo res = TestDataHelper.GetLogins(start, end); List <LogItem> items = res.GetResult <List <LogItem> >(); Assert.IsTrue(res != null); }
public BaseResultInfo GetLogItems() { BaseResultInfo res = new BaseResultInfo() { ResultObject = new List <LogItem>() }; return(res); }
public void TEST_Insert_JSERROR_LOG_TO_DB() { string fileName = "JSTrace_fleet_20151103.log"; List <string> file = LogReader.LogFileReader.ReadFile(fileName); List <LogItem> items = LogReader.LogFileReader.LinesToLogs(file.ToArray(), LOGTYPE.JSError); LogItemRepository repository = new LogItemRepository(); BaseResultInfo res = repository.InsertLogItem(items[0]); Assert.IsTrue(res != null); }
public void TEST_Insert_WARN_LOG_LIST_TO_DB() { string fileName = "Warn_fleet_20151103.log"; List <string> file = LogReader.LogFileReader.ReadFile(fileName); List <LogItem> items = LogReader.LogFileReader.LinesToLogs(file.ToArray(), LOGTYPE.Warn); LogItemRepository repository = new LogItemRepository(); BaseResultInfo res = repository.InsertLogItem(items); Assert.IsTrue(res != null); }
public void TEST_AllLogFilesToDB() { CultureInfo cur_culture = CultureInfo.CreateSpecificCulture("en-US"); DateTimeFormatInfo dtfi = cur_culture.DateTimeFormat; Thread.CurrentThread.CurrentCulture = cur_culture; BaseResultInfo res = TestDataHelper.AllLogFilesToDB(); Assert.IsTrue(res != null); }
public void TEST_Insert_ALL_LOG_LIST_TO_DB() { TestDataHelper.FileToDB("Trace_fleet_20151102.log", LOGTYPE.Trace, true); TestDataHelper.FileToDB("DBTrace_fleet_20151102.log", LOGTYPE.DBTrace, true); TestDataHelper.FileToDB("Warn_fleet_20151103.log", LOGTYPE.Warn, false); TestDataHelper.FileToDB("JSTrace_fleet_20151103.log", LOGTYPE.JSError, false); BaseResultInfo res = TestDataHelper.FileToDB("Fatal_fleet_20151103.log", LOGTYPE.Fatal, true); Assert.IsTrue(res != null); }
public BaseResultInfo SearchItems(LogItemRequest request) { BaseResultInfo result = new BaseResultInfo(); SqlParameterList commandParams = new SqlParameterList(); string select = " select * from LogTBL where InsertDate > @StartDate and InsertDate < @EndDate"; commandParams.Add("@StartDate", SqlDbType.DateTime, request.StartDate); commandParams.Add("@EndDate", SqlDbType.DateTime, request.EndDate); if (request.logType.HasValue) { select += " and LogType = @LogType"; commandParams.Add("@LogType", SqlDbType.NVarChar, request.logType.ToString()); } if (!string.IsNullOrEmpty(request.SiteId)) { select += " and SiteId = @SiteId"; commandParams.Add("@SiteId", SqlDbType.NVarChar, request.SiteId); } if (request.AccountId.HasValue) { select += " and AccountId = @AccountId"; commandParams.Add("@AccountId", SqlDbType.Int, request.AccountId); } List <LogItem> items = new List <LogItem>(); try { using (SqlConnection conn = new SqlConnection(base.ConnectionString)) { using (SqlDataReader dr = SqlHelper.ExecuteReader(conn, CommandType.Text, select, commandParams.ToArray())) { while (dr.Read()) { LogItem a = Serializer.DeSerialize <LogItem>(dr); items.Add(a); } result.ResultObject = items; } } } catch (Exception ex) { if (result.Error == null) { result.Error = new BaseErrorInfo(); } result.Error.BuildException(ex); } return(result); }
public void TEST_Insert_ERROR_LOG_LIST_TO_DB() { string fileName = "Error_fleet_20161211.log"; List <string> file = LogReader.LogFileReader.ReadFile(fileName); List <string> newLins = LogReader.LogFileReader.UnifiedLogLines(file); List <LogItem> items = LogReader.LogFileReader.LinesToLogs(newLins.ToArray(), LOGTYPE.Error); LogItemRepository repository = new LogItemRepository(); BaseResultInfo res = repository.InsertLogItem(items); Assert.IsTrue(res != null); }
public void TEST_TEMP() { string fileName = "Error_fleet_20151109.log"; fileName = TestDataHelper.GetFullName(fileName); List <string> file = LogReader.LogFileReader.ReadFile(fileName); List <string> newLins = LogReader.LogFileReader.UnifiedLogLines(file); List <LogItem> items = LogReader.LogFileReader.LinesToLogs(newLins.ToArray(), LOGTYPE.Warn); LogItemRepository repository = new LogItemRepository(); BaseResultInfo res = repository.InsertLogItem(items); Assert.IsTrue(res != null); }
public BaseResultInfo InsertLogItem(List <LogItem> items) { SiteLogger.ILogger logger = SiteLogger.LoggingFactory.GetLogger; BaseResultInfo result = new BaseResultInfo(); List <ResultLogItem> errorData = new List <ResultLogItem>(); try { using (SqlConnection conn = new SqlConnection(base.ConnectionString)) { conn.Open(); SqlParameterList commandParams = new SqlParameterList(); int successCount = 0; foreach (var item in items) { try { commandParams = SqlSerializer.Serialize(item); int res = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, SQL_ADD_LOG_ITEM, commandParams.ToArray()); successCount++; } catch (Exception ex) { logger.Error(string.Format("INDEX = {0}, DATETIME = {1}, LOG_TYPE = {2}, MESSAGE = {3}", item.Index, item.InsertDate, item.LogType, ex.Message)); errorData.Add(new ResultLogItem() { Log = item, ErrorMessage = ex.Message }); } } result.ReturnValue = successCount; commandParams.GetReturnValue(); result.ResultObject = errorData; conn.Close(); if (result.ReturnValue < 0) { throw new Exception("SQL_ADD_LOG_ITEM"); } } } catch (Exception ex) { if (result.Error == null) { result.Error = new BaseErrorInfo(); } result.Error.BuildException(ex); } return(result); }
public static BaseResultInfo FileToDB(string fileName, LOGTYPE logType, bool isUnified) { List <string> file = LogReader.LogFileReader.ReadFile(fileName); if (isUnified) { file = LogReader.LogFileReader.UnifiedLogLines(file); } List <LogItem> items = LogReader.LogFileReader.LinesToLogs(file.ToArray(), logType); LogItemRepository repository = new LogItemRepository(); BaseResultInfo res = repository.InsertLogItem(items); return(res); }
public void TEST_JOIN_LOGINS_WITH_LENGTH() { DateTime start = DateTime.Now.AddHours(-DateTime.Now.Hour).AddMinutes(-DateTime.Now.Minute);; DateTime end = DateTime.Now; BaseResultInfo res = TestDataHelper.GetLogins(start, end); List <LogItem> items = res.GetResult <List <LogItem> >(); BaseResultInfo resLength = TestDataHelper.GetLoginsLength(start, end); List <LoginLengthInfo> itemsLength = resLength.GetResult <List <LoginLengthInfo> >(); var list = from a in items join b in itemsLength on a.SiteId equals b.SiteId where a.AccountId != -23 select new { a.SiteId, a.AccountId, a.Message, b.StartDate, b.EndDate, b.Length }; int v = list.Count(); Assert.IsTrue(res != null); }
public static List <LoginLengthGridData> GetLoginsUsers(DateTime start, DateTime end) { BaseResultInfo res = DataHelper.GetLogins(start, end); List <LogItem> items = res.GetResult <List <LogItem> >(); BaseResultInfo resLength = DataHelper.GetLoginsLength(start, end); List <LoginLengthInfo> itemsLength = resLength.GetResult <List <LoginLengthInfo> >(); List <LoginLengthGridData> resData = new List <LoginLengthGridData>(); if (items != null) { resData = (from a in items join b in itemsLength on a.SiteId equals b.SiteId where a.AccountId != -23 select new LoginLengthGridData() { SiteId = a.SiteId, AccountId = a.AccountId, Message = a.Message, StartDate = b.StartDate, EndDate = b.EndDate, Length = b.Length }).ToList(); } return(resData); }
private void M_ImeiController_ProofLicenseEvent(object sender, EventArgs e) { this.Invoke(new MethodInvoker(delegate() { if (e != null) { string content = sender.ToString(); BaseResultInfo <string> result = JsonHelper.JSONToObject <BaseResultInfo <string> >(content); if (result.status == 10000) { MessageBox.Show(this, "MEI已被注册", "提示"); //this.DialogResult = DialogResult.OK; } else if (result.status == 60001) { MessageBox.Show(this, "IMEI不存在/未被注册", "提示"); } else if (result.status == 60002) { MessageBox.Show(this, "IMEI已经过期 ", "提示"); } else if (result.status == 60003) { MessageBox.Show(this, "IMEI已注销 ", "提示"); } else { MessageBox.Show(this, result.msg, "提示"); } } else { MessageBox.Show(this, sender.ToString(), "提示"); } })); }
public BaseResultInfo GetLoginsLength(DateTime start, DateTime?end) { BaseResultInfo result = new BaseResultInfo(); SqlParameterList commandParams = new SqlParameterList(); commandParams.Add("@StartDate", SqlDbType.DateTime, start); commandParams.Add("@EndDate", SqlDbType.DateTime, end); List <LoginLengthInfo> items = new List <LoginLengthInfo>(); try { using (SqlConnection conn = new SqlConnection(base.ConnectionString)) { using (SqlDataReader dr = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, SQL_GET_LOGINS_LENGTH, commandParams.ToArray())) { while (dr.Read()) { LoginLengthInfo a = Serializer.DeSerialize <LoginLengthInfo>(dr); items.Add(a); } result.ResultObject = items; } } } catch (Exception ex) { if (result.Error == null) { result.Error = new BaseErrorInfo(); } result.Error.BuildException(ex); } return(result); }
private void btnGetUniq_Click(object sender, EventArgs e) { DateTime start = dtStart.Value; DateTime end = dtEnd.Value; BaseResultInfo res = DataHelper.GetLogins(start, end); List <LogItem> items = res.GetResult <List <LogItem> >(); BaseResultInfo resLength = DataHelper.GetLoginsLength(start, end); List <LoginLengthInfo> itemsLength = resLength.GetResult <List <LoginLengthInfo> >(); if (items != null) { var clearItems = (from a in items where a.AccountId != -23 orderby a.AccountId select new LoginGridData { InsertDate = a.InsertDate, AccountId = a.AccountId, SiteId = a.SiteId, Message = a.Message }).ToList(); lblResult.Text = "NUMBER OF ITEMS {0}".StringFormat(clearItems.Count); dgGrid.DataSource = clearItems; dgGrid.Update(); } }
protected void ExecutePost( Dictionary <string, object> parameterDict, EventHandler <ServiceEventArgs> callbackFunc, Dictionary <string, object> fileDict = null, Dictionary <string, string> headerDict = null, object entity = null) { Task task = Task.Factory.StartNew(() => { bool iss = false; string content = ""; BaseResultInfo <object> result = null; try { content = RestSharpHelper.HttpPost(this.m_Url, this.m_Resource, parameterDict, out iss, fileDict, headerDict, entity); result = JsonHelper.JSONToObject <BaseResultInfo <object> >(content); if (callbackFunc != null) { if (result != null) { callbackFunc(this, new ServiceEventArgs(content, result.status == 10000) { OriginObject = entity, Message = result.msg, ResponseObject = result }); } else { callbackFunc(this, new ServiceEventArgs(content, false) { OriginObject = entity, Message = "解析json(BaseResultInfo<object>)失败!", }); } } } catch (Exception ex) { if (callbackFunc != null) { if (result != null) { callbackFunc(this, new ServiceEventArgs(content, result.status == 10000) { OriginObject = entity, Message = string.Format("Response:{0}\r\n{1}\r\n{2}", content, ex.Message, ex.StackTrace), ResponseObject = result }); } else { callbackFunc(this, new ServiceEventArgs(content, false) { OriginObject = entity, Message = string.Format("Response:{0}\r\n{1}\r\n{2}", content, ex.Message, ex.StackTrace), }); } } } }); }
public void TEST_GET_LAST_ITEM() { BaseResultInfo res = TestDataHelper.GetLastItem(LOGTYPE.DBTrace, null); Assert.IsTrue(res != null); }