-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
138 additions
and
113 deletions.
There are no files selected for viewing
215 changes: 103 additions & 112 deletions
215
...odule.Domain/Stores/EntityEventHandler.cs → ...Handlers/WorkflowDefinitionEventHander.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,112 +1,103 @@ | ||
using System.Threading.Tasks; | ||
using Elsa.Events; | ||
using MediatR; | ||
using Passingwind.Abp.ElsaModule.Common; | ||
using Volo.Abp.DependencyInjection; | ||
using Volo.Abp.Domain.Entities.Events; | ||
using Volo.Abp.EventBus; | ||
|
||
namespace Passingwind.Abp.ElsaModule.Stores | ||
{ | ||
public class EntityEventHandler : | ||
ILocalEventHandler<EntityCreatedEventData<WorkflowDefinitionVersion>>, | ||
ILocalEventHandler<EntityUpdatedEventData<WorkflowDefinitionVersion>>, | ||
ILocalEventHandler<EntityDeletedEventData<WorkflowDefinitionVersion>>, | ||
// | ||
ILocalEventHandler<EntityUpdatedEventData<WorkflowDefinition>>, | ||
// | ||
ILocalEventHandler<EntityDeletedEventData<WorkflowInstance>>, | ||
// | ||
ITransientDependency | ||
{ | ||
private readonly IMediator _mediator; | ||
private readonly IStoreMapper _storeMapper; | ||
private readonly IWorkflowDefinitionRepository _workflowDefinitionRepository; | ||
private readonly IWorkflowDefinitionVersionRepository _workflowDefinitionVersionRepository; | ||
|
||
public EntityEventHandler(IMediator mediator, IStoreMapper storeMapper, IWorkflowDefinitionRepository workflowDefinitionRepository, IWorkflowDefinitionVersionRepository workflowDefinitionVersionRepository) | ||
{ | ||
_mediator = mediator; | ||
_storeMapper = storeMapper; | ||
_workflowDefinitionRepository = workflowDefinitionRepository; | ||
_workflowDefinitionVersionRepository = workflowDefinitionVersionRepository; | ||
} | ||
|
||
public async Task HandleEventAsync(EntityCreatedEventData<WorkflowDefinitionVersion> eventData) | ||
{ | ||
var definitionId = eventData.Entity.DefinitionId; | ||
var definition = await _workflowDefinitionRepository.GetAsync(definitionId); | ||
|
||
var model = _storeMapper.MapToModel(eventData.Entity, definition); | ||
|
||
await _mediator.Publish(new WorkflowDefinitionSaved(model)); | ||
|
||
if (model.IsPublished) | ||
await _mediator.Publish(new WorkflowDefinitionPublished(model)); | ||
} | ||
|
||
public async Task HandleEventAsync(EntityUpdatedEventData<WorkflowDefinitionVersion> eventData) | ||
{ | ||
var definitionId = eventData.Entity.DefinitionId; | ||
var definition = await _workflowDefinitionRepository.GetAsync(definitionId); | ||
|
||
var model = _storeMapper.MapToModel(eventData.Entity, definition); | ||
|
||
await _mediator.Publish(new WorkflowDefinitionSaved(model)); | ||
|
||
if (model.IsPublished) | ||
await _mediator.Publish(new WorkflowDefinitionPublished(model)); | ||
else | ||
await _mediator.Publish(new WorkflowDefinitionRetracted(new Elsa.Models.WorkflowDefinition() { DefinitionId = definitionId.ToString(), Id = eventData.Entity.Id.ToString() })); | ||
} | ||
|
||
public async Task HandleEventAsync(EntityDeletedEventData<WorkflowDefinitionVersion> eventData) | ||
{ | ||
var definitionId = eventData.Entity.DefinitionId; | ||
var definition = new WorkflowDefinition(definitionId); | ||
|
||
var model = _storeMapper.MapToModel(eventData.Entity, definition); | ||
|
||
await _mediator.Publish(new WorkflowDefinitionDeleted(model)); | ||
} | ||
|
||
public async Task HandleEventAsync(EntityDeletedEventData<WorkflowInstance> eventData) | ||
{ | ||
var model = _storeMapper.MapToModel(eventData.Entity); | ||
|
||
await _mediator.Publish(new WorkflowInstanceDeleted(model)); | ||
} | ||
|
||
public async Task HandleEventAsync(EntityUpdatedEventData<WorkflowDefinition> eventData) | ||
{ | ||
var definition = eventData.Entity; | ||
var definitionId = definition.Id; | ||
|
||
// published version | ||
if (definition.PublishedVersion.HasValue) | ||
{ | ||
var publishVersion = definition.PublishedVersion.Value; | ||
var publishtVersionEntity = await _workflowDefinitionVersionRepository.GetByVersionAsync(definitionId, publishVersion); | ||
|
||
var publishModel = _storeMapper.MapToModel(publishtVersionEntity, definition); | ||
|
||
await _mediator.Publish(new WorkflowDefinitionSaved(publishModel)); | ||
await _mediator.Publish(new WorkflowDefinitionPublished(publishModel)); | ||
} | ||
else | ||
{ | ||
var workflowDefinitionRetracted = new WorkflowDefinitionRetracted(new Elsa.Models.WorkflowDefinition { DefinitionId = definitionId.ToString(), Id = definition.Id.ToString() }); | ||
await _mediator.Publish(workflowDefinitionRetracted); | ||
} | ||
|
||
// latest version | ||
var latestVersion = definition.LatestVersion; | ||
var latestVersionEntity = await _workflowDefinitionVersionRepository.GetByVersionAsync(definitionId, latestVersion); | ||
|
||
var latestModel = _storeMapper.MapToModel(latestVersionEntity, definition); | ||
|
||
await _mediator.Publish(new WorkflowDefinitionSaved(latestModel)); | ||
} | ||
|
||
} | ||
} | ||
using System.Threading.Tasks; | ||
using Elsa.Events; | ||
using MediatR; | ||
using Passingwind.Abp.ElsaModule.Common; | ||
using Passingwind.Abp.ElsaModule.Stores; | ||
using Volo.Abp.DependencyInjection; | ||
using Volo.Abp.Domain.Entities.Events; | ||
using Volo.Abp.EventBus; | ||
|
||
namespace Passingwind.Abp.ElsaModule.EventHandlers | ||
{ | ||
public class WorkflowDefinitionEventHander : | ||
ILocalEventHandler<EntityCreatedEventData<WorkflowDefinitionVersion>>, | ||
ILocalEventHandler<EntityUpdatedEventData<WorkflowDefinitionVersion>>, | ||
ILocalEventHandler<EntityDeletedEventData<WorkflowDefinitionVersion>>, | ||
// | ||
ILocalEventHandler<EntityUpdatedEventData<WorkflowDefinition>>, | ||
// | ||
ITransientDependency | ||
{ | ||
private readonly IMediator _mediator; | ||
private readonly IStoreMapper _storeMapper; | ||
private readonly IWorkflowDefinitionRepository _workflowDefinitionRepository; | ||
private readonly IWorkflowDefinitionVersionRepository _workflowDefinitionVersionRepository; | ||
|
||
public WorkflowDefinitionEventHander(IMediator mediator, IStoreMapper storeMapper, IWorkflowDefinitionRepository workflowDefinitionRepository, IWorkflowDefinitionVersionRepository workflowDefinitionVersionRepository) | ||
{ | ||
_mediator = mediator; | ||
_storeMapper = storeMapper; | ||
_workflowDefinitionRepository = workflowDefinitionRepository; | ||
_workflowDefinitionVersionRepository = workflowDefinitionVersionRepository; | ||
} | ||
|
||
public async Task HandleEventAsync(EntityCreatedEventData<WorkflowDefinitionVersion> eventData) | ||
{ | ||
var definitionId = eventData.Entity.DefinitionId; | ||
var definition = await _workflowDefinitionRepository.GetAsync(definitionId); | ||
|
||
var model = _storeMapper.MapToModel(eventData.Entity, definition); | ||
|
||
await _mediator.Publish(new WorkflowDefinitionSaved(model)); | ||
|
||
if (model.IsPublished) | ||
await _mediator.Publish(new WorkflowDefinitionPublished(model)); | ||
} | ||
|
||
public async Task HandleEventAsync(EntityUpdatedEventData<WorkflowDefinitionVersion> eventData) | ||
{ | ||
var definitionId = eventData.Entity.DefinitionId; | ||
var definition = await _workflowDefinitionRepository.GetAsync(definitionId); | ||
|
||
var model = _storeMapper.MapToModel(eventData.Entity, definition); | ||
|
||
await _mediator.Publish(new WorkflowDefinitionSaved(model)); | ||
|
||
if (model.IsPublished) | ||
await _mediator.Publish(new WorkflowDefinitionPublished(model)); | ||
else | ||
await _mediator.Publish(new WorkflowDefinitionRetracted(new Elsa.Models.WorkflowDefinition() { DefinitionId = definitionId.ToString(), Id = eventData.Entity.Id.ToString() })); | ||
} | ||
|
||
public async Task HandleEventAsync(EntityDeletedEventData<WorkflowDefinitionVersion> eventData) | ||
{ | ||
var definitionId = eventData.Entity.DefinitionId; | ||
var definition = new WorkflowDefinition(definitionId); | ||
|
||
var model = _storeMapper.MapToModel(eventData.Entity, definition); | ||
|
||
await _mediator.Publish(new WorkflowDefinitionDeleted(model)); | ||
} | ||
|
||
public async Task HandleEventAsync(EntityUpdatedEventData<WorkflowDefinition> eventData) | ||
{ | ||
var definition = eventData.Entity; | ||
var definitionId = definition.Id; | ||
|
||
// published version | ||
if (definition.PublishedVersion.HasValue) | ||
{ | ||
var publishVersion = definition.PublishedVersion.Value; | ||
var publishtVersionEntity = await _workflowDefinitionVersionRepository.GetByVersionAsync(definitionId, publishVersion); | ||
|
||
var publishModel = _storeMapper.MapToModel(publishtVersionEntity, definition); | ||
|
||
await _mediator.Publish(new WorkflowDefinitionSaved(publishModel)); | ||
await _mediator.Publish(new WorkflowDefinitionPublished(publishModel)); | ||
} | ||
else | ||
{ | ||
var workflowDefinitionRetracted = new WorkflowDefinitionRetracted(new Elsa.Models.WorkflowDefinition { DefinitionId = definitionId.ToString(), Id = definition.Id.ToString() }); | ||
await _mediator.Publish(workflowDefinitionRetracted); | ||
} | ||
|
||
// latest version | ||
var latestVersion = definition.LatestVersion; | ||
var latestVersionEntity = await _workflowDefinitionVersionRepository.GetByVersionAsync(definitionId, latestVersion); | ||
|
||
var latestModel = _storeMapper.MapToModel(latestVersionEntity, definition); | ||
|
||
await _mediator.Publish(new WorkflowDefinitionSaved(latestModel)); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/Passingwind.Abp.ElsaModule.Domain/EventHandlers/WorkflowInstanceEventHander.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Threading.Tasks; | ||
using Elsa.Events; | ||
using MediatR; | ||
using Passingwind.Abp.ElsaModule.Common; | ||
using Passingwind.Abp.ElsaModule.Stores; | ||
using Volo.Abp.DependencyInjection; | ||
using Volo.Abp.Domain.Entities.Events; | ||
using Volo.Abp.EventBus; | ||
|
||
namespace Passingwind.Abp.ElsaModule.EventHandlers | ||
{ | ||
public class WorkflowInstanceEventHander : | ||
ILocalEventHandler<EntityDeletedEventData<WorkflowInstance>>, | ||
// | ||
ITransientDependency | ||
{ | ||
private readonly IMediator _mediator; | ||
private readonly IStoreMapper _storeMapper; | ||
|
||
public WorkflowInstanceEventHander(IMediator mediator, IStoreMapper storeMapper) | ||
{ | ||
_mediator = mediator; | ||
_storeMapper = storeMapper; | ||
} | ||
|
||
public async Task HandleEventAsync(EntityDeletedEventData<WorkflowInstance> eventData) | ||
{ | ||
var model = _storeMapper.MapToModel(eventData.Entity); | ||
|
||
await _mediator.Publish(new WorkflowInstanceDeleted(model)); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters