/// <summary> /// Get page log model /// </summary> /// <param name="id"></param> /// <param name="total"> </param> /// <param name="index"></param> /// <returns></returns> public TemplateLogListingModel GetLogs(int id, int total = 0, int index = 1) { var pageSize = _settingServices.GetSetting <int>(SettingNames.LogsPageSize); var template = GetById(id); if (template != null) { var logs = template.TemplateLogs.OrderByDescending(l => l.Created) .GroupBy(l => l.SessionId) .Skip((index - 1) * pageSize) .Take(pageSize) .ToList() .Select(l => new TemplateLogsModel { SessionId = l.First().SessionId, Creator = _userServices.GetUser(l.First().CreatedBy), From = l.Last().Created, To = l.First().Created, Total = l.Count(), Logs = l.Select(i => new TemplateLogItem(i)).ToList() }).ToList(); total = total + logs.Sum(l => l.Logs.Count); var model = new TemplateLogListingModel { Id = template.Id, Name = template.Name, Total = total, Logs = logs, LoadComplete = total == template.TemplateLogs.Count }; return(model); } return(null); }
/// <summary> /// Get history request for current user /// </summary> /// <param name="index"></param> /// <param name="pageSize"></param> /// <returns></returns> public IEnumerable <SQLCommandHistoryModel> GetHistories(int?index, int?pageSize) { if (!index.HasValue) { index = _settingServices.GetSetting <int>(SettingNames.DefaultHistoryLength); } if (!pageSize.HasValue) { pageSize = _settingServices.GetSetting <int>(SettingNames.DefaultHistoryStart); } var username = HttpContext.Current.User.Identity.Name; return(Fetch(i => i.CreatedBy.Equals(username)) .OrderByDescending(i => i.Created) .Skip(index.Value) .Take(pageSize.Value) .Select( i => new SQLCommandHistoryModel { Id = i.Id, Query = i.Query, CreatedBy = i.CreatedBy })); }
public T SValue <T>(string key) { return(_settingServices.GetSetting <T>(key)); }
/// <summary> /// Executing a SQL query against current DB /// </summary> /// <param name="request"></param> /// <returns></returns> public SQLResult Execute(SQLRequest request) { //save executing query into history if (request.SaveToHistory) { _sqlCommandServices.SaveCommand(request); } //Prepare the result object based on basic information from request var result = new SQLResult { ConnectionString = _connection.ConnectionString, Query = request.Query, ReadOnly = request.ReadOnly, HtmlEncode = request.HtmlEncode }; var returnData = new List <DataResult>(); var startTime = DateTime.Now.Ticks; IDbTransaction transaction = null; bool openConnection = false; try { //open connection if needed if (_connection.State != ConnectionState.Open) { _connection.Open(); openConnection = true; } IDbCommand command = _connection.CreateCommand(); command.CommandText = request.Query; command.CommandType = CommandType.Text; //if executing in read only, we put all SQL statement into a DB transaction //then roll back after then if (request.ReadOnly) { transaction = _connection.BeginTransaction(); command.Transaction = transaction; } //Excuting and parse result IDataReader reader = command.ExecuteReader(); if (reader != null) { do { DataResult dataResult = getResult(reader); if (dataResult != null) { returnData.Add(dataResult); } } while (reader.NextResult()); result.RecordsAffected = reader.RecordsAffected; } } catch (Exception ex) { result.Error = ex; } finally { //Roll back transaction if needed if (transaction != null) { try { transaction.Rollback(); } catch { } } //Close connection if it was opened by us if (openConnection) { try { _connection.Close(); } catch { } } } //Other properties for resutl object result.Tables = GetTableNames(); long endTime = DateTime.Now.Ticks; result.ReturnData = returnData; result.ProcessTime = (long)new TimeSpan(endTime - startTime).TotalMilliseconds; var defaultHistoryLength = _settingServices.GetSetting <int>(SettingNames.DefaultHistoryLength); var defaultHistoryStart = _settingServices.GetSetting <int>(SettingNames.DefaultHistoryStart); result.Histories = _sqlCommandServices.GetHistories(defaultHistoryStart, defaultHistoryLength); return(result); }
/// <summary> /// Replace all curly bracket in the content /// </summary> /// <param name="content"></param> /// <returns></returns> public string Render(string content) { var maxLoop = _settingServices.GetSetting <int>(SettingNames.CurlyBracketMaxLoop); return(CurlyBracketRenderer.ResolverContent(content, maxLoop)); }