public async Task UpdateStateAsync <TModel>(ResourceConfig <TModel> config) where TModel : class { var model = _Target.Get(config); if (model != null) { await _OperationContext.GetOrAdd( config, async() => { // wait for all dependencies var tasks = config .GetResourceDependencies() .Select(UpdateStateAsyncDispatch); await Task.WhenAll(tasks); // call the CreateOrUpdateAsync function for the resource. if (await _ShouldProcess.ShouldCreate(config, model)) { _ProgressReport.Start(config); var result = await config.CreateOrUpdateAsync( _OperationContext.Client, model, _OperationContext.CancellationToken); _ProgressReport.Done(config, _ProgressMap.Get(config)); return(result); } else { return(null); } }); } }
static async Task GetStateAsync <TModel>( this StateOperationContext context, ResourceConfig <TModel> config) where TModel : class => await context.GetOrAdd( config, async() => { var info = await config.GetAsync(context.Client, context.CancellationToken); // Get state of dependencies if the resource doesn't exist if (info == null) { var tasks = config .GetResourceDependencies() .Select(context.GetStateAsyncDispatch); await Task.WhenAll(tasks); } return(info); });