2019-03-16 20:24:33 +08:00
|
|
|
|
using Longbow.Data;
|
2019-04-08 16:01:40 +08:00
|
|
|
|
using Longbow.Web;
|
2019-03-16 20:24:33 +08:00
|
|
|
|
using Longbow.Web.Mvc;
|
2019-04-08 16:01:40 +08:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2019-03-16 20:24:33 +08:00
|
|
|
|
using PetaPoco;
|
|
|
|
|
using System;
|
2019-05-25 14:52:14 +08:00
|
|
|
|
using System.Collections.Generic;
|
2019-03-16 20:24:33 +08:00
|
|
|
|
|
|
|
|
|
namespace Bootstrap.DataAccess
|
|
|
|
|
{
|
|
|
|
|
public static class TraceHelper
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存访问历史记录
|
|
|
|
|
/// </summary>
|
2019-04-08 16:01:40 +08:00
|
|
|
|
/// <param name="context"></param>
|
|
|
|
|
/// <param name="v"></param>
|
|
|
|
|
public static void Save(HttpContext context, OnlineUser v)
|
|
|
|
|
{
|
|
|
|
|
if (context.User.Identity.IsAuthenticated)
|
|
|
|
|
{
|
|
|
|
|
var user = UserHelper.RetrieveUserByUserName(context.User.Identity.Name);
|
|
|
|
|
v.UserName = user.UserName;
|
|
|
|
|
v.DisplayName = user.DisplayName;
|
|
|
|
|
DbContextManager.Create<Trace>().Save(new Trace
|
|
|
|
|
{
|
|
|
|
|
Ip = v.Ip,
|
|
|
|
|
RequestUrl = v.RequestUrl,
|
|
|
|
|
LogTime = v.LastAccessTime,
|
|
|
|
|
City = v.Location,
|
|
|
|
|
Browser = v.Browser,
|
|
|
|
|
OS = v.OS,
|
2019-04-27 20:39:24 +08:00
|
|
|
|
UserName = v.UserName,
|
|
|
|
|
UserAgent = v.UserAgent
|
2019-04-08 16:01:40 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-16 20:24:33 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获得指定IP历史访问记录
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="po"></param>
|
|
|
|
|
/// <param name="startTime"></param>
|
|
|
|
|
/// <param name="endTime"></param>
|
2019-05-04 17:13:29 +08:00
|
|
|
|
/// <param name="ip"></param>
|
2019-03-16 20:24:33 +08:00
|
|
|
|
/// <returns></returns>
|
2019-05-25 14:52:14 +08:00
|
|
|
|
public static Page<Trace> Retrieves(PaginationOption po, DateTime? startTime, DateTime? endTime, string ip) => DbContextManager.Create<Trace>().RetrievePages(po, startTime, endTime, ip);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获得指定IP历史访问记录
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="startTime"></param>
|
|
|
|
|
/// <param name="endTime"></param>
|
|
|
|
|
/// <param name="ip"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static IEnumerable<Trace> RetrieveAll(DateTime? startTime, DateTime? endTime, string ip) => DbContextManager.Create<Trace>().RetrieveAll(startTime, endTime, ip);
|
2019-03-16 20:24:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|