示例#1
0
        public async Task <HttpTrackerResponse <PagedList <HttpTrackerLogDto> > > QueryAsync(QueryInput input)
        {
            var response = new HttpTrackerResponse <PagedList <HttpTrackerLogDto> >();

            var collection = Database.GetCollection <HttpTrackerLog>(CollectionName);

            var query = collection.AsQueryable();

            if (!string.IsNullOrEmpty(input.Type))
            {
                query = query.Where(x => x.Type.Contains(input.Type));
            }
            if (!string.IsNullOrEmpty(input.Keyword))
            {
                query = query.Where(x => x.Description.Contains(input.Keyword));
            }

            var total = await query.CountAsync();

            var list = await query.OrderByDescending(x => x.CreationTime)
                       .Skip((input.Page - 1) * input.Limit)
                       .Take(input.Limit)
                       .Select(x => new HttpTrackerLogDto
            {
                Type        = x.Type,
                Description = x.Description,
                Request     = new RequestInfo
                {
                    UserAgent    = x.UserAgent,
                    Method       = x.Method,
                    Url          = x.Url,
                    Referrer     = x.Referrer,
                    IpAddress    = x.IpAddress,
                    Milliseconds = x.Milliseconds,
                    RequestBody  = x.RequestBody,
                    Cookies      = x.Cookies,
                    Headers      = x.Headers
                },
                Response = new ResponseInfo
                {
                    StatusCode   = x.StatusCode,
                    ResponseBody = x.ResponseBody
                },
                Server = new ServerInfo
                {
                    ServerName = x.ServerName,
                    PId        = x.PId,
                    Host       = x.Host,
                    Port       = x.Port
                },
                Exception = new ExceptionInfo
                {
                    ExceptionType = x.ExceptionType,
                    Message       = x.Message,
                    StackTrace    = x.StackTrace
                },
                CreationTime = x.CreationTime
            }).ToListAsync();

            response.IsSuccess(new PagedList <HttpTrackerLogDto>(total, list));
            return(response);
        }
示例#2
0
        public async Task <HttpTrackerResponse <PagedList <HttpTrackerLogDto> > > QueryAsync(QueryInput input)
        {
            var response = new HttpTrackerResponse <PagedList <HttpTrackerLogDto> >();

            var builder = new StringBuilder();

            if (!string.IsNullOrEmpty(input.Type))
            {
                builder.Append($" AND Type LIKE @Type");

                input.Type = $"%{input.Type}%";
            }
            if (!string.IsNullOrEmpty(input.Keyword))
            {
                builder.Append($" AND Description LIKE @Keyword");

                input.Keyword = $"%{input.Keyword}%";
            }

            var where = builder.ToString();

            var sql = $@"SELECT COUNT(1) FROM {TableName} WHERE 1 = 1 {where};
                         SELECT Type, Description, UserAgent, Method, Url , Referrer, IpAddress, Milliseconds, QueryString, RequestBody , Cookies, Headers, StatusCode, ResponseBody, ServerName , PId, Host, Port, ExceptionType, Message , StackTrace, CreationTime FROM {TableName} WHERE 1 = 1 ORDER BY CreationTime DESC LIMIT @page,@limit";

            using var conn = _dbConnectionProvider.Connection;

            input.Page = (input.Page - 1) * input.Limit;

            var query = await conn.QueryMultipleAsync(sql, input);

            var total = await query.ReadFirstOrDefaultAsync <long>();

            var logs = await query.ReadAsync <HttpTrackerLog>();

            var list = logs.Select(x => new HttpTrackerLogDto
            {
                Type        = x.Type,
                Description = x.Description,
                Request     = new RequestInfo
                {
                    UserAgent    = x.UserAgent,
                    Method       = x.Method,
                    Url          = x.Url,
                    Referrer     = x.Referrer,
                    IpAddress    = x.IpAddress,
                    Milliseconds = x.Milliseconds,
                    RequestBody  = x.RequestBody,
                    Cookies      = x.Cookies,
                    Headers      = x.Headers
                },
                Response = new ResponseInfo
                {
                    StatusCode   = x.StatusCode,
                    ResponseBody = x.ResponseBody
                },
                Server = new ServerInfo
                {
                    ServerName = x.ServerName,
                    PId        = x.PId,
                    Host       = x.Host,
                    Port       = x.Port
                },
                Exception = new ExceptionInfo
                {
                    ExceptionType = x.ExceptionType,
                    Message       = x.Message,
                    StackTrace    = x.StackTrace
                },
                CreationTime = x.CreationTime
            }).ToList();

            response.IsSuccess(new PagedList <HttpTrackerLogDto>(Convert.ToInt32(total), list));
            return(response);
        }
示例#3
0
        public async Task <HttpTrackerResponse <PagedList <HttpTrackerLogDto> > > QueryAsync(QueryInput input)
        {
            var response = new HttpTrackerResponse <PagedList <HttpTrackerLogDto> >();

            var query = new List <QueryContainer>();

            if (!string.IsNullOrEmpty(input.Type))
            {
                query.Add(new MatchPhraseQuery
                {
                    Field = new Field("type"),
                    Query = input.Type
                });
            }
            if (!string.IsNullOrEmpty(input.Keyword))
            {
                query.Add(new MatchPhraseQuery
                {
                    Field = new Field("description"),
                    Query = input.Keyword
                });
            }

            var searchResponse = await Client.SearchAsync <HttpTrackerLog>(x => x.Index(IndexName)
                                                                           .From((input.Page - 1) * input.Limit)
                                                                           .Size(input.Limit)
                                                                           .Query(x => x.Bool(x => x.Should(query.ToArray())))
                                                                           .Sort(s => s.Descending(x => x.CreationTime)));

            var total = Convert.ToInt32(searchResponse.Total);
            var list  = searchResponse.Documents
                        .Select(x => new HttpTrackerLogDto
            {
                Type        = x.Type,
                Description = x.Description,
                Request     = new RequestInfo
                {
                    UserAgent    = x.UserAgent,
                    Method       = x.Method,
                    Url          = x.Url,
                    Referrer     = x.Referrer,
                    IpAddress    = x.IpAddress,
                    Milliseconds = x.Milliseconds,
                    RequestBody  = x.RequestBody,
                    Cookies      = x.Cookies,
                    Headers      = x.Headers
                },
                Response = new ResponseInfo
                {
                    StatusCode   = x.StatusCode,
                    ResponseBody = x.ResponseBody
                },
                Server = new ServerInfo
                {
                    ServerName = x.ServerName,
                    PId        = x.PId,
                    Host       = x.Host,
                    Port       = x.Port
                },
                Exception = new ExceptionInfo
                {
                    ExceptionType = x.ExceptionType,
                    Message       = x.Message,
                    StackTrace    = x.StackTrace
                },
                CreationTime = x.CreationTime
            }).ToList();

            response.IsSuccess(new PagedList <HttpTrackerLogDto>(total, list));
            return(response);
        }