/// <summary> /// Returns a current Azure state for the given resource (config). /// </summary> /// <typeparam name="TModel"></typeparam> /// <param name="config"></param> /// <param name="client"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public static async Task <IState> GetStateAsync <TModel>( this ResourceConfig <TModel> config, IClient client, CancellationToken cancellationToken) where TModel : class { var context = new StateOperationContext(client, cancellationToken); await context.GetStateAsyncDispatch(config); return(context.Result); }
public Context( StateOperationContext operationContext, IState target, IShouldProcess shouldProcess, IProgressReport progressReport, ProgressMap progressMap) { _OperationContext = operationContext; _Target = target; _ShouldProcess = shouldProcess; _ProgressReport = progressReport; _ProgressMap = progressMap; }
/// <summary> /// /// </summary> /// <param name="operationContext">a state operation context.</param> /// <param name="target">An Azure target state.</param> /// <param name="shouldProcess">A 'should process' interface</param> /// <param name="reportTaskProgress">A callback to report progress.</param> /// <param name="progressMap">Task progress information.</param> public Context( StateOperationContext operationContext, IState target, IShouldProcess shouldProcess, Action <ITaskProgress> reportTaskProgress, ProgressMap progressMap) { _OperationContext = operationContext; _Target = target; _ShouldProcess = shouldProcess; _ReportTaskProgress = reportTaskProgress; _ProgressMap = progressMap; }
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); });
static Task GetStateAsyncDispatch( this StateOperationContext context, IResourceConfig config) => config.Accept(new GetStateAsyncVisitor(), context);