mirror of https://github.com/Squidex/squidex.git
30 changed files with 361 additions and 43 deletions
@ -0,0 +1,51 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Squidex.Infrastructure; |
|||
|
|||
namespace Squidex.Domain.Apps.Core.Rules.Actions |
|||
{ |
|||
[TypeName(nameof(AzureQueueAction))] |
|||
public sealed class AzureQueueAction : RuleAction |
|||
{ |
|||
private string connectionString; |
|||
private string queue; |
|||
|
|||
public string ConnectionString |
|||
{ |
|||
get |
|||
{ |
|||
return connectionString; |
|||
} |
|||
set |
|||
{ |
|||
ThrowIfFrozen(); |
|||
|
|||
connectionString = value; |
|||
} |
|||
} |
|||
|
|||
public string Queue |
|||
{ |
|||
get |
|||
{ |
|||
return queue; |
|||
} |
|||
set |
|||
{ |
|||
ThrowIfFrozen(); |
|||
|
|||
queue = value; |
|||
} |
|||
} |
|||
|
|||
public override T Accept<T>(IRuleActionVisitor<T> visitor) |
|||
{ |
|||
return visitor.Visit(this); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,72 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Collections.Concurrent; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.WindowsAzure.Storage; |
|||
using Microsoft.WindowsAzure.Storage.Queue; |
|||
using Newtonsoft.Json; |
|||
using Newtonsoft.Json.Linq; |
|||
using Squidex.Domain.Apps.Core.Rules; |
|||
using Squidex.Domain.Apps.Core.Rules.Actions; |
|||
using Squidex.Domain.Apps.Events; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.EventSourcing; |
|||
|
|||
namespace Squidex.Domain.Apps.Core.HandleRules.Actions |
|||
{ |
|||
public sealed class AzureQueueActionHandler : RuleActionHandler<AzureQueueAction> |
|||
{ |
|||
private readonly ConcurrentDictionary<(string ConnectionString, string QueueName), CloudQueue> queues = new ConcurrentDictionary<(string ConnectionString, string QueueName), CloudQueue>(); |
|||
private readonly RuleEventFormatter formatter; |
|||
|
|||
public AzureQueueActionHandler(RuleEventFormatter formatter) |
|||
{ |
|||
Guard.NotNull(formatter, nameof(formatter)); |
|||
|
|||
this.formatter = formatter; |
|||
} |
|||
|
|||
protected override (string Description, RuleJobData Data) CreateJob(Envelope<AppEvent> @event, string eventName, AzureQueueAction action) |
|||
{ |
|||
var body = formatter.ToRouteData(@event, eventName); |
|||
|
|||
var ruleDescription = $"Send event to azure queue '{action.Queue}'"; |
|||
var ruleData = new RuleJobData |
|||
{ |
|||
["QueueConnectionString"] = action.ConnectionString, |
|||
["QueueName"] = action.Queue, |
|||
["MessageBody"] = body |
|||
}; |
|||
|
|||
return (ruleDescription, ruleData); |
|||
} |
|||
|
|||
public override async Task<(string Dump, Exception Exception)> ExecuteJobAsync(RuleJobData job) |
|||
{ |
|||
var queueConnectionString = job["QueueConnectionString"].Value<string>(); |
|||
var queueName = job["QueueName"].Value<string>(); |
|||
|
|||
var queue = queues.GetOrAdd((queueConnectionString, queueName), s => |
|||
{ |
|||
var storageAccount = CloudStorageAccount.Parse(queueConnectionString); |
|||
|
|||
var queueClient = storageAccount.CreateCloudQueueClient(); |
|||
var queueRef = queueClient.GetQueueReference(queueName); |
|||
|
|||
return queueRef; |
|||
}); |
|||
|
|||
var messageBody = job["MessageBody"].ToString(Formatting.Indented); |
|||
|
|||
await queue.AddMessageAsync(new CloudQueueMessage(messageBody)); |
|||
|
|||
return ("Completed", null); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System.ComponentModel.DataAnnotations; |
|||
using NJsonSchema.Annotations; |
|||
using Squidex.Domain.Apps.Core.Rules; |
|||
using Squidex.Domain.Apps.Core.Rules.Actions; |
|||
using Squidex.Infrastructure.Reflection; |
|||
|
|||
namespace Squidex.Areas.Api.Controllers.Rules.Models.Actions |
|||
{ |
|||
[JsonSchema("AzureQueue")] |
|||
public class AzureQueueActionDto : RuleActionDto |
|||
{ |
|||
/// <summary>
|
|||
/// The connection string to the storage account.
|
|||
/// </summary>
|
|||
[Required] |
|||
public string ConnectionString { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// The queue name.
|
|||
/// </summary>
|
|||
[Required] |
|||
public string Queue { get; set; } |
|||
|
|||
public override RuleAction ToAction() |
|||
{ |
|||
return SimpleMapper.Map(this, new AzureQueueAction()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
<form [formGroup]="actionForm" class="form-horizontal" (ngSubmit)="save()"> |
|||
<div class="form-group row"> |
|||
<label class="col col-3 col-form-label" for="queue">Connection String</label> |
|||
|
|||
<div class="col col-9"> |
|||
<sqx-control-errors for="text" [submitted]="actionFormSubmitted"></sqx-control-errors> |
|||
|
|||
<input type="text" class="form-control" id="connectionString" formControlName="connectionString" /> |
|||
|
|||
<small class="form-text text-muted"> |
|||
The connection string to the storage account. |
|||
</small> |
|||
</div> |
|||
</div> |
|||
|
|||
<div class="form-group row"> |
|||
<label class="col col-3 col-form-label" for="queue">Queue Name</label> |
|||
|
|||
<div class="col col-9"> |
|||
<sqx-control-errors for="queue" [submitted]="actionFormSubmitted"></sqx-control-errors> |
|||
|
|||
<input type="text" class="form-control" id="queue" formControlName="queue" /> |
|||
|
|||
<small class="form-text text-muted"> |
|||
The name of the queue. |
|||
</small> |
|||
</div> |
|||
</div> |
|||
</form> |
|||
@ -0,0 +1,2 @@ |
|||
@import '_vars'; |
|||
@import '_mixins'; |
|||
@ -0,0 +1,61 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|||
*/ |
|||
|
|||
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; |
|||
import { FormBuilder, Validators } from '@angular/forms'; |
|||
|
|||
import { ValidatorsEx } from 'shared'; |
|||
|
|||
@Component({ |
|||
selector: 'sqx-azure-queue-action', |
|||
styleUrls: ['./azure-queue-action.component.scss'], |
|||
templateUrl: './azure-queue-action.component.html' |
|||
}) |
|||
export class AzureQueueActionComponent implements OnInit { |
|||
@Input() |
|||
public action: any; |
|||
|
|||
@Output() |
|||
public actionChanged = new EventEmitter<object>(); |
|||
|
|||
public actionFormSubmitted = false; |
|||
public actionForm = |
|||
this.formBuilder.group({ |
|||
connectionString: ['', |
|||
[ |
|||
Validators.required |
|||
]], |
|||
queue: ['squidex', |
|||
[ |
|||
Validators.required, |
|||
ValidatorsEx.pattern('[a-z][a-z0-9]{2,}(\-[a-z0-9]+)*', 'Name must be a valid azure queue name.') |
|||
]] |
|||
}); |
|||
|
|||
constructor( |
|||
private readonly formBuilder: FormBuilder |
|||
) { |
|||
} |
|||
|
|||
public ngOnInit() { |
|||
this.action = Object.assign({}, { connectionString: '', queue: 'squidex' }, this.action || {}); |
|||
|
|||
this.actionFormSubmitted = false; |
|||
this.actionForm.reset(); |
|||
this.actionForm.setValue(this.action); |
|||
} |
|||
|
|||
public save() { |
|||
this.actionFormSubmitted = true; |
|||
|
|||
if (this.actionForm.valid) { |
|||
const action = this.actionForm.value; |
|||
|
|||
this.actionChanged.emit(action); |
|||
} |
|||
} |
|||
} |
|||
Binary file not shown.
|
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 69 KiB |
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue