Ejemplo n.º 1
0
        public async Task <OpenApiResult> StartWorkflowInstance(string tenantId, StartWorkflowInstanceRequest body)
        {
            ITenant tenant = await this.marainServicesTenancy.GetRequestingTenantAsync(tenantId).ConfigureAwait(false);

            IWorkflowEngine workflowEngine = await this.workflowEngineFactory.GetWorkflowEngineAsync(tenant).ConfigureAwait(false);

            await workflowEngine.StartWorkflowInstanceAsync(body).ConfigureAwait(false);

            return(this.CreatedResult());
        }
Ejemplo n.º 2
0
        public async Task WhenICreateANewInstanceCalledOfTheWorkflowWithId(
            string instanceId,
            string workflowId,
            Table table)
        {
            var context = table.Rows.ToDictionary(x => x["Key"], x => x["Value"]);

            ITenantedWorkflowEngineFactory engineFactory = ContainerBindings.GetServiceProvider(this.featureContext).GetService <ITenantedWorkflowEngineFactory>();
            ITenantProvider tenantProvider = ContainerBindings.GetServiceProvider(this.featureContext).GetService <ITenantProvider>();
            IWorkflowEngine engine         = await engineFactory.GetWorkflowEngineAsync(tenantProvider.Root).ConfigureAwait(false);

            await engine.StartWorkflowInstanceAsync(new StartWorkflowInstanceRequest { Context = context, WorkflowId = workflowId, WorkflowInstanceId = instanceId }).ConfigureAwait(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// The Process method is invoked asynchronously when <see cref="StartProcessing" /> is
        /// called. It will run on a background thread until <see cref="FinishProcessing" />
        /// is called.
        /// </summary>
        /// <returns>
        /// A <see cref="Task" /> that will complete after <see cref="FinishProcessing" /> is called.
        /// </returns>
        private async Task Process()
        {
            while (true)
            {
                if (this.queue.IsEmpty)
                {
                    if (this.shouldComplete)
                    {
                        break;
                    }

                    await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);

                    continue;
                }

                this.queue.TryPeek(out WorkflowMessageEnvelope item);

                IWorkflowInstanceStore instanceStore =
                    await this.workflowInstanceStoreFactory.GetWorkflowInstanceStoreForTenantAsync(this.tenantProvider.Root).ConfigureAwait(false);

                IWorkflowEngine engine =
                    await this.workflowEngineFactory.GetWorkflowEngineAsync(this.tenantProvider.Root).ConfigureAwait(false);

                if (item.IsTrigger)
                {
                    this.logger.LogInformation("Processing trigger with content type {ContentType}", item.ContentType);

                    IWorkflowTrigger trigger = item.Trigger;

                    IEnumerable <string> instanceIds = await instanceStore.GetMatchingWorkflowInstanceIdsForSubjectsAsync(
                        item.Trigger.GetSubjects(),
                        int.MaxValue,
                        0).ConfigureAwait(false);

                    foreach (string current in instanceIds)
                    {
                        await engine.ProcessTriggerAsync(trigger, current).ConfigureAwait(false);
                    }
                }
                else
                {
                    this.logger.LogInformation("Processing start workflow instance request");
                    await engine.StartWorkflowInstanceAsync(item.StartWorkflowInstanceRequest)
                    .ConfigureAwait(false);
                }

                this.queue.TryDequeue(out _);
            }
        }
Ejemplo n.º 4
0
        public async Task GivenIHaveStartedAnInstanceOfTheWorkflowWithInstanceIdAndUsingContextObject(string workflowId, string instanceId, string contextInstanceName)
        {
            ITenantedWorkflowEngineFactory engineFactory = this.serviceProvider.GetRequiredService <ITenantedWorkflowEngineFactory>();
            IWorkflowEngine engine = await engineFactory.GetWorkflowEngineAsync(this.transientTenantManager.PrimaryTransientClient).ConfigureAwait(false);

            IDictionary <string, string> context = this.scenarioContext.Get <IDictionary <string, string> >(contextInstanceName);

            var request =
                new StartWorkflowInstanceRequest
            {
                WorkflowId         = workflowId,
                WorkflowInstanceId = instanceId,
                Context            = context,
            };

            await engine.StartWorkflowInstanceAsync(request).ConfigureAwait(false);
        }