public override ValueTask <string?> SaveAsync(SaveWorkflowContext <Document> context, CancellationToken cancellationToken = default) { var document = context.Context; if (string.IsNullOrWhiteSpace(document.DocumentId)) { document.DocumentId = _idGenerator.Generate(); } _session.Save(document); return(new ValueTask <string?>(document.DocumentId)); }
private async ValueTask <string?> SaveWorkflowContextAsync(WorkflowExecutionContext workflowExecutionContext, WorkflowContextFidelity fidelity, bool always, CancellationToken cancellationToken) { var workflowContext = workflowExecutionContext.WorkflowContext; if (!always && (workflowContext == null || workflowExecutionContext.WorkflowBlueprint.ContextOptions?.ContextFidelity != fidelity)) { return(workflowExecutionContext.WorkflowInstance.ContextId); } var context = new SaveWorkflowContext(workflowExecutionContext); return(await _workflowContextManager.SaveContextAsync(context, cancellationToken)); }
public override ValueTask <string> SaveAsync( SaveWorkflowContext <WorkflowState> context, CancellationToken cancellationToken = default) { var state = context.Context; if (string.IsNullOrWhiteSpace(state.Id)) { state.Id = this.idGenerator.Generate(); } this.session.Save(state); return(new ValueTask <string>(state.Id)); }
public override async ValueTask <string> SaveAsync(SaveWorkflowContext <BlogPost> context, CancellationToken cancellationToken = default) { _logger.LogInformation("SaveAsync..."); var blogPost = context.Context; await using var dbContext = _blogContextFactory.CreateDbContext(); var dbSet = dbContext.BlogPosts; if (blogPost == null) { // new post, get from body blogPost = ((HttpRequestModel)context.WorkflowExecutionContext.Input !).GetBody <BlogPost>(); // generate id blogPost.Id = Guid.NewGuid().ToString("N"); // ensure published is false blogPost.IsPublished = false; // set context context.WorkflowExecutionContext.WorkflowContext = blogPost; context.WorkflowExecutionContext.ContextId = blogPost.Id; _logger.LogInformation($"Save new...{blogPost.Id}"); // add post to db await dbSet.AddAsync(blogPost, cancellationToken); } else { // existing post var blogPostId = blogPost.Id; var existingPost = await dbSet.AsQueryable() .Where(x => x.Id == blogPostId) .FirstAsync(cancellationToken); _logger.LogInformation($"Save existing...{blogPost.Id}"); // update dbContext.Entry(existingPost).CurrentValues.SetValues(blogPost); } await dbContext.SaveChangesAsync(cancellationToken); return(blogPost.Id); }
public async ValueTask <string?> SaveContextAsync(SaveWorkflowContext context, CancellationToken cancellationToken = default) { var provider = GetPersister(context.ContextType); return(provider == null ? context.ContextId : await provider.SaveAsync(context, cancellationToken)); }
public abstract ValueTask <string?> SaveAsync(SaveWorkflowContext context, CancellationToken cancellationToken = default);
public SaveWorkflowContext(SaveWorkflowContext context) : base(context.WorkflowExecutionContext) { }
public virtual ValueTask <string?> SaveAsync(SaveWorkflowContext <T> context, CancellationToken cancellationToken = default) => new(context.ContextId);
ValueTask <string?> ISaveWorkflowContext.SaveAsync(SaveWorkflowContext context, CancellationToken cancellationToken) => SaveAsync(new SaveWorkflowContext <T>(context), cancellationToken);