mirror of https://github.com/abpframework/abp.git
10 changed files with 106 additions and 69 deletions
@ -0,0 +1,17 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.Auditing |
|||
{ |
|||
public class AuditInfoContributionContext : IAuditInfoContributionContext |
|||
{ |
|||
public IServiceProvider ServiceProvider { get; } |
|||
|
|||
public AuditInfo AuditInfo { get; set; } |
|||
|
|||
public AuditInfoContributionContext(IServiceProvider serviceProvider, AuditInfo auditInfo) |
|||
{ |
|||
ServiceProvider = serviceProvider; |
|||
AuditInfo = auditInfo; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.Auditing |
|||
{ |
|||
public class ClientInfoAuditInfoContributor : IAuditInfoContributor |
|||
{ |
|||
public Task Contribute(IAuditInfoContributionContext context) |
|||
{ |
|||
var clientInfoProvider = context.ServiceProvider.GetRequiredService<IClientInfoProvider>(); |
|||
|
|||
if (context.AuditInfo.ClientIpAddress.IsNullOrEmpty()) |
|||
{ |
|||
context.AuditInfo.ClientIpAddress = clientInfoProvider.ClientIpAddress; |
|||
} |
|||
|
|||
if (context.AuditInfo.BrowserInfo.IsNullOrEmpty()) |
|||
{ |
|||
context.AuditInfo.BrowserInfo = clientInfoProvider.BrowserInfo; |
|||
} |
|||
|
|||
if (context.AuditInfo.ClientName.IsNullOrEmpty()) |
|||
{ |
|||
context.AuditInfo.ClientName = clientInfoProvider.ComputerName; |
|||
} |
|||
|
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
} |
|||
@ -1,38 +0,0 @@ |
|||
using System; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.Auditing |
|||
{ |
|||
//TODO: Implement as multiple providers can contribute!
|
|||
|
|||
/// <summary>
|
|||
/// Default implementation of <see cref="IAuditInfoProvider" />.
|
|||
/// </summary>
|
|||
public class DefaultAuditInfoProvider : IAuditInfoProvider, ITransientDependency |
|||
{ |
|||
protected IClientInfoProvider ClientInfoProvider { get; } |
|||
|
|||
public DefaultAuditInfoProvider(IClientInfoProvider clientInfoProvider) |
|||
{ |
|||
ClientInfoProvider = clientInfoProvider; |
|||
} |
|||
|
|||
public virtual void Fill(AuditInfo auditInfo) |
|||
{ |
|||
if (auditInfo.ClientIpAddress.IsNullOrEmpty()) |
|||
{ |
|||
auditInfo.ClientIpAddress = ClientInfoProvider.ClientIpAddress; |
|||
} |
|||
|
|||
if (auditInfo.BrowserInfo.IsNullOrEmpty()) |
|||
{ |
|||
auditInfo.BrowserInfo = ClientInfoProvider.BrowserInfo; |
|||
} |
|||
|
|||
if (auditInfo.ClientName.IsNullOrEmpty()) |
|||
{ |
|||
auditInfo.ClientName = ClientInfoProvider.ComputerName; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.Auditing |
|||
{ |
|||
public interface IAuditInfoContributionContext : IServiceProviderAccessor |
|||
{ |
|||
AuditInfo AuditInfo { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.Auditing |
|||
{ |
|||
public interface IAuditInfoContributor |
|||
{ |
|||
Task Contribute(IAuditInfoContributionContext context); |
|||
} |
|||
} |
|||
@ -1,14 +0,0 @@ |
|||
namespace Volo.Abp.Auditing |
|||
{ |
|||
/// <summary>
|
|||
/// Provides an interface to provide audit informations in the upper layers.
|
|||
/// </summary>
|
|||
public interface IAuditInfoProvider |
|||
{ |
|||
/// <summary>
|
|||
/// Called to fill needed properties.
|
|||
/// </summary>
|
|||
/// <param name="auditInfo">Audit info that is partially filled</param>
|
|||
void Fill(AuditInfo auditInfo); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue