public async Task <WorkflowDefinition> PublishAsync(WorkflowDefinition workflowDefinition, CancellationToken cancellationToken = default) { var definitionId = workflowDefinition.DefinitionId; // Reset current latest and published definitions. var publishedAndOrLatestDefinitions = await _workflowDefinitionStore.FindManyAsync(new LatestOrPublishedWorkflowDefinitionIdSpecification(definitionId), cancellationToken : cancellationToken).ToList(); foreach (var publishedAndOrLatestDefinition in publishedAndOrLatestDefinitions) { publishedAndOrLatestDefinition.IsPublished = false; publishedAndOrLatestDefinition.IsLatest = false; await _workflowDefinitionStore.SaveAsync(publishedAndOrLatestDefinition, cancellationToken); } if (workflowDefinition.IsPublished) { workflowDefinition.Version++; } else { workflowDefinition.IsPublished = true; } workflowDefinition.IsLatest = true; workflowDefinition = Initialize(workflowDefinition); await _mediator.Publish(new WorkflowDefinitionPublishing(workflowDefinition), cancellationToken); await _workflowDefinitionStore.SaveAsync(workflowDefinition, cancellationToken); await _mediator.Publish(new WorkflowDefinitionPublished(workflowDefinition), cancellationToken); return(workflowDefinition); }
public override async IAsyncEnumerable <IWorkflowBlueprint> ListAsync( VersionOptions versionOptions, int?skip = default, int?take = default, string?tenantId = default, [EnumeratorCancellation] CancellationToken cancellationToken = default) { var specification = (ISpecification <WorkflowDefinition>) new VersionOptionsSpecification(versionOptions); if (!string.IsNullOrWhiteSpace(tenantId)) { specification = specification.WithTenant(tenantId); } var paging = skip != null && take != null ? new Paging(skip.Value, take.Value) : default; var orderBy = new OrderBy <WorkflowDefinition>(x => x.Name !, SortDirection.Ascending); var workflowDefinitions = await _workflowDefinitionStore.FindManyAsync(specification, orderBy, paging, cancellationToken); foreach (var workflowDefinition in workflowDefinitions) { var workflowBlueprint = await TryMaterializeBlueprintAsync(workflowDefinition, cancellationToken); if (workflowBlueprint != null) { yield return(workflowBlueprint); } } }
public async Task <ActionResult <PagedList <WorkflowDefinitionSummaryModel> > > Handle( [FromQuery] string?ids, [FromQuery] string?searchTerm = default, int?page = default, int?pageSize = default, VersionOptions?version = default, CancellationToken cancellationToken = default) { var tenantId = await _tenantAccessor.GetTenantIdAsync(cancellationToken); version ??= VersionOptions.Latest; var specification = GetSpecification(ids, version.Value).And(new TenantSpecification <WorkflowDefinition>(tenantId)); if (!string.IsNullOrWhiteSpace(searchTerm)) { specification = specification.And(new WorkflowDefinitionSearchTermSpecification(searchTerm)); } var totalCount = await _workflowDefinitionStore.CountAsync(specification, cancellationToken); var paging = page == null || pageSize == null ? default : Paging.Page(page.Value, pageSize.Value); var items = await _workflowDefinitionStore.FindManyAsync(specification, new OrderBy <WorkflowDefinition>(x => x.Name !, SortDirection.Ascending), paging, cancellationToken); var summaries = _mapper.Map <IList <WorkflowDefinitionSummaryModel> >(items); var pagedList = new PagedList <WorkflowDefinitionSummaryModel>(summaries, page, pageSize, totalCount); return(Json(pagedList, SerializationHelper.GetSettingsForWorkflowDefinition())); }
public override async IAsyncEnumerable <IWorkflowBlueprint> GetWorkflowsAsync([EnumeratorCancellation] CancellationToken cancellationToken) { var workflowDefinitions = await _workflowDefinitionStore.FindManyAsync(Specification <WorkflowDefinition> .Identity, cancellationToken : cancellationToken); foreach (var workflowDefinition in workflowDefinitions) { var workflowBlueprint = await TryMaterializeBlueprintAsync(workflowDefinition, cancellationToken); if (workflowBlueprint != null) { yield return(workflowBlueprint); } } }
public async Task <ActionResult <PagedList <WorkflowDefinitionSummaryModel> > > Handle(int?page = default, int?pageSize = default, VersionOptions?version = default, CancellationToken cancellationToken = default) { version ??= VersionOptions.Latest; var specification = new VersionOptionsSpecification(version.Value); var totalCount = await _workflowDefinitionStore.CountAsync(specification, cancellationToken); var paging = page == null || pageSize == null ? default : Paging.Page(page.Value, pageSize.Value); var items = await _workflowDefinitionStore.FindManyAsync(specification, paging: paging, cancellationToken : cancellationToken); var summaries = _mapper.Map <IList <WorkflowDefinitionSummaryModel> >(items); var pagedList = new PagedList <WorkflowDefinitionSummaryModel>(summaries, page, pageSize, totalCount); return(Json(pagedList, _serializer.GetSettings())); }
public async Task <IActionResult> Handle(string definitionId, CancellationToken cancellationToken = default) { var tenantId = await _tenantAccessor.GetTenantIdAsync(cancellationToken); var specification = GetSpecification(definitionId).And(new TenantSpecification <WorkflowDefinition>(tenantId)); var definitions = await _workflowDefinitionStore.FindManyAsync(specification, new OrderBy <WorkflowDefinition>(x => x.Version, SortDirection.Descending), cancellationToken : cancellationToken); var versionModels = _mapper.Map <IList <WorkflowDefinitionVersionModel> >(definitions); var model = new { Items = versionModels }; return(Json(model, SerializationHelper.GetSettingsForWorkflowDefinition())); }
public async Task <ActionResult <WorkflowDefinitionSummaryModel[]> > Handle([RequiredFromQuery] string?ids, VersionOptions?version = default, CancellationToken cancellationToken = default) { IList <WorkflowDefinitionSummaryModel> summaries = new List <WorkflowDefinitionSummaryModel>(); if (!string.IsNullOrWhiteSpace(ids)) { version ??= VersionOptions.Latest; var splitIds = ids.Split(',', StringSplitOptions.RemoveEmptyEntries); var specification = new VersionOptionsSpecification(version.Value).And(new ManyWorkflowDefinitionIdsSpecification(splitIds)); var items = await _workflowDefinitionStore.FindManyAsync(specification, cancellationToken : cancellationToken); summaries = _mapper.Map <IList <WorkflowDefinitionSummaryModel> >(items); } return(Json(new ListModel <WorkflowDefinitionSummaryModel>(summaries), _serializer.GetSettings())); }
public Task <IEnumerable <WorkflowDefinition> > FindManyAsync(ISpecification <WorkflowDefinition> specification, IOrderBy <WorkflowDefinition>?orderBy = null, IPaging?paging = null, CancellationToken cancellationToken = default) => _store.FindManyAsync(specification, orderBy, paging, cancellationToken);
protected override async ValueTask <IEnumerable <IWorkflowBlueprint> > OnGetWorkflowsAsync(CancellationToken cancellationToken) { var workflowDefinitions = await _workflowDefinitionStore.FindManyAsync(Specification <WorkflowDefinition> .Identity, cancellationToken : cancellationToken); return(await Task.WhenAll(workflowDefinitions.Select(async x => await _workflowBlueprintMaterializer.CreateWorkflowBlueprintAsync(x, cancellationToken)))); }