public AggregateProvisioningStateFlow(
     params IProvisioningStateFlow[] flows)
 {
     this.flows       = flows.ToList();
     this.currentFlow = this.firstFlow = flows.FirstOrDefault();
     this.lastFlow    = flows.LastOrDefault();
 }
Exemplo n.º 2
0
        public async Task <IProvisioningJob> ScheduleJobAsync(IProvisioningStateFlow flow)
        {
            var scope = this.serviceProvider.CreateScope();

            var job = new ProvisioningJob(flow, scope);
            await job.InitializeAsync();

            if (!this.jobsByIds.TryAdd(job.Id, job))
            {
                throw new InvalidOperationException("Could not add job to concurrent dictionary.");
            }

            this.jobQueue.Enqueue(job);

            return(job);
        }
        public async Task <IProvisioningState?> GetNextStateAsync(NextStateContext context)
        {
            var nextState = await this.currentFlow.GetNextStateAsync(context);

            if (nextState != null)
            {
                return(nextState);
            }

            if (this.currentFlow == this.lastFlow)
            {
                return(null);
            }

            var currentFlowIndex = this.flows.IndexOf(this.currentFlow);

            this.currentFlow = this.flows[currentFlowIndex + 1];

            return(await this.currentFlow.GetInitialStateAsync(
                       new InitialStateContext(
                           context.Mediator,
                           context.StateFactory)));
        }