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));
        }
예제 #2
0
        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));
        }
예제 #3
0
        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);
        }
예제 #5
0
        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));
        }
예제 #6
0
 public abstract ValueTask <string?> SaveAsync(SaveWorkflowContext context, CancellationToken cancellationToken = default);
예제 #7
0
 public SaveWorkflowContext(SaveWorkflowContext context) : base(context.WorkflowExecutionContext)
 {
 }
예제 #8
0
 public virtual ValueTask <string?> SaveAsync(SaveWorkflowContext <T> context, CancellationToken cancellationToken = default) => new(context.ContextId);
예제 #9
0
 ValueTask <string?> ISaveWorkflowContext.SaveAsync(SaveWorkflowContext context, CancellationToken cancellationToken) => SaveAsync(new SaveWorkflowContext <T>(context), cancellationToken);