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);
                        }
                    });
                }
            }
Пример #2
0
        static DependencyLocation GetDependencyLocation <TModel>(
            this IState state, ResourceConfig <TModel> config)
            where TModel : class
        {
            var info = state.Get(config);

            return(info != null
                ? new DependencyLocation(
                       config.Strategy.GetLocation(info),
                       config.Strategy.CompulsoryLocation)
                : config
                   .GetResourceDependencies()
                   .Select(state.GetDependencyLocationDispatch)
                   .Aggregate(null as DependencyLocation, Merge));
        }
Пример #3
0
 public TModel GetOrAdd <TModel>(ResourceConfig <TModel> config)
     where TModel : class
 => Target.GetOrAdd(
     config,
     () =>
 {
     foreach (var dependency in config.GetResourceDependencies())
     {
         AddIfRequired(dependency);
     }
     var model = config.CreateModel(Engine);
     config.Strategy.Location.Set(model, Location);
     UpdateNested(config, model);
     return(model);
 });
 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);
 });