12 changed files with 267 additions and 10 deletions
@ -0,0 +1,16 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<Import Project="..\..\..\configureawait.props" /> |
||||
|
<Import Project="..\..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netstandard2.0</TargetFramework> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\LINGYUN.Abp.WebhooksManagement.HttpApi.Client\LINGYUN.Abp.WebhooksManagement.HttpApi.Client.csproj" /> |
||||
|
<ProjectReference Include="..\LINGYUN.Abp.Webhooks\LINGYUN.Abp.Webhooks.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,10 @@ |
|||||
|
using LINGYUN.Abp.WebhooksManagement; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Webhooks.ClientProxies; |
||||
|
|
||||
|
[DependsOn(typeof(AbpWebhooksModule))] |
||||
|
[DependsOn(typeof(WebhooksManagementHttpApiClientModule))] |
||||
|
public class AbpWebHooksClientProxiesModule : AbpModule |
||||
|
{ |
||||
|
} |
||||
@ -0,0 +1,91 @@ |
|||||
|
using LINGYUN.Abp.WebhooksManagement; |
||||
|
using Newtonsoft.Json; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Webhooks.ClientProxies; |
||||
|
|
||||
|
[Dependency(ReplaceServices = true)] |
||||
|
public class ClientProxiesWebhookPublisher : IWebhookPublisher, ITransientDependency |
||||
|
{ |
||||
|
protected IWebhooksPublishAppService PublishAppService { get; } |
||||
|
|
||||
|
public ClientProxiesWebhookPublisher( |
||||
|
IWebhooksPublishAppService publishAppService) |
||||
|
{ |
||||
|
PublishAppService = publishAppService; |
||||
|
} |
||||
|
|
||||
|
public async virtual Task PublishAsync(string webhookName, object data, bool sendExactSameData = false, WebhookHeader headers = null) |
||||
|
{ |
||||
|
var input = new WebhooksPublishInput |
||||
|
{ |
||||
|
WebhookName = webhookName, |
||||
|
Data = JsonConvert.SerializeObject(data), |
||||
|
SendExactSameData = sendExactSameData, |
||||
|
}; |
||||
|
if (headers != null) |
||||
|
{ |
||||
|
input.Header = new WebhooksHeaderInput |
||||
|
{ |
||||
|
UseOnlyGivenHeaders = headers.UseOnlyGivenHeaders, |
||||
|
Headers = headers.Headers |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
await PublishAsync(input); |
||||
|
} |
||||
|
|
||||
|
public async virtual Task PublishAsync(string webhookName, object data, Guid? tenantId, bool sendExactSameData = false, WebhookHeader headers = null) |
||||
|
{ |
||||
|
var input = new WebhooksPublishInput |
||||
|
{ |
||||
|
WebhookName = webhookName, |
||||
|
Data = JsonConvert.SerializeObject(data), |
||||
|
SendExactSameData = sendExactSameData, |
||||
|
TenantIds = new List<Guid?> |
||||
|
{ |
||||
|
tenantId |
||||
|
}, |
||||
|
}; |
||||
|
if (headers != null) |
||||
|
{ |
||||
|
input.Header = new WebhooksHeaderInput |
||||
|
{ |
||||
|
UseOnlyGivenHeaders = headers.UseOnlyGivenHeaders, |
||||
|
Headers = headers.Headers |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
await PublishAsync(input); |
||||
|
} |
||||
|
|
||||
|
public async virtual Task PublishAsync(Guid?[] tenantIds, string webhookName, object data, bool sendExactSameData = false, WebhookHeader headers = null) |
||||
|
{ |
||||
|
var input = new WebhooksPublishInput |
||||
|
{ |
||||
|
WebhookName = webhookName, |
||||
|
Data = JsonConvert.SerializeObject(data), |
||||
|
SendExactSameData = sendExactSameData, |
||||
|
TenantIds = tenantIds.ToList(), |
||||
|
}; |
||||
|
if (headers != null) |
||||
|
{ |
||||
|
input.Header = new WebhooksHeaderInput |
||||
|
{ |
||||
|
UseOnlyGivenHeaders = headers.UseOnlyGivenHeaders, |
||||
|
Headers = headers.Headers |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
await PublishAsync(input); |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task PublishAsync(WebhooksPublishInput input) |
||||
|
{ |
||||
|
await PublishAppService.PublishAsync(input); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
|
||||
|
namespace LINGYUN.Abp.WebhooksManagement; |
||||
|
|
||||
|
public interface IWebhooksPublishAppService : IApplicationService |
||||
|
{ |
||||
|
Task PublishAsync(WebhooksPublishInput input); |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using Volo.Abp.Validation; |
||||
|
|
||||
|
namespace LINGYUN.Abp.WebhooksManagement; |
||||
|
|
||||
|
public class WebhooksPublishInput |
||||
|
{ |
||||
|
[Required] |
||||
|
[DynamicStringLength(typeof(WebhookEventRecordConsts), nameof(WebhookEventRecordConsts.MaxWebhookNameLength))] |
||||
|
public string WebhookName { get; set; } |
||||
|
|
||||
|
[Required] |
||||
|
[DynamicStringLength(typeof(WebhookEventRecordConsts), nameof(WebhookEventRecordConsts.MaxDataLength))] |
||||
|
public string Data { get; set; } |
||||
|
|
||||
|
public bool SendExactSameData { get; set; } |
||||
|
|
||||
|
public WebhooksHeaderInput Header { get; set; } = new WebhooksHeaderInput(); |
||||
|
|
||||
|
public List<Guid?> TenantIds { get; set; } = new List<Guid?>(); |
||||
|
} |
||||
|
|
||||
|
public class WebhooksHeaderInput |
||||
|
{ |
||||
|
public bool UseOnlyGivenHeaders { get; set; } |
||||
|
|
||||
|
public IDictionary<string, string> Headers { get; set; } = new Dictionary<string, string>(); |
||||
|
} |
||||
@ -0,0 +1,45 @@ |
|||||
|
using LINGYUN.Abp.Webhooks; |
||||
|
using LINGYUN.Abp.WebhooksManagement.Authorization; |
||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Newtonsoft.Json; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace LINGYUN.Abp.WebhooksManagement; |
||||
|
|
||||
|
[Authorize(WebhooksManagementPermissions.Publish)] |
||||
|
public class WebhooksPublishAppService : WebhooksManagementAppServiceBase, IWebhooksPublishAppService |
||||
|
{ |
||||
|
protected IWebhookPublisher InnerPublisher { get; } |
||||
|
|
||||
|
public WebhooksPublishAppService(IWebhookPublisher innerPublisher) |
||||
|
{ |
||||
|
InnerPublisher = innerPublisher; |
||||
|
} |
||||
|
|
||||
|
public async virtual Task PublishAsync(WebhooksPublishInput input) |
||||
|
{ |
||||
|
var webhookHeader = new WebhookHeader |
||||
|
{ |
||||
|
UseOnlyGivenHeaders = input.Header.UseOnlyGivenHeaders, |
||||
|
Headers = input.Header.Headers, |
||||
|
}; |
||||
|
var inputData = JsonConvert.DeserializeObject(input.Data); |
||||
|
|
||||
|
if (input.TenantIds.Any()) |
||||
|
{ |
||||
|
await InnerPublisher.PublishAsync( |
||||
|
input.TenantIds.ToArray(), |
||||
|
input.WebhookName, |
||||
|
inputData, |
||||
|
input.SendExactSameData, |
||||
|
webhookHeader); |
||||
|
return; |
||||
|
} |
||||
|
await InnerPublisher.PublishAsync( |
||||
|
input.WebhookName, |
||||
|
inputData, |
||||
|
input.SendExactSameData, |
||||
|
webhookHeader); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
using LINGYUN.Abp.WebhooksManagement.Authorization; |
||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp; |
||||
|
|
||||
|
namespace LINGYUN.Abp.WebhooksManagement; |
||||
|
|
||||
|
[RemoteService(Name = WebhooksManagementRemoteServiceConsts.RemoteServiceName)] |
||||
|
[Area(WebhooksManagementRemoteServiceConsts.ModuleName)] |
||||
|
[Authorize(WebhooksManagementPermissions.Publish)] |
||||
|
[Route("api/webhooks/publish")] |
||||
|
public class WebhooksPublishController : WebhooksManagementControllerBase, IWebhooksPublishAppService |
||||
|
{ |
||||
|
protected IWebhooksPublishAppService PublishAppService { get; } |
||||
|
|
||||
|
public WebhooksPublishController(IWebhooksPublishAppService publishAppService) |
||||
|
{ |
||||
|
PublishAppService = publishAppService; |
||||
|
} |
||||
|
|
||||
|
[HttpPost] |
||||
|
public virtual Task PublishAsync(WebhooksPublishInput input) |
||||
|
{ |
||||
|
return PublishAppService.PublishAsync(input); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue